Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON UFOs for intermediate output #731

Closed
madig opened this issue Sep 20, 2023 · 10 comments
Closed

Use JSON UFOs for intermediate output #731

madig opened this issue Sep 20, 2023 · 10 comments
Labels
builder Issues related to the gftools-builder enhancement

Comments

@madig
Copy link
Contributor

madig commented Sep 20, 2023

Glyphs files are converted to normal UFOs currently, which is slow. Writing out JSON blobs is faster, especially for bigger projects.

@eliheuer
Copy link
Contributor

eliheuer commented Sep 20, 2023

Thanks! This can all be done just with ufoLib2 right? The stuff from this PR?

@eliheuer eliheuer added enhancement builder Issues related to the gftools-builder labels Sep 20, 2023
@madig
Copy link
Contributor Author

madig commented Sep 21, 2023

Yep. Instead of Font.open(...) and ufo.save(...) you do Font.json_loads(...) ufo.json_dumps(...) or whatsitcalled.

@anthrotype
Copy link
Member

if you're calling fontmake as a subprocess (as you should) you just need to pass --ufo-structure=json option, optionally with --indent-json if you want it human readable (probably not if you care about speed).
If you're messing with fontmake internal API, there's a ufo_structure and indent_json parameters to various methods on FontProject that accomplish the same (grep for it).

@anthrotype
Copy link
Member

also, you want to depend on fontmake[json] extra which activates ufoLib2[json] extra which in turns pulls in cattrs and orjson

@simoncozens
Copy link
Contributor

After much trial and error I discovered that I need to write a function like this:

def open_ufo(path):
    if os.path.isdir(path):
        return ufoLib2.Font.open(path)
    else:
        return ufoLib2.Font.json_loads(open(path, "rb").read())

@anthrotype
Copy link
Member

yes, like fontmake itself does: https://github.com/googlefonts/fontmake/blob/6a8b2907891537ce559dd3d6fcfe68d8b55d6bc9/Lib/fontmake/font_project.py#L160-L169

we didn't want Font.open to handle json because this is not an official UFO format but only a private ufoLib2-only serialization format

@anthrotype
Copy link
Member

anthrotype commented Sep 22, 2023

@simoncozens your open_ufo snippet above would not correctly handle .ufoz (zipped UFOs, which are also not a directory), it's better you check if the suffix is .json, treat it as such otherwise let ufoLib2 Font.open handle the others

@simoncozens
Copy link
Contributor

I sort of see that for UFO libraries in general, this is ufoLib2 and we're talking about ufoLib2-specific format. It should be able to open its own files.

@simoncozens
Copy link
Contributor

Using standard UFOs in the new builder, on Noto Sans Mono (158 build steps, 120 targets)

1238.11s user 90.81s system 654% cpu 3:23.10 total
1274.70s user 91.34s system 667% cpu 3:24.56 total

Using JSON UFOs:

998.50s user 31.00s system 665% cpu 2:34.74 total
1047.40s user 33.79s system 626% cpu 2:52.69 total

20% speed-up. Nice.

@simoncozens
Copy link
Contributor

Closing this because builder2 (which is the future) does it.

simoncozens added a commit that referenced this issue Mar 12, 2024
* WIP new builder

* These modules are now an integral part of the builder

* Add subset adder (needs merge of #730)

* Various noto fixes

* Actually use tempdir for temporaries

* Change case of recipe_provider to match others

* Fix instance directory

* Fix paths in noto builder

* Include the googlefonts/ targets for noto

* Fix building STAT tables

* Add some validation for TTF builds

* Comments

* Compatibility with older Pythons

* Build UI VFs

* Use temporary directory for stamp files

* Move main function

* Fix command-line args

* Build web fonts

* Correct ninja syntax on Windows

* Continue losing on Windows

* Allow passing a dict config

* Allow ints as well as hexints in subset YAML (for machine-generated configs)

* Use JSON format UFOs for intermediaries, fixes #731

* Properly save JSON-based subset UFOs

* Fix fontmake arguments

* Everyone gets a STAT table!

* Add --include-source-fixes when fixing googlefonts outputs

* Call ninja and report exit status

* Don't pass argv to ninja

* Don’t do STAT inplace

* Allow other args to subspacer

* cmap remapper

* I believe this makes buildSTAT work everywhere

* Deepcopy steps so the YAML doesn't go all referency with --generate

* Allow disabling buildWebfont!

* Allow source->operation->source

* Keep notdef outline, saves a FAIL

* Add a --deep option to remap inside GSUB

* Pass --deep option to remap

* [builder2] Pass --glyph-data to fontmake when converting glyphs to ufo (#743)

This seems to have been dropped during the refactoring.

* Support glyphspackage

* Quieten fontmake jobs

* Use a jobrunner to quieten successful jobs and highlight failing ones

* Add a build-vtt utility and operation

* Port more options from the old builder

* glyphData is an array

* glyphData is an array, and only for Glyphs sources

* Handier error message format

* Let's not autohint OTFs

* Don't run buildSTAT on woff2 as well

* Documentation

* Additional docs about recipe overrides

* This seems to be needed?

* Better handle recipe provider inheritance

* Black

* Use strictYAML, first step in getting proper validation

* Consistently use "args", not "fontmake_args", "fixargs" etc.

* Use schema to validate

* Fix up notobuilder after strictYAMLification

* This is yucky.

* black

* Autohint OTF

* Move base schema to .schema, rename GF schema

* Allow postprocess-only overrides

* StrictYAML has made things confusing, use typing to help

* Reformat with black

* More strictyaml fixes

* Make --generate work again with strictyaml

* Everything that comes from .config is strictYAML now and needs .data

* Revalidate STAT to schema

* Make STAT values optional

* More StrictYAML pollution

* More StrictYAML pollution

* More StrictYAML pollution, needed for UIVFs

* Cope with the same step being in a recipe twice

* Fail early on silly graphs

* gf recipe: fix revalidate stat tables

* gf recipe: fix flag typo

* gf recipe: toggle compatibility check for ds sources as well

* add missing import

* autohintOTF: use --no-sonzes-stems if dflt fails

* fix string concat

* fix typo

* Allow extra fontmake args in config file

* Fix more StrictYAML annoyance

* Add remap layout operation

* Allow the use of $in and $out in exec args

* Allow passing args to rename

* Default autohintOTF to false

* Derive output directory defaults from outputDir, fixes #846

---------

Co-authored-by: خالد حسني (Khaled Hosny) <khaled@aliftype.com>
Co-authored-by: Marc Foley <m.foley.88@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builder Issues related to the gftools-builder enhancement
Projects
None yet
Development

No branches or pull requests

4 participants