diff --git a/Userland/Libraries/LibPDF/Document.cpp b/Userland/Libraries/LibPDF/Document.cpp index cf6faa0e10..38a70d1989 100644 --- a/Userland/Libraries/LibPDF/Document.cpp +++ b/Userland/Libraries/LibPDF/Document.cpp @@ -109,15 +109,10 @@ PDFErrorOr Document::get_page(u32 index) auto page_object = TRY(get_or_load_value(page_object_index)); auto raw_page_object = TRY(resolve_to(page_object)); - if (!raw_page_object->contains(CommonNames::Resources)) { - // This page inherits its resource dictionary - TODO(); - } - - auto resources = TRY(raw_page_object->get_dict(this, CommonNames::Resources)); + auto resources = TRY(get_inheritable_object(CommonNames::Resources, raw_page_object))->cast(); auto contents = TRY(raw_page_object->get_object(this, CommonNames::Contents)); - auto media_box_array = TRY(raw_page_object->get_array(this, CommonNames::MediaBox)); + auto media_box_array = TRY(get_inheritable_object(CommonNames::MediaBox, raw_page_object))->cast(); auto media_box = Rectangle { media_box_array->at(0).to_float(), media_box_array->at(1).to_float(), @@ -262,6 +257,15 @@ PDFErrorOr Document::create_destination_from_parameters(NonnullRefP return Destination { type, page_ref, parameters }; } +PDFErrorOr> Document::get_inheritable_object(FlyString const& name, NonnullRefPtr object) +{ + if (!object->contains(name)) { + auto parent = TRY(object->get_dict(this, CommonNames::Parent)); + return get_inheritable_object(name, parent); + } + return object->get_object(this, name); +} + PDFErrorOr> Document::build_outline_item(NonnullRefPtr const& outline_item_dict) { auto outline_item = adopt_ref(*new OutlineItem {}); diff --git a/Userland/Libraries/LibPDF/Document.h b/Userland/Libraries/LibPDF/Document.h index 4c6d39331f..83cf7453a5 100644 --- a/Userland/Libraries/LibPDF/Document.h +++ b/Userland/Libraries/LibPDF/Document.h @@ -150,6 +150,8 @@ private: PDFErrorOr create_destination_from_parameters(NonnullRefPtr); + PDFErrorOr> get_inheritable_object(FlyString const& name, NonnullRefPtr); + NonnullRefPtr m_parser; RefPtr m_catalog; RefPtr m_trailer;