diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index 85bf2c59db..8a97f0fcb3 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -42,10 +42,18 @@ static Gfx::Path rect_path(float x, float y, float width, float height) return path; } +template +static void rect_path(Gfx::Path& path, Gfx::Rect rect) +{ + return rect_path(path, rect.x(), rect.y(), rect.width(), rect.height()); +} + template static Gfx::Path rect_path(Gfx::Rect rect) { - return rect_path(rect.x(), rect.y(), rect.width(), rect.height()); + Gfx::Path path; + rect_path(path, rect); + return path; } Renderer::Renderer(RefPtr document, Page const& page, RefPtr bitmap, RenderingPreferences rendering_preferences) @@ -229,14 +237,8 @@ RENDERER_HANDLER(path_close) 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()); - rect_path(m_current_path, pos.x(), pos.y(), size.width(), size.height()); + auto rect = Gfx::FloatRect(args[0].to_float(), args[1].to_float(), args[2].to_float(), args[3].to_float()); + rect_path(m_current_path, map(rect)); return {}; } @@ -624,8 +626,7 @@ RENDERER_TODO(compatibility_end) template Gfx::Point Renderer::map(T x, T y) const { - auto mapped = state().ctm.map(Gfx::Point { x, y }); - return { mapped.x(), static_cast(m_bitmap->height()) - mapped.y() }; + return state().ctm.map(Gfx::Point { x, y }); } template