Number equation environments in route-D
This commit is contained in:
1 parent
3cbfdabe03
commit
bb897411d0
5 files changed
+207
-6
No files matched your search
@@ -53,6 +53,10 @@ pub enum MathAtom {
|
||||
vertical: bool,
|
||||
},
|
||||
Strut,
|
||||
Tagged {
|
||||
body: Box<MathAtom>,
|
||||
tag: String,
|
||||
},
|
||||
Limits {
|
||||
base: Box<MathAtom>,
|
||||
sub: Option<Box<MathAtom>>,
|
||||
@@ -584,6 +588,18 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
||||
depth: base_box.depth + 2 * 65_536,
|
||||
}
|
||||
}
|
||||
MathAtom::Tagged { body, tag } => {
|
||||
let body_box = layout_math(body, font);
|
||||
let tag_width: i64 = tag
|
||||
.chars()
|
||||
.map(|character| Cmr10Metrics::Roman.width(character))
|
||||
.sum();
|
||||
MathBox {
|
||||
width: body_box.width.max(tag_width),
|
||||
height: body_box.height.max(7 * 65_536),
|
||||
depth: body_box.depth.max(2 * 65_536),
|
||||
}
|
||||
}
|
||||
MathAtom::Script { base, sub, sup } => {
|
||||
let base_box = layout_math(base, font);
|
||||
let sub_box = sub.as_deref().map(|atom| layout_math(atom, font));
|
||||
@@ -2092,3 +2108,32 @@ mod spacing_class_tests {
|
||||
assert_eq!(width(r"\sum x") - sum - font.width('x'), 3 * 65_536 / 18);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tagged_equation_tests {
|
||||
use super::*;
|
||||
use crate::cmr10::Cmr10Metrics;
|
||||
|
||||
fn roman_width(text: &str) -> i64 {
|
||||
text.chars()
|
||||
.map(|character| Cmr10Metrics::Roman.width(character))
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tagged_formula_reserves_room_for_the_tag() {
|
||||
let font = Cmr10Metrics::Math;
|
||||
let body = parse_math("x");
|
||||
let plain = layout_math(&body, &font);
|
||||
let tagged = layout_math(
|
||||
&MathAtom::Tagged {
|
||||
body: Box::new(body),
|
||||
tag: "(12)".to_string(),
|
||||
},
|
||||
&font,
|
||||
);
|
||||
assert_eq!(tagged.width, plain.width.max(roman_width("(12)")));
|
||||
assert_eq!(tagged.height, plain.height.max(7 * 65_536));
|
||||
assert_eq!(tagged.depth, plain.depth.max(2 * 65_536));
|
||||
}
|
||||
}
|
||||
@@ -671,6 +671,26 @@ impl Page {
|
||||
cursor += width;
|
||||
}
|
||||
}
|
||||
MathAtom::Tagged { body, tag } => {
|
||||
let body_box = math::layout_math(body, font);
|
||||
Self::paint_math(body, font, x, baseline, size, list);
|
||||
let tag_width: i64 = tag
|
||||
.chars()
|
||||
.map(|character| Cmr10Metrics::Roman.width(character))
|
||||
.sum();
|
||||
let mut pen = x + body_box.width.max(tag_width) - tag_width;
|
||||
for character in tag.chars() {
|
||||
let width = Cmr10Metrics::Roman.width(character);
|
||||
list.push(DisplayItem::Text {
|
||||
font: FontFace::Roman,
|
||||
x: pen,
|
||||
y: baseline,
|
||||
size,
|
||||
text: character.to_string(),
|
||||
});
|
||||
pen += width;
|
||||
}
|
||||
}
|
||||
MathAtom::Script { base, sub, sup } => {
|
||||
let base_box = math::layout_math(base, font);
|
||||
Self::paint_math(base, font, x, baseline, size, list);
|
||||
|
||||
Reference in new issue
Block a user