From 583f8fb6fafac7f705276d1eff810a66b53b3361 Mon Sep 17 00:00:00 2001 From: Dave Allie Date: Sun, 28 Dec 2025 21:35:08 +1100 Subject: [PATCH] Use font ascender height for baseline offset Instead of line height which positioned lines too low --- lib/GfxRenderer/GfxRenderer.cpp | 11 ++++++++++- lib/GfxRenderer/GfxRenderer.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index c9a2554..1c021d4 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -85,7 +85,7 @@ void GfxRenderer::drawCenteredText(const int fontId, const int y, const char* te void GfxRenderer::drawText(const int fontId, const int x, const int y, const char* text, const bool black, const EpdFontStyle style) const { - const int yPos = y + getLineHeight(fontId); + const int yPos = y + getFontAscenderSize(fontId); int xpos = x; // cannot draw a NULL / empty string @@ -276,6 +276,15 @@ int GfxRenderer::getSpaceWidth(const int fontId) const { return fontMap.at(fontId).getGlyph(' ', REGULAR)->advanceX; } +int GfxRenderer::getFontAscenderSize(const int fontId) const { + if (fontMap.count(fontId) == 0) { + Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); + return 0; + } + + return fontMap.at(fontId).getData(REGULAR)->ascender; +} + int GfxRenderer::getLineHeight(const int fontId) const { if (fontMap.count(fontId) == 0) { Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); diff --git a/lib/GfxRenderer/GfxRenderer.h b/lib/GfxRenderer/GfxRenderer.h index d1083a0..55d0808 100644 --- a/lib/GfxRenderer/GfxRenderer.h +++ b/lib/GfxRenderer/GfxRenderer.h @@ -74,6 +74,7 @@ class GfxRenderer { void drawCenteredText(int fontId, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const; void drawText(int fontId, int x, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const; int getSpaceWidth(int fontId) const; + int getFontAscenderSize(int fontId) const; int getLineHeight(int fontId) const; // UI Components