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

[skrifa] glyf: use gvar for advance delta when HVAR is missing #1312

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Jan 9, 2025

We were using gvar to compute deltas for left side-bearings but not for advance widths when the HVAR table is missing.

This only affects the TrueType interpreter (for Skia's usage) and hinted VFs are rare so it took a while to catch this one.

Fixes #1311

We were using gvar to compute deltas for left side-bearings but not for advance widths when the HVAR table is missing.

Fixes #1311
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, tricky little one...

// Modify only LSB
AvailableVarMetrics::MissingSideBearings => points.len() - 3,
// Modify nothing
AvailableVarMetrics::Present => points.len() - 4,
Copy link
Member

Choose a reason for hiding this comment

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

we know we've always got at least the four phantom points I suppose?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, we ensure at least 4 points at entry to the function:

if iup_buffer.len() < glyph.points.len() || glyph.points.len() < PHANTOM_POINT_COUNT {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why isn't it written as len - PHANTOM_POINT_COUNT?

@dfrg dfrg merged commit 036b3e6 into main Jan 9, 2025
10 checks passed
@dfrg dfrg deleted the hint-no-hvar branch January 9, 2025 18:07
MissingSideBearings,
/// No variable metrics table.
Missing,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I would expect these to be named for what is available not what isn't? - e.g. All, Advances, None as opposed to Present/MissingSide/Missing

}
}
None => AvailableVarMetrics::Missing,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO this might still read better (closer to left-to-right top to bottom) as map? - something like glyph_metrics.hvar.map(|hvar| hvar.lsb_mapping.map(present).unwrap_or(missing sides)).unwrap_or(missing everything)

}
AvailableVarMetrics::MissingSideBearings => {
self.phantom[0].x += deltas[count - 4].x;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reading deltas at count - magic # is recurring, I wonder if there is an opportunity to make a helper fn or newtype with a nicely named (and probably always inlined) accessor?

@dfrg
Copy link
Member Author

dfrg commented Jan 9, 2025

@rsheeter sure, will do a follow up with some of these changes

dfrg added a commit that referenced this pull request Jan 9, 2025
Additional code cleanup suggested after merging #1312
aarongable pushed a commit to chromium/chromium that referenced this pull request Jan 10, 2025
Fixes issue with advance width computation for variable fonts
that lack an HVAR table, for details see [1].

Updated crates:

* skrifa: 0.26.3 => 0.26.4

* [email protected] vetted for does-not-implement-crypto, safe-to-deploy, ub-risk-0

[1] googlefonts/fontations#1312

Fixed: chromium:385924890
Change-Id: I294d3286071fbf25d416a3225489ec9618125f15
Cq-Include-Trybots: chromium/try:android-rust-arm32-rel
Cq-Include-Trybots: chromium/try:android-rust-arm64-dbg
Cq-Include-Trybots: chromium/try:android-rust-arm64-rel
Cq-Include-Trybots: chromium/try:linux-rust-x64-dbg
Cq-Include-Trybots: chromium/try:linux-rust-x64-rel
Cq-Include-Trybots: chromium/try:win-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-rel
Disable-Rts: True
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6163787
Commit-Queue: Dominik Röttsches <[email protected]>
Reviewed-by: Łukasz Anforowicz <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1404768}
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.

Incorrect hinted advance for variable font with CVT variable hinting input values
3 participants