8000 Add `varLib.hvar` module by behdad · Pull Request #3780 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add varLib.hvar module #3780

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

Merged
merged 4 commits into from
Feb 27, 2025
Merged

Add varLib.hvar module #3780

merged 4 commits into from
Feb 27, 2025

Conversation

behdad
Copy link
Member
@behdad behdad commented Feb 24, 2025

Fixes #3778

Mildly tested. In particular, on RobotoFlex VF, it produces smaller HVAR table. I have not investigated. The code is heavily lifted from varLib.__init__.

@behdad behdad requested a review from anthrotype February 24, 2025 21:29
storeBuilder.setSupports(supports)
advMapping[glyphName] = storeBuilder.storeDeltas(deltas, round=noRound)

singleModel = all(advMapping[g] >> 16 == 0 for g in glyphOrder)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this check that all the supports are the same (like we do in the varLib _get_advance_metrics)?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's one way. My reasoning here was that if the OnlineVarStoreBuilder put them all in the same group (ie. all major's match), then we can do this. I'll try to revert to other logic.

phantoms[1] = phantoms[1][phantomIndex] if phantoms[1] is not None else 0
deltas.append(phantoms[1] - phantoms[0])

allDeltas[glyphName] = deltas[1:]
Copy link
Member

Choose a reason for hiding this comment

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

why skip the first one? an inline comment might help the reader

Copy link
Member Author

Choose a reason for hiding this comment

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

First "delta" is the actual advance itself.

directStore = None
if singleModel:
# Build direct mapping
supports = supports[1:]
Copy link
Member

Choose a reason for hiding this comment

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

same as above (probably related) why skip the first?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. I think I messed up both of these. I'll fix. I used to have {} as first item, but I think I removed it.

@anthrotype
Copy link
Member
anthrotype commented Feb 25, 2025

I wish we could reuse more of the code that's already in varLib.__init__ (e.g. _get_advance_metrics) instead of maintaining two very similar copies

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

I wish we could reuse more of the code that's already in varLib.__init__ (e.g. _get_advance_metrics) instead of maintaining two very similar copies

Me too. I'll work on it.

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

I addressed reviews.

One thing occurs to me that in a post-64k world, we should be more careful building the direct mapping since not all will fit in a VarData.

I'll see about more code sharing. And needs some kinds of tests.

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

I haven't found a font yet that this fully roundtrips to the same XML...

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

I haven't found a font yet that this fully roundtrips to the same XML...

We changed the sort algorithm a bit. Maybe it's that.

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

I haven't found a font yet that this fully roundtrips to the same XML...

We changed the sort algorithm a bit. Maybe it's that.

Oh it's probably because we don't go through the VariationModel, just directly to deltas. Anyway, I've convinced myself that the code is correct. Now onto refactoring.

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

Refactoring done. PTAL.

@behdad
Copy link
Member Author
behdad commented Feb 25, 2025

VORG is not done in this module. VVAR is done but untested.

< 8000 a class="d-inline-block" data-hovercard-type="user" data-hovercard-url="/users/anthrotype/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="/anthrotype">@anthrotype
Copy link
Member

I haven't found a font yet that this fully roundtrips to the same XML...

maybe because we end up ordering the VarRegions differently in the VarRegionList?

And needs some kinds of tests.

yes, ideally

@behdad
Copy link
Member Author
behdad commented Feb 27, 2025

I haven't found a font yet that this fully roundtrips to the same XML...

maybe because we end up ordering the VarRegions differently in the VarRegionList?

I built a fresh NotoSansArabic, and HVAR roundtrips perfectly.

@behdad behdad force-pushed the hvar-module branch 3 times, most recently from 577b8e4 to 65a8974 Compare February 27, 2025 18:18
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!

@behdad behdad merged commit 64e5277 into main Feb 27, 2025
9 checks passed
@behdad behdad deleted the hvar-module branch February 27, 2025 18:30
@yisibl yisibl mentioned this pull request Apr 2, 2025
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.

Add HVAR synthesis
2 participants
0