27 * glyphs[n] unicode character numbers (int)
28 * bitmaps[n] character bitmaps (char[rows * cols])
37 static void *xread(int fd
, int len
)
39 void *buf
= malloc(len
);
40 if (buf
&& read(fd
, buf
, len
) == len
)
46 struct font
*font_open(char *path
)
50 int fd
= open(path
, O_RDONLY
);
51 if (fd
< 0 || read(fd
, &head
, sizeof(head
)) != sizeof(head
)) {
55 font
= malloc(sizeof(*font
));
57 font
->rows
= head
.rows
;
58 font
->cols
= head
.cols
;
59 font
->glyphs
= xread(fd
, font
->n
* sizeof(int));
60 font
->data
= xread(fd
, font
->n
* font
->rows
* font
->cols
);
62 if (!font
->glyphs
|| !font
->data
) {
69 static int find_glyph(struct font
*font
, int c
)
75 if (font
->glyphs
[m
] == c
)
77 if (c
< font
->glyphs
[m
])
85 int font_bitmap(struct font
*font
, void *dst
, int c
)
87 int i
= find_glyph(font
, c
);
88 int len
= font
->rows
* font
->cols
;
91 memcpy(dst
, font
->data
+ i
* len
, len
);
95 void font_free(struct font
*font
)
104 int font_rows(struct font
*font
)
109 int font_cols(struct font
*font
)