mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03: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
Notes:
sideshowbarker
2024-07-17 08:34:29 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/69c965b987 Pull-request: https://github.com/SerenityOS/serenity/pull/19967 Reviewed-by: https://github.com/mattco98 ✅ Reviewed-by: https://github.com/trflynn89 ✅
@ -16,6 +16,7 @@ set(SOURCES
|
|||||||
Fonts/Type1FontProgram.cpp
|
Fonts/Type1FontProgram.cpp
|
||||||
Interpolation.cpp
|
Interpolation.cpp
|
||||||
ObjectDerivatives.cpp
|
ObjectDerivatives.cpp
|
||||||
|
Page.cpp
|
||||||
Parser.cpp
|
Parser.cpp
|
||||||
Reader.cpp
|
Reader.cpp
|
||||||
Renderer.cpp
|
Renderer.cpp
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -28,6 +28,8 @@ struct Page {
|
|||||||
Rectangle crop_box;
|
Rectangle crop_box;
|
||||||
float user_unit;
|
float user_unit;
|
||||||
int rotate;
|
int rotate;
|
||||||
|
|
||||||
|
PDFErrorOr<ByteBuffer> page_contents(Document&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,28 +85,7 @@ Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitm
|
|||||||
|
|
||||||
PDFErrorsOr<void> Renderer::render()
|
PDFErrorsOr<void> Renderer::render()
|
||||||
{
|
{
|
||||||
if (m_page.contents.is_null())
|
auto operators = TRY(Parser::parse_operators(m_document, TRY(m_page.page_contents(*m_document))));
|
||||||
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
|
|
||||||
// stream object. Do the text operators treat this concatenated stream
|
|
||||||
// as one stream or multiple?
|
|
||||||
ByteBuffer byte_buffer;
|
|
||||||
|
|
||||||
if (m_page.contents->is<ArrayObject>()) {
|
|
||||||
auto contents = m_page.contents->cast<ArrayObject>();
|
|
||||||
for (auto& ref : *contents) {
|
|
||||||
auto bytes = TRY(m_document->resolve_to<StreamObject>(ref))->bytes();
|
|
||||||
byte_buffer.append(bytes.data(), bytes.size());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
auto bytes = m_page.contents->cast<StreamObject>()->bytes();
|
|
||||||
byte_buffer.append(bytes.data(), bytes.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto operators = TRY(Parser::parse_operators(m_document, byte_buffer));
|
|
||||||
|
|
||||||
Errors errors;
|
Errors errors;
|
||||||
for (auto& op : operators) {
|
for (auto& op : operators) {
|
||||||
|
Loading…
Reference in New Issue
Block a user