-
Notifications
You must be signed in to change notification settings - Fork 64
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
Open
kekelp
wants to merge
4
commits into
linebender:main
Choose a base branch
from
kekelp:justified-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,8 @@ pub(crate) struct LineData { | |
| pub(crate) max_advance: f32, | ||
| /// Number of justified clusters on the line. | ||
| pub(crate) num_spaces: usize, | ||
| /// Max advance for the line before justification. | ||
| pub(crate) unjustified_advance: f32, | ||
|
Comment on lines
+170
to
+171
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. It's probably fine to store the unjustified advance here, as the user likely doesn't need to know. |
||
| } | ||
|
|
||
| impl LineData { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.advancelarger than thealignment_width, as trailing whitespace is counted twice? (I haven't run this locally yet.)Uh oh!
There was an error while loading. Please reload this page.
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.advancefor the width of their selection box, so now it stops exactly at the end of thealignment_width. The first line calculates the selection box manually without usingline.metrics.advance, and it shows that the trailing whitespace lives beyondlayout.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.advanceis documented as "Full advance of the line, including trailing whitespace". So I think it's correct thatline.metrics.advanceis larger than thealignment_widthin 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: