8 static FT_Library library
;
10 static int rows
, cols
;
14 FT_Init_FreeType(&library
);
15 FT_New_Face(library
, FONTFACE
, 0, &face
);
16 FT_Set_Char_Size(face
, 0, FONTSIZE
<< 6, DPI
, DPI
);
17 rows
= face
->size
->metrics
.height
>> 6;
18 cols
= (face
->size
->metrics
.max_advance
>> 6) + WIDTHDIFF
;
21 unsigned char *font_bitmap(int c
)
23 static unsigned char bits
[MAXDOTS
];
26 if (FT_Load_Char(face
, c
, FT_LOAD_RENDER
))
28 sr
= MAX(0, rows
+ (face
->size
->metrics
.descender
>> 6) -
29 (face
->glyph
->metrics
.horiBearingY
>> 6));
30 sc
= MAX(0, face
->glyph
->metrics
.horiBearingX
>> 6);
31 er
= MIN(rows
, sr
+ face
->glyph
->bitmap
.rows
);
32 ec
= MIN(cols
, sc
+ face
->glyph
->bitmap
.width
);
33 memset(bits
, 0, sr
* cols
);
34 for (i
= sr
; i
< er
; i
++) {
35 unsigned char *rowaddr
= face
->glyph
->bitmap
.buffer
+
36 (i
- sr
) * face
->glyph
->bitmap
.pitch
;
37 memset(&bits
[i
* cols
], 0, sc
);
38 memcpy(&bits
[i
* cols
+ sc
], rowaddr
, ec
- sc
);
39 memset(&bits
[i
* cols
+ ec
], 0, cols
- ec
);
41 memset(&bits
[er
* cols
], 0, (rows
- er
) * cols
);
48 FT_Done_FreeType(library
);