25 * glyphs[n] unicode character numbers (int)
26 * bitmaps[n] character bitmaps (char[rows * cols])
35 static void *xread(int fd
, int len
)
37 void *buf
= malloc(len
);
38 if (buf
&& read(fd
, buf
, len
) == len
)
44 struct font
*font_open(char *path
)
48 int fd
= open(path
, O_RDONLY
);
49 if (fd
< 0 || read(fd
, &head
, sizeof(head
)) != sizeof(head
)) {
53 font
= malloc(sizeof(*font
));
55 font
->rows
= head
.rows
;
56 font
->cols
= head
.cols
;
57 font
->glyphs
= xread(fd
, font
->n
* sizeof(int));
58 font
->data
= xread(fd
, font
->n
* font
->rows
* font
->cols
);
60 if (!font
->glyphs
|| !font
->data
) {
67 static int find_glyph(struct font
*font
, int c
)
73 if (font
->glyphs
[m
] == c
)
75 if (c
< font
->glyphs
[m
])
83 int font_bitmap(struct font
*font
, void *dst
, int c
)
85 int i
= find_glyph(font
, c
);
86 int len
= font
->rows
* font
->cols
;
89 memcpy(dst
, font
->data
+ i
* len
, len
);
93 void font_free(struct font
*font
)
102 int font_rows(struct font
*font
)
107 int font_cols(struct font
*font
)