Paint overbrace and underbrace bars
This commit is contained in:
1 parent
3f1dd0c077
commit
17d41cbffd
2 files changed
+48
-3
No files matched your search
@@ -1838,6 +1838,28 @@ mod tests {
|
|||||||
assert!(svg.contains("font-family=\"monospace\">face3"));
|
assert!(svg.contains("font-family=\"monospace\">face3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overbrace_paints_a_brace_bar() {
|
||||||
|
let document = Document::new(
|
||||||
|
1000,
|
||||||
|
vec![Unit::math(
|
||||||
|
1,
|
||||||
|
crate::math::parse_math("\\overbrace{x}"),
|
||||||
|
&Cmr10Metrics::default(),
|
||||||
|
)],
|
||||||
|
);
|
||||||
|
let engine = Engine::layout(&document);
|
||||||
|
let list = engine.pages()[0].display_list();
|
||||||
|
let rules = list
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.filter(|item| matches!(item, DisplayItem::Rule { .. }))
|
||||||
|
.count();
|
||||||
|
assert!(
|
||||||
|
rules >= 3,
|
||||||
|
"expected a brace bar and two ticks, got {rules}"
|
||||||
|
);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn display_list_paints_limits_above_and_below() {
|
fn display_list_paints_limits_above_and_below() {
|
||||||
let document = Document::new(
|
let document = Document::new(
|
||||||
|
|||||||
@@ -709,9 +709,32 @@ impl Page {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MathAtom::Brace { base, .. }
|
MathAtom::Brace { base, above } => {
|
||||||
| MathAtom::Smash { body: base, .. }
|
let base_box = math::layout_math(base, font);
|
||||||
| MathAtom::Classed { body: base, .. } => {
|
Self::paint_math(base, font, x, baseline, size, list);
|
||||||
|
let thickness = (size / 8).max(1);
|
||||||
|
let y = if *above {
|
||||||
|
baseline - base_box.height - size / 2
|
||||||
|
} else {
|
||||||
|
baseline + base_box.depth + size / 2
|
||||||
|
};
|
||||||
|
list.push(DisplayItem::Rule {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width: base_box.width,
|
||||||
|
height: thickness,
|
||||||
|
});
|
||||||
|
let tick = size / 2;
|
||||||
|
for tick_x in [x, x + base_box.width - thickness] {
|
||||||
|
list.push(DisplayItem::Rule {
|
||||||
|
x: tick_x,
|
||||||
|
y: if *above { y + thickness } else { y - tick },
|
||||||
|
width: thickness,
|
||||||
|
height: tick,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MathAtom::Smash { body: base, .. } | MathAtom::Classed { body: base, .. } => {
|
||||||
Self::paint_math(base, font, x, baseline, size, list)
|
Self::paint_math(base, font, x, baseline, size, list)
|
||||||
}
|
}
|
||||||
MathAtom::Binomial {
|
MathAtom::Binomial {
|
||||||
|
|||||||
Reference in new issue
Block a user