fix font printing hopefuly

This commit is contained in:
PoliEcho 2025-09-16 11:15:12 +02:00
parent 655f1dc5ae
commit 4013d840c5
2 changed files with 37 additions and 29 deletions

View File

@ -758,42 +758,50 @@ void gc9a01_text(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x
} }
} }
void gc9a01_text_gfx(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t fg_color, uint16_t bg_color) { void gc9a01_text_gfx(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t color) {
const uint16_t first = font->first; int16_t cursor_x = x0;
const uint16_t last = font->last; int16_t cursor_y = y0;
const uint8_t *bitmap = font->bitmap;
const GFXglyph *glyph = font->glyph;
uint16_t cursor_x = x0; // Process each character in the string
uint16_t cursor_y = y0; for (int i = 0; str[i] != '\0'; i++) {
char c = str[i];
while (*str) { // Check if character is in font range
char c = *str++; if (c < font->first || c > font->last) {
if (c < first || c > last) continue; continue; // Skip unsupported characters
}
// Get glyph info for this character // Get glyph data for this character
GFXglyph *g = &glyph[c - first]; uint8_t glyph_index = c - font->first;
uint8_t w = g->width; GFXglyph *glyph = &font->glyph[glyph_index];
uint8_t h = g->height; uint8_t *bitmap = font->bitmap;
int8_t xOffset = g->xOffset;
int8_t yOffset = g->yOffset;
uint8_t xAdvance = g->xAdvance;
uint32_t bitmapOffset = g->bitmapOffset;
// Draw character bitmap // Calculate starting position for this glyph
for (int y = 0; y < h; y++) { int16_t glyph_x = cursor_x + glyph->xOffset;
for (int x = 0; x < w; x++) { int16_t glyph_y = cursor_y + glyph->yOffset;
// Calculate bit position in packed bitmap
uint32_t bit_pos = bitmapOffset + (y * w + x);
uint8_t byte_val = bitmap[bit_pos / 8];
uint8_t bit_mask = 1 << (7 - (bit_pos % 8));
uint16_t pixel_color = (byte_val & bit_mask) ? fg_color : bg_color; // Render the glyph bitmap
gc9a01_draw_pixel(self, cursor_x + x + xOffset, cursor_y + y + yOffset, pixel_color); uint32_t bitmap_offset = glyph->bitmapOffset;
uint8_t bit_index = 0;
for (int16_t row = 0; row < glyph->height; row++) {
for (int16_t col = 0; col < glyph->width; col++) {
// Get current bit from bitmap
uint8_t byte_index = bitmap_offset + (bit_index / 8);
uint8_t bit_position = 7 - (bit_index % 8);
uint8_t pixel = (bitmap[byte_index] >> bit_position) & 0x01;
// Draw pixel if bit is set
if (pixel) {
gc9a01_draw_pixel(self, glyph_x + col, glyph_y + row, color);
}
bit_index++;
} }
} }
cursor_x += xAdvance; // Advance cursor to next character position
cursor_x += glyph->xAdvance;
} }
} }

View File

@ -101,7 +101,7 @@ void gc9a01_set_rotation(gc9a01_GC9A01_obj_t *self);
void gc9a01_hline(gc9a01_GC9A01_obj_t *self, uint16_t x, uint16_t y, uint16_t w, uint16_t color); void gc9a01_hline(gc9a01_GC9A01_obj_t *self, uint16_t x, uint16_t y, uint16_t w, uint16_t color);
void gc9a01_vline(gc9a01_GC9A01_obj_t *self, uint16_t x, uint16_t y, uint16_t w, uint16_t color); void gc9a01_vline(gc9a01_GC9A01_obj_t *self, uint16_t x, uint16_t y, uint16_t w, uint16_t color);
void gc9a01_text(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t fg_color, uint16_t bg_color); void gc9a01_text(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t fg_color, uint16_t bg_color);
void gc9a01_text_gfx(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t fg_color, uint16_t bg_color); void gc9a01_text_gfx(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t color);
uint8_t gc9a01_get_color(uint8_t bpp); uint8_t gc9a01_get_color(uint8_t bpp);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b); uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
#ifdef __cplusplus #ifdef __cplusplus