Draw mathcal letters from cmsy10

This commit is contained in:
gloamxun committed 2026-10-24 03:49:55 +08:00
1 parent 66ceabad0e
commit e229809581
7 files changed
+114 -8

No files matched your search

+9 -3
View File
@@ -13,6 +13,7 @@ pub enum MathAlphabet {
Italic,
Sans,
Mono,
Calligraphic,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
@@ -305,6 +306,7 @@ pub(crate) fn alphabet_metrics(font: Cmr10Metrics, alphabet: MathAlphabet) -> Cm
MathAlphabet::Mono => {
Cmr10Metrics::for_paragraph_font(crate::paragraph::ParagraphFont::Mono)
}
MathAlphabet::Calligraphic => Cmr10Metrics::MathCalligraphic,
}
}
@@ -1344,6 +1346,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
"mathit" => Some(MathAlphabet::Italic),
"mathsf" => Some(MathAlphabet::Sans),
"mathtt" => Some(MathAlphabet::Mono),
"mathcal" => Some(MathAlphabet::Calligraphic),
_ => None,
};
match alphabet {
@@ -1557,12 +1560,15 @@ mod tests {
}
#[test]
fn mathcal_keeps_character_widths() {
fn mathcal_uses_calligraphic_widths() {
let font = Cmr10Metrics::default();
let calligraphic = layout_math(&parse_math("\\mathcal{N}"), &font);
let upright = layout_math(&parse_math("\\mathrm{N}"), &font);
assert_eq!(calligraphic.width, upright.width);
assert_eq!(calligraphic.height, upright.height);
assert_ne!(calligraphic.width, upright.width);
assert_eq!(
calligraphic.width,
crate::cmr10::math_symbol_width('N').expect("cmsy has calligraphic capitals")
);
}
#[test]