9#include <utils/gp_vec.h>
25static int emit_glyph(uint8_t **data,
const struct gpf_glyph *glyph,
28 unsigned int row_bytes = (glyph->
width + 7) / 8;
29 size_t need = 5 + (size_t)row_bytes * glyph->
height;
30 size_t pos = gp_vec_len(*data);
35 need = (need + 3) & ~(
size_t)3;
37 dst = gp_vec_expand(*data, need);
46 dst[0] = glyph->width;
47 dst[1] = glyph->height;
48 dst[2] = glyph->bearing_x;
49 dst[3] = glyph->bearing_y;
50 dst[4] = glyph->advance;
52 for (y = 0; y < glyph->height; y++) {
53 for (x = 0; x < glyph->width; x++) {
55 dst[5 + y * row_bytes + x/8] |= 0x80 >> (x%8);
65 gp_glyphs *table, uint32_t min, uint32_t max,
66 uint8_t **data, gp_font_face *face,
67 gp_glyph_offset blank)
70 size_t cnt = max - min + 1;
72 table->offsets = malloc(cnt *
sizeof(gp_glyph_offset));
76 table->min_glyph = min;
77 table->max_glyph = max;
79 for (code = min; code <= max; code++) {
90 table->offsets[code - min] = blank;
95 if (emit_glyph(data, &res.glyph, &table->offsets[code - min])) {
102 if (width > face->max_glyph_width)
103 face->max_glyph_width = width;
105 if (res.glyph.advance > face->max_glyph_advance)
106 face->max_glyph_advance = res.glyph.advance;
120 uint32_t high_max = 0;
121 unsigned int tables = 1, i;
124 gp_glyph_offset blank_off;
130 for (j = 0; j < gp_vec_len(codes); j++) {
131 if (codes[j] > ASCII_MAX)
140 face = calloc(1,
sizeof(gp_font_face) + tables *
sizeof(gp_glyphs));
144 data = gp_vec_new(0, 1);
150 snprintf(face->family_name,
sizeof(face->family_name),
"%s", m->
family);
155 face->style |= GP_FONT_BOLD;
157 face->glyph_tables = tables;
160 face->glyph_bitmap_format = GP_FONT_BITMAP_1BPP;
182 if (emit_glyph(&data, &blank, &blank_off))
185 if (build_table(font,
id, &face->glyphs[0], ASCII_MIN, ASCII_MAX,
186 &data, face, blank_off))
190 if (build_table(font,
id, &face->glyphs[1], ASCII_MAX + 1,
191 high_max, &data, face, blank_off))
199 for (i = 0; i < tables; i++)
200 face->glyphs[i].glyphs = data;
206 for (i = 0; i < tables; i++)
207 free(face->glyphs[i].offsets);
215void gpf_face_free(gp_font_face *self)
222 for (i = 0; i < self->glyph_tables; i++)
223 free(self->glyphs[i].offsets);
225 gp_vec_free(self->priv);
Compiles a gfxprim font face from an in-memory gpf font.
static int gpf_glyph_pixel(const struct gpf_glyph *self, unsigned int x, unsigned int y)
Returns a glyph ink pixel.
gpf_variant_id
Font face variant.
@ GPF_BOLD_MONO
Bold monospace glyphs.
@ GPF_MONO
Monospace glyphs, the base variant.
uint32_t * gpf_font_codes(struct gpf_font *self)
Returns every codepoint the font mentions, in any variant.
The glyph variant lattice.
void gpf_resolved_clear(struct gpf_resolved *self)
Clears the resolved glyph.
int gpf_resolve(struct gpf_font *font, enum gpf_variant_id id, uint32_t code, struct gpf_resolved *res)
Resolves a glyph variant metric and ink.
struct gpf_family_meta meta
Font meta data.
unsigned int height
Glyph ink height.
unsigned int width
Glyph ink width.
int bearing_x
Glyph bearing x.
A resolved glyph and where it was drawn from.
struct gpf_glyph glyph
Freshly allocated glyph with copied/generated ink.