Render legacy XeLaTeX composite Type 1 fonts
This commit is contained in:
1 parent
ff52a9f66b
commit
e7ab132520
11 files changed
+497
-116
No files matched your search
@@ -1401,3 +1401,91 @@ fn xdv_text_mapping_uses_the_resource_active_at_each_shipped_special() {
|
||||
}
|
||||
assert_eq!(titles, [b"\xfe\xff\x65\xe5\x57\x0b".as_slice(), b"\xfe\xff\x65\xe5\x67\x2c", b"AB"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xdv_type1_unicode_keeps_alternate_codes_for_the_same_charstring() {
|
||||
use lopdf::Document;
|
||||
use sha2::{Digest, Sha256};
|
||||
use texrra_tex_core::{
|
||||
native_font::resolve_native_fonts,
|
||||
pdf::shipout_lists_to_native_pdf_document,
|
||||
render::DisplayItem,
|
||||
resources::{LoadedResource, ResourceKind, ResourceVersion},
|
||||
};
|
||||
|
||||
fn resource(name: &str, bytes: &[u8]) -> LoadedResource {
|
||||
LoadedResource {
|
||||
version: ResourceVersion {
|
||||
path: name.into(),
|
||||
bytes: bytes.len() as u64,
|
||||
sha256: format!("{:x}", Sha256::digest(bytes)),
|
||||
},
|
||||
data: bytes.to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
struct Fonts;
|
||||
impl SourceProvider for Fonts {
|
||||
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 resource(
|
||||
&mut self, kind: ResourceKind, name: &str, _: &str,
|
||||
) -> Result<LoadedResource, String> {
|
||||
let bytes: &[u8] = match (kind, name) {
|
||||
(ResourceKind::Tfm, "mapped.tfm") => include_bytes!("../assets/cmr10.tfm"),
|
||||
(ResourceKind::Type1, "cmr10.pfb") => include_bytes!("../../../assets/fonts/cmr10.pfb"),
|
||||
_ => return Err(format!("unexpected font resource {kind:?} {name}")),
|
||||
};
|
||||
Ok(resource(name, bytes))
|
||||
}
|
||||
|
||||
fn optional_font_file(
|
||||
&mut self, kind: ResourceKind, name: &str, from: &str,
|
||||
) -> Result<Option<LoadedResource>, String> {
|
||||
Ok(match (kind, name) {
|
||||
(ResourceKind::Tfm, "mapped.tfm") => Some(self.resource(kind, name, from)?),
|
||||
(ResourceKind::Map, "texglyphlist.txt") => Some(resource(name, b"A;005E\n")),
|
||||
(ResourceKind::Map, "glyphlist.txt") => {
|
||||
Some(resource(name, include_bytes!("../assets/glyphlist.txt")))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn optional_font_map(&mut self, _: &str, _: &str) -> Result<Option<LoadedResource>, String> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
\font\proof=mapped at10pt
|
||||
\shipout\hbox{\special{pdf:mapline mapped unicode cmr10.pfb -w 1}\proof A\char94B}
|
||||
\end"),
|
||||
&mut Fonts,
|
||||
).unwrap();
|
||||
let mut pages = execution.shipout_display_lists().unwrap();
|
||||
resolve_native_fonts(&mut pages, &mut Fonts).unwrap();
|
||||
let letters: Vec<_> = pages[0].items.iter().filter_map(|item| match item {
|
||||
DisplayItem::NativeGlyph { character, slot, paint: Some(paint), .. } => {
|
||||
Some((*character, &paint.glyph_paths[slot]))
|
||||
}
|
||||
_ => None,
|
||||
}).collect();
|
||||
assert_eq!(letters.iter().map(|(character, _)| character).collect::<String>(), "^^B");
|
||||
assert_eq!(letters[0].1, letters[1].1);
|
||||
assert_ne!(letters[0].1, letters[2].1);
|
||||
assert!(pages[0].try_to_svg().unwrap().contains("matrix(0.00000000 -0.01000000 -0.01000000 0 "));
|
||||
let output = shipout_lists_to_native_pdf_document(&pages, execution.state.pdf_final_options()).unwrap();
|
||||
let pdf = Document::load_mem(&output.bytes).unwrap();
|
||||
assert!(pdf.objects.values().filter_map(|object| object.as_stream().ok()).any(|stream| {
|
||||
stream.dict.get(b"Subtype").and_then(|value| value.as_name()).is_ok_and(|name| name == b"CIDFontType0C")
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user