summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Offenhäuser <offenhaeuser@protonmail.com>2022-08-25 10:36:36 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-16 17:44:54 +0200
commit36f83cecabd7fd264d9b77c5f594237534d4f335 (patch)
treea55ecf122b0f215778366cc1f731b5f431c5c20a
parent2f71e0f09a562f8e48f5d7d328eb2ea8ee772ff6 (diff)
downloadserenity-36f83cecabd7fd264d9b77c5f594237534d4f335.zip
LibPDF: Allow page objects to inherit the MediaBox and Resources entries
-rw-r--r--Userland/Libraries/LibPDF/Document.cpp18
-rw-r--r--Userland/Libraries/LibPDF/Document.h2
2 files changed, 13 insertions, 7 deletions
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<Page> Document::get_page(u32 index)
auto page_object = TRY(get_or_load_value(page_object_index));
auto raw_page_object = TRY(resolve_to<DictObject>(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<DictObject>();
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<ArrayObject>();
auto media_box = Rectangle {
media_box_array->at(0).to_float(),
media_box_array->at(1).to_float(),
@@ -262,6 +257,15 @@ PDFErrorOr<Destination> Document::create_destination_from_parameters(NonnullRefP
return Destination { type, page_ref, parameters };
}
+PDFErrorOr<NonnullRefPtr<Object>> Document::get_inheritable_object(FlyString const& name, NonnullRefPtr<DictObject> 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<NonnullRefPtr<OutlineItem>> Document::build_outline_item(NonnullRefPtr<DictObject> 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<Destination> create_destination_from_parameters(NonnullRefPtr<ArrayObject>);
+ PDFErrorOr<NonnullRefPtr<Object>> get_inheritable_object(FlyString const& name, NonnullRefPtr<DictObject>);
+
NonnullRefPtr<DocumentParser> m_parser;
RefPtr<DictObject> m_catalog;
RefPtr<DictObject> m_trailer;