-
Notifications
You must be signed in to change notification settings - Fork 49
Adjust advance when justifying text #397
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
base: main
Are you sure you want to change the base?
Conversation
Accept suggestions Co-authored-by: Daniel McNab <[email protected]>
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.
I think the direction makes sense, as the current state of LineMetrics::advance
not taking padding into account certainly can be confusing. I've placed a few comments/questions inline.
/// Max advance for the line before justification. | ||
pub(crate) unjustified_advance: f32, |
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.
It's probably fine to store the unjustified advance here, as the user likely doesn't need to know.
} | ||
if cluster.info.whitespace().is_space_or_nbsp() { | ||
cluster.advance += adjustment; | ||
line.metrics.advance += adjustment; |
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.
Could this be set (outside the loop) as line.metrics.advance = layout.alignment_width
, for all except the final line? For very wide lines with many clusters, this iterative calculation will probably become quite lossy.
Does the code in the PR currently lead to a line.metrics.advance
larger than the alignment_width
, as trailing whitespace is counted twice? (I haven't run this locally yet.)
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.
Setting line.metrics.advance = layout.alignment_width
, this is what happens:

The 2nd and 3rd lines use line.metrics.advance
for the width of their selection box, so now it stops exactly at the end of the alignment_width
. The first line calculates the selection box manually without using line.metrics.advance
, and it shows that the trailing whitespace lives beyond layout.alignment_width
, because the justification code ignores it.
We could just change the selection box code, of course, but the thing is that line.metrics.advance
is documented as "Full advance of the line, including trailing whitespace". So I think it's correct that line.metrics.advance
is larger than the alignment_width
in this case.
Still, we can probably still avoid the iterative calculation by just setting line.metrics.advance = layout.alignment_width + line.metrics.trailing_whitespace
. I'm not sure about the RTL line and the one with a trailing newline instead of a trailing space, but this seems to work as well:

Resolves #396.