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

Offsetting and scaling #143

Merged
merged 2 commits into from
Jul 6, 2023
Merged

Conversation

hecrj
Copy link
Contributor

@hecrj hecrj commented Jun 20, 2023

This PR introduces a new PhysicalGlyph type that allows deferring the computation of a CacheKey while offsetting and scaling a glyph after layout.

This allows consumers to benefit from layout linearity and leverage subpixel glyph positioning.

}

impl LayoutGlyph {
pub fn physical(&self, offset: (f32, f32), scale: f32) -> PhysicalGlyph {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really like the name. Ideally, it should be a verb; but I can't quite come up with anything. I'll keep thinking about it.

self.font_size * scale,
(
(self.x + x_offset) * scale + offset.0,
((self.y - y_offset) * scale + offset.1).trunc(), // Hinting in Y axis
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe hinting could be an argument flag to this method and could be passed and stored in the CacheKey. This way we could tie it all together with the swash::swash_image function in a type safe way.

Copy link
Contributor Author

@hecrj hecrj Jun 20, 2023

Choose a reason for hiding this comment

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

From a Discord discussion, the author of swash shared:

My general recommendation would be to never apply fractional offsets in the y direction. We do so in the x direction because scaled advance widths are almost never integral and we’re generally rasterizing to a fixed grid so if the fractional component of the advance is not taken into account, you end up with very noticeable inconsistent spacing between glyphs and the error accumulates quickly over a line.
For most body text, the line height is consistent so rounding is fine (and imho, preferable).

So I guess we can just keep hinting hardcoded like this.

@Dimchikkk
Copy link
Contributor

Hello @hecrj! I noticed the presence of the font_size attribute on LayoutGlyph in the code. I'm curious to know if this addition will address the issue mentioned in #64 or not really?

@hecrj
Copy link
Contributor Author

hecrj commented Jun 26, 2023

@StaffEngineer No. font_size is on LayoutGlyph only to defer the computation of the CacheKey.

@hecrj hecrj marked this pull request as ready for review June 28, 2023 14:45
@jackpot51 jackpot51 merged commit c3cd24d into pop-os:main Jul 6, 2023
@jackpot51
Copy link
Member

I fixed the test failures in 85ac473

hecrj added a commit to hecrj/glyphon that referenced this pull request Jul 7, 2023
The latest `cosmic-text` release performs bucketing calculations after
layouting. This allows us to provide proper subpixel offsets, as well as
scale any buffer thanks to its linear layout properties.

See pop-os/cosmic-text#143.
hecrj added a commit to hecrj/glyphon that referenced this pull request Jul 7, 2023
The latest `cosmic-text` release performs bucketing calculations after
layouting. This allows us to provide proper subpixel offsets, as well as
scale any buffer thanks to its linear layout properties.

See pop-os/cosmic-text#143.
hecrj added a commit to hecrj/glyphon that referenced this pull request Jul 10, 2023
The latest `cosmic-text` release performs bucketing calculations after
layouting. This allows us to provide proper subpixel offsets, as well as
scale any buffer thanks to its linear layout properties.

See pop-os/cosmic-text#143.
grovesNL pushed a commit to grovesNL/glyphon that referenced this pull request Jul 11, 2023
The latest `cosmic-text` release performs bucketing calculations after
layouting. This allows us to provide proper subpixel offsets, as well as
scale any buffer thanks to its linear layout properties.

See pop-os/cosmic-text#143.
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.

3 participants