Skip to content

When hinting glyphs, round y-offsets to integers#896

Merged
tomcur merged 3 commits intomainfrom
glyph-hint-y-offset
Apr 7, 2025
Merged

When hinting glyphs, round y-offsets to integers#896
tomcur merged 3 commits intomainfrom
glyph-hint-y-offset

Conversation

@tomcur
Copy link
Member

@tomcur tomcur commented Apr 4, 2025

Without this, while glyph outlines will be hinted to integers, the translation can bump the outlines to fractional locations again.

@waywardmonkeys
Copy link
Collaborator

This makes me think of rounding stuff in Parley recently.

@tomcur
Copy link
Member Author

tomcur commented Apr 4, 2025

This makes me think of rounding stuff in Parley recently.

This one? linebender/parley#297

@waywardmonkeys
Copy link
Collaborator

Yes, sir.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

I don't know if we have any good docs for this, but https://docs.google.com/document/d/1gEqf7ehTzd89Djf_VpkL0B_Fb15e0w5fuv_UzyacAPU/edit?disco=AAABctut6QY is relevant (it's a link to a specific comment) here.

I don't think this is quite the right place to be doing this quantisation; we would need to be rounding the absolute y coordinate, not the "local" y coordinate.

Separately: ideally, there's be some way to warn if this changed frame-by-frame (that is, the baseline isn't rounded). But I don't think there's any way to detect that, because the relationship between y and the baseline is not so simple.

@tomcur
Copy link
Member Author

tomcur commented Apr 4, 2025

I don't think this is quite the right place to be doing this quantisation; we would need to be rounding the absolute y coordinate, not the "local" y coordinate.

Hmm... I guess you're right, in that depending on GlyphRenderer, we don't quite know where the outline is going to be placed. I believe currently using vello_cpu, the y-coordinate here is the absolute coordinate.

@DJMcNab
Copy link
Member

DJMcNab commented Apr 4, 2025

Hmm... I guess you're right, in that depending on GlyphRenderer, we don't quite know where the outline is going to be placed. I believe currently using vello_cpu, the y-coordinate here is the absolute coordinate.

Is it not impacted by the "adding" of the transform on (new) line 163?

@tomcur
Copy link
Member Author

tomcur commented Apr 4, 2025

Is it not impacted by the "adding" of the transform on (new) line 163?

I was going to write it is not, but on second thought it is partially impacted. The order of operations is effectively:

transform * translate * skew * glyph_transform

(Where you have to read b * a as b after a.) In this code-path transform is guaranteed to have a scale of 1 because take_uniform_scale has taken the scale out of transform.

However, if transform itself translates with fractional coordinates, the outline can still be bumped to a fractional coordinate. We can account for that here.

@tomcur tomcur requested a review from DJMcNab April 4, 2025 13:32
Copy link
Contributor

@taj-p taj-p left a comment

Choose a reason for hiding this comment

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

LGTM

@tomcur tomcur added this pull request to the merge queue Apr 7, 2025
Merged via the queue into main with commit 96e171d Apr 7, 2025
17 checks passed
@tomcur tomcur deleted the glyph-hint-y-offset branch April 7, 2025 10:50
github-merge-queue bot pushed a commit that referenced this pull request Apr 7, 2025
On top of #896 (that should land
first). See c0b7786 and onwards for the
changes here.

This builds on the work landed in
#889.

This generalizes our detection of when (vertical-only) hinting can be
performed. When the second coefficient (`b`) of the affine
transformation matrix is 0 (first column, second row), glyphs are not
skewed vertically or rotated, and can be hinted. Because of this
generalization, the `horizontal_skew` special case has been removed.

We now calculate the total transformation matrix once, and separately
calculate the glyph translations using the run's transformation matrix
for global glyph positioning. This reduces the number of affine
multiplies per glyph to one-and-a-bit down from three.
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.

4 participants