PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M2: the two Identity-H ToUnicode rules point at each other
Claudeb88c8d79abd4
diff --git a/crates/fonts/src/pdf.rs b/crates/fonts/src/pdf.rsindex 6197d8e5c..fe2a8a905 100644--- a/crates/fonts/src/pdf.rs+++ b/crates/fonts/src/pdf.rs@@ -1216,7 +1216,9 @@ fn unicode_map(doc: &Document, font: &Dict, composite: bool) -> Unicode {// `/ToUnicode /Identity-H` is not a stream, as ISO 32000-2 §9.10.3 requires, but CAD// exporters (WSCAD among them) write it for composite fonts whose two-byte codes are the// UTF-16 code units. Acrobat shows them as code = Unicode, and so does the renderer's- // text layer; without it the text could be seen but not edited or found.+ // text layer; without it the text could be seen but not edited or found. The same rule+ // (code = Unicode, no controls or lone surrogates) is in the vendored renderer,+ // `Type0Font::char_code_to_unicode` in vendor/hayro-interpret/src/font/cid.rs: keep both alike.Some(Object::Name(n)) if composite && matches!(n.as_slice(), b"Identity-H" | b"Identity-V") => {parse_to_unicode(&identity_to_unicode(), &mut out);}diff --git a/vendor/hayro-interpret/src/font/cid.rs b/vendor/hayro-interpret/src/font/cid.rsindex 426c3c34c..145135925 100644--- a/vendor/hayro-interpret/src/font/cid.rs+++ b/vendor/hayro-interpret/src/font/cid.rs@@ -445,7 +445,8 @@ impl Type0Font {/// identity `/ToUnicode` name, when the code is a control or a lone surrogate).pub(crate) fn char_code_to_unicode(&self, code: u32) -> Option<BfString> {if self.identity_to_unicode {- // Controls and lone surrogates are not text.+ // Controls and lone surrogates are not text. The same rule builds the editing+ // map, `identity_to_unicode` in crates/fonts/src/pdf.rs: keep both alike.return char::from_u32(code).filter(|c| !c.is_control()).map(BfString::Char);