Remove microjustification

This commit is contained in:
diquah 2025-04-10 19:05:30 -07:00
parent 07ba1c1636
commit 7d6d46c4d8
2 changed files with 7 additions and 51 deletions

View File

@ -71,16 +71,6 @@ impl Line<'_> {
count count
} }
/// How many glyphs are in the text where we can insert micro-amounts
/// of additional space when encountering underfull lines.
fn microjustifiables(&self) -> usize {
let mut count = 0;
for shaped in self.items.iter().filter_map(Item::text) {
count += shaped.microjustifiables();
}
count
}
/// How much the line can stretch. /// How much the line can stretch.
pub fn stretchability(&self) -> Abs { pub fn stretchability(&self) -> Abs {
self.items self.items
@ -482,21 +472,12 @@ pub fn commit(
let fr = line.fr(); let fr = line.fr();
let mut justification_ratio = 0.0; let mut justification_ratio = 0.0;
let mut extra_justification = Abs::zero(); let mut extra_justification = Abs::zero();
let mut extra_microjustification = Abs::zero();
let shrinkability = line.shrinkability(); let shrinkability = line.shrinkability();
let stretchability = line.stretchability(); let stretchability = line.stretchability();
if remaining < Abs::zero() && shrinkability > Abs::zero() { if remaining < Abs::zero() && shrinkability > Abs::zero() {
// Attempt to reduce the length of the line, using shrinkability. // Attempt to reduce the length of the line, using shrinkability.
let microjustifiables = line.microjustifiables(); justification_ratio = (remaining / shrinkability).max(-1.0);
extra_microjustification = (remaining / microjustifiables as f64)
.max(p.config.microtype.max_retract.abs);
justification_ratio = ((remaining
- extra_microjustification * microjustifiables as f64)
/ shrinkability)
.max(-1.0);
remaining = (remaining + shrinkability).min(Abs::zero()); remaining = (remaining + shrinkability).min(Abs::zero());
} else if line.justify && fr.is_zero() { } else if line.justify && fr.is_zero() {
@ -507,17 +488,10 @@ pub fn commit(
} }
let justifiables = line.justifiables(); let justifiables = line.justifiables();
let microjustifiables = line.microjustifiables();
if justifiables > 0 && remaining > Abs::zero() { if justifiables > 0 && remaining > Abs::zero() {
// Underfull line, distribute the extra space. // Underfull line, distribute the extra space.
extra_microjustification = (remaining / microjustifiables as f64) extra_justification = remaining / justifiables as f64;
.min(p.config.microtype.max_expand.abs);
extra_justification = (remaining
- extra_microjustification * microjustifiables as f64)
/ justifiables as f64;
remaining = Abs::zero(); remaining = Abs::zero();
} }
} }
@ -559,7 +533,6 @@ pub fn commit(
&p.spans, &p.spans,
justification_ratio, justification_ratio,
extra_justification, extra_justification,
extra_microjustification,
); );
push(&mut offset, frame); push(&mut offset, frame);
} }

View File

@ -84,8 +84,6 @@ pub struct ShapedGlyph {
pub c: char, pub c: char,
/// Whether this glyph is justifiable for CJK scripts. /// Whether this glyph is justifiable for CJK scripts.
pub is_justifiable: bool, pub is_justifiable: bool,
/// Whether this glyph is allowed additional kerning for microjustification.
pub is_microjustifiable: bool,
/// The script of the glyph. /// The script of the glyph.
pub script: Script, pub script: Script,
} }
@ -110,11 +108,6 @@ impl ShapedGlyph {
self.is_justifiable self.is_justifiable
} }
/// Whether the glyph is microjustifiable.
pub fn is_microjustifiable(&self) -> bool {
self.is_microjustifiable
}
/// Whether the glyph is part of Chinese or Japanese script (i.e. CJ, not CJK). /// Whether the glyph is part of Chinese or Japanese script (i.e. CJ, not CJK).
pub fn is_cj_script(&self) -> bool { pub fn is_cj_script(&self) -> bool {
is_cj_script(self.c, self.script) is_cj_script(self.c, self.script)
@ -153,7 +146,11 @@ impl ShapedGlyph {
|| self.c.is_ascii_digit() || self.c.is_ascii_digit()
} }
pub fn base_adjustability(&self, style: CjkPunctStyle, microtype: Microtype) -> Adjustability { pub fn base_adjustability(
&self,
style: CjkPunctStyle,
microtype: Microtype,
) -> Adjustability {
let width = self.x_advance; let width = self.x_advance;
if self.is_space() { if self.is_space() {
Adjustability { Adjustability {
@ -227,7 +224,6 @@ impl<'a> ShapedText<'a> {
spans: &SpanMapper, spans: &SpanMapper,
justification_ratio: f64, justification_ratio: f64,
extra_justification: Abs, extra_justification: Abs,
extra_microjustification: Abs,
) -> Frame { ) -> Frame {
let (top, bottom) = self.measure(engine); let (top, bottom) = self.measure(engine);
let size = Size::new(self.width, top + bottom); let size = Size::new(self.width, top + bottom);
@ -273,10 +269,6 @@ impl<'a> ShapedText<'a> {
justification_right += justification_right +=
Em::from_length(extra_justification, self.size) Em::from_length(extra_justification, self.size)
} }
if shaped.is_microjustifiable() {
justification_right +=
Em::from_length(extra_microjustification, self.size)
}
frame.size_mut().x += justification_left.at(self.size) frame.size_mut().x += justification_left.at(self.size)
+ justification_right.at(self.size); + justification_right.at(self.size);
@ -391,12 +383,6 @@ impl<'a> ShapedText<'a> {
self.glyphs.iter().filter(|g| g.is_justifiable()).count() self.glyphs.iter().filter(|g| g.is_justifiable()).count()
} }
/// How many glyphs are in the text that are allowed extra kerning for the
/// use of justification when encountering underfull lines.
pub fn microjustifiables(&self) -> usize {
self.glyphs.iter().filter(|g| g.is_microjustifiable()).count()
}
/// Whether the last glyph is a CJK character which should not be justified /// Whether the last glyph is a CJK character which should not be justified
/// on line end. /// on line end.
pub fn cjk_justifiable_at_last(&self) -> bool { pub fn cjk_justifiable_at_last(&self) -> bool {
@ -518,7 +504,6 @@ impl<'a> ShapedText<'a> {
safe_to_break: true, safe_to_break: true,
c: '-', c: '-',
is_justifiable: false, is_justifiable: false,
is_microjustifiable: false,
script: Script::Common, script: Script::Common,
}; };
match side { match side {
@ -904,7 +889,6 @@ fn shape_segment<'a>(
x_advance, x_advance,
Adjustability::default().stretchability, Adjustability::default().stretchability,
), ),
is_microjustifiable: false,
script, script,
}); });
} else { } else {
@ -997,7 +981,6 @@ fn shape_tofus(ctx: &mut ShapingContext, base: usize, text: &str, font: Font) {
x_advance, x_advance,
Adjustability::default().stretchability, Adjustability::default().stretchability,
), ),
is_microjustifiable: false,
script, script,
}); });
}; };