diff --git a/library/src/math/accent.rs b/library/src/math/accent.rs
index 797a4761d..223ada4f9 100644
--- a/library/src/math/accent.rs
+++ b/library/src/math/accent.rs
@@ -84,7 +84,7 @@ impl LayoutMath for AccentNode {
let base = ctx.layout_fragment(&self.base)?;
ctx.unstyle();
- let base_attach = match base {
+ let base_attach = match &base {
MathFragment::Glyph(base) => {
attachment(ctx, base.id, base.italics_correction)
}
@@ -118,7 +118,7 @@ impl LayoutMath for AccentNode {
let mut frame = Frame::new(size);
frame.set_baseline(baseline);
frame.push_frame(accent_pos, accent);
- frame.push_frame(base_pos, base.to_frame(ctx));
+ frame.push_frame(base_pos, base.to_frame());
ctx.push(FrameFragment::new(ctx, frame).with_base_ascent(base_ascent));
Ok(())
diff --git a/library/src/math/attach.rs b/library/src/math/attach.rs
index 6adbd47ad..7e6ac3882 100644
--- a/library/src/math/attach.rs
+++ b/library/src/math/attach.rs
@@ -225,18 +225,18 @@ fn scripts(
let mut frame = Frame::new(Size::new(width, ascent + descent));
frame.set_baseline(ascent);
- frame.push_frame(base_pos, base.to_frame(ctx));
+ frame.push_frame(base_pos, base.to_frame());
if let Some(sup) = sup {
let sup_pos =
Point::new(sup_delta + base_width, ascent - shift_up - sup.ascent());
- frame.push_frame(sup_pos, sup.to_frame(ctx));
+ frame.push_frame(sup_pos, sup.to_frame());
}
if let Some(sub) = sub {
let sub_pos =
Point::new(sub_delta + base_width, ascent + shift_down - sub.ascent());
- frame.push_frame(sub_pos, sub.to_frame(ctx));
+ frame.push_frame(sub_pos, sub.to_frame());
}
ctx.push(FrameFragment::new(ctx, frame).with_class(class));
@@ -279,17 +279,17 @@ fn limits(
let mut frame = Frame::new(Size::new(width, height));
frame.set_baseline(base_pos.y + base.ascent());
- frame.push_frame(base_pos, base.to_frame(ctx));
+ frame.push_frame(base_pos, base.to_frame());
if let Some(top) = top {
let top_pos = Point::with_x((width - top.width()) / 2.0 + delta);
- frame.push_frame(top_pos, top.to_frame(ctx));
+ frame.push_frame(top_pos, top.to_frame());
}
if let Some(bottom) = bottom {
let bottom_pos =
Point::new((width - bottom.width()) / 2.0 - delta, height - bottom.height());
- frame.push_frame(bottom_pos, bottom.to_frame(ctx));
+ frame.push_frame(bottom_pos, bottom.to_frame());
}
ctx.push(FrameFragment::new(ctx, frame).with_class(class));
diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs
index 4f390817a..d43d1b2ae 100644
--- a/library/src/math/ctx.rs
+++ b/library/src/math/ctx.rs
@@ -118,7 +118,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
}
pub fn layout_frame(&mut self, node: &dyn LayoutMath) -> SourceResult {
- Ok(self.layout_fragment(node)?.to_frame(self))
+ Ok(self.layout_fragment(node)?.to_frame())
}
pub fn layout_content(&mut self, content: &Content) -> SourceResult {
diff --git a/library/src/math/delimited.rs b/library/src/math/delimited.rs
index b69e4c39d..5b9decb6e 100644
--- a/library/src/math/delimited.rs
+++ b/library/src/math/delimited.rs
@@ -101,7 +101,7 @@ fn scale(
Some(MathClass::Opening | MathClass::Closing | MathClass::Fence)
) {
let glyph = match fragment {
- MathFragment::Glyph(glyph) => *glyph,
+ MathFragment::Glyph(glyph) => glyph.clone(),
MathFragment::Variant(variant) => GlyphFragment::new(ctx, variant.c),
_ => return,
};
diff --git a/library/src/math/fragment.rs b/library/src/math/fragment.rs
index 843021f48..93c5946bb 100644
--- a/library/src/math/fragment.rs
+++ b/library/src/math/fragment.rs
@@ -105,9 +105,9 @@ impl MathFragment {
}
}
- pub fn to_frame(self, ctx: &MathContext) -> Frame {
+ pub fn to_frame(self) -> Frame {
match self {
- Self::Glyph(glyph) => glyph.to_frame(ctx),
+ Self::Glyph(glyph) => glyph.to_frame(),
Self::Variant(variant) => variant.frame,
Self::Frame(fragment) => fragment.frame,
_ => Frame::new(self.size()),
@@ -133,10 +133,11 @@ impl From for MathFragment {
}
}
-#[derive(Clone, Copy)]
+#[derive(Clone)]
pub struct GlyphFragment {
pub id: GlyphId,
pub c: char,
+ pub font: Font,
pub lang: Lang,
pub fill: Paint,
pub width: Abs,
@@ -178,6 +179,7 @@ impl GlyphFragment {
Self {
id,
c,
+ font: ctx.font.clone(),
lang: ctx.styles().get(TextNode::LANG),
fill: ctx.styles().get(TextNode::FILL),
style: ctx.style,
@@ -197,11 +199,11 @@ impl GlyphFragment {
self.ascent + self.descent
}
- pub fn to_variant(&self, ctx: &MathContext) -> VariantFragment {
+ pub fn to_variant(&self) -> VariantFragment {
VariantFragment {
c: self.c,
id: Some(self.id),
- frame: self.to_frame(ctx),
+ frame: self.to_frame(),
style: self.style,
font_size: self.font_size,
italics_correction: self.italics_correction,
@@ -209,9 +211,9 @@ impl GlyphFragment {
}
}
- pub fn to_frame(&self, ctx: &MathContext) -> Frame {
+ pub fn to_frame(&self) -> Frame {
let text = Text {
- font: ctx.font.clone(),
+ font: self.font.clone(),
size: self.font_size,
fill: self.fill,
lang: self.lang,
diff --git a/library/src/math/row.rs b/library/src/math/row.rs
index ecd37f462..1271e49e6 100644
--- a/library/src/math/row.rs
+++ b/library/src/math/row.rs
@@ -139,7 +139,7 @@ impl MathRow {
let mut frame = Frame::new(Size::zero());
for (i, row) in rows.into_iter().enumerate() {
- let sub = row.to_line_frame(ctx, &points, align);
+ let sub = row.to_line_frame(&points, align);
let size = frame.size_mut();
if i > 0 {
size.y += leading;
@@ -155,11 +155,11 @@ impl MathRow {
}
frame
} else {
- self.to_line_frame(ctx, points, align)
+ self.to_line_frame(points, align)
}
}
- fn to_line_frame(self, ctx: &MathContext, points: &[Abs], align: Align) -> Frame {
+ fn to_line_frame(self, points: &[Abs], align: Align) -> Frame {
let ascent = self.ascent();
let descent = self.descent();
let size = Size::new(Abs::zero(), ascent + descent);
@@ -192,7 +192,7 @@ impl MathRow {
let y = ascent - fragment.ascent();
let pos = Point::new(x, y);
x += fragment.width();
- frame.push_frame(pos, fragment.to_frame(ctx));
+ frame.push_frame(pos, fragment.to_frame());
}
frame.size_mut().x = x;
diff --git a/library/src/math/stretch.rs b/library/src/math/stretch.rs
index d308975d0..1c9948029 100644
--- a/library/src/math/stretch.rs
+++ b/library/src/math/stretch.rs
@@ -57,7 +57,7 @@ fn stretch_glyph(
// If the base glyph is good enough, use it.
let advance = if horizontal { base.width } else { base.height() };
if short_target <= advance {
- return base.to_variant(ctx);
+ return base.to_variant();
}
// Search for a pre-made variant with a good advance.
@@ -65,7 +65,7 @@ fn stretch_glyph(
let mut best_advance = base.width;
for variant in construction.variants {
best_id = variant.variant_glyph;
- best_advance = variant.advance_measurement.scaled(ctx);
+ best_advance = base.font.to_em(variant.advance_measurement).at(base.font_size);
if short_target <= best_advance {
break;
}
@@ -73,7 +73,7 @@ fn stretch_glyph(
// This is either good or the best we've got.
if short_target <= best_advance || construction.assembly.is_none() {
- return GlyphFragment::with_id(ctx, base.c, best_id).to_variant(ctx);
+ return GlyphFragment::with_id(ctx, base.c, best_id).to_variant();
}
// Assemble from parts.
@@ -169,7 +169,7 @@ fn assemble(
} else {
Point::with_y(full - offset - fragment.height())
};
- frame.push_frame(pos, fragment.to_frame(ctx));
+ frame.push_frame(pos, fragment.to_frame());
offset += advance;
}