summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPDF
diff options
context:
space:
mode:
authorJulian Offenhäuser <offenhaeuser@protonmail.com>2023-03-24 22:15:17 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-03-25 16:27:30 -0600
commit95a804bc4e297496495784b67fb623d77ef984f8 (patch)
tree555f6aa3d80bc8b2c188a7ccff4f81be7d8eca6f /Userland/Libraries/LibPDF
parentb90a794d78b3c25764401585ebca3fe84e151dc2 (diff)
downloadserenity-95a804bc4e297496495784b67fb623d77ef984f8.zip
LibPDF: Allow the page rotation to be inherited
Diffstat (limited to 'Userland/Libraries/LibPDF')
-rw-r--r--Userland/Libraries/LibPDF/Document.cpp16
-rw-r--r--Userland/Libraries/LibPDF/Document.h1
2 files changed, 15 insertions, 2 deletions
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<Page> 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<int>();
+ 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<Optional<NonnullRefPtr<Object>>> Document::get_inheritable_object(Dep
return TRY(object->get_object(this, name));
}
+PDFErrorOr<Optional<Value>> Document::get_inheritable_value(DeprecatedFlyString const& name, NonnullRefPtr<DictObject> 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<Destination> Document::create_destination_from_dictionary_entry(NonnullRefPtr<Object> const& entry, HashMap<u32, u32> const& page_number_by_index_ref)
{
if (entry->is<ArrayObject>()) {
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<Destination> create_destination_from_dictionary_entry(NonnullRefPtr<Object> const& entry, HashMap<u32, u32> const& page_number_by_index_ref);
PDFErrorOr<Optional<NonnullRefPtr<Object>>> get_inheritable_object(DeprecatedFlyString const& name, NonnullRefPtr<DictObject>);
+ PDFErrorOr<Optional<Value>> get_inheritable_value(DeprecatedFlyString const& name, NonnullRefPtr<DictObject>);
PDFErrorOr<NonnullRefPtr<Object>> find_in_name_tree(NonnullRefPtr<DictObject> root, DeprecatedFlyString name);
PDFErrorOr<NonnullRefPtr<Object>> find_in_name_tree_nodes(NonnullRefPtr<ArrayObject> siblings, DeprecatedFlyString name);