15 static const struct mf_bwfont_char_range_s *find_char_range(
16 const struct mf_bwfont_s *font, uint16_t character, uint16_t *index_ret)
19 const struct mf_bwfont_char_range_s *range;
20 for (i = 0; i < font->char_range_count; i++)
22 range = &font->char_ranges[i];
23 index = character - range->first_char;
24 if (character >= range->first_char && index < range->char_count)
34 static uint8_t get_width(
const struct mf_bwfont_char_range_s *r, uint16_t index)
38 return r->width + r->offset_x;
42 return r->glyph_widths[index];
46 static uint8_t render_char(
const struct mf_bwfont_char_range_s *r,
47 int16_t x0, int16_t y0, uint16_t index,
48 mf_pixel_callback_t callback,
51 const uint8_t *data, *p;
52 uint8_t stride, runlen;
53 uint8_t x, y, height, num_cols;
54 uint8_t bit, byte, mask;
55 bool oldstate, newstate;
59 data = r->glyph_data + r->width * index * r->height_bytes;
64 data = r->glyph_data + r->glyph_offsets[index] * r->height_bytes;
65 num_cols = r->glyph_offsets[index + 1] - r->glyph_offsets[index];
68 stride = r->height_bytes;
69 height = r->height_pixels;
75 for (y = 0; y < height; y++)
82 for (x = 0; x < num_cols; x++, p += stride)
85 if (newstate != oldstate)
87 if (oldstate && runlen)
89 callback(x0 + x - runlen, y0 + y, runlen, 255, state);
99 if (oldstate && runlen)
101 callback(x0 + x - runlen, y0 + y, runlen, 255, state);
112 return get_width(r, index);
115 uint8_t mf_bwfont_render_character(
const struct mf_font_s *font,
116 int16_t x0, int16_t y0,
118 mf_pixel_callback_t callback,
121 const struct mf_bwfont_s *bwfont = (
const struct mf_bwfont_s*)font;
122 const struct mf_bwfont_char_range_s *range;
125 range = find_char_range(bwfont, character, &index);
129 return render_char(range, x0, y0, index, callback, state);
132 uint8_t mf_bwfont_character_width(
const struct mf_font_s *font,
135 const struct mf_bwfont_s *bwfont = (
const struct mf_bwfont_s*)font;
136 const struct mf_bwfont_char_range_s *range;
139 range = find_char_range(bwfont, character, &index);
143 return get_width(range, index);
146 #endif //MF_NO_COMPILE