Use CMEX size variants for big math delimiters
This commit is contained in:
1 parent
03afc828f3
commit
4c2aefd490
4 files changed
+148
-18
No files matched your search
@@ -4,7 +4,7 @@
|
||||
//! geometry the route-D page builder needs; token-to-atom conversion and the
|
||||
//! final painter arrive in later M4 slices.
|
||||
|
||||
use crate::cmr10::Cmr10Metrics;
|
||||
use crate::cmr10::{Cmr10Metrics, cmex_delimiter};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum MathAtom {
|
||||
@@ -375,20 +375,30 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
||||
}
|
||||
MathAtom::Classed { body, .. } => layout_math(body, font),
|
||||
MathAtom::SizedDelimiter { delimiter, size } => {
|
||||
let extent = match *size {
|
||||
1 => 8 * 65_536,
|
||||
2 => 11 * 65_536,
|
||||
3 => 14 * 65_536,
|
||||
_ => 17 * 65_536,
|
||||
};
|
||||
MathBox {
|
||||
width: if *delimiter == '.' {
|
||||
0
|
||||
} else {
|
||||
(extent as f64 * 0.35) as i64
|
||||
},
|
||||
height: extent,
|
||||
depth: 2 * 65_536,
|
||||
if *delimiter == '.' {
|
||||
MathBox {
|
||||
width: 0,
|
||||
height: 0,
|
||||
depth: 0,
|
||||
}
|
||||
} else if let Some((width, height, depth)) = cmex_delimiter(*delimiter, *size) {
|
||||
MathBox {
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
}
|
||||
} else {
|
||||
let extent = match *size {
|
||||
1 => 8 * 65_536,
|
||||
2 => 11 * 65_536,
|
||||
3 => 14 * 65_536,
|
||||
_ => 17 * 65_536,
|
||||
};
|
||||
MathBox {
|
||||
width: (extent as f64 * 0.35) as i64,
|
||||
height: extent,
|
||||
depth: 2 * 65_536,
|
||||
}
|
||||
}
|
||||
}
|
||||
MathAtom::StackLines(rows) => {
|
||||
@@ -1852,3 +1862,33 @@ mod cmsy_symbol_tests {
|
||||
assert_ne!(laid_out.width, Cmr10Metrics::Roman.width('\u{00D7}'));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod cmex_size_tests {
|
||||
use super::*;
|
||||
use crate::cmr10::{Cmr10Metrics, cmex_delimiter};
|
||||
|
||||
#[test]
|
||||
fn big_delimiters_use_cmex_metrics() {
|
||||
let font = Cmr10Metrics::Math;
|
||||
let big = layout_math(&parse_math(r"\big("), &font);
|
||||
let (width, height, depth) = cmex_delimiter('(', 1).expect("cmex big paren");
|
||||
assert_eq!(big.width, width);
|
||||
assert_eq!(big.height, height);
|
||||
assert_eq!(big.depth, depth);
|
||||
let plain = layout_math(&parse_math("("), &font);
|
||||
assert!(big.height > plain.height);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bigger_delimiters_pick_larger_cmex_variants() {
|
||||
let font = Cmr10Metrics::Math;
|
||||
let big = layout_math(&parse_math(r"\Big["), &font);
|
||||
let bigg = layout_math(&parse_math(r"\bigg["), &font);
|
||||
let slot_big = cmex_delimiter('[', 2).expect("cmex Big bracket");
|
||||
let slot_bigg = cmex_delimiter('[', 3).expect("cmex bigg bracket");
|
||||
assert_eq!(big.width, slot_big.0);
|
||||
assert_eq!(bigg.width, slot_bigg.0);
|
||||
assert!(bigg.height > big.height);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user