From fad1a801a40b88d24cc7935c64a910315439334c Mon Sep 17 00:00:00 2001 From: SurprisedDuck Date: Sun, 7 Jun 2026 00:55:47 +0200 Subject: [PATCH] fix: scale SUP/SUB underline to match 50%-scaled glyphs (#2255) --- lib/Epub/Epub/blocks/TextBlock.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Epub/Epub/blocks/TextBlock.cpp b/lib/Epub/Epub/blocks/TextBlock.cpp index 3549087e..96c96f51 100644 --- a/lib/Epub/Epub/blocks/TextBlock.cpp +++ b/lib/Epub/Epub/blocks/TextBlock.cpp @@ -78,6 +78,13 @@ void TextBlock::render(const GfxRenderer& renderer, const int fontId, const int underlineWidth = visibleWidth; } + // SUP/SUB words are rendered at 50% glyph scale (see the baseline comment + // above and drawText), but getTextWidth reports the full-size width, so the + // underline would be drawn ~2x too long. Halve it to match the scaled glyphs. + if ((currentStyle & (EpdFontFamily::SUP | EpdFontFamily::SUB)) != 0) { + underlineWidth = (underlineWidth + 1) / 2; + } + renderer.drawLine(startX, underlineY, startX + underlineWidth, underlineY, true); } }