6 #define FONTFACE "/usr/lib/X11/fonts/TTF/DejaVuSansMono.ttf"
9 #define MAXDOTS (1 << 10)
12 static FT_Library library
;
14 static int rows
, cols
;
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
, int bold
)
27 static unsigned char bits
[MAXDOTS
];
30 if (FT_Load_Char(face
, c
, FT_LOAD_RENDER
))
33 int FT_GlyphSlot_Own_Bitmap(FT_GlyphSlot
);
34 FT_GlyphSlot_Own_Bitmap(face
->glyph
);
35 FT_Bitmap_Embolden(library
, &face
->glyph
->bitmap
, 32, 32);
37 sr
= rows
+ (face
->size
->metrics
.descender
>> 6) -
38 (face
->glyph
->metrics
.horiBearingY
>> 6);
39 sc
= face
->glyph
->metrics
.horiBearingX
>> 6;
40 er
= MIN(rows
, sr
+ face
->glyph
->bitmap
.rows
);
41 ec
= MIN(cols
, sc
+ face
->glyph
->bitmap
.width
);
42 memset(bits
, 0, sr
* cols
);
43 for (i
= sr
; i
< er
; i
++) {
44 unsigned char *rowaddr
= face
->glyph
->bitmap
.buffer
+
45 (i
- sr
) * face
->glyph
->bitmap
.pitch
;
46 memset(&bits
[i
* cols
], 0, sc
);
47 memcpy(&bits
[i
* cols
+ sc
], rowaddr
, ec
- sc
);
48 memset(&bits
[i
* cols
+ ec
], 0, cols
- ec
);
50 memset(&bits
[er
* cols
], 0, (rows
- er
) * cols
);
57 FT_Done_FreeType(library
);