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/ctx.rs | |
| parent | a59b9fff93f708d5a35d2bf61c3b21efee71b7e9 (diff) | |
Fix math spacing bugs
Diffstat (limited to 'library/src/math/ctx.rs')
| -rw-r--r-- | library/src/math/ctx.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs index 41299f98..551d6cd7 100644 --- a/library/src/math/ctx.rs +++ b/library/src/math/ctx.rs @@ -30,6 +30,7 @@ pub(super) struct MathContext<'a, 'b, 'v> { pub ttf: &'a ttf_parser::Face<'a>, pub table: ttf_parser::math::Table<'a>, pub constants: ttf_parser::math::Constants<'a>, + pub space_width: Em, pub fill: Paint, pub lang: Lang, pub row: MathRow, @@ -50,6 +51,14 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { let table = font.ttf().tables().math.unwrap(); let constants = table.constants.unwrap(); let size = styles.get(TextNode::SIZE); + + let ttf = font.ttf(); + let space_width = ttf + .glyph_index(' ') + .and_then(|id| ttf.glyph_hor_advance(id)) + .map(|advance| font.to_em(advance)) + .unwrap_or(THICK); + Self { vt, outer: styles, @@ -71,6 +80,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { ttf: font.ttf(), table, constants, + space_width, row: MathRow::new(), base_size: size, scaled_size: size, @@ -79,7 +89,16 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { } pub fn push(&mut self, fragment: impl Into<MathFragment>) { - self.row.push(self.scaled_size, self.style, fragment); + self.row + .push(self.scaled_size, self.space_width, self.style, fragment); + } + + pub fn extend(&mut self, row: MathRow) { + let mut iter = row.0.into_iter(); + if let Some(first) = iter.next() { + self.push(first); + } + self.row.0.extend(iter); } pub fn layout_non_math(&mut self, content: &Content) -> SourceResult<Frame> { |
