mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 01:59:14 +03:00
LibPDF: Move ScopedState from a function on Renderer into Renderer
No behavior change.
This commit is contained in:
parent
126a0be595
commit
5513f8bbe3
Notes:
sideshowbarker
2024-07-17 11:33:34 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/5513f8bbe3 Pull-request: https://github.com/SerenityOS/serenity/pull/21946 Reviewed-by: https://github.com/AtkinsSJ
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user