diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2022-03-24 11:50:37 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-31 18:10:45 +0200 |
commit | 130846f337e6da970209a5dc97a43027564c7547 (patch) | |
tree | ddd1abc3cb8b5558a55471b68a0c08726f1cea73 | |
parent | 8224ca61506b806e3ea983c554731307497d6ff7 (diff) | |
download | serenity-130846f337e6da970209a5dc97a43027564c7547.zip |
LibPDF: Use AntiAliasingPainter in Renderer when possible
-rw-r--r-- | Userland/Libraries/LibPDF/Renderer.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/Renderer.h | 2 |
2 files changed, 13 insertions, 5 deletions
diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index ed280c4afb..bb180f26e9 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -31,6 +31,7 @@ Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitm , m_bitmap(bitmap) , m_page(page) , m_painter(*bitmap) + , m_anti_aliasing_painter(m_painter) { auto media_box = m_page.media_box; @@ -207,6 +208,11 @@ RENDERER_HANDLER(path_append_rect) auto pos = map(args[0].to_float(), args[1].to_float()); auto size = map(Gfx::FloatSize { args[2].to_float(), args[3].to_float() }); + // FIXME: Why do we need to flip the y axis of rectangles here? The coordinates + // in the PDF file seem to be correct, with the same flipped-ness as + // everything else in a PDF file. + pos.set_y(m_bitmap->height() - pos.y() - size.height()); + m_current_path.move_to(pos); m_current_path.line_to({ pos.x() + size.width(), pos.y() }); m_current_path.line_to({ pos.x() + size.width(), pos.y() + size.height() }); @@ -217,7 +223,7 @@ RENDERER_HANDLER(path_append_rect) RENDERER_HANDLER(path_stroke) { - m_painter.stroke_path(m_current_path, state().stroke_color, state().line_width); + m_anti_aliasing_painter.stroke_path(m_current_path, state().stroke_color, state().line_width); m_current_path.clear(); return {}; } @@ -231,7 +237,7 @@ RENDERER_HANDLER(path_close_and_stroke) RENDERER_HANDLER(path_fill_nonzero) { - m_painter.fill_path(m_current_path, state().paint_color, Gfx::Painter::WindingRule::Nonzero); + m_anti_aliasing_painter.fill_path(m_current_path, state().paint_color, Gfx::Painter::WindingRule::Nonzero); m_current_path.clear(); return {}; } @@ -244,21 +250,21 @@ RENDERER_HANDLER(path_fill_nonzero_deprecated) RENDERER_HANDLER(path_fill_evenodd) { - m_painter.fill_path(m_current_path, state().paint_color, Gfx::Painter::WindingRule::EvenOdd); + m_anti_aliasing_painter.fill_path(m_current_path, state().paint_color, Gfx::Painter::WindingRule::EvenOdd); m_current_path.clear(); return {}; } RENDERER_HANDLER(path_fill_stroke_nonzero) { - m_painter.stroke_path(m_current_path, state().stroke_color, state().line_width); + m_anti_aliasing_painter.stroke_path(m_current_path, state().stroke_color, state().line_width); TRY(handle_path_fill_nonzero(args)); return {}; } RENDERER_HANDLER(path_fill_stroke_evenodd) { - m_painter.stroke_path(m_current_path, state().stroke_color, state().line_width); + m_anti_aliasing_painter.stroke_path(m_current_path, state().stroke_color, state().line_width); TRY(handle_path_fill_evenodd(args)); return {}; } diff --git a/Userland/Libraries/LibPDF/Renderer.h b/Userland/Libraries/LibPDF/Renderer.h index 3a57c866d1..cccc83fb36 100644 --- a/Userland/Libraries/LibPDF/Renderer.h +++ b/Userland/Libraries/LibPDF/Renderer.h @@ -8,6 +8,7 @@ #include <AK/Format.h> #include <LibGfx/AffineTransform.h> +#include <LibGfx/AntiAliasingPainter.h> #include <LibGfx/Bitmap.h> #include <LibGfx/Font.h> #include <LibGfx/FontDatabase.h> @@ -121,6 +122,7 @@ private: RefPtr<Gfx::Bitmap> m_bitmap; Page const& m_page; Gfx::Painter m_painter; + Gfx::AntiAliasingPainter m_anti_aliasing_painter; Gfx::Path m_current_path; Vector<GraphicsState> m_graphics_state_stack; |