From 97ed4106e5203ffd6b5806ba58a94c9b6ca69504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= Date: Fri, 19 Aug 2022 09:02:46 +0200 Subject: LibPDF: Fix text positioning with operator TJ As per spec, the positioning (or kerning) parameter of this operator should translate the text matrix before the next showing of text. Previously, this calculation was slightly wrong and also only applied after the text was already shown. --- Userland/Libraries/LibPDF/Renderer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Userland/Libraries/LibPDF/Renderer.cpp') diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index f7766c4912..79b33f7332 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -453,8 +453,10 @@ RENDERER_HANDLER(text_show_string_array) } else if (element.has()) { next_shift = element.get(); } else { + auto shift = next_shift / 1000.0f; + m_text_matrix.translate(-shift * text_state().font_size * text_state().horizontal_scaling, 0.0f); auto str = element.get>()->cast()->string(); - show_text(str, next_shift); + show_text(str); } } @@ -637,7 +639,7 @@ PDFErrorOr Renderer::set_graphics_state_from_dict(NonnullRefPtr(), code_point, *font, state().paint_color); auto glyph_width = char_width * font_size; - auto tx = (glyph_width - shift / 1000.0f); + auto tx = glyph_width; tx += text_state().character_spacing; if (code_point == ' ') -- cgit v1.2.3