X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Ftests%2FFTBench.c;fp=src%2Ftests%2FFTBench.c;h=9bb6dacc6a313c937a9f1ff4d4e53bd33e42b928;hb=3eb15f58ca0911489d7d9bdc0ac2c575d27a68d8;hp=0000000000000000000000000000000000000000;hpb=a6ee28ca37621098ed040e6d1c4ae103934c3e97;p=nestedvm.git diff --git a/src/tests/FTBench.c b/src/tests/FTBench.c new file mode 100644 index 0000000..9bb6dac --- /dev/null +++ b/src/tests/FTBench.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include + +#define FT_Check(expr) do { \ + if((expr) != 0) { \ + fprintf(stderr,#expr " failed\n"); \ + exit(EXIT_FAILURE); \ + } \ +} while(0) + +#define BMP_WIDTH 800 +#define BMP_HEIGHT 600 + +static char buf[BMP_WIDTH*BMP_HEIGHT]; + +int main(int argc, char **argv) { + char *ttf; + char *out; + FT_Library library; + FT_Face face; + FT_GlyphSlot glyph; + int num_glyphs; + int c; + int glyph_index; + int loc_x; + int loc_y; + int glyph_width; + int glyph_height; + int i,j; + int fd; + char *p; + int n,count; + char *glyph_buf; + int pixel_size; + + if(argc < 3) { + fprintf(stderr,"Usage: %s ttf bmp\n",argv[0]); + exit(1); + } + + ttf = argv[1]; + out = argv[2]; + + memset(buf,'\377',BMP_WIDTH*BMP_HEIGHT); + + FT_Check(FT_Init_FreeType(&library)); + FT_Check(FT_New_Face(library,ttf,0,&face)); + + loc_y = loc_x = 0; + for(pixel_size=8;pixel_size<48;pixel_size+=4) { + FT_Check(FT_Set_Pixel_Sizes(face,0,pixel_size)); + for(c=32;c<127;c++) { + glyph_index = FT_Get_Char_Index(face,c); + FT_Check(FT_Load_Glyph(face,glyph_index,FT_LOAD_DEFAULT)); + FT_Check(FT_Render_Glyph(face->glyph, ft_render_mode_normal)); + glyph = face->glyph; + glyph_width = glyph->bitmap.width; + glyph_height = glyph->bitmap.rows; + glyph_buf = glyph->bitmap.buffer; + if(loc_x + glyph_width + glyph->bitmap_left >= BMP_WIDTH) { + loc_x = 0; + loc_y += pixel_size; + if(loc_y >= BMP_HEIGHT-pixel_size) goto done; + } + + for(i=0;iglyph->advance.x/64; + } + } +done: + + if((fd = open(out,O_CREAT|O_WRONLY,0644)) < 0) { + perror("open"); + exit(1); + } + p = buf; + count = BMP_WIDTH*BMP_HEIGHT; + + while(count) { + n = write(fd,p,count); + if(n < 0) { + perror("write"); + exit(1); + } + count -=n; + p += n; + } + close(fd); + + return 0; +}