mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
of the day manager text positioning placement fix
This commit is contained in:
@@ -381,11 +381,22 @@ class OfTheDayManager:
|
|||||||
draw.text((x, y), text, fill=color, font=face)
|
draw.text((x, y), text, fill=color, font=face)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Compute baseline from font ascender so caller can pass top-left y
|
||||||
|
try:
|
||||||
|
ascender_px = face.size.ascender >> 6
|
||||||
|
except Exception:
|
||||||
|
ascender_px = 0
|
||||||
|
baseline_y = y + ascender_px
|
||||||
|
|
||||||
# Otherwise, render BDF glyphs manually
|
# Otherwise, render BDF glyphs manually
|
||||||
for char in text:
|
for char in text:
|
||||||
face.load_char(char)
|
face.load_char(char)
|
||||||
bitmap = face.glyph.bitmap
|
bitmap = face.glyph.bitmap
|
||||||
|
|
||||||
|
# Get glyph metrics
|
||||||
|
glyph_left = face.glyph.bitmap_left
|
||||||
|
glyph_top = face.glyph.bitmap_top
|
||||||
|
|
||||||
for i in range(bitmap.rows):
|
for i in range(bitmap.rows):
|
||||||
for j in range(bitmap.width):
|
for j in range(bitmap.width):
|
||||||
try:
|
try:
|
||||||
@@ -393,9 +404,12 @@ class OfTheDayManager:
|
|||||||
if byte_index < len(bitmap.buffer):
|
if byte_index < len(bitmap.buffer):
|
||||||
byte = bitmap.buffer[byte_index]
|
byte = bitmap.buffer[byte_index]
|
||||||
if byte & (1 << (7 - (j % 8))):
|
if byte & (1 << (7 - (j % 8))):
|
||||||
draw_y = y - face.glyph.bitmap_top + i
|
# Calculate actual pixel position
|
||||||
draw_x = x + face.glyph.bitmap_left + j
|
pixel_x = x + glyph_left + j
|
||||||
draw.point((draw_x, draw_y), fill=color)
|
pixel_y = baseline_y - glyph_top + i
|
||||||
|
# Only draw if within bounds
|
||||||
|
if (0 <= pixel_x < self.display_manager.width and 0 <= pixel_y < self.display_manager.height):
|
||||||
|
draw.point((pixel_x, pixel_y), fill=color)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.warning(f"Index out of range for char '{char}' at position ({i}, {j})")
|
logger.warning(f"Index out of range for char '{char}' at position ({i}, {j})")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user