LibPDF: Move ScopedState from a function on Renderer into Renderer

No behavior change.
This commit is contained in:
Nico Weber 2023-11-14 10:35:40 -05:00 committed by Sam Atkins
parent 126a0be595
commit 5513f8bbe3
Notes: sideshowbarker 2024-07-17 11:33:34 +09:00
2 changed files with 26 additions and 23 deletions

View File

@ -21,6 +21,30 @@
namespace PDF {
// Use a RAII object to restore the graphics state, to make sure it gets restored even if
// a TRY(handle_operator()) causes us to exit the operators loop early.
// Explicitly resize stack size at the end so that if the recursive document contains
// `q q unsupportedop Q Q`, we undo the stack pushes from the inner `q q` even if
// `unsupportedop` terminates processing the inner instruction stream before `Q Q`
// would normally pop state.
class Renderer::ScopedState {
public:
ScopedState(Renderer& renderer)
: m_renderer(renderer)
, m_starting_stack_depth(m_renderer.m_graphics_state_stack.size())
{
MUST(m_renderer.handle_save_state({}));
}
~ScopedState()
{
m_renderer.m_graphics_state_stack.shrink(m_starting_stack_depth);
}
private:
Renderer& m_renderer;
size_t m_starting_stack_depth;
};
PDFErrorsOr<void> Renderer::render(Document& document, Page const& page, RefPtr<Gfx::Bitmap> bitmap, RenderingPreferences rendering_preferences)
{
return Renderer(document, page, bitmap, rendering_preferences).render();
@ -655,29 +679,6 @@ RENDERER_HANDLER(paint_xobject)
return {};
}
// Use a RAII object to restore the graphics state, to make sure it gets restored even if
// a TRY(handle_operator()) causes us to exit the operators loop early.
// Explicitly resize stack size at the end so that if the recursive document contains
// `q q unsupportedop Q Q`, we undo the stack pushes from the inner `q q` even if
// `unsupportedop` terminates processing the inner instruction stream before `Q Q`
// would normally pop state.
class ScopedState {
public:
ScopedState(Renderer& renderer)
: m_renderer(renderer)
, m_starting_stack_depth(m_renderer.m_graphics_state_stack.size())
{
MUST(m_renderer.handle_save_state({}));
}
~ScopedState()
{
m_renderer.m_graphics_state_stack.shrink(m_starting_stack_depth);
}
private:
Renderer& m_renderer;
size_t m_starting_stack_depth;
};
ScopedState scoped_state { *this };
Vector<Value> matrix;

View File

@ -150,6 +150,8 @@ private:
PDFErrorOr<NonnullRefPtr<PDFFont>> get_font(FontCacheKey const&);
class ScopedState;
RefPtr<Document> m_document;
RefPtr<Gfx::Bitmap> m_bitmap;
Page const& m_page;