mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibPDF: Use AntiAliasingPainter in Renderer when possible
This commit is contained in:
parent
8224ca6150
commit
130846f337
2 changed files with 13 additions and 5 deletions
|
@ -31,6 +31,7 @@ Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitm
|
||||||
, m_bitmap(bitmap)
|
, m_bitmap(bitmap)
|
||||||
, m_page(page)
|
, m_page(page)
|
||||||
, m_painter(*bitmap)
|
, m_painter(*bitmap)
|
||||||
|
, m_anti_aliasing_painter(m_painter)
|
||||||
{
|
{
|
||||||
auto media_box = m_page.media_box;
|
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 pos = map(args[0].to_float(), args[1].to_float());
|
||||||
auto size = map(Gfx::FloatSize { args[2].to_float(), args[3].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.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() });
|
||||||
m_current_path.line_to({ pos.x() + size.width(), pos.y() + size.height() });
|
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)
|
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();
|
m_current_path.clear();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -231,7 +237,7 @@ RENDERER_HANDLER(path_close_and_stroke)
|
||||||
|
|
||||||
RENDERER_HANDLER(path_fill_nonzero)
|
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();
|
m_current_path.clear();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -244,21 +250,21 @@ RENDERER_HANDLER(path_fill_nonzero_deprecated)
|
||||||
|
|
||||||
RENDERER_HANDLER(path_fill_evenodd)
|
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();
|
m_current_path.clear();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
RENDERER_HANDLER(path_fill_stroke_nonzero)
|
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));
|
TRY(handle_path_fill_nonzero(args));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
RENDERER_HANDLER(path_fill_stroke_evenodd)
|
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));
|
TRY(handle_path_fill_evenodd(args));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <LibGfx/AffineTransform.h>
|
#include <LibGfx/AffineTransform.h>
|
||||||
|
#include <LibGfx/AntiAliasingPainter.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/FontDatabase.h>
|
#include <LibGfx/FontDatabase.h>
|
||||||
|
@ -121,6 +122,7 @@ private:
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
Page const& m_page;
|
Page const& m_page;
|
||||||
Gfx::Painter m_painter;
|
Gfx::Painter m_painter;
|
||||||
|
Gfx::AntiAliasingPainter m_anti_aliasing_painter;
|
||||||
|
|
||||||
Gfx::Path m_current_path;
|
Gfx::Path m_current_path;
|
||||||
Vector<GraphicsState> m_graphics_state_stack;
|
Vector<GraphicsState> m_graphics_state_stack;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue