Add text last-line alignment modes for "Justify Center", "Justify Right", and "Justify All" (#4024)

* feat: Add justify proper alignments(right/left/centre/all)

* chore: fmt

* chore: refactor

* Cleanup

* Fix crash when changing selected layer's alignment from the Text tool control bar

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Jatin Bharti
2026-05-07 07:46:19 +05:30
committed by GitHub
parent 1c2ac19b16
commit c0a8241f50
8 changed files with 142 additions and 32 deletions

View File

@@ -52,10 +52,20 @@ impl PathBuilder {
}
#[allow(clippy::too_many_arguments)]
fn draw_glyph(&mut self, glyph: &OutlineGlyph<'_>, size: f32, normalized_coords: &[NormalizedCoord], glyph_offset: DVec2, style_skew: Option<DAffine2>, skew: DAffine2, per_glyph_items: bool) {
fn draw_glyph(
&mut self,
glyph: &OutlineGlyph<'_>,
size: f32,
normalized_coords: &[NormalizedCoord],
glyph_offset: DVec2,
style_skew: Option<DAffine2>,
skew: DAffine2,
per_glyph_items: bool,
) -> bool {
let location_ref = LocationRef::new(normalized_coords);
let settings = DrawSettings::unhinted(Size::new(size), location_ref);
glyph.draw(settings, self).unwrap();
let has_geometry = !self.glyph_subpaths.is_empty();
// Apply transforms in correct order: style-based skew first, then user-requested skew
// This ensures font synthesis (italic) is applied before user transformations
@@ -91,10 +101,12 @@ impl PathBuilder {
self.merged_click_target_baselines.push(glyph_offset.y);
}
}
has_geometry
}
pub fn render_glyph_run(&mut self, glyph_run: &GlyphRun<'_, ()>, tilt: f64, per_glyph_items: bool) {
let mut run_x = glyph_run.offset();
pub fn render_glyph_run(&mut self, glyph_run: &GlyphRun<'_, ()>, tilt: f64, per_glyph_items: bool, x_offset: f32, space_extra: f32) {
let mut run_x = glyph_run.offset() + x_offset;
let run_y = glyph_run.baseline();
let run = glyph_run.run();
@@ -142,7 +154,11 @@ impl PathBuilder {
if !per_glyph_items {
self.origin = glyph_offset;
}
self.draw_glyph(&glyph_outline, font_size, &normalized_coords, glyph_offset, style_skew, skew, per_glyph_items);
let drew_geometry = self.draw_glyph(&glyph_outline, font_size, &normalized_coords, glyph_offset, style_skew, skew, per_glyph_items);
if !drew_geometry && space_extra != 0. && glyph.advance > 0. {
run_x += space_extra;
}
}
}
}