mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibPDF: Add initial implementation of XObject rendering
This implementation currently handles Form XObjects only, skipping image XObjects. When rendering an XObject, its resources are passed to the underlying operations so they use those instead of the Page's.
This commit is contained in:
parent
b3007c17bd
commit
cb3e05f476
Notes:
sideshowbarker
2024-07-17 03:50:25 +09:00
Author: https://github.com/rtobar
Commit: cb3e05f476
Pull-request: https://github.com/SerenityOS/serenity/pull/16135
Reviewed-by: https://github.com/TobyAsE
Reviewed-by: https://github.com/janso3 ✅
1 changed files with 32 additions and 1 deletions
|
@ -620,7 +620,38 @@ RENDERER_TODO(shade)
|
|||
RENDERER_TODO(inline_image_begin)
|
||||
RENDERER_TODO(inline_image_begin_data)
|
||||
RENDERER_TODO(inline_image_end)
|
||||
RENDERER_TODO(paint_xobject)
|
||||
RENDERER_HANDLER(paint_xobject)
|
||||
{
|
||||
VERIFY(args.size() > 0);
|
||||
auto resources = extra_resources.value_or(m_page.resources);
|
||||
auto xobject_name = args[0].get<NonnullRefPtr<Object>>()->cast<NameObject>()->name();
|
||||
auto xobjects_dict = MUST(resources->get_dict(m_document, CommonNames::XObject));
|
||||
auto xobject = MUST(xobjects_dict->get_stream(m_document, xobject_name));
|
||||
|
||||
auto subtype = MUST(xobject->dict()->get_name(m_document, CommonNames::Subtype))->name();
|
||||
if (subtype == CommonNames::Image) {
|
||||
dbgln("Skipping image");
|
||||
return {};
|
||||
}
|
||||
|
||||
MUST(handle_save_state({}));
|
||||
Vector<Value> matrix;
|
||||
if (xobject->dict()->contains(CommonNames::Matrix)) {
|
||||
matrix = xobject->dict()->get_array(m_document, CommonNames::Matrix).value()->elements();
|
||||
} else {
|
||||
matrix = Vector { Value { 1 }, Value { 0 }, Value { 0 }, Value { 1 }, Value { 0 }, Value { 0 } };
|
||||
}
|
||||
MUST(handle_concatenate_matrix(matrix));
|
||||
Optional<NonnullRefPtr<DictObject>> xobject_resources {};
|
||||
if (xobject->dict()->contains(CommonNames::Resources)) {
|
||||
xobject_resources = xobject->dict()->get_dict(m_document, CommonNames::Resources).value();
|
||||
}
|
||||
auto operators = TRY(Parser::parse_operators(m_document, xobject->bytes()));
|
||||
for (auto& op : operators)
|
||||
TRY(handle_operator(op, xobject_resources));
|
||||
MUST(handle_restore_state({}));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(marked_content_point)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue