Select real Computer Modern small caps

Add the cmcsc10 face for \scshape and \textsc, including its Type1 outline, and compose the sc shape with the surrounding family and series. Bold small caps substitute cmbx10 and a later shape command wins, matching NFSS.
This commit is contained in:
gloamxun committed 2026-10-24 12:52:15 +08:00
1 parent 9140990a7d
commit e303f7852f
11 files changed
+150 -13

No files matched your search

+30 -1
View File
@@ -16,7 +16,7 @@ use crate::cmr10::Cmr10Metrics;
use crate::render::{DisplayItem, DisplayList, FontFace};
use crate::type1::Type1Font;
const FACE_COUNT: usize = 13;
const FACE_COUNT: usize = 14;
fn deflate(bytes: &[u8]) -> Vec<u8> {
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default());
@@ -110,6 +110,12 @@ static FULL_FACES: [PdfFace; FACE_COUNT] = [
italic_angle: -12,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset/LiberationSerif-Regular.ttf"),
base: "LiberationSerif-SmallCaps",
italic_angle: 0,
font: OnceLock::new(),
},
];
static MIN_FACES: [PdfFace; FACE_COUNT] = [
@@ -191,6 +197,12 @@ static MIN_FACES: [PdfFace; FACE_COUNT] = [
italic_angle: -12,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationSerif-Regular.ttf"),
base: "LiberationSerif-SmallCaps",
italic_angle: 0,
font: OnceLock::new(),
},
];
fn minimal_text_char(ch: char) -> bool {
@@ -326,6 +338,7 @@ fn font_resource(font: FontFace) -> &'static str {
FontFace::MathFraktur => "F11",
FontFace::SansBold => "F12",
FontFace::SansItalic => "F13",
FontFace::SmallCaps => "F14",
}
}
@@ -354,6 +367,7 @@ fn type1_bytes(slot: usize) -> Option<&'static [u8]> {
Some(include_bytes!("../../../assets/fonts/eufm10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmssbx10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmssi10.pfb")),
Some(include_bytes!("../../../assets/fonts/cmcsc10.pfb")),
];
PFBS[slot]
}
@@ -989,6 +1003,21 @@ mod type1_pdf_tests {
assert!(text.contains("/BaseFont /CMSSI10"), "{text}");
}
#[test]
fn small_caps_text_embeds_cmcsc10() {
let mut list = hello_list();
list.items[0] = DisplayItem::Text {
x: 0,
y: 800_000,
size: 655_360,
text: "Small".to_string(),
font: FontFace::SmallCaps,
};
let pdf = write(&[list]);
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/BaseFont /CMCSC10"), "{text}");
}
#[test]
fn math_italic_text_embeds_cmmi10() {
let mut list = hello_list();