Draw big operators with cmex10 outlines

This commit is contained in:
gloamxun committed 2026-10-24 03:46:50 +08:00
1 parent 6446de6b6b
commit 66ceabad0e
7 files changed
+167 -28

No files matched your search

+56 -16
View File
@@ -152,6 +152,12 @@ impl Cmr10Metrics {
return width;
}
}
if let Some(slot) = math_extension_slot(character) {
let width = math_extension_metrics().width(char::from(slot));
if width > 0 {
return width;
}
}
}
let width = self.metrics().width(character);
if width > 0 { width } else { 327_680 }
@@ -168,6 +174,9 @@ impl Cmr10Metrics {
if let Some(slot) = math_symbol_slot(character) {
return math_symbol_metrics().height(char::from(slot));
}
if let Some(slot) = math_extension_slot(character) {
return math_extension_metrics().height(char::from(slot));
}
}
self.metrics().height(character)
}
@@ -183,6 +192,9 @@ impl Cmr10Metrics {
if let Some(slot) = math_symbol_slot(character) {
return math_symbol_metrics().depth(char::from(slot));
}
if let Some(slot) = math_extension_slot(character) {
return math_extension_metrics().depth(char::from(slot));
}
}
self.metrics().depth(character)
}
@@ -195,6 +207,9 @@ impl Cmr10Metrics {
if let Some(slot) = math_symbol_slot(character) {
return math_symbol_metrics().italic(char::from(slot));
}
if let Some(slot) = math_extension_slot(character) {
return math_extension_metrics().italic(char::from(slot));
}
}
self.metrics().italic(character)
}
@@ -234,28 +249,53 @@ impl Cmr10Metrics {
/// Metrics for a named Computer Modern extension big operator (`\sum` and friends).
pub fn cmex_operator(name: &str) -> Option<(i64, i64, i64)> {
let slot = match name {
"sum" => 'P',
"prod" => 'Q',
"coprod" => 'R',
"int" => 'S',
"oint" => 'T',
"bigcap" => 'U',
"bigcup" => 'V',
"bigsqcup" => 'W',
"bigvee" => 'X',
"bigwedge" => 'Y',
"bigodot" => 'Z',
"bigotimes" => '[',
"bigoplus" => '\\',
"biguplus" => ']',
"sum" => 80,
"prod" => 81,
"coprod" => 96,
"int" => 82,
"oint" => 72,
"bigcap" => 84,
"bigcup" => 83,
"bigsqcup" => 85,
"bigvee" => 87,
"bigwedge" => 86,
"bigodot" => 74,
"bigotimes" => 78,
"bigoplus" => 76,
"biguplus" => 85,
_ => return None,
};
let metrics = math_extension_metrics();
let width = metrics.width(slot);
let width = metrics.width(char::from(slot));
if width == 0 {
return None;
}
Some((width, metrics.height(slot), metrics.depth(slot)))
Some((
width,
metrics.height(char::from(slot)),
metrics.depth(char::from(slot)),
))
}
/// Map a Unicode n-ary operator to its slot in the bundled cmex10 font.
pub fn math_extension_slot(character: char) -> Option<u8> {
let slot = match character {
'\u{2211}' => 80, // \sum
'\u{220F}' => 81, // \prod
'\u{2210}' => 96, // \coprod
'\u{222B}' => 82, // \int
'\u{222E}' => 72, // \oint
'\u{22C2}' => 84, // \bigcap
'\u{22C3}' => 83, // \bigcup
'\u{2A06}' => 85, // \bigsqcup
'\u{22C1}' => 87, // \bigvee
'\u{22C0}' => 86, // \bigwedge
'\u{2A00}' => 74, // \bigodot
'\u{2A02}' => 78, // \bigotimes
'\u{2A01}' => 76, // \bigoplus
_ => return None,
};
Some(slot)
}
#[cfg(test)]