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

[fontbe/avar] don't skip no-op segment maps #586

Merged
merged 2 commits into from
Nov 21, 2023
Merged

Conversation

anthrotype
Copy link
Member

GS contains a GRAD axis whose avar segment maps does not have any interesting mappings.
It happens to be the last one in the axis order. We were filtering out axis segment maps that contain only identity maps, leading to an avar table with fewer segment maps than there are fvar axes, which is invalid as OTS correctly points out.

So we now still emit these non-interesting segment maps when bulding avar and there's at least one of them that is not an identity map.

Also note that, despite the OT spec allows for empty segment maps for axis that don't distort the default normalization, we want to match fontmake/fonttools and emit the required {-1:1, 0:0, 1:1} mappings even when no other interesting mappings are present for an axis, because apparently some old implementations need that (see fonttools/fonttools#1026).

Fixes #582 avar axis mismatch OTS error

I can confirm that after this, the GS avar table is the same when built with fontc vs fontmake.

GS contains a GRAD axis whose avar segment maps does not have any interesting mappings. It happens to be the last one in the axis order. We were filtering out axis segment maps that contain only identity maps, leading to an avar table with fewer segment maps than there are fvar axes, which is invalid as OTS correctly points out. So we now still emit these when bulding avar and there's at least one segment map that is not an identity map.
Note that, despite the OT spec allows for empty segment maps for axis that don't distort the default normalization, we want to match fontmake/fonttools and emit the required {-1:1, 0:0, 1:1} mappings even when no other interesting mappings are present for an axis.

Fixes #582 avar axis mismatch OTS error

after this GS avar table is the same when built with fontc vs fontmake.
@anthrotype anthrotype requested a review from rsheeter November 20, 2023 18:35
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Looks good, I appreciate all the explanation inline.

Comment on lines 25 to 31
/// Return true if the SegmentMaps is not a boring identity map
fn is_interesting(segment_map: &SegmentMaps) -> bool {
segment_map
.axis_value_maps
.iter()
.any(|av| av.from_coordinate != av.to_coordinate)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this makes sense as a method on the SegmentMaps type in write-fonts? I'd probably flip the logic and call it is_identity.

One option would be to add the method there, merge this as-is, and open an issue to fix this when we next publish write-fonts.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 making the method is_identity

}

/// Return a default avar SegmentMaps containing the required {-1:-1, 0:0, 1:1} maps
fn default_segment_map() -> SegmentMaps {
Copy link
Member

Choose a reason for hiding this comment

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

and this feels like it should probably be the impl of Default for SegmentMaps; however we currently autogenerate Default impls for all write types, and there's no mechanism to override this, so this is probably fine.

Copy link
Contributor

@rsheeter rsheeter left a comment

Choose a reason for hiding this comment

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

Good catch!

@rsheeter
Copy link
Contributor

I appreciate all the explanation inline

Vigorous +1, it's helpful to us now and incredibly helpful to future editors

we shall use the SegmentMaps instance method once that is added to write-fonts

also, use then() instead of then_some() so it's lazily eval
anthrotype added a commit to googlefonts/fontations that referenced this pull request Nov 21, 2023
as proposed in googlefonts/fontc#586 to be used when building avar table in fontc
@anthrotype anthrotype added this pull request to the merge queue Nov 21, 2023
Merged via the queue into main with commit 69e5e16 Nov 21, 2023
10 checks passed
@anthrotype anthrotype deleted the fix-avar-axis-miscount branch November 21, 2023 13:16
dfrg pushed a commit to googlefonts/fontations that referenced this pull request Nov 21, 2023
as proposed in googlefonts/fontc#586 to be used when building avar table in fontc
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.

GS build with fontc raises OTS error + warning
3 participants