diff options
author | Julian Offenhäuser <offenhaeuser@protonmail.com> | 2023-03-24 22:12:31 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-03-25 16:27:30 -0600 |
commit | b90a794d78b3c25764401585ebca3fe84e151dc2 (patch) | |
tree | 02152d71fbf95fd72f97467b7110744ebf3a360e /Userland/Libraries | |
parent | fde990ead8bde644a27eeb190b82397753cb3f78 (diff) | |
download | serenity-b90a794d78b3c25764401585ebca3fe84e151dc2.zip |
LibPDF: Allow pages with no specified contents
The contents object may be omitted as per spec, which will just leave
the page blank.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibPDF/Document.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/Document.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/Renderer.cpp | 3 |
3 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Libraries/LibPDF/Document.cpp b/Userland/Libraries/LibPDF/Document.cpp index de1a373a95..72340e229c 100644 --- a/Userland/Libraries/LibPDF/Document.cpp +++ b/Userland/Libraries/LibPDF/Document.cpp @@ -116,7 +116,9 @@ PDFErrorOr<Page> Document::get_page(u32 index) else resources = adopt_ref(*new DictObject({})); - auto contents = TRY(raw_page_object->get_object(this, CommonNames::Contents)); + RefPtr<Object> contents; + if (raw_page_object->contains(CommonNames::Contents)) + contents = TRY(raw_page_object->get_object(this, CommonNames::Contents)); Rectangle media_box; auto maybe_media_box_object = TRY(get_inheritable_object(CommonNames::MediaBox, raw_page_object)); diff --git a/Userland/Libraries/LibPDF/Document.h b/Userland/Libraries/LibPDF/Document.h index 8880c653a2..787d37a3f2 100644 --- a/Userland/Libraries/LibPDF/Document.h +++ b/Userland/Libraries/LibPDF/Document.h @@ -30,7 +30,7 @@ struct Rectangle { struct Page { NonnullRefPtr<DictObject> resources; - NonnullRefPtr<Object> contents; + RefPtr<Object> contents; Rectangle media_box; Rectangle crop_box; float user_unit; diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index eb1f0681d2..945f93ab4c 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -85,6 +85,9 @@ Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitm PDFErrorsOr<void> Renderer::render() { + if (m_page.contents.is_null()) + return {}; + // Use our own vector, as the /Content can be an array with multiple // streams which gets concatenated // FIXME: Text operators are supposed to only have effects on the current |