mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 13:42:59 +00:00
attempt to simplify font drawing
This commit is contained in:
@@ -171,17 +171,14 @@ class OfTheDayManager:
|
|||||||
for char in text:
|
for char in text:
|
||||||
face.load_char(char)
|
face.load_char(char)
|
||||||
bitmap = face.glyph.bitmap
|
bitmap = face.glyph.bitmap
|
||||||
# Calculate baseline position
|
# Simple approach: draw each character at the specified y position
|
||||||
# bitmap_top is the distance from baseline to top of bitmap
|
|
||||||
baseline_y = y
|
|
||||||
glyph_y = baseline_y + 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):
|
||||||
byte_index = i * bitmap.pitch + (j // 8)
|
byte_index = i * bitmap.pitch + (j // 8)
|
||||||
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.point((x + j, glyph_y + i), fill=color)
|
draw.point((x + j, y + i), fill=color)
|
||||||
x += face.glyph.advance.x >> 6
|
x += face.glyph.advance.x >> 6
|
||||||
return x - orig_x
|
return x - orig_x
|
||||||
|
|
||||||
@@ -196,35 +193,30 @@ class OfTheDayManager:
|
|||||||
title_font = self.title_font
|
title_font = self.title_font
|
||||||
body_font = self.body_font
|
body_font = self.body_font
|
||||||
|
|
||||||
# Get font heights
|
# Get font heights - simplified
|
||||||
title_height = title_font.height
|
title_font.load_char('A')
|
||||||
# Calculate actual body height from the font
|
title_height = title_font.glyph.bitmap.rows
|
||||||
body_font.load_char('A') # Load a character to get its height
|
body_font.load_char('A')
|
||||||
body_height = body_font.glyph.bitmap.rows
|
body_height = body_font.glyph.bitmap.rows
|
||||||
|
|
||||||
# --- Draw Title (always at top, 5x7.bdf) ---
|
# --- Draw Title (always at top) ---
|
||||||
title_y = 0 # Start at top
|
title_y = 0 # Start at top
|
||||||
self._draw_bdf_text(draw, title_font, title, 1, title_y, color=self.title_color)
|
self._draw_bdf_text(draw, title_font, title, 1, title_y, color=self.title_color)
|
||||||
|
|
||||||
# Calculate title width and actual height for proper spacing
|
# Calculate title width for underline
|
||||||
title_width = 0
|
title_width = 0
|
||||||
max_title_height = 0
|
|
||||||
for c in title:
|
for c in title:
|
||||||
title_font.load_char(c)
|
title_font.load_char(c)
|
||||||
title_width += title_font.glyph.advance.x
|
title_width += title_font.glyph.advance.x
|
||||||
# Track the maximum height of any character in the title
|
|
||||||
bitmap = title_font.glyph.bitmap
|
|
||||||
if bitmap.rows > max_title_height:
|
|
||||||
max_title_height = bitmap.rows
|
|
||||||
title_width = title_width // 64
|
title_width = title_width // 64
|
||||||
|
|
||||||
# Underline below title using actual title height
|
# Underline below title
|
||||||
underline_y = max_title_height + 1 # Just below the actual title
|
underline_y = title_height + 1
|
||||||
draw.line([(1, underline_y), (1 + title_width, underline_y)], fill=self.title_color, width=1)
|
draw.line([(1, underline_y), (1 + title_width, underline_y)], fill=self.title_color, width=1)
|
||||||
|
|
||||||
# --- Draw Subtitle or Description (rotating, 5x7.bdf) ---
|
# --- Draw Subtitle or Description (rotating) ---
|
||||||
# Start subtitle/description below the title with proper spacing
|
# Start subtitle/description below the title
|
||||||
y_start = max_title_height + 3 # Leave space between title and subtitle
|
y_start = title_height + 3 # Leave space between title and subtitle
|
||||||
available_height = matrix_height - y_start
|
available_height = matrix_height - y_start
|
||||||
available_width = matrix_width - 2
|
available_width = matrix_width - 2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user