|
10 | 10 | #include <LibPDF/Renderer.h>
|
11 | 11 |
|
12 | 12 | #define RENDERER_HANDLER(name) \
|
13 |
| - PDFErrorOr<void> Renderer::handle_##name([[maybe_unused]] Vector<Value> const& args) |
| 13 | + PDFErrorOr<void> Renderer::handle_##name([[maybe_unused]] Vector<Value> const& args, [[maybe_unused]] Optional<NonnullRefPtr<DictObject>> extra_resources) |
14 | 14 |
|
15 | 15 | #define RENDERER_TODO(name) \
|
16 | 16 | RENDERER_HANDLER(name) \
|
@@ -118,20 +118,20 @@ PDFErrorOr<void> Renderer::render()
|
118 | 118 | return {};
|
119 | 119 | }
|
120 | 120 |
|
121 |
| -PDFErrorOr<void> Renderer::handle_operator(Operator const& op) |
| 121 | +PDFErrorOr<void> Renderer::handle_operator(Operator const& op, Optional<NonnullRefPtr<DictObject>> extra_resources) |
122 | 122 | {
|
123 | 123 | switch (op.type()) {
|
124 |
| -#define V(name, snake_name, symbol) \ |
125 |
| - case OperatorType::name: \ |
126 |
| - TRY(handle_##snake_name(op.arguments())); \ |
| 124 | +#define V(name, snake_name, symbol) \ |
| 125 | + case OperatorType::name: \ |
| 126 | + MUST(handle_##snake_name(op.arguments(), extra_resources)); \ |
127 | 127 | break;
|
128 | 128 | ENUMERATE_OPERATORS(V)
|
129 | 129 | #undef V
|
130 | 130 | case OperatorType::TextNextLineShowString:
|
131 |
| - TRY(handle_text_next_line_show_string(op.arguments())); |
| 131 | + MUST(handle_text_next_line_show_string(op.arguments())); |
132 | 132 | break;
|
133 | 133 | case OperatorType::TextNextLineShowStringSetSpacing:
|
134 |
| - TRY(handle_text_next_line_show_string_set_spacing(op.arguments())); |
| 134 | + MUST(handle_text_next_line_show_string_set_spacing(op.arguments())); |
135 | 135 | break;
|
136 | 136 | }
|
137 | 137 |
|
@@ -204,9 +204,9 @@ RENDERER_TODO(set_flatness_tolerance)
|
204 | 204 |
|
205 | 205 | RENDERER_HANDLER(set_graphics_state_from_dict)
|
206 | 206 | {
|
207 |
| - VERIFY(m_page.resources->contains(CommonNames::ExtGState)); |
| 207 | + auto resources = extra_resources.value_or(m_page.resources); |
208 | 208 | auto dict_name = MUST(m_document->resolve_to<NameObject>(args[0]))->name();
|
209 |
| - auto ext_gstate_dict = MUST(m_page.resources->get_dict(m_document, CommonNames::ExtGState)); |
| 209 | + auto ext_gstate_dict = MUST(resources->get_dict(m_document, CommonNames::ExtGState)); |
210 | 210 | auto target_dict = MUST(ext_gstate_dict->get_dict(m_document, dict_name));
|
211 | 211 | TRY(set_graphics_state_from_dict(target_dict));
|
212 | 212 | return {};
|
@@ -421,8 +421,9 @@ RENDERER_HANDLER(text_set_leading)
|
421 | 421 |
|
422 | 422 | RENDERER_HANDLER(text_set_font)
|
423 | 423 | {
|
| 424 | + auto resources = extra_resources.value_or(m_page.resources); |
424 | 425 | auto target_font_name = MUST(m_document->resolve_to<NameObject>(args[0]))->name();
|
425 |
| - auto fonts_dictionary = MUST(m_page.resources->get_dict(m_document, CommonNames::Font)); |
| 426 | + auto fonts_dictionary = MUST(resources->get_dict(m_document, CommonNames::Font)); |
426 | 427 | auto font_dictionary = MUST(fonts_dictionary->get_dict(m_document, target_font_name));
|
427 | 428 |
|
428 | 429 | text_state().font_size = args[1].to_float();
|
@@ -527,14 +528,14 @@ RENDERER_TODO(type3_font_set_glyph_width_and_bbox)
|
527 | 528 |
|
528 | 529 | RENDERER_HANDLER(set_stroking_space)
|
529 | 530 | {
|
530 |
| - state().stroke_color_space = TRY(get_color_space(args[0], m_page.resources)); |
| 531 | + state().stroke_color_space = TRY(get_color_space(args[0], extra_resources.value_or(m_page.resources))); |
531 | 532 | VERIFY(state().stroke_color_space);
|
532 | 533 | return {};
|
533 | 534 | }
|
534 | 535 |
|
535 | 536 | RENDERER_HANDLER(set_painting_space)
|
536 | 537 | {
|
537 |
| - state().paint_color_space = TRY(get_color_space(args[0], m_page.resources)); |
| 538 | + state().paint_color_space = TRY(get_color_space(args[0], extra_resources.value_or(m_page.resources))); |
538 | 539 | VERIFY(state().paint_color_space);
|
539 | 540 | return {};
|
540 | 541 | }
|
|
0 commit comments