Resolve imported PDF CFF device fonts from real OpenType faces

This commit is contained in:
gloamxun committed 2026-11-28 04:35:52 +08:00
1 parent 84d6f3ae51
commit 82e54894c4
14 files changed
+326 -38

No files matched your search

@@ -7,11 +7,19 @@ use std::collections::{BTreeSet, HashSet};
struct Names {
type1: BTreeSet<String>,
truetype: BTreeSet<String>,
cid_cff: BTreeSet<String>,
}
pub(super) fn capture(doc: &Document, resources: Option<&Object>) -> (Vec<String>, Vec<String>) {
#[derive(Default)]
pub(super) struct DeviceFontNames {
pub(super) type1: Vec<String>,
pub(super) truetype: Vec<String>,
pub(super) cid_cff: Vec<String>,
}
pub(super) fn capture(doc: &Document, resources: Option<&Object>) -> DeviceFontNames {
let Some(resources) = resources.and_then(|value| resolved(doc, value).ok()) else {
return (Vec::new(), Vec::new());
return DeviceFontNames::default();
};
let mut pending = vec![resources];
let mut seen = HashSet::new();
@@ -70,10 +78,11 @@ pub(super) fn capture(doc: &Document, resources: Option<&Object>) -> (Vec<String
}
}
}
(
names.type1.into_iter().collect(),
names.truetype.into_iter().collect(),
)
DeviceFontNames {
type1: names.type1.into_iter().collect(),
truetype: names.truetype.into_iter().collect(),
cid_cff: names.cid_cff.into_iter().collect(),
}
}
fn get<'a>(doc: &'a Document, dict: &'a Dictionary, key: &[u8]) -> Option<&'a Object> {
@@ -106,10 +115,12 @@ fn capture_font<'a>(
.first()
.and_then(|value| resolved(doc, value).ok())
.and_then(|value| value.as_dict().ok())
&& get(doc, descendant, b"Subtype").and_then(|value| value.as_name().ok())
== Some(b"CIDFontType2")
{
capture_name(doc, descendant, &mut names.truetype);
match get(doc, descendant, b"Subtype").and_then(|value| value.as_name().ok()) {
Some(b"CIDFontType2") => capture_name(doc, descendant, &mut names.truetype),
Some(b"CIDFontType0") => capture_name(doc, descendant, &mut names.cid_cff),
_ => {}
}
}
}
Some(b"Type3") => {
@@ -149,6 +149,7 @@ pub(super) fn read(
imported_fonts: Vec::new(),
device_type1_fonts: Vec::new(),
device_truetype_fonts: Vec::new(),
device_cid_cff_fonts: Vec::new(),
pdftex_source: None,
restored_pdf_origin: None,
},