Paint sqrt degrees before the radical
This commit is contained in:
1 parent
17d41cbffd
commit
0446a35b8c
2 files changed
+51
-4
No files matched your search
@@ -1838,6 +1838,46 @@ mod tests {
|
||||
assert!(svg.contains("font-family=\"monospace\">face3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sqrt_degree_is_painted_before_the_radical() {
|
||||
let document = Document::new(
|
||||
1000,
|
||||
vec![Unit::math(
|
||||
1,
|
||||
crate::math::parse_math("\\sqrt[3]{x}"),
|
||||
&Cmr10Metrics::default(),
|
||||
)],
|
||||
);
|
||||
let engine = Engine::layout(&document);
|
||||
let list = engine.pages()[0].display_list();
|
||||
let texts: Vec<_> = list
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
DisplayItem::Text { text, .. } => Some(text.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert!(texts.contains(&"3"));
|
||||
assert!(texts.contains(&"x"));
|
||||
let degree_x = list
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
DisplayItem::Text { text, x, .. } if text == "3" => Some(*x),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
let radical_x = list
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
DisplayItem::Text { text, x, .. } if text == "√" => Some(*x),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
assert!(radical_x > degree_x);
|
||||
}
|
||||
#[test]
|
||||
fn overbrace_paints_a_brace_bar() {
|
||||
let document = Document::new(
|
||||
|
||||
@@ -574,18 +574,25 @@ impl Page {
|
||||
height: 26_214,
|
||||
});
|
||||
}
|
||||
MathAtom::Sqrt { radicand, .. } => {
|
||||
MathAtom::Sqrt { radicand, degree } => {
|
||||
let box_ = math::layout_math(radicand, font);
|
||||
let small = (size as f64 * 0.7) as i64;
|
||||
let mut radical_x = x;
|
||||
if let Some(degree) = degree {
|
||||
let degree_box = math::layout_math(degree, font);
|
||||
Self::paint_math(degree, font, x, baseline - box_.height - small, small, list);
|
||||
radical_x += degree_box.width;
|
||||
}
|
||||
list.push(DisplayItem::Text {
|
||||
font: FontFace::Roman,
|
||||
x,
|
||||
x: radical_x,
|
||||
y: baseline,
|
||||
size,
|
||||
text: "√".to_string(),
|
||||
});
|
||||
Self::paint_math(radicand, font, x + 4 * 65_536, baseline, size, list);
|
||||
Self::paint_math(radicand, font, radical_x + 4 * 65_536, baseline, size, list);
|
||||
list.push(DisplayItem::Rule {
|
||||
x: x + 4 * 65_536,
|
||||
x: radical_x + 4 * 65_536,
|
||||
y: baseline - box_.height - 65_536,
|
||||
width: box_.width,
|
||||
height: 26_214,
|
||||
|
||||
Reference in new issue
Block a user