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
];
27 if (FT_Load_Char(face
, c
, FT_LOAD_RENDER
))
29 sr
= MAX(0, rows
+ (face
->size
->metrics
.descender
>> 6) -
30 (face
->glyph
->metrics
.horiBearingY
>> 6));
31 sc
= MAX(0, face
->glyph
->metrics
.horiBearingX
>> 6);
32 er
= MIN(rows
, sr
+ face
->glyph
->bitmap
.rows
);
33 ec
= MIN(cols
, sc
+ face
->glyph
->bitmap
.width
);
34 memset(bits
, 0, sr
* cols
);
35 for (i
= sr
; i
< er
; i
++) {
36 unsigned char *rowaddr
= face
->glyph
->bitmap
.buffer
+
37 (i
- sr
) * face
->glyph
->bitmap
.pitch
;
38 memset(&bits
[i
* cols
], 0, sc
);
39 memcpy(&bits
[i
* cols
+ sc
], rowaddr
, ec
- sc
);
40 memset(&bits
[i
* cols
+ ec
], 0, cols
- ec
);
42 memset(&bits
[er
* cols
], 0, (rows
- er
) * cols
);
49 FT_Done_FreeType(library
);