59 #ifndef CONFIG_FONT_PIXELS_PER_BYTE 60 # define CONFIG_FONT_PIXELS_PER_BYTE 8 63 #define EXTMEM_BUF_SIZE 20 65 #if defined(CONFIG_HUGEMEM) || defined(__DOXYGEN__) 86 static void gfx_draw_char_hugemem(
const char ch,
const gfx_coord_t x,
91 uint8_t char_row_size;
93 uint16_t glyph_data_offset;
94 uint8_t char_buff[EXTMEM_BUF_SIZE];
104 char_row_size = font->
width / CONFIG_FONT_PIXELS_PER_BYTE;
105 if (font->
width % CONFIG_FONT_PIXELS_PER_BYTE) {
109 glyph_size = char_row_size * font->
height;
110 glyph_data_offset = glyph_size * ((uint8_t)ch - font->
first_char);
111 buffer_pos = EXTMEM_BUF_SIZE;
115 static uint8_t glyph_byte = 0;
116 uint8_t pixelsToDraw = font->
width;
118 for (i = 0; i < pixelsToDraw; i++) {
119 if (i % CONFIG_FONT_PIXELS_PER_BYTE == 0) {
121 if (buffer_pos >= EXTMEM_BUF_SIZE) {
123 = font->data.hugemem;
124 source = (hugemem_ptr_t)
128 hugemem_read_block(char_buff, source,
131 glyph_data_offset += EXTMEM_BUF_SIZE;
135 glyph_byte = char_buff[buffer_pos];
140 if ((glyph_byte & 0x80)) {
150 }
while (--rows_left > 0);
178 uint8_t PROGMEM_PTR_T glyph_data;
179 uint16_t glyph_data_offset;
180 uint8_t char_row_size;
190 char_row_size = font->
width / CONFIG_FONT_PIXELS_PER_BYTE;
191 if (font->
width % CONFIG_FONT_PIXELS_PER_BYTE) {
195 glyph_data_offset = char_row_size * font->
height *
197 glyph_data = font->data.
progmem + glyph_data_offset;
201 uint8_t glyph_byte = 0;
202 uint8_t pixelsToDraw = font->
width;
204 for (i = 0; i < pixelsToDraw; i++) {
205 if (i % CONFIG_FONT_PIXELS_PER_BYTE == 0) {
206 glyph_byte = PROGMEM_READ_BYTE(glyph_data);
210 if ((glyph_byte & 0x80)) {
221 }
while (rows_left > 0);
235 const struct font *font,
const gfx_color_t bg_color,
242 switch (font->
type) {
247 #ifdef CONFIG_HUGEMEM 248 case FONT_LOC_HUGEMEM:
249 gfx_draw_char_hugemem(c, x, y, font, text_color);
273 const struct font *font,
const gfx_color_t bg_color,
296 const struct font *font,
const gfx_color_t bg_color,
319 }
else if (text_pos & TEXT_POS_RIGHT) {
324 while (*str !=
'\0') {
325 const char *curr_line_text = str;
334 }
else if (*str !=
'\r') {
335 curr_line_width += font->
width;
337 }
while (*(++str) !=
'\0');
342 if (text_align == TEXT_ALIGN_CENTER) {
343 curr_line_x += (bounding_x / 2) - (curr_line_width / 2);
345 curr_line_x += bounding_x - curr_line_width;
352 if (*curr_line_text ==
'\n') {
354 }
else if (*curr_line_text !=
'\r') {
356 font, bg_color, text_color);
361 curr_line_x += font->
width;
363 }
while (*(++curr_line_text) !=
'\0');
429 &bounding_x, &bounding_y);
441 }
else if (text_pos & TEXT_POS_RIGHT) {
445 curr_str_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)str);
448 while (curr_str_char !=
'\0') {
449 char PROGMEM_PTR_T curr_line_text = str;
456 if (curr_str_char ==
'\n') {
459 (uint8_t PROGMEM_PTR_T)(++str));
461 }
else if (curr_str_char !=
'\r') {
462 curr_line_width += font->
width;
465 curr_str_char = PROGMEM_READ_BYTE(
466 (uint8_t PROGMEM_PTR_T)(++str));
467 }
while (curr_str_char !=
'\0');
472 if (text_align == TEXT_ALIGN_CENTER) {
473 curr_line_x += (bounding_x / 2) - (curr_line_width / 2);
475 curr_line_x += bounding_x - curr_line_width;
478 curr_line_char = PROGMEM_READ_BYTE(
479 (uint8_t PROGMEM_PTR_T)curr_line_text);
485 if (*curr_line_text ==
'\n') {
487 }
else if (*curr_line_text !=
'\r') {
489 font, bg_color, text_color);
494 curr_line_x += font->
width;
497 curr_line_char = PROGMEM_READ_BYTE(
498 (uint8_t PROGMEM_PTR_T)(++curr_line_text));
499 }
while (curr_line_char !=
'\0');
538 max_height += font_height;
539 }
else if (*str ==
'\r') {
551 *height = max_height;
582 temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)str);
586 if (temp_char ==
'\n') {
588 max_height += font_height;
589 }
else if (*str ==
'\r') {
598 temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)(++str));
603 *height = max_height;
void gfx_draw_string(const char *str, gfx_coord_t x, gfx_coord_t y, const struct font *font, const gfx_color_t bg_color, const gfx_color_t text_color)
Draws a string to the display.
void gfx_get_progmem_string_bounding_box(char PROGMEM_PTR_T str, const struct font *font, gfx_coord_t *width, gfx_coord_t *height)
Computes the bounding box of a string located in program memory.
void gfx_draw_progmem_string(char PROGMEM_PTR_T str, gfx_coord_t x, gfx_coord_t y, const struct font *font, const gfx_color_t bg_color, const gfx_color_t text_color)
Draws a string located in program memory to the display.
Commonly used includes, types and macros.
#define Assert(expr)
This macro is used to test fatal errors.
void gfx_get_string_bounding_box(const char *str, const struct font *font, gfx_coord_t *width, gfx_coord_t *height)
Computes the bounding box of a string.
#define gfx_draw_pixel(x, y, color)
#define GFX_COLOR_TRANSPARENT
Value used as input to font functions to give a transparent background region.
ili9341_coord_t gfx_coord_t
Data type representing a coordinate on the screen.
Graphical library API header file.
static void gfx_draw_char_progmem(const char ch, const gfx_coord_t x, const gfx_coord_t y, const struct font *font, const gfx_color_t color)
Helper function that draws a character from a font in progmem to the display.
void gfx_draw_progmem_string_aligned(char PROGMEM_PTR_T str, gfx_coord_t x, gfx_coord_t y, const struct font *font, const gfx_color_t bg_color, const gfx_color_t text_color, enum gfx_text_position text_pos, enum gfx_text_alignment text_align)
Draws an aligned string located in program memory to the display.
Graphic library API header file.
#define gfx_draw_filled_rect(x, y, width, height, color)
void gfx_draw_string_aligned(const char *str, gfx_coord_t x, gfx_coord_t y, const struct font *font, const gfx_color_t bg_color, const gfx_color_t text_color, enum gfx_text_position text_pos, enum gfx_text_alignment text_align)
Draws an aligned string to the display.
ili9341_color_t gfx_color_t
Data type for color values native to the display.
void gfx_draw_char(const char c, const gfx_coord_t x, const gfx_coord_t y, const struct font *font, const gfx_color_t bg_color, const gfx_color_t text_color)
Draws a character to the display.
uint8_t PROGMEM_PTR_T progmem