Apply XeLaTeX CMaps to document text and embedded fonts
This commit is contained in:
1 parent
af6466cd98
commit
7d460e0fa1
20 files changed
+747
-65
No files matched your search
@@ -1329,3 +1329,75 @@ fn xdv_font_map_changes_apply_at_shipout_and_keep_loaded_programs() {
|
||||
assert_eq!(programs, [vec!["CMR10"], vec!["CMR10", "CMTI10"], vec!["CMR10"]]);
|
||||
assert!(pages[2].try_to_svg().unwrap().contains("matrix(0.01200000 0 0.00180000 -0.01000000"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xdv_text_mapping_uses_the_resource_active_at_each_shipped_special() {
|
||||
use lopdf::Document;
|
||||
use sha2::{Digest, Sha256};
|
||||
use texrra_tex_core::{
|
||||
pdf::shipout_lists_to_native_pdf_document,
|
||||
resources::{LoadedResource, ResourceKind, ResourceVersion},
|
||||
};
|
||||
|
||||
struct Maps;
|
||||
impl SourceProvider for Maps {
|
||||
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
|
||||
Err(format!("unexpected input {name}"))
|
||||
}
|
||||
fn default_pk_resolution(&mut self) -> Result<i32, String> {
|
||||
Ok(600)
|
||||
}
|
||||
fn optional_font_file(
|
||||
&mut self, kind: ResourceKind, name: &str, _: &str,
|
||||
) -> Result<Option<LoadedResource>, String> {
|
||||
assert_eq!(kind, ResourceKind::CMap);
|
||||
let data = match name {
|
||||
"Base" => b"begincmap 1 begincodespacerange <00> <FF> endcodespacerange
|
||||
1 beginbfrange <41> <42> [<65e5> <672c>] endbfrange endcmap".to_vec(),
|
||||
"Overlay" => b"begincmap /Base usecmap
|
||||
1 beginbfchar <42> <570b> endbfchar endcmap".to_vec(),
|
||||
_ => return Ok(None),
|
||||
};
|
||||
let version = ResourceVersion {
|
||||
path: name.into(),
|
||||
bytes: data.len() as u64,
|
||||
sha256: format!("{:x}", Sha256::digest(&data)),
|
||||
};
|
||||
Ok(Some(LoadedResource { version, data }))
|
||||
}
|
||||
}
|
||||
|
||||
let state = State::initex().with_etex().with_input_profile(InputProfile::XeTeX);
|
||||
let execution = Executor::new(state, Limits::default()).with_native_pages().run(
|
||||
source(r"\catcode123=1 \catcode125=2
|
||||
\shipout\hbox{%
|
||||
\special{pdf:tounicode Overlay [/Alt]}%
|
||||
\special{pdf:outline 1 << /Title (AB) /Dest [@thispage /Fit] >>}%
|
||||
\special{pdf:tounicode Base}%
|
||||
\special{pdf:outline 1 << /Title (AB) /Dest [@thispage /Fit] >>}%
|
||||
\special{pdf:docinfo << /Alt (AB) /Private (AB) /Title <feff03a9> >>}%
|
||||
\vrule width10pt height5pt}
|
||||
\shipout\hbox{%
|
||||
\special{pdf:tounicode Missing}%
|
||||
\special{pdf:outline 1 << /Title (AB) /Dest [@thispage /Fit] >>}%
|
||||
\vrule width10pt height5pt}
|
||||
\end"),
|
||||
&mut Maps,
|
||||
).unwrap();
|
||||
let pages = execution.shipout_display_lists().unwrap();
|
||||
let output = shipout_lists_to_native_pdf_document(&pages, execution.state.pdf_final_options()).unwrap();
|
||||
let pdf = Document::load_mem(&output.bytes).unwrap();
|
||||
let info = pdf.get_dictionary(pdf.trailer.get(b"Info").unwrap().as_reference().unwrap()).unwrap();
|
||||
assert_eq!(info.get(b"Title").unwrap().as_str().unwrap(), b"\xfe\xff\x03\xa9");
|
||||
assert_eq!(info.get(b"Alt").unwrap().as_str().unwrap(), b"\xfe\xff\x65\xe5\x67\x2c");
|
||||
assert_eq!(info.get(b"Private").unwrap().as_str().unwrap(), b"AB");
|
||||
let outlines = pdf.catalog().unwrap().get(b"Outlines").unwrap().as_reference().unwrap();
|
||||
let mut item = pdf.get_dictionary(outlines).unwrap().get(b"First").ok();
|
||||
let mut titles = Vec::new();
|
||||
while let Some(current) = item {
|
||||
let node = pdf.get_dictionary(current.as_reference().unwrap()).unwrap();
|
||||
titles.push(node.get(b"Title").unwrap().as_str().unwrap());
|
||||
item = node.get(b"Next").ok();
|
||||
}
|
||||
assert_eq!(titles, [b"\xfe\xff\x65\xe5\x57\x0b".as_slice(), b"\xfe\xff\x65\xe5\x67\x2c", b"AB"]);
|
||||
}
|
||||
Reference in new issue
Block a user