/* example1_Modified.c */ /* */ /* This small program shows how to print a glyph CID 4838 with HeisiMinchoW3 */ /* FreeType 2 library. */ #include #include #include #include #include FT_FREETYPE_H #include #define WIDTH 400 #define HEIGHT 400 #define GLYPH_4838 4838 #define RES_X 600 #define RES_Y 360 #define POINTSIZE 7 #define GetBitInByte(ByteSrc,BitNum) \ (((ByteSrc) & (1 << (BitNum)))?1:0) /* origin is the upper left corner */ unsigned char image[HEIGHT][WIDTH]; /* Replace this function with something useful. */ void draw_bitmap( FT_Bitmap* bitmap) { FT_Int xcurr,ycurr; FT_Byte byte_; FT_Byte Bit_; FT_Byte *l_pBuffer; for(ycurr = 0;ycurrrows;ycurr++) { l_pBuffer = bitmap->buffer + bitmap->pitch*ycurr; Bit_ = 0; for(xcurr = 0;xcurrwidth;xcurr++) { byte_ = GetBitInByte(*l_pBuffer,7-Bit_); if(byte_) image[ycurr][xcurr] = 255; else image[ycurr][xcurr] = 0; Bit_++; if(Bit_ == 8) { Bit_ = 0; l_pBuffer++; } } } } void show_image( FT_Bitmap* bitmap ) { int i, j; putchar( '\n' ); putchar( '\n' ); for ( i = 0; i < bitmap->rows; i++ ) { for ( j = 0; j < bitmap->width; j++ ) { putchar( image[i][j] == 0 ? ' ' : '*' ); } putchar( '\n' ); } } int main( int argc, char** argv ) { FT_Library library; FT_Face face; FT_Error error; char* filename; int target_height; FT_Render_Mode l_FT_Render_Mode; FT_Glyph l_FT_Glyph; FT_BitmapGlyph l_BitmapGlyph; FT_Int32 l_LoadFlags; if ( argc != 2 ) { fprintf ( stderr, "usage: %s font sample-text\n", argv[0] ); exit( 1 ); } filename = argv[1]; /* first argument */ target_height = HEIGHT; error = FT_Init_FreeType( &library ); /* initialize library */ /* error handling omitted */ error = FT_New_Face( library, filename, 0, &face );/* create face object */ /* error handling omitted */ /* use 7 at 600x360dpi */ error = FT_Set_Char_Size( face, POINTSIZE * 64, POINTSIZE * 64, RES_X, RES_Y ); /* set character size */ /* Init Value */ l_FT_Glyph = NULL; l_LoadFlags = FT_LOAD_TARGET_MONO; l_BitmapGlyph = NULL; l_FT_Render_Mode = FT_RENDER_MODE_MONO; /* Load specific glyph Value */ error = FT_Load_Glyph(face, GLYPH_4838,l_LoadFlags); /* get glyph */ error = FT_Get_Glyph(face->glyph,&l_FT_Glyph); /* Raster */ error = FT_Glyph_To_Bitmap(&l_FT_Glyph,l_FT_Render_Mode,(FT_Vector *) NULL,1); /* now, draw to our target surface (convert position) */ l_BitmapGlyph = (FT_BitmapGlyph) l_FT_Glyph; draw_bitmap( &l_BitmapGlyph->bitmap); /* Console */ show_image(&l_BitmapGlyph->bitmap); FT_Done_Face ( face ); FT_Done_FreeType( library ); return 0; } /* EOF */