mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:48:11 +00:00
LibPDF: Move code to compute full page contents into Page
Pure code move, no behavior change.
This commit is contained in:
parent
f4f8a6a1bf
commit
69c965b987
4 changed files with 41 additions and 22 deletions
37
Userland/Libraries/LibPDF/Page.cpp
Normal file
37
Userland/Libraries/LibPDF/Page.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Matthew Olsson <mattco@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibPDF/Document.h>
|
||||
#include <LibPDF/ObjectDerivatives.h>
|
||||
#include <LibPDF/Page.h>
|
||||
|
||||
namespace PDF {
|
||||
|
||||
PDFErrorOr<ByteBuffer> Page::page_contents(Document& document) const
|
||||
{
|
||||
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?
|
||||
ByteBuffer byte_buffer;
|
||||
if (contents->is<ArrayObject>()) {
|
||||
auto array = contents->cast<ArrayObject>();
|
||||
for (auto& ref : *array) {
|
||||
auto bytes = TRY(document.resolve_to<StreamObject>(ref))->bytes();
|
||||
byte_buffer.append(bytes.data(), bytes.size());
|
||||
}
|
||||
} else {
|
||||
auto bytes = contents->cast<StreamObject>()->bytes();
|
||||
byte_buffer.append(bytes.data(), bytes.size());
|
||||
}
|
||||
return byte_buffer;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue