Use font ascender height for baseline offset

Instead of line height which positioned lines too low
This commit is contained in:
Dave Allie 2025-12-28 21:35:08 +11:00
parent dd280bdc97
commit 583f8fb6fa
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F
2 changed files with 11 additions and 1 deletions

View File

@ -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);

View File

@ -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