mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
LibPDF: An Encoding's /Differences entry is optional
Per "TABLE 5.11 Entries in an encoding dictionary", /Differences is optional. (Per "Encodings for TrueType Fonts" in 5.5.5 Character Encoding, nonsymbolic truetype fonts are even recommended to have "no Differences array." But in practice, most seem to have it.) Fixes crashes on: * 0000001.pdf * 0000574.pdf * 0000337.pdf All three don't render super great, but at least they no longer crash.
This commit is contained in:
parent
e9dfa61588
commit
ad5fc0eda1
1 changed files with 16 additions and 14 deletions
|
@ -50,22 +50,24 @@ PDFErrorOr<NonnullRefPtr<Encoding>> Encoding::from_object(Document* document, No
|
|||
encoding->m_descriptors = TRY(base_encoding->m_descriptors.clone());
|
||||
encoding->m_name_mapping = TRY(base_encoding->m_name_mapping.clone());
|
||||
|
||||
auto differences_array = TRY(dict->get_array(document, CommonNames::Differences));
|
||||
if (dict->contains(CommonNames::Differences)) {
|
||||
auto differences_array = TRY(dict->get_array(document, CommonNames::Differences));
|
||||
|
||||
u16 current_code_point = 0;
|
||||
bool first = true;
|
||||
u16 current_code_point = 0;
|
||||
bool first = true;
|
||||
|
||||
for (auto& item : *differences_array) {
|
||||
if (item.has_u32()) {
|
||||
current_code_point = item.to_int();
|
||||
first = false;
|
||||
} else {
|
||||
VERIFY(item.has<NonnullRefPtr<Object>>());
|
||||
VERIFY(!first);
|
||||
auto& object = item.get<NonnullRefPtr<Object>>();
|
||||
auto name = object->cast<NameObject>()->name();
|
||||
encoding->set(current_code_point, name);
|
||||
current_code_point++;
|
||||
for (auto& item : *differences_array) {
|
||||
if (item.has_u32()) {
|
||||
current_code_point = item.to_int();
|
||||
first = false;
|
||||
} else {
|
||||
VERIFY(item.has<NonnullRefPtr<Object>>());
|
||||
VERIFY(!first);
|
||||
auto& object = item.get<NonnullRefPtr<Object>>();
|
||||
auto name = object->cast<NameObject>()->name();
|
||||
encoding->set(current_code_point, name);
|
||||
current_code_point++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue