From 1520e4f3b1f485a52634ecbc26643dd7803aee7f Mon Sep 17 00:00:00 2001 From: clydebarrow <2366188+clydebarrow@users.noreply.github.com> Date: Sun, 23 Feb 2025 14:51:49 +1100 Subject: [PATCH] Use advance instead of bitmap width --- esphome/components/font/__init__.py | 3 ++- esphome/components/font/font.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/esphome/components/font/__init__.py b/esphome/components/font/__init__.py index 30221ccb5c..9405bdbd65 100644 --- a/esphome/components/font/__init__.py +++ b/esphome/components/font/__init__.py @@ -387,7 +387,8 @@ def validate_file_shorthand(value): } ) - if value.endswith(".pcf") or value.endswith(".bdf"): + extension = Path(value).suffix + if extension in BITMAP_EXTENSIONS: return font_file_schema( { CONF_TYPE: TYPE_LOCAL_BITMAP, diff --git a/esphome/components/font/font.cpp b/esphome/components/font/font.cpp index 8c4cba34b3..32464d87ee 100644 --- a/esphome/components/font/font.cpp +++ b/esphome/components/font/font.cpp @@ -81,7 +81,7 @@ void Font::measure(const char *str, int *width, int *x_offset, int *baseline, in if (glyph_n < 0) { // Unknown char, skip if (!this->get_glyphs().empty()) - x += this->get_glyphs()[0].glyph_data_->width; + x += this->get_glyphs()[0].glyph_data_->advance; i++; continue; } @@ -92,7 +92,7 @@ void Font::measure(const char *str, int *width, int *x_offset, int *baseline, in } else { min_x = std::min(min_x, x + glyph.glyph_data_->offset_x); } - x += glyph.glyph_data_->width + glyph.glyph_data_->offset_x; + x += glyph.glyph_data_->advance; i += match_length; has_char = true; @@ -111,7 +111,7 @@ void Font::print(int x_start, int y_start, display::Display *display, Color colo // Unknown char, skip ESP_LOGW(TAG, "Encountered character without representation in font: '%c'", text[i]); if (!this->get_glyphs().empty()) { - uint8_t glyph_width = this->get_glyphs()[0].glyph_data_->width; + uint8_t glyph_width = this->get_glyphs()[0].glyph_data_->advance; display->filled_rectangle(x_at, y_start, glyph_width, this->height_, color); x_at += glyph_width; } @@ -161,7 +161,7 @@ void Font::print(int x_start, int y_start, display::Display *display, Color colo } } } - x_at += glyph.glyph_data_->width + glyph.glyph_data_->offset_x; + x_at += glyph.glyph_data_->advance; i += match_length; }