diff --git a/Userland/Libraries/LibPDF/Page.cpp b/Userland/Libraries/LibPDF/Page.cpp index d77b743bfe..efdefc38d4 100644 --- a/Userland/Libraries/LibPDF/Page.cpp +++ b/Userland/Libraries/LibPDF/Page.cpp @@ -12,25 +12,20 @@ namespace PDF { PDFErrorOr Page::page_contents(Document& document) const { + // Table 3.27 Entries in a page object on Contents: + // "If this entry is absent, the page is empty. [...]" if (contents.is_null()) return ByteBuffer {}; - // 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 - // stream object. Do the text operators treat this concatenated stream - // as one stream or multiple? + // "The value may be either a single stream or an array of streams. If the value + // is an array, the effect is as if all the streams in the array were concatenated, + // in order, to form a single stream." + if (contents->is()) + return TRY(ByteBuffer::copy(contents->cast()->bytes())); + ByteBuffer byte_buffer; - if (contents->is()) { - auto array = contents->cast(); - for (auto& ref : *array) { - auto bytes = TRY(document.resolve_to(ref))->bytes(); - byte_buffer.append(bytes.data(), bytes.size()); - } - } else { - auto bytes = contents->cast()->bytes(); - byte_buffer.append(bytes.data(), bytes.size()); - } + for (auto& ref : *contents->cast()) + TRY(byte_buffer.try_append(TRY(document.resolve_to(ref))->bytes())); return byte_buffer; }