Share size-independent XDV Type 1 font dictionaries
This commit is contained in:
1 parent
01c6f1d4bd
commit
e72104eab3
4 files changed
+147
-11
No files matched your search
@@ -793,6 +793,75 @@ fn xetex_type1_widths_follow_the_encoded_glyph_program() {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xetex_type1_shares_the_font_dictionary_across_sizes_and_pages() {
|
||||
use lopdf::{Document, content::Content};
|
||||
use texrra_tex_core::execution::InputProfile;
|
||||
|
||||
let root = directory("xetex-type1-shared-face");
|
||||
let mut job = request(&root);
|
||||
job.input_profile = InputProfile::XeTeX;
|
||||
for kind in [ResourceKind::Encoding, ResourceKind::Map, ResourceKind::Tfm] {
|
||||
job.world.paths.entry(kind).or_default().insert(
|
||||
0, SearchPath::directory(root.clone(), false),
|
||||
);
|
||||
}
|
||||
fs::write(
|
||||
root.join("recoded.tfm"),
|
||||
include_bytes!("../crates/texrra-tex-core/assets/cmr10.tfm"),
|
||||
)
|
||||
.unwrap();
|
||||
let mut glyphs = [".notdef"; 256];
|
||||
glyphs[b'A' as usize] = "V";
|
||||
let encoding = format!("/ProbeVector [{}] def\n", glyphs.map(|glyph| format!("/{glyph}")).join(" "));
|
||||
fs::write(root.join("probe.enc"), encoding).unwrap();
|
||||
fs::write(
|
||||
root.join("pdftex.map"),
|
||||
"cmr10 CMR10 <cmr10.pfb\nrecoded CMR10 \"ProbeVector ReEncodeFont\" <probe.enc <cmr10.pfb\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
root.join("main.tex"),
|
||||
br"\catcode123=1 \catcode125=2
|
||||
\font\small=cmr10 at 10pt
|
||||
\font\large=cmr10 at 14pt
|
||||
\font\recoded=recoded
|
||||
\shipout\hbox{\small A\kern5pt\large W}
|
||||
\shipout\hbox{\large M\kern5pt\recoded A}
|
||||
\end",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let result = NativeCompiler::default().compile(job).unwrap();
|
||||
let pdf = Document::load_mem(result.pdf.as_deref().unwrap()).unwrap();
|
||||
let pages = pdf.get_pages();
|
||||
let content = Content::decode(&pdf.get_page_content(pages[&1]).unwrap()).unwrap();
|
||||
let selections: Vec<_> = content
|
||||
.operations
|
||||
.iter()
|
||||
.filter(|op| op.operator == "Tf")
|
||||
.map(|op| (op.operands[0].as_name().unwrap(), op.operands[1].as_f64().unwrap()))
|
||||
.collect();
|
||||
assert_eq!(selections.len(), 2);
|
||||
assert_eq!(selections[0].0, selections[1].0);
|
||||
assert_ne!(selections[0].1, selections[1].1);
|
||||
|
||||
let first = pdf.get_page_fonts(pages[&1]);
|
||||
let second = pdf.get_page_fonts(pages[&2]);
|
||||
assert_eq!(first.len(), 1);
|
||||
assert_eq!(second.len(), 2);
|
||||
let shared = first[selections[0].0];
|
||||
assert!(std::ptr::eq(shared, second[selections[0].0]));
|
||||
assert!(shared.get(b"Encoding").is_err());
|
||||
assert!(second.values().any(|font| font.get(b"Encoding").is_ok()));
|
||||
let first = shared.get(b"FirstChar").unwrap().as_i64().unwrap();
|
||||
let widths = shared.get(b"Widths").unwrap().as_array().unwrap();
|
||||
for slot in [b'A', b'M', b'W'] {
|
||||
assert!(widths[(i64::from(slot) - first) as usize].as_f64().unwrap() > 0.);
|
||||
}
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xetex_opentype_font_switch_uses_the_current_text_line_origin() {
|
||||
use lopdf::{Document, content::Content};
|
||||
|
||||
Reference in new issue
Block a user