Read mapped Type 1 fonts from PFA programs
This commit is contained in:
1 parent
868814288c
commit
60d67bbb7b
7 files changed
+211
-18
No files matched your search
@@ -1888,6 +1888,66 @@ fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mapped_type1_pfa_embeds_original_cipher_and_tracks_its_input() {
|
||||
use std::io::Write;
|
||||
use texrra_tex_core::{native_font::NativeFontProgram, render::DisplayItem, type1::Type1Font};
|
||||
|
||||
let root = directory("mapped-type1-pfa").canonicalize().unwrap();
|
||||
let outline = root.join("face.pfa");
|
||||
let font = Type1Font::from_pfb(include_bytes!("../assets/fonts/cmr10.pfb")).unwrap();
|
||||
let cipher = &font.program[font.length1..font.length1 + font.length2];
|
||||
let mut pfa = font.program[..font.length1].to_vec();
|
||||
for line in cipher.chunks(32) {
|
||||
for byte in line {
|
||||
write!(pfa, "{byte:02X}").unwrap();
|
||||
}
|
||||
pfa.extend_from_slice(b"\r\n");
|
||||
}
|
||||
pfa.extend_from_slice(&font.program[font.length1 + font.length2..]);
|
||||
fs::write(&outline, &pfa).unwrap();
|
||||
fs::write(root.join("pdftex.map"), b"cmr10 CMR10 <<face.pfa\n").unwrap();
|
||||
fs::write(
|
||||
root.join("main.tex"),
|
||||
br"\catcode123=1 \catcode125=2 \pdfoutput=1 \pdfcompresslevel=0
|
||||
\font\mapped=cmr10 \shipout\hbox{\mapped ABC}
|
||||
\end",
|
||||
)
|
||||
.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 first = compiler.compile(job.clone()).unwrap();
|
||||
let glyphs: String = first.pages[0].items.iter().filter_map(|item| match item {
|
||||
DisplayItem::NativeGlyph { slot, character, paint: Some(paint), .. } => {
|
||||
assert!(matches!(paint.program, NativeFontProgram::Type1(_)));
|
||||
assert!(!paint.glyph_paths[slot].is_empty());
|
||||
Some(*character)
|
||||
}
|
||||
_ => None,
|
||||
}).collect();
|
||||
assert_eq!(glyphs, "ABC");
|
||||
assert!(first.resources.trace.reads.contains(&file_version(&outline).unwrap().unwrap()));
|
||||
|
||||
let pdf = lopdf::Document::load_mem(first.pdf.as_deref().unwrap()).unwrap();
|
||||
let embedded = pdf.objects.values().filter_map(|object| object.as_stream().ok())
|
||||
.find(|stream| stream.dict.has(b"Length2")).unwrap();
|
||||
let length1 = embedded.dict.get(b"Length1").unwrap().as_i64().unwrap() as usize;
|
||||
let length2 = embedded.dict.get(b"Length2").unwrap().as_i64().unwrap() as usize;
|
||||
assert_eq!(&embedded.content[length1..length1 + length2], cipher);
|
||||
|
||||
pfa[font.length1 + 6] = b'Z';
|
||||
fs::write(&outline, pfa).unwrap();
|
||||
let error = compiler.compile_detailed(job).err().unwrap().error.to_string();
|
||||
assert!(error.contains("face.pfa") && error.contains("hexadecimal"), "{error}");
|
||||
assert!(Arc::ptr_eq(&first, &compiler.latest().unwrap()));
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mapped_opentype_cff_paints_reencoded_glyphs_and_embeds_the_original_table() {
|
||||
use texrra_tex_core::{native_font::NativeFontProgram, render::DisplayItem};
|
||||
|
||||
Reference in new issue
Block a user