11 static const char *
const TAG =
"font";
19 for (uint32_t i = 0;; i++) {
33 for (uint32_t i = 0;; i++) {
50 : baseline_(baseline), height_(height), bpp_(bpp) {
52 for (
int i = 0; i < data_nr; ++i)
57 int hi = this->
glyphs_.size() - 1;
59 int mid = (lo + hi + 1) / 2;
60 if (this->
glyphs_[mid].compare_to(str)) {
66 *match_length = this->
glyphs_[lo].match_length(str);
67 if (*match_length <= 0)
71 void Font::measure(
const char *str,
int *width,
int *x_offset,
int *baseline,
int *height) {
76 bool has_char =
false;
78 while (str[i] !=
'\0') {
80 int glyph_n = this->
match_next_glyph((
const uint8_t *) str + i, &match_length);
106 int scan_x1, scan_y1, scan_width, scan_height;
107 while (text[i] !=
'\0') {
109 int glyph_n = this->
match_next_glyph((
const uint8_t *) text + i, &match_length);
112 ESP_LOGW(TAG,
"Encountered character without representation in font: '%c'", text[i]);
114 uint8_t glyph_width = this->
get_glyphs()[0].glyph_data_->width;
124 glyph.
scan_area(&scan_x1, &scan_y1, &scan_width, &scan_height);
127 const int max_x = x_at + scan_x1 + scan_width;
128 const int max_y = y_start + scan_y1 + scan_height;
131 uint8_t pixel_data = 0;
132 uint8_t bpp_max = (1 << this->
bpp_) - 1;
133 auto diff_r = (float) color.
r - (
float) background.
r;
134 auto diff_g = (float) color.
g - (
float) background.
g;
135 auto diff_b = (float) color.
b - (
float) background.
b;
136 auto b_r = (float) background.
r;
137 auto b_g = (
float) background.
g;
138 auto b_b = (float) background.
g;
139 for (
int glyph_y = y_start + scan_y1; glyph_y != max_y; glyph_y++) {
140 for (
int glyph_x = x_at + scan_x1; glyph_x != max_x; glyph_x++) {
142 for (
int bit_num = 0; bit_num != this->
bpp_; bit_num++) {
148 if ((pixel_data & bitmask) != 0)
152 if (pixel == bpp_max) {
154 }
else if (pixel != 0) {
155 auto on = (float) pixel / (
float) bpp_max;
157 Color((uint8_t) (diff_r * on + b_r), (uint8_t) (diff_g * on + b_g), (uint8_t) (diff_b * on + b_b));
Font(const GlyphData *data, int data_nr, int baseline, int height, uint8_t bpp=1)
Construct the font with the given glyphs.
void print(int x_start, int y_start, display::Display *display, Color color, const char *text, Color background) override
const uint8_t * get_char() const
void filled_rectangle(int x1, int y1, int width, int height, Color color=COLOR_ON)
Fill a rectangle with the top left point at [x1,y1] and the bottom right point at [x1+width...
int match_next_glyph(const uint8_t *str, int *match_length)
void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override
const std::vector< Glyph, ExternalRAMAllocator< Glyph > > & get_glyphs() const
uint8_t progmem_read_byte(const uint8_t *addr)
void draw_pixel_at(int x, int y)
Set a single pixel at the specified coordinates to default color.
Implementation of SPI Controller mode.
int match_length(const uint8_t *str) const
bool compare_to(const uint8_t *str) const
const GlyphData * glyph_data_
std::vector< Glyph, ExternalRAMAllocator< Glyph > > glyphs_
void scan_area(int *x1, int *y1, int *width, int *height) const