fix(fonts): fall back to raw stream for uncompressed ToUnicode CMaps

lopdf's decompressed_content() fails with DictKey("Filter") when a
ToUnicode stream has no /Filter entry (uncompressed raw text). Now
falls back to the raw stream.content when decompression fails.

Fixes Identity-H fonts with valid uncompressed ToUnicode CMaps
producing empty text (e.g. neoenergia tabela PDF).
This commit is contained in:
Abimael Martell
2026-03-20 19:42:11 -07:00
parent 2a8e628396
commit 95b45d154e
3 changed files with 15 additions and 13 deletions
+7 -6
View File
@@ -75,12 +75,13 @@ pub(crate) fn extract_page_text_items(
if let Ok(obj_ref) = tounicode.as_reference() {
font_tounicode_refs.insert(resource_name, obj_ref.0);
} else if let Object::Stream(s) = tounicode {
if let Ok(data) = s.decompressed_content() {
if let Some(entry) =
crate::tounicode::build_cmap_entry_from_stream(&data, font_dict, doc, 0)
{
inline_cmaps.insert(resource_name, entry);
}
let data = s
.decompressed_content()
.unwrap_or_else(|_| s.content.clone());
if let Some(entry) =
crate::tounicode::build_cmap_entry_from_stream(&data, font_dict, doc, 0)
{
inline_cmaps.insert(resource_name, entry);
}
}
}
+7 -6
View File
@@ -179,12 +179,13 @@ fn extract_form_xobject_text_inner(
if let Ok(obj_ref) = tounicode.as_reference() {
font_tounicode_refs.insert(resource_name, obj_ref.0);
} else if let Object::Stream(s) = tounicode {
if let Ok(data) = s.decompressed_content() {
if let Some(entry) =
crate::tounicode::build_cmap_entry_from_stream(&data, font_dict, doc, 0)
{
inline_cmaps.insert(resource_name, entry);
}
let data = s
.decompressed_content()
.unwrap_or_else(|_| s.content.clone());
if let Some(entry) =
crate::tounicode::build_cmap_entry_from_stream(&data, font_dict, doc, 0)
{
inline_cmaps.insert(resource_name, entry);
}
}
}