27 * glyphs[n] unicode character numbers (int)
28 * bitmaps[n] character bitmaps (char[rows * cols])
37 struct font
*font_open(char *path
)
41 font
= malloc(sizeof(*font
));
42 font
->fd
= open(path
, O_RDONLY
);
45 fcntl(font
->fd
, F_SETFD
, fcntl(font
->fd
, F_GETFD
) | FD_CLOEXEC
);
46 if (read(font
->fd
, &head
, sizeof(head
)) != sizeof(head
))
49 font
->rows
= head
.rows
;
50 font
->cols
= head
.cols
;
51 font
->glyphs
= malloc(font
->n
* sizeof(int));
52 if (read(font
->fd
, font
->glyphs
, font
->n
* sizeof(int)) != font
->n
* sizeof(int))
57 static int find_glyph(struct font
*font
, int c
)
63 if (font
->glyphs
[m
] == c
)
65 if (c
< font
->glyphs
[m
])
73 int font_bitmap(struct font
*font
, void *dst
, int c
)
75 int i
= find_glyph(font
, c
);
78 lseek(font
->fd
, sizeof(struct tinyfont
) + font
->n
* sizeof(int) +
79 i
* font
->rows
* font
->cols
, 0);
80 read(font
->fd
, dst
, font
->rows
* font
->cols
);
84 void font_free(struct font
*font
)
91 int font_rows(struct font
*font
)
96 int font_cols(struct font
*font
)