Support unembedded pdfTeX Type 1 device fonts in export and preview

This commit is contained in:
gloamxun committed 2026-11-28 03:44:29 +08:00
1 parent 60d67bbb7b
commit c0970bdbf6
10 files changed
+466 -34

No files matched your search

+56
View File
@@ -1888,6 +1888,62 @@ fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
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};
let root = directory("mapped-device-type1").canonicalize().unwrap();
let outline = root.join("CMR10.pfb");
let source = root.join("main.tex");
fs::write(&outline, include_bytes!("../assets/fonts/cmr10.pfb")).unwrap();
fs::write(root.join("pdftex.map"), b"cmr10 CMR10 4\n").unwrap();
let body = r"\catcode123=1 \catcode125=2 \pdfoutput=1 \pdfcompresslevel=0
\font\f=cmr10 \shipout\hbox{\f ABC}";
fs::write(&source, format!("{body}\\end\n")).unwrap();
let mut job = request(&root);
for kind in [ResourceKind::Map, ResourceKind::Type1] {
job.world.paths.insert(kind, vec![SearchPath::directory(&root, false)]);
}
let compiler = NativeCompiler::default();
let native = compiler.compile(job.clone()).unwrap();
let first = native.preview_since(None).unwrap();
assert!(first.pages[0].svg.contains("<path"));
assert!(native.resources.trace.reads.contains(&file_version(&outline).unwrap().unwrap()));
assert!(native.pages[0].items.iter().any(|item| matches!(item,
DisplayItem::NativeGlyph { paint: Some(paint), .. }
if matches!(&paint.program, NativeFontProgram::DeviceType1(font) if font.name == "CMR10")
)));
fs::write(&source, format!("{body}\\shipout\\hbox{{\\pdfliteral direct {{q Q}}\\f ABC}}\\end\n")).unwrap();
let mixed = compiler.compile(job.clone()).unwrap();
assert!(mixed.pages[1].has_embedded_pdf());
let delta = mixed.preview_since(Some(native.revision())).unwrap();
assert_eq!(delta.pages.len(), 1);
assert_eq!(delta.pages[0].index, 1);
assert!(delta.pages[0].svg.contains("<path"));
let pdf = lopdf::Document::load_mem(mixed.pdf.as_deref().unwrap()).unwrap();
let descriptor = pdf.objects.values().filter_map(|object| object.as_dict().ok()).find(
|dict| dict.get(b"FontName").and_then(|name| name.as_name()).ok() == Some(b"CMR10"),
).unwrap();
assert!(!descriptor.has(b"FontFile"));
let updated_body = body.replace("ABC", "ADC");
fs::write(
&source,
format!("{updated_body}\\shipout\\hbox{{\\pdfliteral direct {{q Q}}\\f ABC}}\\end\n"),
).unwrap();
let edited = compiler.compile(job.clone()).unwrap();
let delta = edited.preview_since(Some(mixed.revision())).unwrap();
assert_eq!(delta.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [0]);
fs::remove_file(&outline).unwrap();
let missing = compiler.compile(job).unwrap();
assert!(missing.pdf.is_some());
let error = missing.preview_since(None).unwrap_err();
assert!(error.contains("actual device font CMR10"), "{error}");
fs::remove_dir_all(root).unwrap();
}
#[test]
fn mapped_type1_pfa_embeds_original_cipher_and_tracks_its_input() {
use std::io::Write;