Add basic support for text-align: justify (#30807)

This also enables parsing of `text-justify` for non-legacy layout,
though only None is supported (disabling justification).
This commit is contained in:
Martin Robinson 2023-12-15 15:00:13 +01:00 committed by GitHub
parent 0be30b30ce
commit ccf0b739df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 154 additions and 417 deletions

View file

@ -282,7 +282,11 @@ impl Fragment {
.translate(containing_block.origin.to_vector());
let mut baseline_origin = rect.origin.clone();
baseline_origin.y += Length::from(fragment.font_metrics.ascent);
let glyphs = glyphs(&fragment.glyphs, baseline_origin);
let glyphs = glyphs(
&fragment.glyphs,
baseline_origin,
fragment.justification_adjustment,
);
if glyphs.is_empty() {
return;
}
@ -760,6 +764,7 @@ fn rgba(color: AbsoluteColor) -> wr::ColorF {
fn glyphs(
glyph_runs: &[Arc<GlyphStore>],
mut origin: PhysicalPoint<Length>,
justification_adjustment: Length,
) -> Vec<wr::GlyphInstance> {
use gfx_traits::ByteIndex;
use range::Range;
@ -778,6 +783,8 @@ fn glyphs(
point,
};
glyphs.push(glyph);
} else {
origin.x += justification_adjustment;
}
origin.x += Length::from(glyph.advance());
}