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),
|
||||
|
||||
Reference in new issue
Block a user