Render and embed TrueType fonts selected by pdfTeX maps
This commit is contained in:
1 parent
aa780a800b
commit
46ef76f890
9 files changed
+570
-36
No files matched your search
@@ -1888,6 +1888,77 @@ fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
|
||||
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};
|
||||
|
||||
let root = directory("mapped-truetype").canonicalize().unwrap();
|
||||
let outline = root.join("face.ttf");
|
||||
let map = root.join("pdftex.map");
|
||||
let program = include_bytes!("../assets/fonts-subset/LiberationSerif-Regular.ttf");
|
||||
fs::write(&outline, program).unwrap();
|
||||
fs::write(&map, b"cmr10 LiberationSerif <<face.ttf\n").unwrap();
|
||||
fs::write(
|
||||
root.join("main.tex"),
|
||||
br"\catcode123=1 \catcode125=2 \pdfoutput=1 \pdfcompresslevel=0
|
||||
\font\mapped=cmr10 \shipout\hbox{\mapped AV}
|
||||
\end",
|
||||
)
|
||||
.unwrap();
|
||||
let mut job = request(&root);
|
||||
for kind in [ResourceKind::Map, ResourceKind::TrueType] {
|
||||
job.world
|
||||
.paths
|
||||
.insert(kind, vec![SearchPath::directory(&root, false)]);
|
||||
}
|
||||
let compiler = NativeCompiler::default();
|
||||
let first = compiler.compile(job.clone()).unwrap();
|
||||
let mut glyphs = String::new();
|
||||
for item in &first.pages[0].items {
|
||||
if let DisplayItem::NativeGlyph {
|
||||
slot,
|
||||
character,
|
||||
paint: Some(paint),
|
||||
..
|
||||
} = item
|
||||
{
|
||||
assert!(matches!(paint.program, NativeFontProgram::TrueType(_)));
|
||||
assert!(!paint.glyph_paths[slot].is_empty());
|
||||
glyphs.push(*character);
|
||||
}
|
||||
}
|
||||
assert_eq!(glyphs, "AV");
|
||||
for path in [&map, &outline] {
|
||||
assert!(
|
||||
first
|
||||
.resources
|
||||
.trace
|
||||
.reads
|
||||
.contains(&file_version(path).unwrap().unwrap())
|
||||
);
|
||||
}
|
||||
let pdf = lopdf::Document::load_mem(first.pdf.as_deref().unwrap()).unwrap();
|
||||
let font = pdf
|
||||
.objects
|
||||
.values()
|
||||
.find_map(|object| {
|
||||
let dict = object.as_dict().ok()?;
|
||||
(dict.get(b"Subtype").ok()?.as_name().ok()? == b"TrueType").then_some(dict)
|
||||
})
|
||||
.unwrap();
|
||||
let descriptor = font.get(b"FontDescriptor").unwrap().as_reference().unwrap();
|
||||
let descriptor = pdf.get_dictionary(descriptor).unwrap();
|
||||
let font_file = descriptor.get(b"FontFile2").unwrap().as_reference().unwrap();
|
||||
let embedded = pdf.get_object(font_file).unwrap().as_stream().unwrap();
|
||||
assert_eq!(embedded.content, program);
|
||||
|
||||
fs::remove_file(&outline).unwrap();
|
||||
let error = compiler.compile_detailed(job).err().unwrap().error.to_string();
|
||||
assert!(error.contains("face.ttf"), "{error}");
|
||||
assert!(Arc::ptr_eq(&first, &compiler.latest().unwrap()));
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loaded_format_uses_current_letterspace_font_programs() {
|
||||
use texrra_tex_core::render::DisplayItem;
|
||||
|
||||
Reference in new issue
Block a user