mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibPDF: Move ScopedState from a function on Renderer into Renderer
No behavior change.
This commit is contained in:
parent
126a0be595
commit
5513f8bbe3
2 changed files with 26 additions and 23 deletions
|
@ -21,6 +21,30 @@
|
||||||
|
|
||||||
namespace PDF {
|
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)
|
PDFErrorsOr<void> Renderer::render(Document& document, Page const& page, RefPtr<Gfx::Bitmap> bitmap, RenderingPreferences rendering_preferences)
|
||||||
{
|
{
|
||||||
return Renderer(document, page, bitmap, rendering_preferences).render();
|
return Renderer(document, page, bitmap, rendering_preferences).render();
|
||||||
|
@ -655,29 +679,6 @@ RENDERER_HANDLER(paint_xobject)
|
||||||
return {};
|
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 };
|
ScopedState scoped_state { *this };
|
||||||
|
|
||||||
Vector<Value> matrix;
|
Vector<Value> matrix;
|
||||||
|
|
|
@ -150,6 +150,8 @@ private:
|
||||||
|
|
||||||
PDFErrorOr<NonnullRefPtr<PDFFont>> get_font(FontCacheKey const&);
|
PDFErrorOr<NonnullRefPtr<PDFFont>> get_font(FontCacheKey const&);
|
||||||
|
|
||||||
|
class ScopedState;
|
||||||
|
|
||||||
RefPtr<Document> m_document;
|
RefPtr<Document> m_document;
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
Page const& m_page;
|
Page const& m_page;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue