From 470d1d8dcf9cfda3be7c4d2fe00725c5580a4afe Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 16 Jan 2024 17:14:56 -0500 Subject: [PATCH] LibPDF: Fix order of parameter, text, and current transform matrix PDF spec 1.7 5.3.3 Text Space Details gives the correct multiplication order: parameters * textmatrix * ctm. We used to do text * ctm * parameters (AffineTransform::multiply() does left-multiplication). This only matters if `text_state().rise` is non-zero. In practice, it's almost always zero, in which case the paramter matrix is a diagonal matrix that commutes. Fixes the horizontal offset of "super" in Tests/LibPDF/text.pdf. --- Userland/Libraries/LibPDF/Renderer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index 528e44548f..d756fa7180 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -1308,15 +1308,17 @@ Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix() const { if (m_text_rendering_matrix_is_dirty) { // PDF 1.7, 5.3.3. Text Space Details - m_text_rendering_matrix = Gfx::AffineTransform( + Gfx::AffineTransform parameter_matrix { text_state().horizontal_scaling, 0.0f, 0.0f, 1.0f, 0.0f, - text_state().rise); - m_text_rendering_matrix.multiply(state().ctm); + text_state().rise + }; + m_text_rendering_matrix = state().ctm; m_text_rendering_matrix.multiply(m_text_matrix); + m_text_rendering_matrix.multiply(parameter_matrix); m_text_rendering_matrix_is_dirty = false; } return m_text_rendering_matrix;