diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2021-05-28 12:18:11 -0700 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-06-12 22:45:01 +0430 |
commit | 0a4d8ef98d8e402b1f42c5c895c899ee83eb9a75 (patch) | |
tree | 5e0852973a8f5a0462e2d9aeb6b0191d25f84bea /Userland | |
parent | 449ef14895d9e47028a1fa3d8a9426d2ecc8197f (diff) | |
download | serenity-0a4d8ef98d8e402b1f42c5c895c899ee83eb9a75.zip |
LibPDF: Bake the flipped y-axis directly into the CTM matrix
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibPDF/Renderer.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index 55e65605fa..fe17b1d72a 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -42,6 +42,15 @@ Renderer::Renderer(RefPtr<Document> document, const Page& page, RefPtr<Gfx::Bitm float scale_y = static_cast<float>(bitmap->height()) / height; userspace_matrix.scale(scale_x, scale_y); + // PDF user-space coordinate y axis increases from bottom to top, so we have to + // insert a horizontal reflection about the vertical midpoint into our transformation + // matrix + + static Gfx::AffineTransform horizontal_reflection_matrix = { 1, 0, 0, -1, 0, 0 }; + + userspace_matrix.multiply(horizontal_reflection_matrix); + userspace_matrix.translate(0.0f, -height); + m_graphics_state_stack.append(GraphicsState { userspace_matrix }); m_bitmap->fill(Gfx::Color::NamedColor::White); @@ -530,8 +539,6 @@ void Renderer::show_text(const String& string, float shift) VERIFY(font); auto glyph_position = text_rendering_matrix.map(Gfx::FloatPoint { 0.0f, 0.0f }); - // Reverse the Y axis - glyph_position.set_y(static_cast<float>(m_bitmap->height()) - glyph_position.y()); // Account for the reversed font baseline glyph_position.set_y(glyph_position.y() - static_cast<float>(font->baseline())); |