-
Notifications
You must be signed in to change notification settings - Fork 223
Generalize glyph hinting: allow glyph transforms and global skews #897
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
Changes from all commits
8fef42d
6971227
a35245a
fc115dd
1849cd3
6f8b30d
c2c6f3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,7 @@ fn glyphs_skewed() { | |
| ctx.set_paint(REBECCA_PURPLE.with_alpha(0.5).into()); | ||
| ctx.glyph_run(&font) | ||
| .font_size(font_size) | ||
| .horizontal_skew(-20_f32.to_radians()) | ||
| .glyph_transform(Affine::skew(-20_f64.to_radians().tan(), 0.)) | ||
| .hint(true) | ||
| .fill_glyphs(glyphs.into_iter()); | ||
|
|
||
|
|
@@ -98,13 +98,93 @@ fn glyphs_skewed_unhinted() { | |
| ctx.set_paint(REBECCA_PURPLE.with_alpha(0.5).into()); | ||
| ctx.glyph_run(&font) | ||
| .font_size(font_size) | ||
| .horizontal_skew(-20_f32.to_radians()) | ||
| .glyph_transform(Affine::skew(-20_f64.to_radians().tan(), 0.)) | ||
| .hint(false) | ||
| .fill_glyphs(glyphs.into_iter()); | ||
|
|
||
| check_ref(&ctx, "glyphs_skewed_unhinted"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn glyphs_skewed_long() { | ||
| let mut ctx = get_ctx(250, 75, false); | ||
| let font_size: f32 = 20_f32; | ||
| let (font, glyphs) = layout_glyphs( | ||
| "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.\nSed ornare arcu lectus.", | ||
| font_size, | ||
| ); | ||
|
|
||
| ctx.set_transform(Affine::translate((0., f64::from(font_size)))); | ||
| ctx.set_paint(REBECCA_PURPLE.into()); | ||
| ctx.glyph_run(&font) | ||
| .font_size(font_size) | ||
| .glyph_transform(Affine::skew(-10_f64.to_radians().tan(), 0.)) | ||
| .hint(true) | ||
| .fill_glyphs(glyphs.into_iter()); | ||
|
|
||
| check_ref(&ctx, "glyphs_skewed_long"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn glyphs_skewed_long_unhinted() { | ||
| let mut ctx = get_ctx(250, 75, false); | ||
| let font_size: f32 = 20_f32; | ||
| let (font, glyphs) = layout_glyphs( | ||
| "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.\nSed ornare arcu lectus.", | ||
| font_size, | ||
| ); | ||
|
|
||
| ctx.set_transform(Affine::translate((0., f64::from(font_size)))); | ||
| ctx.set_paint(REBECCA_PURPLE.into()); | ||
| ctx.glyph_run(&font) | ||
| .font_size(font_size) | ||
| .glyph_transform(Affine::skew(-10_f64.to_radians().tan(), 0.)) | ||
| .hint(false) | ||
| .fill_glyphs(glyphs.into_iter()); | ||
|
|
||
| check_ref(&ctx, "glyphs_skewed_long_unhinted"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn glyphs_skewed_unskewed() { | ||
| let mut ctx = get_ctx(150, 125, false); | ||
| let font_size: f32 = 50_f32; | ||
| let (font, glyphs) = layout_glyphs("Hello,\nworld!", font_size); | ||
|
|
||
| ctx.set_transform( | ||
| Affine::translate((0., f64::from(font_size))) | ||
| * Affine::skew(-20_f64.to_radians().tan(), 0.), | ||
| ); | ||
| ctx.set_paint(REBECCA_PURPLE.into()); | ||
| ctx.glyph_run(&font) | ||
| .font_size(font_size) | ||
| .glyph_transform(Affine::skew(20_f64.to_radians().tan(), 0.)) | ||
| .hint(true) | ||
| .fill_glyphs(glyphs.into_iter()); | ||
|
|
||
| check_ref(&ctx, "glyphs_skewed_unskewed"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: This rendering does now in fact look right to me - I missed that This rendering doesn't look right to me. If we're skewing each glyph individually, that should be a different operation to skewing the global box. (this is the same issue as my other comment) |
||
| } | ||
|
|
||
| #[test] | ||
| fn glyphs_skewed_unskewed_unhinted() { | ||
| let mut ctx = get_ctx(150, 125, false); | ||
| let font_size: f32 = 50_f32; | ||
| let (font, glyphs) = layout_glyphs("Hello,\nworld!", font_size); | ||
|
|
||
| ctx.set_transform( | ||
| Affine::translate((0., f64::from(font_size))) | ||
| * Affine::skew(-20_f64.to_radians().tan(), 0.), | ||
| ); | ||
| ctx.set_paint(REBECCA_PURPLE.into()); | ||
| ctx.glyph_run(&font) | ||
| .font_size(font_size) | ||
| .glyph_transform(Affine::skew(20_f64.to_radians().tan(), 0.)) | ||
| .hint(false) | ||
| .fill_glyphs(glyphs.into_iter()); | ||
|
|
||
| check_ref(&ctx, "glyphs_skewed_unskewed_unhinted"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn glyphs_scaled() { | ||
| let mut ctx = get_ctx(150, 125, false); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels suspicious to me. In theory, we want to skew, then translate locally, then transform globally, right?
But this ordering seems to me to be translate locally, then skew, then transform globally.
In any case, we need a test which has a long-ish text run skewed using
glyph_transform.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity: we apply
glyph_transform, then translate with the glyph position from shaping/layouting, then apply the globaltransform.Mathematically that's
transform * glyph_translation * glyph_transform, where all of these are 3x3 affine matrices.glyph_translationonly adds a translation. That means we can equivalently calculatetransform * glyph_transform, and then add the (transformed) translation component fromglyph_translationto the total transform. This order is slightly cheaper to calculate.