From 13f007aadb1cfd967923c4c36e0e3040cfdb45cf Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 16 Jan 2024 20:25:07 -0500 Subject: [PATCH] LibPDF: Tweak vertical position of truetype fonts The vertical coordinates for truetype fonts are different somehow. We compensated a bit for that; now we compensate some more. This is still not 100% perfect, but much better than before. --- Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp | 3 ++- Userland/Libraries/LibPDF/Fonts/Type1Font.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp index ef23b9f04d0..29410033152 100644 --- a/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp +++ b/Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp @@ -53,7 +53,8 @@ PDFErrorOr TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint auto style = renderer.state().paint_style; // Account for the reversed font baseline - auto position = point.translated(0, -m_font->baseline()); + auto position = point.translated(0, -m_font->pixel_metrics().descent - m_font->baseline()); + if (style.has()) { painter.draw_glyph(position, char_code, *m_font, style.get()); } else { diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp index 01bfb2ca5c0..2d4b5244d23 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp @@ -71,7 +71,7 @@ PDFErrorOr Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint po if (!m_font_program) { // Account for the reversed font baseline - auto position = point.translated(0, -m_font->baseline()); + auto position = point.translated(0, -m_font->pixel_metrics().descent - m_font->baseline()); // FIXME: Bounding box and sample point look to be pretty wrong if (style.has()) { painter.draw_glyph(position, char_code, *m_font, style.get());