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

Smart components #822

Merged
merged 15 commits into from
Oct 23, 2022
Merged

Smart components #822

merged 15 commits into from
Oct 23, 2022

Conversation

simoncozens
Copy link
Collaborator

Fixes #91. Does not round trip!

@simoncozens simoncozens marked this pull request as draft October 11, 2022 13:15
@simoncozens
Copy link
Collaborator Author

Hmm, the smart component tests work but now other tests are failing. Bah.

@simoncozens simoncozens marked this pull request as ready for review October 11, 2022 13:32
@simoncozens simoncozens marked this pull request as draft October 11, 2022 13:42
@simoncozens
Copy link
Collaborator Author

simoncozens commented Oct 11, 2022

Urgh. This works with the tests but not real life files. The decomposed layers need to be positioned. It is also very slow and (with all the decomposition warnings) quite noisy.

@simoncozens simoncozens marked this pull request as ready for review October 11, 2022 14:15
@simoncozens
Copy link
Collaborator Author

OK, I'm done here and my fonts work.

@simoncozens
Copy link
Collaborator Author

Regression test fails are mainly because we now decompose smart components instead of just treating them as dumb components, plus something that looks like an incompatible path.

Copy link
Member

@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks so much Simon for implementing this, it's been on top of the feature requests for literally years...

I left some comments.

@khaledhosny
Copy link
Collaborator

Glyphs’ smart components support extrapolation, is it supported in this PR as well?

@anthrotype
Copy link
Member

Glyphs’ smart components support extrapolation, is it supported in this PR as well?

maybe it's just a matter of setting extrapolate=True when constructing VariationModel..

@anthrotype
Copy link
Member

I wonder if we should support round-tripping smart components as such (i.e. without instantiating them to "regular" components) when going through glyphs=>UFO=>glyphs. Maybe we should enable the smart component instantiation when minimal=True or minimize glypsh diffs=False?

@simoncozens
Copy link
Collaborator Author

I wonder if we should support round-tripping smart components as such (i.e. without instantiating them to "regular" components) when going through glyphs=>UFO=>glyphs. Maybe we should enable the smart component instantiation when minimal=True or minimize glypsh diffs=False?

I think this is a good idea, but for later - once we've tidied up the minimal/minimize_glyphs_diffs mess. Perhaps the answer is to replace all those flags with a for_compilation flag (we can bikeshed the name) - I think that's the cleanest way of signalling that we don't want a complete representation of the font, we just want the data required to produce a TTF.

@anthrotype
Copy link
Member

for VariationModel(extrapolate=True) you want at least fonttools >= 4.37, you may as well bump to current latest both setup.py and requirements.txt

@anthrotype
Copy link
Member

extrapolate=True

note that the current implementation has some limitations fonttools/fonttools#2843 which are being addressed by fonttools/fonttools#2846 (unreleased)

@anthrotype
Copy link
Member

maybe we could first release a new fonttools with that extrapolation patch, and then bump the requirements in here before merging and releasing glyphsLib

@anthrotype
Copy link
Member

@simoncozens could we add a test that extrapolation works as intended? I know the CI will fail until fonttools gets updated but it'd still good to verify that we do something equivalent to what Glyphs.app would produce with the same data.

@justvanrossum
Copy link
Contributor

Regarding future round-tripping, it would be nice to converge to something along these lines: https://github.com/BlackFoundryCom/variable-components-in-ufo.

@simoncozens
Copy link
Collaborator Author

Regarding future round-tripping, it would be nice to converge to something along these lines:
https://github.com/BlackFoundryCom/variable-components-in-ufo.

Oh, hrm. If that's going to be the future, then ufo2ft needs to handle it. Which means all this decomposition code needs to move there instead of here.

@justvanrossum
Copy link
Contributor

Could be optional. Also relevant to this WIP: https://github.com/harfbuzz/boring-expansion-spec/blob/glyf1/glyf1.md

@simoncozens
Copy link
Collaborator Author

Well, with glyf1, we're talking about relatively far future. :-)

I would prefer to stick with what we have for now and not make the perfect the enemy of the good, especially since it looks like the UFO stuff isn't quite defined/standardized yet. We can move it around when all those things are sorted out.

@anthrotype
Copy link
Member

i'm ok to merge this first, try it out a bit on real world fonts, and then later we work on translating between Glyphs.app and this proposed variable ufo components and implmenent that in ufo2ft.

@anthrotype
Copy link
Member

but thanks @justvanrossum for reminding us of that. Maybe we should file an issue somewhere to track support for these variable components in the UFO build pipeline

@simoncozens
Copy link
Collaborator Author

OK. Will work on the extrapolation stuff if you could cut a fonttools release.

@justvanrossum
Copy link
Contributor

I don't suggest to change anything now, I'd just like you to know that the UFO stuff is being worked in, just in case round-tripping is at some point desirable. Or just conversion of .glyphs to ufo+variable-components, which I may want for prototype-ish reasons sooner than glyf1 will be a viable format.

@simoncozens
Copy link
Collaborator Author

Actually before you do the fonttools release I would need this:

diff --git a/Lib/fontTools/varLib/models.py b/Lib/fontTools/varLib/models.py
index a7e020b00..db7c98008 100644
--- a/Lib/fontTools/varLib/models.py
+++ b/Lib/fontTools/varLib/models.py
@@ -43,7 +43,7 @@ def subList(truth, lst):
     return [l for l, t in zip(lst, truth) if t]


-def normalizeValue(v, triple):
+def normalizeValue(v, triple, extrapolate=False):
     """Normalizes value based on a min/default/max triple.

       >>> normalizeValue(400, (100, 400, 900))
@@ -59,7 +59,8 @@ def normalizeValue(v, triple):
             f"Invalid axis values, must be minimum, default, maximum: "
             f"{lower:3.3f}, {default:3.3f}, {upper:3.3f}"
         )
-    v = max(min(v, upper), lower)
+    if not extrapolate:
+        v = max(min(v, upper), lower)
     if v == default:
         v = 0.0
     elif v < default:

@simoncozens
Copy link
Collaborator Author

Possibly. Or maybe with the extrapolation stuff in VariationModel there's a smart way to do it. This is new to me and it's not clear to me how it works out what the default is without normalised locations.

@simoncozens
Copy link
Collaborator Author

@anthrotype Please check my requirements-dev fiddling before merging; it seems like if we don't pin the version there, we get a conflict between the requirements.txt and requirements-dev.txt.

@simoncozens simoncozens merged commit 3ea0218 into main Oct 23, 2022
@khaledhosny khaledhosny deleted the smart-components branch October 24, 2022 18:46
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.

Handle smart components
5 participants