fix font printing hopefuly
This commit is contained in:
parent
655f1dc5ae
commit
4013d840c5
@ -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) {
|
||||
const uint16_t first = font->first;
|
||||
const uint16_t last = font->last;
|
||||
const uint8_t *bitmap = font->bitmap;
|
||||
const GFXglyph *glyph = font->glyph;
|
||||
void gc9a01_text_gfx(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t color) {
|
||||
int16_t cursor_x = x0;
|
||||
int16_t cursor_y = y0;
|
||||
|
||||
uint16_t cursor_x = x0;
|
||||
uint16_t cursor_y = y0;
|
||||
// Process each character in the string
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
char c = str[i];
|
||||
|
||||
while (*str) {
|
||||
char c = *str++;
|
||||
if (c < first || c > last) continue;
|
||||
// Check if character is in font range
|
||||
if (c < font->first || c > font->last) {
|
||||
continue; // Skip unsupported characters
|
||||
}
|
||||
|
||||
// Get glyph info for this character
|
||||
GFXglyph *g = &glyph[c - first];
|
||||
uint8_t w = g->width;
|
||||
uint8_t h = g->height;
|
||||
int8_t xOffset = g->xOffset;
|
||||
int8_t yOffset = g->yOffset;
|
||||
uint8_t xAdvance = g->xAdvance;
|
||||
uint32_t bitmapOffset = g->bitmapOffset;
|
||||
// Get glyph data for this character
|
||||
uint8_t glyph_index = c - font->first;
|
||||
GFXglyph *glyph = &font->glyph[glyph_index];
|
||||
uint8_t *bitmap = font->bitmap;
|
||||
|
||||
// Draw character bitmap
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
// 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));
|
||||
// Calculate starting position for this glyph
|
||||
int16_t glyph_x = cursor_x + glyph->xOffset;
|
||||
int16_t glyph_y = cursor_y + glyph->yOffset;
|
||||
|
||||
uint16_t pixel_color = (byte_val & bit_mask) ? fg_color : bg_color;
|
||||
gc9a01_draw_pixel(self, cursor_x + x + xOffset, cursor_y + y + yOffset, pixel_color);
|
||||
// Render the glyph bitmap
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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_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_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);
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
||||
#ifdef __cplusplus
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user