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

+31 -2
View File
@@ -516,7 +516,9 @@ fn write_pdf(
.iter()
.filter_map(|character| {
let code = if slot == FontFace::MathSymbol as usize {
crate::cmr10::math_symbol_slot(*character)
crate::cmr10::math_symbol_slot(*character).or_else(|| {
character.is_ascii_uppercase().then_some(*character as u8)
})
} else {
crate::cmr10::math_extension_slot(*character)
};
@@ -568,7 +570,18 @@ fn write_pdf(
let mut next_code = first;
for code in first..=last {
let width = by_code.get(&code).map_or(0, |character| {
(metrics.width(*character) * 100 / 65_536) as i64
let width = match slot {
slot if slot == FontFace::MathSymbol as usize => {
crate::cmr10::math_symbol_width(*character)
.unwrap_or_else(|| metrics.width(*character))
}
slot if slot == FontFace::MathExtension as usize => {
crate::cmr10::math_extension_width(*character)
.unwrap_or_else(|| metrics.width(*character))
}
_ => metrics.width(*character),
};
(width * 100 / 65_536) as i64
});
widths.push(width.to_string());
let glyph = if slot == FontFace::MathSymbol as usize
@@ -924,6 +937,22 @@ mod type1_pdf_tests {
assert!(!text.contains("/BaseFont /CMR10"), "{text}");
}
#[test]
fn mathcal_letters_embed_cmsy10() {
let mut list = hello_list();
list.items[0] = DisplayItem::Text {
x: 0,
y: 800_000,
size: 655_360,
text: "A".to_string(),
font: FontFace::MathSymbol,
};
let pdf = write(&[list]);
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/BaseFont /CMSY10"), "{text}");
assert!(text.contains("(\\101)"), "{text}");
}
#[test]
fn math_symbols_embed_cmsy10() {
let mut list = hello_list();