diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dce0012..6e35e495 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 diff --git a/parley/src/layout/alignment.rs b/parley/src/layout/alignment.rs index a0703bfb..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 { @@ -177,6 +177,7 @@ fn align_impl( } if cluster.info.whitespace().is_space_or_nbsp() { cluster.advance += adjustment; + line.metrics.advance += adjustment; applied += 1; } }); diff --git a/parley/src/layout/data.rs b/parley/src/layout/data.rs index e590eb1d..68df55f5 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() });