From 95a804bc4e297496495784b67fb623d77ef984f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= Date: Fri, 24 Mar 2023 22:15:17 +0100 Subject: LibPDF: Allow the page rotation to be inherited --- Userland/Libraries/LibPDF/Document.cpp | 16 ++++++++++++++-- Userland/Libraries/LibPDF/Document.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'Userland/Libraries/LibPDF') diff --git a/Userland/Libraries/LibPDF/Document.cpp b/Userland/Libraries/LibPDF/Document.cpp index 72340e229c..2478e8cdb4 100644 --- a/Userland/Libraries/LibPDF/Document.cpp +++ b/Userland/Libraries/LibPDF/Document.cpp @@ -158,8 +158,9 @@ PDFErrorOr Document::get_page(u32 index) user_unit = raw_page_object->get_value(CommonNames::UserUnit).to_float(); int rotate = 0; - if (raw_page_object->contains(CommonNames::Rotate)) { - rotate = raw_page_object->get_value(CommonNames::Rotate).get(); + auto maybe_rotate = TRY(get_inheritable_value(CommonNames::Rotate, raw_page_object)); + if (maybe_rotate.has_value()) { + rotate = maybe_rotate.value().to_int(); VERIFY(rotate % 90 == 0); } @@ -339,6 +340,17 @@ PDFErrorOr>> Document::get_inheritable_object(Dep return TRY(object->get_object(this, name)); } +PDFErrorOr> Document::get_inheritable_value(DeprecatedFlyString const& name, NonnullRefPtr object) +{ + if (!object->contains(name)) { + if (!object->contains(CommonNames::Parent)) + return { OptionalNone() }; + auto parent = TRY(object->get_dict(this, CommonNames::Parent)); + return get_inheritable_value(name, parent); + } + return object->get(name); +} + PDFErrorOr Document::create_destination_from_dictionary_entry(NonnullRefPtr const& entry, HashMap const& page_number_by_index_ref) { if (entry->is()) { diff --git a/Userland/Libraries/LibPDF/Document.h b/Userland/Libraries/LibPDF/Document.h index 787d37a3f2..91243643c3 100644 --- a/Userland/Libraries/LibPDF/Document.h +++ b/Userland/Libraries/LibPDF/Document.h @@ -144,6 +144,7 @@ private: PDFErrorOr create_destination_from_dictionary_entry(NonnullRefPtr const& entry, HashMap const& page_number_by_index_ref); PDFErrorOr>> get_inheritable_object(DeprecatedFlyString const& name, NonnullRefPtr); + PDFErrorOr> get_inheritable_value(DeprecatedFlyString const& name, NonnullRefPtr); PDFErrorOr> find_in_name_tree(NonnullRefPtr root, DeprecatedFlyString name); PDFErrorOr> find_in_name_tree_nodes(NonnullRefPtr siblings, DeprecatedFlyString name); -- cgit v1.2.3