diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-27 15:09:05 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-27 15:32:05 +0100 |
| commit | 2e039cb052fcb768027053cbf02ce396f6d7a6be (patch) | |
| tree | b1a1c1da0440805b296e3204fa30cd9666322a0e /library/src/math/row.rs | |
| parent | a59b9fff93f708d5a35d2bf61c3b21efee71b7e9 (diff) | |
Fix math spacing bugs
Diffstat (limited to 'library/src/math/row.rs')
| -rw-r--r-- | library/src/math/row.rs | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/library/src/math/row.rs b/library/src/math/row.rs index f7b2b384..f75aed99 100644 --- a/library/src/math/row.rs +++ b/library/src/math/row.rs @@ -15,36 +15,60 @@ impl MathRow { pub fn push( &mut self, font_size: Abs, + space_width: Em, style: MathStyle, fragment: impl Into<MathFragment>, ) { - let fragment = fragment.into(); - if let Some(fragment_class) = fragment.class() { - for (i, prev) in self.0.iter().enumerate().rev() { - if matches!(prev, MathFragment::Align) { - continue; - } + let mut fragment = fragment.into(); + if !fragment.participating() { + self.0.push(fragment); + return; + } - let mut amount = Abs::zero(); - if let MathFragment::Glyph(glyph) = *prev { - if !glyph.italics_correction.is_zero() - && fragment_class != MathClass::Alphabetic - { - amount += glyph.italics_correction; - } + let mut space = false; + for (i, prev) in self.0.iter().enumerate().rev() { + if !prev.participating() { + space |= matches!(prev, MathFragment::Space); + if matches!(prev, MathFragment::Spacing(_)) { + break; } + continue; + } - if let Some(prev_class) = prev.class() { - amount += spacing(prev_class, fragment_class, style).at(font_size); + if fragment.class() == Some(MathClass::Vary) { + if matches!( + prev.class(), + Some( + MathClass::Normal + | MathClass::Alphabetic + | MathClass::Binary + | MathClass::Closing + | MathClass::Fence + | MathClass::Relation + ) + ) { + fragment.set_class(MathClass::Binary); } + } - if !amount.is_zero() { - self.0.insert(i + 1, MathFragment::Spacing(amount)); + let mut amount = Abs::zero(); + if let MathFragment::Glyph(glyph) = *prev { + if !glyph.italics_correction.is_zero() + && fragment.class() != Some(MathClass::Alphabetic) + { + amount += glyph.italics_correction; } + } + + amount += spacing(prev, &fragment, style, space, space_width).at(font_size); - break; + if !amount.is_zero() { + self.0.insert(i + 1, MathFragment::Spacing(amount)); } + + break; } + self.0.push(fragment); } |
