font: remove the unused arg of font_bitmap()
[fbpad.git] / font.c
blobc91b8c0ab2f159d03f621d4981e697914eb2dbc7
1 #include <ft2build.h>
2 #include FT_FREETYPE_H
3 #include FT_BITMAP_H
4 #include "font.h"
5 #include "util.h"
7 #define FONTFACE "/usr/lib/X11/fonts/TTF/DejaVuSansMono.ttf"
8 #define FONTSIZE 10
9 #define DPI 192
10 #define WIDTHDIFF 1
12 static FT_Library library;
13 static FT_Face face;
14 static int rows, cols;
16 void font_init(void)
18 FT_Init_FreeType(&library);
19 FT_New_Face(library, FONTFACE, 0, &face);
20 FT_Set_Char_Size(face, 0, FONTSIZE << 6, DPI, DPI);
21 rows = face->size->metrics.height >> 6;
22 cols = (face->size->metrics.max_advance >> 6) + WIDTHDIFF;
25 unsigned char *font_bitmap(int c)
27 static unsigned char bits[MAXDOTS];
28 int sr, sc, er, ec;
29 int i;
30 if (FT_Load_Char(face, c, FT_LOAD_RENDER))
31 return NULL;
32 sr = MAX(0, rows + (face->size->metrics.descender >> 6) -
33 (face->glyph->metrics.horiBearingY >> 6));
34 sc = MAX(0, face->glyph->metrics.horiBearingX >> 6);
35 er = MIN(rows, sr + face->glyph->bitmap.rows);
36 ec = MIN(cols, sc + face->glyph->bitmap.width);
37 memset(bits, 0, sr * cols);
38 for (i = sr; i < er; i++) {
39 unsigned char *rowaddr = face->glyph->bitmap.buffer +
40 (i - sr) * face->glyph->bitmap.pitch;
41 memset(&bits[i * cols], 0, sc);
42 memcpy(&bits[i * cols + sc], rowaddr, ec - sc);
43 memset(&bits[i * cols + ec], 0, cols - ec);
45 memset(&bits[er * cols], 0, (rows - er) * cols);
46 return bits;
49 void font_free(void)
51 FT_Done_Face(face);
52 FT_Done_FreeType(library);
55 int font_rows(void)
57 return rows;
60 int font_cols(void)
62 return cols;