Repository navigation
Remove tracking from the last glyph in a line - #8963
Conversation
ce557f3 to
947f183
Compare
laurmaedje
left a comment
There was a problem hiding this comment.
Thanks for the PR! Ideally, I would like to have a cleaner solution, but I think that would require a larger refactor which should not block this fix. So I'm okay with proceeding here, pending a few comments:
-
Currently, the PR will unconditionally cause the glyphs to be cloned due to
glyphs.to_mut. This should be avoided by checking whether a change will be made to the glyphs first (similarly to the CJK code paths). -
I've made a PR to avoid a regression with CJK adjustability and fix some further tracking-related bugs, so this PR will require a rebase. In particular
Em::from_abs(shaped.styles.resolve(..))should becomeEm::from_length(shaped.styles.get(..))to match the updated code inapply_tracking.
947f183 to
9629ba0
Compare
|
Thanks for the review! I've resolved the function to check if a change is needed before cloning and amended the tracking calculation to be consistent with the updated code from your PR. I also made sure to reset |
|
Thanks! |
|
I think the minified test was not updated properly. Locally, the minified test generates a different |
75784d9 to
003f010
Compare
|
Strange, I thought I looked at the image before pushing and considered it correct, even though it clearly wasn't. Should work now. |
trackingis flattened intox_advanceduring the shaping stage and this is always retained by the last non-space glyph in a line except in (at least) two cases:One consequence of this is that line width includes the trailing tracking, which is not the right behavior. This manifests in #8931 as a right gutter at the line end when justification is applied. A naive fix would be to subtract tracking from the
x_advanceof the last glyph of the line (if we are not in 1. or 2.). But this is fragile because it is unclear if tracking has been applied to the last glyph.This PR adds a
tracking_appliedboolean field to shaped glyphs, so the line end fix only removestrackingwhen it has actually been applied to the glyph’sx_advance. The adjustment is applied in the line constructorGenerally,
x_advanceis not trustworthy because shrink, stretch and tracking calculations are absorbed by it at different points, so there is no guarantee on what it contains when read. Existing patches to start/end line behaviour:adjust_cj_at_line_endwork by subtracting an amount (the shrink applied earlier by
add_cjk_latin_spacing) from the glyph’sx_advance. This bakes in the assumption thatx_advancecontains exactly that shrink, which must be respected by patches that come before it:Apply
adjust_glyph_tracking_at_line_endafteradjust_cj_at_line_endthen the change will cause end line CJK characters to overhang on the right bytracking.A possible refactor could make explicit what
x_advancecontains by storing and updating shrink, stretch and tracking amounts separately, then computex_advancewhen it’s needed. This would also aid a fix for the #8959 issue which confuses character width with width + tracking.Fixes #8931.