8 static FT_Library library
;
10 static int rows
, cols
;
12 static void xdie(char *msg
)
14 fprintf(stderr
, "%s\n", msg
);
20 FT_Init_FreeType(&library
);
21 if (FT_New_Face(library
, FONTFACE
, 0, &face
))
22 xdie("failed to load font");
23 FT_Set_Char_Size(face
, 0, FONTSIZE
<< 6, DPI
, DPI
);
24 rows
= face
->size
->metrics
.height
>> 6;
25 cols
= (face
->size
->metrics
.max_advance
>> 6) + WIDTHDIFF
;
28 unsigned char *font_bitmap(int c
)
30 static unsigned char bits
[MAXDOTS
];
34 if (FT_Load_Char(face
, c
, FT_LOAD_RENDER
))
36 sr
= rows
+ (face
->size
->metrics
.descender
>> 6) -
37 face
->glyph
->bitmap_top
;
38 sc
= face
->glyph
->bitmap_left
;
39 er
= MIN(rows
, sr
+ face
->glyph
->bitmap
.rows
);
40 ec
= MIN(cols
, sc
+ face
->glyph
->bitmap
.width
);
41 memset(bits
, 0, rows
* cols
);
42 src
= face
->glyph
->bitmap
.buffer
- MIN(0, sc
);
44 for (i
= MAX(0, sr
); i
< er
; i
++) {
45 int w
= face
->glyph
->bitmap
.pitch
;
46 memcpy(&bits
[i
* cols
+ sc
], src
+ (i
- sr
) * w
, ec
- sc
);
54 FT_Done_FreeType(library
);