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

filters/featureWriters: use '...' as placeholder for loading from UFO lib #604

Merged
merged 8 commits into from
Apr 8, 2022

Conversation

anthrotype
Copy link
Member

Currently the filters and featureWriters parameters always override the ones defined in the UFO lib.plist, and it's impossible to extend instead of replace these, e.g. inserting some additional filter or writer either before or after.

This PR allows to pass a special value ... (the actual Ellipsis singleton, not the str literal '...') in both these lists, which acts as a placeholder to signal one wants to extend the list of predefined filters/writers.

E.g.:

filters=[..., DecomposeTransformedComponentsFilter(pre=True)]

The ellipsis is replaced by the custom filters defined in the UFO lib (if any), and the additional one is appended to the list.
Only one ellipsis is allowed in the list.
Same for the featureWriters.

Fontmake will also be updated to allow passing --filter='...' or --feature-writer='...' CLI options to use this feature.

Part of fixing googlefonts/fontmake#872

… lib

Currently the `filters` and `featureWriters` parameters override the ones defined in the UFO lib.plist, and it's impossible to extend instead of replace these, e.g. inserting some additional filter or writer either before or after.

This PR allows to pass a special value `...` (the actual ``ellipsis`` singleton, not the str literal '...') in both these lists, which acts as a placeholder to signal one wants to extend the list of predefined filters/writers.

E.g.:

filters=[..., DecomposeTransformedComponentsFilter(pre=True)]

The ellipsis is replaced by the custom filters defined in the UFO lib (if any), and the additional one is appended to the list.
Only one ellipsis is allowed in the list.

Fontmake will also be updated to allow passing --filter='...' or --feature-writer='...' CLI options to use this feature.

Part of fixing googlefonts/fontmake#872
only for self-documentation as we don't run static typechecker. there's a lot of duck-typing in ufo2ft.. One day maybe we'll define protocols for Font, Filter, etc.
latest flake8 suddenly started complaining about unrelated stuff like:

B020 Found for loop that reassigns the iterable it is iterating with each iterable value.

I just fixed these even if they don't belong here, just to make CI go green.

Also apparently flake8 cares about undefined names inside `# type: ` comment, I guess that's a feature.
Let's see if I can fool it.

https://github.com/googlefonts/ufo2ft/runs/5871883161?check_suite_focus=true#step:5:35
for st in st.statements:
for s in feaLib.statements:
if isinstance(s, ast.TableBlock) and s.name == "GDEF":
for st in s.statements:
Copy link
Member Author

Choose a reason for hiding this comment

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

this change is unrelated, it was just to appease flake8 complaining about loop variable reassigning the iterable it's iterating on

groups = defaultdict(list)
for node, color in color.items():
for node, color in colors.items():
Copy link
Member Author

Choose a reason for hiding this comment

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

same here, just to make flake8 happy

@anthrotype
Copy link
Member Author

/cc @m4rc1e

anthrotype added a commit to googlefonts/fontmake that referenced this pull request Apr 7, 2022
anthrotype added a commit to googlefonts/fontmake that referenced this pull request Apr 7, 2022
Copy link
Contributor

@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.

I've just had a play with this pr and googlefonts/fontmake#874 (review) in gftools builder and it is working nicely.

Before:

INFO:ufo2ft.filters.base:Running FlattenComponentsFilter on MavenPro-Regular
INFO:ufo2ft.filters.flattenComponents:Flattened composite glyphs: 343
INFO:ufo2ft.filters.base:Running DecomposeTransformedComponentsFilter on MavenPro-Regular

After:

INFO:ufo2ft:Pre-processing glyphs
INFO:ufo2ft.filters.base:Running EraseOpenCornersFilter on MavenPro-Regular
INFO:ufo2ft.filters.base:Running FlattenComponentsFilter on MavenPro-Regular
INFO:ufo2ft.filters.flattenComponents:Flattened composite glyphs: 343
INFO:ufo2ft.filters.base:Running DecomposeTransformedComponentsFilter on MavenPro-Regular

We can see the additional filters are now being executed.

AFAIK I'm happy but I'm not really a maintainer of this repo so if someone else would like to give it the all good, feel free.

@anthrotype anthrotype merged commit ad28eea into main Apr 8, 2022
@anthrotype anthrotype deleted the extend-filters branch April 8, 2022 10:12
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.

2 participants