15 static const struct mf_bwfont_char_range_s *find_char_range(
16 const struct mf_bwfont_s *font, gU16 character, gU16 *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 gU8 get_width(
const struct mf_bwfont_char_range_s *r, gU16 index)
38 return r->width + r->offset_x;
42 return r->glyph_widths[index];
46 static gU8 render_char(
const struct mf_bwfont_char_range_s *r,
47 gI16 x0, gI16 y0, gU16 index,
48 mf_pixel_callback_t callback,
53 gU8 x, y, height, num_cols;
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 gU8 mf_bwfont_render_character(
const struct mf_font_s *font,
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 gU8 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);