Render Type1 map slant and extension in PDF and SVG

This commit is contained in:
gloamxun committed 2026-11-21 10:04:48 +08:00
1 parent 28dfba5a5e
commit 3caf1eced2
7 files changed
+274 -70

No files matched your search

@@ -358,3 +358,46 @@ fn font_map_file_binds_new_font_ids_and_locks_used_entries() {
}
fs::remove_dir_all(map).unwrap();
}
#[test]
fn pdf_and_svg_keep_distinct_transformations_of_the_same_type1_file() {
let mut files = Files::new(600);
let execution = native(
r#"\pdfcompresslevel=0
\pdfmapline{cmr10 CMR10 ".82 ExtendFont -.167 SlantFont" <cmr10.pfb}
\pdfmapline{cmr7 CMR10 ".167 SlantFont" <cmr10.pfb}
\font\combined=cmr10 \font\slanted=cmr7
\shipout\hbox{\combined A}
\shipout\hbox{\slanted A}
\end"#,
&mut files,
)
.unwrap();
let mut pages = execution.shipout_display_lists().unwrap();
resolve_native_fonts(&mut pages, &mut files).unwrap();
let svg = |page: usize| pages[page].try_to_svg().unwrap();
for (i, name) in ["CMR10-Slant_-167-Extend_820", "CMR10-Slant_167"].iter().enumerate() {
use texrra_tex_core::{render::DisplayItem, type1_outline::Type1Outlines};
let paint = pages[i].items.iter().find_map(|item| match item {
DisplayItem::NativeGlyph { paint, .. } => paint.as_deref(),
_ => None,
}).unwrap();
let NativeFontProgram::Type1(program) = &paint.program else {
panic!("expected transformed Type1 program");
};
assert_eq!(&program.name, name);
let expected = Type1Outlines::parse(program).unwrap().glyph_path("A").unwrap();
assert!(svg(i).contains(&expected));
}
let pdf = shipout_lists_to_native_pdf(&pages, execution.state.pdf_final_options()).unwrap();
let pdf = String::from_utf8_lossy(&pdf);
for (name, matrix) in [
("CMR10-Slant_-167-Extend_820", "[0.00082 0 -0.00013694 0.001 0 0]"),
("CMR10-Slant_167", "[0.001 0 0.000167 0.001 0 0]"),
] {
assert!(pdf.contains(&format!("/BaseFont /{name}")));
assert!(pdf.contains(&format!("/FontName /{name} def")));
assert!(pdf.contains(&format!("/FontMatrix {matrix}")));
}
assert_eq!(pdf.matches("/Type /FontDescriptor").count(), 2);
}