mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibPDF: Don't expect glyph width arrays to contain integers
They might also contain floats, in which case we convert them to int before use.
This commit is contained in:
parent
97ed4106e5
commit
36828f1385
2 changed files with 7 additions and 7 deletions
|
@ -29,7 +29,7 @@ PDFErrorOr<NonnullRefPtr<Type0Font>> Type0Font::create(Document* document, Nonnu
|
||||||
|
|
||||||
u16 default_width = 1000;
|
u16 default_width = 1000;
|
||||||
if (descendant_font->contains(CommonNames::DW))
|
if (descendant_font->contains(CommonNames::DW))
|
||||||
default_width = descendant_font->get_value(CommonNames::DW).get<int>();
|
default_width = descendant_font->get_value(CommonNames::DW).to_int();
|
||||||
|
|
||||||
HashMap<u16, u16> widths;
|
HashMap<u16, u16> widths;
|
||||||
|
|
||||||
|
@ -40,16 +40,16 @@ PDFErrorOr<NonnullRefPtr<Type0Font>> Type0Font::create(Document* document, Nonnu
|
||||||
for (size_t i = 0; i < widths_array->size(); i++) {
|
for (size_t i = 0; i < widths_array->size(); i++) {
|
||||||
auto& value = widths_array->at(i);
|
auto& value = widths_array->at(i);
|
||||||
if (!pending_code.has_value()) {
|
if (!pending_code.has_value()) {
|
||||||
pending_code = value.get<int>();
|
pending_code = value.to_int();
|
||||||
} else if (value.has<NonnullRefPtr<Object>>()) {
|
} else if (value.has<NonnullRefPtr<Object>>()) {
|
||||||
auto array = value.get<NonnullRefPtr<Object>>()->cast<ArrayObject>();
|
auto array = value.get<NonnullRefPtr<Object>>()->cast<ArrayObject>();
|
||||||
auto code = pending_code.release_value();
|
auto code = pending_code.release_value();
|
||||||
for (auto& width : *array)
|
for (auto& width : *array)
|
||||||
widths.set(code++, width.get<int>());
|
widths.set(code++, width.to_int());
|
||||||
} else {
|
} else {
|
||||||
auto first_code = pending_code.release_value();
|
auto first_code = pending_code.release_value();
|
||||||
auto last_code = value.get<int>();
|
auto last_code = value.to_int();
|
||||||
auto width = widths_array->at(i + 1).get<int>();
|
auto width = widths_array->at(i + 1).to_int();
|
||||||
for (u16 code = first_code; code <= last_code; code++)
|
for (u16 code = first_code; code <= last_code; code++)
|
||||||
widths.set(code, width);
|
widths.set(code, width);
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,12 @@ PDFErrorOr<Type1Font::Data> Type1Font::parse_data(Document* document, NonnullRef
|
||||||
|
|
||||||
HashMap<u16, u16> widths;
|
HashMap<u16, u16> widths;
|
||||||
for (size_t i = 0; i < widths_array->size(); i++)
|
for (size_t i = 0; i < widths_array->size(); i++)
|
||||||
widths.set(first_char + i, widths_array->at(i).get<int>());
|
widths.set(first_char + i, widths_array->at(i).to_int());
|
||||||
|
|
||||||
u16 missing_width = 0;
|
u16 missing_width = 0;
|
||||||
auto descriptor = MUST(dict->get_dict(document, CommonNames::FontDescriptor));
|
auto descriptor = MUST(dict->get_dict(document, CommonNames::FontDescriptor));
|
||||||
if (descriptor->contains(CommonNames::MissingWidth))
|
if (descriptor->contains(CommonNames::MissingWidth))
|
||||||
missing_width = descriptor->get_value(CommonNames::MissingWidth).get<int>();
|
missing_width = descriptor->get_value(CommonNames::MissingWidth).to_int();
|
||||||
|
|
||||||
return Type1Font::Data { to_unicode, encoding.release_nonnull(), move(widths), missing_width };
|
return Type1Font::Data { to_unicode, encoding.release_nonnull(), move(widths), missing_width };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue