2 #include <freetype/freetype.h>
6 #define FT_Check(expr) do { \
8 fprintf(stderr,#expr " failed\n"); \
14 #define BMP_HEIGHT 600
16 static char buf[BMP_WIDTH*BMP_HEIGHT];
18 int main(int argc, char **argv) {
39 fprintf(stderr,"Usage: %s ttf bmp\n",argv[0]);
46 memset(buf,'\377',BMP_WIDTH*BMP_HEIGHT);
48 FT_Check(FT_Init_FreeType(&library));
49 FT_Check(FT_New_Face(library,ttf,0,&face));
52 for(pixel_size=8;pixel_size<48;pixel_size+=4) {
53 FT_Check(FT_Set_Pixel_Sizes(face,0,pixel_size));
55 glyph_index = FT_Get_Char_Index(face,c);
56 FT_Check(FT_Load_Glyph(face,glyph_index,FT_LOAD_DEFAULT));
57 FT_Check(FT_Render_Glyph(face->glyph, ft_render_mode_normal));
59 glyph_width = glyph->bitmap.width;
60 glyph_height = glyph->bitmap.rows;
61 glyph_buf = glyph->bitmap.buffer;
62 if(loc_x + glyph_width + glyph->bitmap_left >= BMP_WIDTH) {
65 if(loc_y >= BMP_HEIGHT-pixel_size) goto done;
68 for(i=0;i<glyph_height;i++)
69 for(j=0;j<glyph_width;j++)
70 buf[(loc_y+i)*BMP_WIDTH+loc_x+j] &= (~glyph_buf[i*glyph_width+j]);
71 loc_x += face->glyph->advance.x/64;
76 if((fd = open(out,O_CREAT|O_WRONLY,0644)) < 0) {
81 count = BMP_WIDTH*BMP_HEIGHT;
84 n = write(fd,p,count);