Resolve pdfTeX SFD subfonts against actual TrueType cmaps

This commit is contained in:
gloamxun committed 2026-11-28 03:04:48 +08:00
1 parent fd5ab59f42
commit 868814288c
10 files changed
+481 -43

No files matched your search

+54
View File
@@ -1957,6 +1957,60 @@ fn mapped_opentype_cff_paints_reencoded_glyphs_and_embeds_the_original_table() {
fs::remove_dir_all(root).unwrap();
}
#[test]
fn mapped_truetype_sfd_selects_cmap_glyphs_and_tracks_the_definition() {
use texrra_tex_core::render::DisplayItem;
let root = directory("mapped-truetype-sfd").canonicalize().unwrap();
let sfd = root.join("glyphs.sfd");
let font = include_bytes!("../assets/fonts-subset/LiberationSerif-Regular.ttf");
let metrics = include_bytes!("../crates/texrra-tex-core/assets/cmr10.tfm");
fs::write(root.join("face.ttf"), font).unwrap();
fs::write(root.join("route00.tfm"), metrics).unwrap();
fs::write(root.join("pdftex.map"), b"% no default entry\n").unwrap();
fs::write(&sfd, b"# one subfont\n00 0x41: 0x56_0x57 \\\n 0x58\n").unwrap();
fs::write(
root.join("main.tex"),
br"\catcode123=1 \catcode125=2 \pdfoutput=1
\pdfmapline{+route@glyphs@ LiberationSerif PidEid=3, 1 <face.ttf}
\font\mapped=route00 \shipout\hbox{\mapped ABC}
\end",
)
.unwrap();
let mut job = request(&root);
for kind in [
ResourceKind::Map,
ResourceKind::TrueType,
ResourceKind::Tfm,
ResourceKind::Sfd,
] {
job.world
.paths
.insert(kind, vec![SearchPath::directory(&root, false)]);
}
let compiler = NativeCompiler::default();
let first = compiler.compile(job.clone()).unwrap();
let glyphs: String = first.pages[0].items.iter().filter_map(|item| {
match item {
DisplayItem::NativeGlyph { character, slot, paint: Some(paint), .. } => {
assert!(!paint.glyph_paths[slot].is_empty());
Some(*character)
}
_ => None,
}
}).collect();
assert_eq!(glyphs, "VWX");
assert!(
first.resources.trace.reads.contains(&file_version(&sfd).unwrap().unwrap())
);
fs::write(&sfd, b"00 255: 0x41_0x42\n").unwrap();
let error = compiler.compile_detailed(job).err().unwrap().error.to_string();
assert!(error.contains("glyphs.sfd") && error.contains("subfont slots exceed 255"), "{error}");
assert!(Arc::ptr_eq(&first, &compiler.latest().unwrap()));
fs::remove_dir_all(root).unwrap();
}
#[test]
fn mapped_truetype_paints_and_embeds_the_actual_font() {
use texrra_tex_core::{native_font::NativeFontProgram, render::DisplayItem};