/* * * This program bitmap_embolden.c is intended to illustrate strange * behaviors observed in freetype 2.1.0 and freetype 2.3.7 function * FT_Bitmap_Embolden() * * Usage: bitmap_embolden * * For example: bitmap_embolden FreeMono.ttf M 512 512 * * The font files should be available in the directory ./fonts * */ #include #include FT_FREETYPE_H #include FT_BITMAP_H #include FT_GLYPH_H #include FT_IMAGE_H #include #define FT_RENDER_MODE_NORMAL 0 #define FT_PIXEL_MODE_MONO 1 #define TRUE 1 int main(int argc, char ** argv) { FT_Library library = NULL; FT_Face face = NULL; FT_Glyph glyph = NULL; FT_BitmapGlyph bglyph = NULL; FT_Bitmap * bitmap = NULL; char * file_face = NULL; FT_Bitmap emb_bitmap; FT_BBox cbox; FT_Error error, err_ebd; char char_test; int xStrength, yStrength; int width1, width2; int height1, height2; int left1, bottom1; int left2, bottom2; int top1, top2; char pixel_mode; char *tmp = argv[2]; file_face = argv[1]; char_test = argv[2][0]; xStrength = atoi(argv[3]); yStrength = atoi(argv[4]); int char_size[] = {100*64, 0, 100, 0}; if( file_face == NULL ) { printf("Cannot allocate memory."); return 0; } error = FT_Init_FreeType( &library ); if( (error != 0) || (library == NULL) ) { printf("Cannot initialize a new FreeType library object."); return 0; } error = FT_New_Face( library, file_face, 0, &face ); if( (error != 0) || (face == NULL) ) { printf("Cannot create a handle to face object."); return 0; } if( FT_IS_SCALABLE(face) ) { error = FT_Set_Char_Size( face, char_size[0], char_size[1], char_size[2], char_size[3] ); if( (error != 0) || (face == NULL) ) { printf("Cannot set the character dimensions of a given face object."); return 0; } FT_Set_Transform( face, 0, 0 ); } FT_Load_Char(face, char_test, 0); error = FT_Get_Glyph( face->glyph, &glyph ); if (error != 0) { printf("Cannot get glyph."); return 0; } if( (face->glyph->format != FT_GLYPH_FORMAT_BITMAP) ) { error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, NULL, TRUE); if(error != 0) { printf("Cannot change glyph to bitmap glyph."); return 0; } bglyph = (FT_BitmapGlyph)glyph; bitmap = &bglyph->bitmap; } else { bitmap = &face->glyph->bitmap; } FT_Glyph_Get_CBox( glyph, 0, &cbox ); width1 = cbox.xMax - cbox.xMin; height1 = cbox.yMax - cbox.yMin; left1 = cbox.xMin; bottom1 = cbox.yMin; top1 = cbox.yMax; FT_Bitmap_New(&emb_bitmap); error = FT_Bitmap_Copy(library, bitmap, &emb_bitmap); if( error != 0 ) { printf("The function did not copy the source bitmap to the target bitmap."); return 0; } if(emb_bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { if(xStrength > (8<<6)) { printf("The 'xStrength' must be less than or equal to 8 in 26.6 pixel format."); return 0; } } err_ebd = FT_Bitmap_Embolden(library, &emb_bitmap, xStrength, yStrength); ((FT_BitmapGlyph)glyph)->bitmap = emb_bitmap; FT_Glyph_Get_CBox( glyph, 0, &cbox ); width2 = cbox.xMax - cbox.xMin; height2 = cbox.yMax - cbox.yMin; left2 = cbox.xMin; bottom2 = cbox.yMin; top2 = cbox.yMax; printf("The bottom border before embolden is %d\n", bottom1); printf("The bottom border after embolden is %d\n\n", bottom2); printf("The top border before embolden is %d\n", top1); printf("The top border after embolden is %d\n", top2); if(face) { FT_Done_Face(face); } FT_Bitmap_Done(library, &emb_bitmap); if(library) { FT_Done_FreeType(library); } return 0; }