Keep sum superscripts above the operator
Large-operator limits used the ordinary-base superscript gap, which could leave N just below the sum baseline. Use a negative gap for large operators so both limits straddle the operator, and add a unit test asserting the subscript is below and the superscript above the base within 12pt. Test count is 1080.
This commit is contained in:
1 parent
02742d201f
commit
676eb7f323
6 files changed
+41
-8
No files matched your search
@@ -3912,6 +3912,34 @@ mod tagged_equation_tests {
|
||||
assert_eq!(tagged.height, plain.height.max(7 * 65_536));
|
||||
assert_eq!(tagged.depth, plain.depth.max(2 * 65_536));
|
||||
}
|
||||
#[test]
|
||||
fn display_sum_limits_sit_close_to_the_operator() {
|
||||
let atom = parse_math(r"\sum_{i=1}^{N}");
|
||||
let unit = crate::Unit::math(1, atom, &Cmr10Metrics::default());
|
||||
let document = crate::Document::new(700 * 65_536, vec![unit]);
|
||||
let engine = crate::Engine::layout(&document);
|
||||
let display = engine.pages()[0].display_list();
|
||||
let find = |text: &str| {
|
||||
display
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
crate::render::DisplayItem::Text { text: value, y, .. } if value == text => {
|
||||
Some(*y)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(|| panic!("no {text} glyph"))
|
||||
};
|
||||
let base = find("∑");
|
||||
let sub = find("i");
|
||||
let sup = find("N");
|
||||
assert!(sub > base, "subscript {sub} above base {base}");
|
||||
assert!(sup < base, "superscript {sup} below base {base}");
|
||||
let gap = (sub - base) as f64 / 65_536.0;
|
||||
assert!(gap < 12.0, "sum limit gap {gap} pt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whitespace_before_a_script_still_attaches() {
|
||||
let atom = parse_math(r"\alpha _{i}");
|
||||
|
||||
@@ -1591,11 +1591,16 @@ impl Page {
|
||||
let small = (size as f64 * 0.7) as i64;
|
||||
if let Some(sup) = sup {
|
||||
let sup_box = math::script_metrics(math::layout_math(sup, font));
|
||||
let sup_gap = if Self::large_operator(base) {
|
||||
-96_993
|
||||
} else {
|
||||
96_993
|
||||
};
|
||||
Self::paint_math(
|
||||
sup,
|
||||
font,
|
||||
x + (base_box.width - sup_box.width).max(0) / 2,
|
||||
baseline - base_box.height - sup_box.depth + 96_993,
|
||||
baseline - base_box.height - sup_box.depth + sup_gap,
|
||||
small,
|
||||
list,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user