Check stacked limits against pdfLaTeX
This commit is contained in:
1 parent
52a74755f7
commit
569160f805
6 files changed
+107
-13
No files matched your search
@@ -896,6 +896,33 @@ fn math_environment(chars: &[char], index: usize) -> Option<(MathAtom, usize)> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Scale a math box to TeX's 70% script size.
|
||||
pub(crate) fn script_metrics(box_: MathBox) -> MathBox {
|
||||
MathBox {
|
||||
width: box_.width * 7 / 10,
|
||||
height: box_.height * 7 / 10,
|
||||
depth: box_.depth * 7 / 10,
|
||||
}
|
||||
}
|
||||
|
||||
/// The glyph depth TeX would use for a base, without the 2pt floor that
|
||||
/// ordinary math boxes apply for visual spacing.
|
||||
pub(crate) fn intrinsic_depth(atom: &MathAtom, font: &Cmr10Metrics) -> i64 {
|
||||
match atom {
|
||||
MathAtom::Symbol(character) => font.depth(*character).max(0),
|
||||
MathAtom::Row(atoms) => atoms
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|atom| intrinsic_depth(atom, font))
|
||||
.find(|depth| *depth > 0)
|
||||
.unwrap_or(0),
|
||||
MathAtom::Classed { body, .. } => intrinsic_depth(body, font),
|
||||
MathAtom::Script { base, .. } => intrinsic_depth(base, font),
|
||||
MathAtom::Limits { base, .. } => intrinsic_depth(base, font),
|
||||
_ => layout_math(atom, font).depth,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
||||
match atom {
|
||||
MathAtom::Symbol(character) => {
|
||||
@@ -1053,15 +1080,25 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
||||
}
|
||||
MathAtom::Limits { base, sub, sup } => {
|
||||
let base = layout_math(base, font);
|
||||
let sub = sub.as_ref().map(|atom| layout_math(atom, font));
|
||||
let sup = sup.as_ref().map(|atom| layout_math(atom, font));
|
||||
let sub = sub
|
||||
.as_ref()
|
||||
.map(|atom| script_metrics(layout_math(atom, font)));
|
||||
let sup = sup
|
||||
.as_ref()
|
||||
.map(|atom| script_metrics(layout_math(atom, font)));
|
||||
MathBox {
|
||||
width: base
|
||||
.width
|
||||
.max(sub.as_ref().map_or(0, |item| item.width))
|
||||
.max(sup.as_ref().map_or(0, |item| item.width)),
|
||||
height: base.height + sup.as_ref().map_or(0, |item| item.height + 65_536),
|
||||
depth: base.depth + sub.as_ref().map_or(0, |item| item.height + 65_536),
|
||||
height: base.height
|
||||
+ sup
|
||||
.as_ref()
|
||||
.map_or(0, |item| item.height + item.depth + 65_536),
|
||||
depth: base.depth
|
||||
+ sub
|
||||
.as_ref()
|
||||
.map_or(0, |item| item.height + item.depth + 65_536),
|
||||
}
|
||||
}
|
||||
MathAtom::Classed { body, .. } => layout_math(body, font),
|
||||
|
||||
@@ -1232,23 +1232,28 @@ impl Page {
|
||||
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);
|
||||
let sup_box = math::script_metrics(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,
|
||||
baseline - base_box.height - sup_box.depth + 96_993,
|
||||
small,
|
||||
list,
|
||||
);
|
||||
}
|
||||
if let Some(sub) = sub {
|
||||
let sub_box = math::layout_math(sub, font);
|
||||
let sub_box = math::script_metrics(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,
|
||||
baseline
|
||||
+ math::intrinsic_depth(base, font)
|
||||
+ 131_072
|
||||
+ sub_box.height
|
||||
+ 65_536
|
||||
+ 46_531,
|
||||
small,
|
||||
list,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user