Resolve imported PDF Type 1 device fonts in native previews

This commit is contained in:
gloamxun committed 2026-11-28 04:08:05 +08:00
1 parent c0970bdbf6
commit b640b26eff
12 files changed
+586 -106

No files matched your search

+65
View File
@@ -1888,6 +1888,71 @@ fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
fs::remove_dir_all(root).unwrap();
}
#[test]
fn imported_device_type1_tracks_the_selected_pages_local_outline() {
let root = directory("imported-device-type1").canonicalize().unwrap();
let fonts = root.join("fonts");
fs::create_dir(&fonts).unwrap();
let regular = fonts.join("cmr10.pfb");
let other = fonts.join("cmtt10.pfb");
let original = include_bytes!("../assets/fonts/cmr10.pfb");
fs::write(&regular, original).unwrap();
fs::write(&other, include_bytes!("../assets/fonts/cmtt10.pfb")).unwrap();
fs::write(fonts.join("pdftex.map"), b"cmr10 CMR10 4\ncmtt10 CMTT10 4\n").unwrap();
let mut job = request(&root);
for kind in [ResourceKind::Map, ResourceKind::Type1] {
job.world.paths.insert(kind, vec![SearchPath::directory(&fonts, false)]);
}
fs::write(root.join("figure.tex"), br"\catcode123=1 \catcode125=2
\pdfoutput=1 \pdfcompresslevel=0 \pdfpagewidth=200pt \pdfpageheight=180pt
\font\roman=cmr10 \font\mono=cmtt10
\setbox0=\hbox{\roman ABC}
\pdfxform0
\setbox0=\hbox{\pdfrefxform\pdflastxform}
\pdfxform0
\shipout\hbox{\pdfrefxform\pdflastxform}
\shipout\hbox{\mono OUTSIDE THE SELECTED PAGE}
\end
").unwrap();
let mut figure = job.clone();
figure.input = root.join("figure.tex");
figure.output = PathBuf::from("figure.pdf");
NativeCompiler::default().compile(figure).unwrap();
fs::write(root.join("main.tex"), br"\catcode123=1 \catcode125=2
\pdfoutput=1 \pdfcompresslevel=0 \pdfpagewidth=240pt \pdfpageheight=200pt
\immediate\pdfximage page2 {figure.pdf}
\pdfximage width120pt page1 {figure.pdf}
\shipout\hbox{\vrule height10pt width10pt}
\shipout\hbox{\pdfrefximage\pdflastximage}
\end
").unwrap();
let compiler = NativeCompiler::default();
let first = compiler.compile(job.clone()).unwrap();
let svg = first.preview_since(None).unwrap().pages[1].svg.clone();
assert!(svg.contains(r#"viewBox="0 0 239.103 199.253""#), "{svg}");
let (_, drawing) = svg.split_once("</defs>").unwrap();
assert!(drawing.contains("<path") || drawing.contains("<use"), "{svg}");
assert!(first.resources.trace.reads.contains(&file_version(&regular).unwrap().unwrap()));
assert!(!first.resources.trace.reads.contains(&file_version(&other).unwrap().unwrap()));
let marker = b"/FontMatrix [0.001";
let index = original.windows(marker.len()).position(|value| value == marker).unwrap();
let mut changed = original.to_vec();
changed[index + marker.len() - 1] = b'2';
fs::write(&regular, changed).unwrap();
let second = compiler.compile(job.clone()).unwrap();
assert_eq!(first.pdf, second.pdf);
let delta = second.preview_since(Some(first.revision())).unwrap();
assert_eq!(delta.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [1]);
assert_ne!(svg, delta.pages[0].svg);
fs::remove_file(&regular).unwrap();
let missing = compiler.compile(job).unwrap();
assert_eq!(first.pdf, missing.pdf);
assert!(missing.preview_since(None).unwrap_err().contains("actual device font"));
fs::remove_dir_all(root).unwrap();
}
#[test]
fn mapped_device_type1_uses_actual_preview_font_without_pdf_embedding() {
use texrra_tex_core::{native_font::NativeFontProgram, render::DisplayItem};