8 static FT_Library library
;
10 static int rows
, cols
;
14 FT_Init_FreeType(&library
);
15 if (FT_New_Face(library
, FONTFACE
, 0, &face
))
16 xerror("failed to load font");
17 FT_Set_Char_Size(face
, 0, FONTSIZE
<< 6, DPI
, DPI
);
18 rows
= face
->size
->metrics
.height
>> 6;
19 cols
= (face
->size
->metrics
.max_advance
>> 6) + WIDTHDIFF
;
22 unsigned char *font_bitmap(int c
)
24 static unsigned char bits
[MAXDOTS
];
28 if (FT_Load_Char(face
, c
, FT_LOAD_RENDER
))
30 sr
= rows
+ (face
->size
->metrics
.descender
>> 6) -
31 face
->glyph
->bitmap_top
;
32 sc
= face
->glyph
->bitmap_left
;
33 er
= MIN(rows
, sr
+ face
->glyph
->bitmap
.rows
);
34 ec
= MIN(cols
, sc
+ face
->glyph
->bitmap
.width
);
35 memset(bits
, 0, rows
* cols
);
36 src
= face
->glyph
->bitmap
.buffer
- MIN(0, sc
);
38 for (i
= MAX(0, sr
); i
< er
; i
++) {
39 int w
= face
->glyph
->bitmap
.pitch
;
40 memcpy(&bits
[i
* cols
+ sc
], src
+ (i
- sr
) * w
, ec
- sc
);
48 FT_Done_FreeType(library
);