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

[subset] FeatureVariations subsetting is wrong #1881

Closed
anthrotype opened this issue Apr 20, 2020 · 15 comments · Fixed by #1882
Closed

[subset] FeatureVariations subsetting is wrong #1881

anthrotype opened this issue Apr 20, 2020 · 15 comments · Fixed by #1882
Assignees

Comments

@anthrotype
Copy link
Member

originally reported by @behdad at harfbuzz/harfbuzz#2334 (comment)

We cannot drop FeatureVariationsRecords that have empty substitutions. That changes the behavior. A FeatureVariationsRecords stops the search when the conditions match; so even if there's no susbstitutions we cannot drop the record as that will keep the search going.
The only optimizations we can do are 1. dropping from the end of the array any records with no susbtitutions, and 2. dropping records earlier with no susbstitution only after analysing the conditions and proving that the dropping does not change functionality.
Both of those are unnecessary right now. We should fix the functionality.
This seems to be wrong in FontTools as well:
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/subset/__init__.py#L1325

@anthrotype anthrotype self-assigned this Apr 20, 2020
@behdad
Copy link
Member

behdad commented Apr 20, 2020

I'll try submitting a minimal fix and a simple pruning but won't be able to contribute tests. I hope there are tests for those code path already.

@anthrotype
Copy link
Member Author

thanks Behdad, i'll fix up the tests as needed

@anthrotype
Copy link
Member Author

To test this dropping-from-end-of-array of FeatureVariationRecords with no substitutions, we need create a VF where FeatureTableSubstitutions contain more than one SubstitutionRecords referencing different FeatureIndex; then we'd drop one feature while keeping another and assert that the thus emptied FeatureVariationRecords at the end of the FeatureVariations are dropped, and that empty records that precede non-empty ones are kept.
The current featureVars API can only create FeatureVariations for a one feature at a time (e.g. rvrn). Making a test font manually is not fun.. I will try again when I get the chance. I'll keep this open in the meantime as reminder.

@anthrotype anthrotype reopened this Apr 25, 2020
anthrotype added a commit that referenced this issue Apr 25, 2020
…ationRecords

Added a TODO for the partial dropping of FeatureVariationRecords
#1881 (comment)
@anthrotype
Copy link
Member Author

@behdad when the subsetter has dropped all the existing FeatureVariationRecords, should it not also remove the emptied FeatureVariations table and downgrade the GSUB/GPOS table version to 0x00010000 (inside prune_post_subset)?

@behdad
Copy link
Member

behdad commented Apr 28, 2020

@behdad when the subsetter has dropped all the existing FeatureVariationRecords, should it not also remove the emptied FeatureVariations table and downgrade the GSUB/GPOS table version to 0x00010000 (inside prune_post_subset)?

Yes. I thought that's implemented.

@behdad
Copy link
Member

behdad commented Apr 28, 2020

The current featureVars API can only create FeatureVariations for a one feature at a time (e.g. rvrn). Making a test font manually is not fun.. I will try again when I get the chance. I'll keep this open in the meantime as reminder.

Right. You will hit same situ in partial instancing as well. I don't know how to share such pruning code....

@anthrotype
Copy link
Member Author

I thought that's implemented.

if you mean this:

if hasattr(table, 'FeatureVariations') and not table.FeatureVariations:
if table.Version == 0x00010001:
table.Version = 0x00010000

then nobody seems to be setting table.FeatureVariations = None when FeatureVariationRecords list is empty

@behdad
Copy link
Member

behdad commented Apr 28, 2020

then nobody seems to be setting table.FeatureVariations = None when FeatureVariationRecords list is empty

Right... That's normally done when subset() return false. But clearly not in this case..

@anthrotype
Copy link
Member Author

@behdad something like this #1903

anthrotype added a commit to anthrotype/fonttools that referenced this issue Apr 28, 2020
@anthrotype
Copy link
Member Author

You will hit same situ in partial instancing as well. I don't know how to share such pruning code....

I didn't quite get what you meant here.

@behdad
Copy link
Member

behdad commented Apr 29, 2020

You will hit same situ in partial instancing as well. I don't know how to share such pruning code....

I didn't quite get what you meant here

I mean, I assume you implemented FeatureVariations updating in your partial-instancer code. That code can also do some pruning and possibly removing FeatureVariations if empty.

@anthrotype
Copy link
Member Author

ah yes, we do remove FeatureVariations when left empty in the instancer.

simoncozens pushed a commit to simoncozens/fonttools that referenced this issue May 11, 2020
simoncozens pushed a commit to simoncozens/fonttools that referenced this issue May 11, 2020
…ationRecords

Added a TODO for the partial dropping of FeatureVariationRecords
fonttools#1881 (comment)
simoncozens pushed a commit to simoncozens/fonttools that referenced this issue May 11, 2020
@behdad
Copy link
Member

behdad commented Mar 29, 2021

Fixed in #1903

@behdad behdad closed this as completed Mar 29, 2021
@behdad
Copy link
Member

behdad commented Mar 29, 2021

Humm. Not sure.

@behdad behdad reopened this Mar 29, 2021
@behdad
Copy link
Member

behdad commented Mar 29, 2021

Was fixed in cab7d13

@behdad behdad closed this as completed Apr 1, 2021
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 a pull request may close this issue.

2 participants