[font] More robust handling of fixed font sizes. (#8443)
CI / Create common environment (push) Waiting to run
CI / Check ruff (push) Blocked by required conditions
CI / Check flake8 (push) Blocked by required conditions
CI / Check pylint (push) Blocked by required conditions
CI / Check pyupgrade (push) Blocked by required conditions
CI / Run script/ci-custom (push) Blocked by required conditions
CI / Run pytest (macOS-latest, 3.11) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.10) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.9) (push) Blocked by required conditions
CI / Run pytest (windows-latest, 3.11) (push) Blocked by required conditions
CI / Check clang-format (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 IDF (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP8266 (push) Blocked by required conditions
CI / list-components (push) Blocked by required conditions
CI / Component test ${{ matrix.file }} (push) Blocked by required conditions
CI / Split components for testing into 20 groups maximum (push) Blocked by required conditions
CI / Test split components (push) Blocked by required conditions
CI / CI Status (push) Blocked by required conditions
YAML lint / yamllint (push) Waiting to run

Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
Clyde Stubbs
2025-03-24 20:35:42 +11:00
committed by GitHub
parent 6cfe3ac44d
commit bc999b50b3
3 changed files with 3270 additions and 7 deletions
+21 -7
View File
@@ -7,7 +7,15 @@ from pathlib import Path
import re
import esphome_glyphsets as glyphsets
from freetype import Face, ft_pixel_mode_grays, ft_pixel_mode_mono
# pylint: disable=no-name-in-module
from freetype import (
FT_LOAD_NO_BITMAP,
FT_LOAD_RENDER,
Face,
ft_pixel_mode_grays,
ft_pixel_mode_mono,
)
import requests
from esphome import external_files
@@ -204,7 +212,7 @@ def validate_font_config(config):
if font.get_char_index(x) != 0
]
if font.has_fixed_sizes:
if not font.is_scalable:
sizes = [pt_to_px(x.size) for x in font.available_sizes]
if not sizes:
raise cv.Invalid(
@@ -507,10 +515,16 @@ async def to_code(config):
# create the data array for all glyphs
for codepoint in codepoints:
font = point_font_map[codepoint]
format = font.get_format().decode("utf-8")
if format != "PCF":
if not font.is_scalable:
sizes = [pt_to_px(x.size) for x in font.available_sizes]
if size in sizes:
font.select_size(sizes.index(size))
else:
font.set_pixel_sizes(size, 0)
font.load_char(codepoint)
flags = FT_LOAD_RENDER
if bpp != 1:
flags |= FT_LOAD_NO_BITMAP
font.load_char(codepoint, flags)
font.glyph.render(mode)
width = font.glyph.bitmap.width
height = font.glyph.bitmap.rows
@@ -535,7 +549,7 @@ async def to_code(config):
pos += 1
ascender = pt_to_px(font.size.ascender)
if ascender == 0:
if font.has_fixed_sizes:
if not font.is_scalable:
ascender = size
else:
_LOGGER.error(
@@ -585,7 +599,7 @@ async def to_code(config):
font_height = pt_to_px(base_font.size.height)
ascender = pt_to_px(base_font.size.ascender)
if font_height == 0:
if base_font.has_fixed_sizes:
if not base_font.is_scalable:
font_height = size
ascender = font_height
else:
File diff suppressed because it is too large Load Diff
+3
View File
@@ -43,6 +43,9 @@ font:
id: default_font
- file: $component_dir/x11.pcf
id: pcf_font
- file: $component_dir/Tamzen5x9b.bdf
id: bdf_font
size: 7
i2c:
scl: ${i2c_scl}