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

Support for fontc and crater #1047

Merged
merged 16 commits into from
Nov 5, 2024
Merged

Support for fontc and crater #1047

merged 16 commits into from
Nov 5, 2024

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Oct 14, 2024

Here is my attempt to add support in gftools builder for running fontc, and generally making it easier to use in the context of fontc_crater.

  • adds the --experimental-fontc flag, which, if set:
    • replaces the BuildVariable, BuildTTF, and BuildOTF operations with alternatives that use fontc
    • modifies the config so that only one of buildVariable and buildStatic is true (so do not instance variable fonts) and also so that only one of buildTTF and buildOTF are true (fontc does not currently build CFF outlines, so we turn buildOTF off if buildTTF is true)
  • adds the --experimental-simple-output=PATH option, which:
    • if modifies the config so that all built fonts end up in one directory
    • and does the same config pruning as above, so that we can get the same set of outputs with both compilers.

Overall I've tried to make this as noninvasive as possible to the existing code, and I think that has been reasonably successful?

@cmyr cmyr force-pushed the fontc-flag-sketch branch 3 times, most recently from df92c63 to 46a4b3e Compare October 16, 2024 17:21
@cmyr cmyr changed the title Sketch of overriding operations based on a CLI flag Support for fontc and crater Oct 16, 2024
@cmyr cmyr marked this pull request as ready for review October 16, 2024 17:31
@cmyr
Copy link
Member Author

cmyr commented Oct 16, 2024

Okay I've gone and cleaned this up to the point where I think it is ready to merge, or at least is ready for more considered review. Overall I'm quite happy with how this has gone; I've gotten more or less everything I was hoping for without needing to do anything very invasive.

@rsheeter
Copy link
Contributor

Heads up CI is upset with you

@cmyr cmyr force-pushed the fontc-flag-sketch branch 3 times, most recently from 23f958e to a1ec830 Compare October 25, 2024 21:23
@cmyr
Copy link
Member Author

cmyr commented Oct 25, 2024

@m4rc1e would you like to take a look at this and let me know if it seems sane / if there's a simpler way I might achieve any of my goals, here?

In the presence of a new CLI flag, the builder will now override certain
operations so that they are driven by fontc.
This does two things:

- it takes a path, where all our final build products will be saved
- it reduces the set of build targets to match what we would build
  with fontc
this requires an ugly global in order to expose this to the relevant
operations, but that was the best solution I could come up with.
This instructs gftools to only build the single named source file.
This way if we are running multiple instances of gftools agains the same
sources, we aren't overwriting each other's build files.
@@ -47,6 +47,12 @@ def is_designspace(self):
def is_font_source(self):
return self.is_glyphs or self.is_ufo or self.is_designspace

@cached_property
def is_variable(self) -> bool:
return (self.is_glyphs and len(self.gsfont.masters) > 1) or (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be too simple since I have a seen a family that has 4 masters and 4 instances which are not MM compatible so it could only export 4 static fonts.

Something like self.is_glyphs and len(self.gsfont.masters) < len(self.gsfont.instances) but it still isn't 100% reliable.

Copy link
Member

@anthrotype anthrotype Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps maybe_variable is a better name for the method. But I think the gftools config provides an even stronger hint as to whether a font is supposed to be variable: if the font dev asks to build a variable font, then it must be variable; if they disables building the VF (is it buildVariable: false?) then one should treat it as not variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the gftools config provides an even stronger hint as to whether a font is supposed to be variable: if the font dev asks to build a variable font, then it must be variable; if they disables building the VF (is it buildVariable: false?) then one should treat it as not variable.

I'm not sure I understand this. buildStatic, buildVariable, buildOTF, buildWebfont etc. are parameters about targets, not about sources. "I don't want you to build a variable font today" does not mean "this is not a variable font".

def rewrite_fontmake_args_for_fontc(args: str) -> str:
out_args = []
arg_list = args.split()
# reverse so we can pop in order
Copy link
Collaborator

@m4rc1e m4rc1e Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. I'm probably being dense here but couldn't we skip the reverse part and just keep popping the first element by using args.pop(0).

Copy link
Collaborator

@m4rc1e m4rc1e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @cmyr. I'm not the original author of builder 2 so I'll let @simoncozens have a look before merging.

I've tested it on a few families and it's working well for its intended purposes.

I have no problems with this PR being merged. However, once fontc and its sibling libs/tools have matured, it would be great to drop the experimental flags and allow the user to specify which compiler they would like in the config file. This will drop the need to have a seperate fontc_args argument for the GFBuilder class, which should make the code a touch tidier.

My only slight hesitation is:

modifies the config so that only one of buildVariable and buildStatic is true

Currently, a config's default settings will export otf, ttf and var and make web versions for all formats. It's sad to see this go but since it is an experimental feature used solely by you folks, I'm ok with this.

@m4rc1e m4rc1e merged commit ad287cc into main Nov 5, 2024
11 checks passed
@cmyr cmyr deleted the fontc-flag-sketch branch November 5, 2024 15:55
@cmyr cmyr restored the fontc-flag-sketch branch November 5, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants