Paint math limits above and below their base
This commit is contained in:
1 parent
b004cd2efb
commit
3f1dd0c077
2 files changed
+47
-1
No files matched your search
@@ -1837,6 +1837,26 @@ mod tests {
|
|||||||
assert!(svg.contains("font-style=\"italic\">face2"));
|
assert!(svg.contains("font-style=\"italic\">face2"));
|
||||||
assert!(svg.contains("font-family=\"monospace\">face3"));
|
assert!(svg.contains("font-family=\"monospace\">face3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn display_list_paints_limits_above_and_below() {
|
||||||
|
let document = Document::new(
|
||||||
|
1000,
|
||||||
|
vec![Unit::math(
|
||||||
|
1,
|
||||||
|
crate::math::parse_math("\\sum_{i=1}^{n}"),
|
||||||
|
&Cmr10Metrics::default(),
|
||||||
|
)],
|
||||||
|
);
|
||||||
|
let engine = Engine::layout(&document);
|
||||||
|
let list = engine.pages()[0].display_list();
|
||||||
|
let texts = list
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.filter(|item| matches!(item, DisplayItem::Text { .. }))
|
||||||
|
.count();
|
||||||
|
assert!(texts >= 4, "expected sum plus both limits, got {texts}");
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn math_display_list_paints_symbols_and_fraction_rule() {
|
fn math_display_list_paints_symbols_and_fraction_rule() {
|
||||||
let atom = crate::math::parse_math("x + \\frac{a}{b}");
|
let atom = crate::math::parse_math("x + \\frac{a}{b}");
|
||||||
|
|||||||
@@ -682,9 +682,35 @@ impl Page {
|
|||||||
list,
|
list,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
MathAtom::Limits { base, sub, sup } => {
|
||||||
|
let base_box = math::layout_math(base, font);
|
||||||
|
Self::paint_math(base, font, x, baseline, size, list);
|
||||||
|
let small = (size as f64 * 0.7) as i64;
|
||||||
|
if let Some(sup) = sup {
|
||||||
|
let sup_box = math::layout_math(sup, font);
|
||||||
|
Self::paint_math(
|
||||||
|
sup,
|
||||||
|
font,
|
||||||
|
x + (base_box.width - sup_box.width).max(0) / 2,
|
||||||
|
baseline - base_box.height - small,
|
||||||
|
small,
|
||||||
|
list,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if let Some(sub) = sub {
|
||||||
|
let sub_box = math::layout_math(sub, font);
|
||||||
|
Self::paint_math(
|
||||||
|
sub,
|
||||||
|
font,
|
||||||
|
x + (base_box.width - sub_box.width).max(0) / 2,
|
||||||
|
baseline + base_box.depth + small,
|
||||||
|
small,
|
||||||
|
list,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
MathAtom::Brace { base, .. }
|
MathAtom::Brace { base, .. }
|
||||||
| MathAtom::Smash { body: base, .. }
|
| MathAtom::Smash { body: base, .. }
|
||||||
| MathAtom::Limits { base, .. }
|
|
||||||
| MathAtom::Classed { body: base, .. } => {
|
| MathAtom::Classed { body: base, .. } => {
|
||||||
Self::paint_math(base, font, x, baseline, size, list)
|
Self::paint_math(base, font, x, baseline, size, list)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user