From b09284cc9e756985d9ecb1b5c721428b77386b71 Mon Sep 17 00:00:00 2001 From: kekelp Date: Mon, 1 Dec 2025 08:55:44 +0100 Subject: [PATCH 1/4] Adjust advance when justifying text --- parley/src/layout/alignment.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/parley/src/layout/alignment.rs b/parley/src/layout/alignment.rs index a0703bfb..bb7381b5 100644 --- a/parley/src/layout/alignment.rs +++ b/parley/src/layout/alignment.rs @@ -177,6 +177,7 @@ fn align_impl( } if cluster.info.whitespace().is_space_or_nbsp() { cluster.advance += adjustment; + line.metrics.advance += adjustment; applied += 1; } }); From ec8ae672f76398dac33a2c78f281017eeada935a Mon Sep 17 00:00:00 2001 From: kekelp Date: Mon, 1 Dec 2025 08:57:58 +0100 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dce0012..3d8c8aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,7 @@ fn bounding_box_to_rect(bb: parley::BoundingBox) -> kurbo::Rect { #### Parley +- Adjust the advance of the whole line when justifying text. ([#397][] by [@kekelp][]) - Selection extension moves the focus to the side being extended. ([#385][] by [@kekelp][]) - Ranged builder default style not respecting `scale`. ([#368][] by [@xStrom][]) - Cluster source character not correct. ([#402][] by [@taj-p][]) @@ -438,6 +439,7 @@ This release has an [MSRV][] of 1.70. [#451]: https://github.com/linebender/parley/pull/451 [#467]: https://github.com/linebender/parley/pull/467 [#468]: https://github.com/linebender/parley/pull/468 +[#397]: https://github.com/linebender/parley/pull/397 [Unreleased]: https://github.com/linebender/parley/compare/v0.7.0...HEAD [0.7.0]: https://github.com/linebender/parley/compare/v0.6.0...v0.7.0 From 11af1416307ea289e9b557816ae560091dfde22e Mon Sep 17 00:00:00 2001 From: kekelp Date: Mon, 1 Dec 2025 08:57:58 +0100 Subject: [PATCH 3/4] Store unjustified advance for unjustify calculation --- parley/src/layout/alignment.rs | 2 +- parley/src/layout/data.rs | 2 ++ parley/src/layout/line_break.rs | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/parley/src/layout/alignment.rs b/parley/src/layout/alignment.rs index bb7381b5..ecd78832 100644 --- a/parley/src/layout/alignment.rs +++ b/parley/src/layout/alignment.rs @@ -110,7 +110,7 @@ fn align_impl( // Compute free space. let free_space = - layout.alignment_width - line.metrics.advance + line.metrics.trailing_whitespace; + layout.alignment_width - line.unjustified_advance + line.metrics.trailing_whitespace; if !options.align_when_overflowing && free_space <= 0.0 { if is_rtl { diff --git a/parley/src/layout/data.rs b/parley/src/layout/data.rs index e590eb1d..119fb49a 100644 --- a/parley/src/layout/data.rs +++ b/parley/src/layout/data.rs @@ -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, } impl LineData { diff --git a/parley/src/layout/line_break.rs b/parley/src/layout/line_break.rs index e933c8d6..007727bf 100644 --- a/parley/src/layout/line_break.rs +++ b/parley/src/layout/line_break.rs @@ -892,6 +892,7 @@ fn try_commit_line( advance: state.x, ..Default::default() }, + unjustified_advance: state.x, ..Default::default() }); From 663f59ed5d68f315ade8e05fc35f5a303ef67470 Mon Sep 17 00:00:00 2001 From: kekelp <79485912+kekelp@users.noreply.github.com> Date: Mon, 1 Dec 2025 08:57:58 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Accept suggestions Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> --- CHANGELOG.md | 2 +- parley/src/layout/data.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d8c8aa5..6e35e495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,7 +128,7 @@ fn bounding_box_to_rect(bb: parley::BoundingBox) -> kurbo::Rect { #### Parley -- Adjust the advance of the whole line when justifying text. ([#397][] by [@kekelp][]) +- Adjust the advance of the whole line when justifying text. ([#397][] by [@kekelp][]) - Selection extension moves the focus to the side being extended. ([#385][] by [@kekelp][]) - Ranged builder default style not respecting `scale`. ([#368][] by [@xStrom][]) - Cluster source character not correct. ([#402][] by [@taj-p][]) diff --git a/parley/src/layout/data.rs b/parley/src/layout/data.rs index 119fb49a..68df55f5 100644 --- a/parley/src/layout/data.rs +++ b/parley/src/layout/data.rs @@ -167,7 +167,7 @@ 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 + /// Max advance for the line before justification. pub(crate) unjustified_advance: f32, }