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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user