Draw negated math with a diagonal rule
This commit is contained in:
1 parent
f88fa7fd9d
commit
7376acffb2
2 files changed
+87
-1
No files matched your search
@@ -80,6 +80,22 @@ fn page_content(list: &DisplayList, height: i64, image_names: &BTreeMap<usize, S
|
|||||||
pt(*rule_height)
|
pt(*rule_height)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
DisplayItem::Line {
|
||||||
|
x1,
|
||||||
|
y1,
|
||||||
|
x2,
|
||||||
|
y2,
|
||||||
|
width: line_width,
|
||||||
|
} => {
|
||||||
|
content.push_str(&format!(
|
||||||
|
"{} w {} {} m {} {} l S\n",
|
||||||
|
pt(*line_width),
|
||||||
|
pt(*x1),
|
||||||
|
pt(height - *y1),
|
||||||
|
pt(*x2),
|
||||||
|
pt(height - *y2)
|
||||||
|
));
|
||||||
|
}
|
||||||
DisplayItem::Image {
|
DisplayItem::Image {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ pub enum DisplayItem {
|
|||||||
width: i64,
|
width: i64,
|
||||||
height: i64,
|
height: i64,
|
||||||
},
|
},
|
||||||
|
Line {
|
||||||
|
x1: i64,
|
||||||
|
y1: i64,
|
||||||
|
x2: i64,
|
||||||
|
y2: i64,
|
||||||
|
width: i64,
|
||||||
|
},
|
||||||
Image {
|
Image {
|
||||||
x: i64,
|
x: i64,
|
||||||
y: i64,
|
y: i64,
|
||||||
@@ -105,6 +112,12 @@ impl DisplayList {
|
|||||||
*x += dx;
|
*x += dx;
|
||||||
*y += dy;
|
*y += dy;
|
||||||
}
|
}
|
||||||
|
DisplayItem::Line { x1, y1, x2, y2, .. } => {
|
||||||
|
*x1 += dx;
|
||||||
|
*y1 += dy;
|
||||||
|
*x2 += dx;
|
||||||
|
*y2 += dy;
|
||||||
|
}
|
||||||
DisplayItem::Image { x, y, .. } | DisplayItem::Link { x, y, .. } => {
|
DisplayItem::Image { x, y, .. } | DisplayItem::Link { x, y, .. } => {
|
||||||
*x += dx;
|
*x += dx;
|
||||||
*y += dy;
|
*y += dy;
|
||||||
@@ -190,6 +203,22 @@ impl DisplayList {
|
|||||||
escape(content)
|
escape(content)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
DisplayItem::Line {
|
||||||
|
x1,
|
||||||
|
y1,
|
||||||
|
x2,
|
||||||
|
y2,
|
||||||
|
width,
|
||||||
|
} => {
|
||||||
|
let x1 = *x1 as f64 / 65_536.0;
|
||||||
|
let y1 = *y1 as f64 / 65_536.0;
|
||||||
|
let x2 = *x2 as f64 / 65_536.0;
|
||||||
|
let y2 = *y2 as f64 / 65_536.0;
|
||||||
|
let width = *width as f64 / 65_536.0;
|
||||||
|
out.push_str(&format!(
|
||||||
|
"<line x1=\"{x1:.3}\" y1=\"{y1:.3}\" x2=\"{x2:.3}\" y2=\"{y2:.3}\" stroke=\"#000000\" stroke-width=\"{width:.3}\"/>\n"
|
||||||
|
));
|
||||||
|
}
|
||||||
DisplayItem::Image {
|
DisplayItem::Image {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@@ -641,7 +670,7 @@ impl Page {
|
|||||||
text: accent.to_string(),
|
text: accent.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
MathAtom::Underline { base } | MathAtom::Negated { base } => {
|
MathAtom::Underline { base } => {
|
||||||
let base_box = math::layout_math(base, font);
|
let base_box = math::layout_math(base, font);
|
||||||
Self::paint_math(base, font, x, baseline, size, list);
|
Self::paint_math(base, font, x, baseline, size, list);
|
||||||
list.push(DisplayItem::Rule {
|
list.push(DisplayItem::Rule {
|
||||||
@@ -651,6 +680,17 @@ impl Page {
|
|||||||
height: 26_214,
|
height: 26_214,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
MathAtom::Negated { base } => {
|
||||||
|
let base_box = math::layout_math(base, font);
|
||||||
|
Self::paint_math(base, font, x, baseline, size, list);
|
||||||
|
list.push(DisplayItem::Line {
|
||||||
|
x1: x,
|
||||||
|
y1: baseline + base_box.depth,
|
||||||
|
x2: x + base_box.width,
|
||||||
|
y2: baseline - base_box.height,
|
||||||
|
width: 26_214,
|
||||||
|
});
|
||||||
|
}
|
||||||
MathAtom::Boxed { body } => {
|
MathAtom::Boxed { body } => {
|
||||||
let body_box = math::layout_math(body, font);
|
let body_box = math::layout_math(body, font);
|
||||||
Self::paint_math(body, font, x + 65_536, baseline, size, list);
|
Self::paint_math(body, font, x + 65_536, baseline, size, list);
|
||||||
@@ -817,3 +857,33 @@ impl Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn negated_math_draws_a_diagonal_line() {
|
||||||
|
let mut items = Vec::new();
|
||||||
|
Page::paint_math(
|
||||||
|
&MathAtom::Negated {
|
||||||
|
base: Box::new(MathAtom::Symbol('=')),
|
||||||
|
},
|
||||||
|
&Cmr10Metrics::default(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
10 * 65_536,
|
||||||
|
&mut items,
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
items
|
||||||
|
.iter()
|
||||||
|
.any(|item| matches!(item, DisplayItem::Line { .. }))
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!items
|
||||||
|
.iter()
|
||||||
|
.any(|item| matches!(item, DisplayItem::Rule { .. }))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user