freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re[ft-devel] ndering bitmap!!!


From: VHP1988
Subject: re[ft-devel] ndering bitmap!!!
Date: Mon, 31 Jan 2011 22:03:06 -0800 (PST)

Hi every one, I am trying to get a bitmap generated for a particular character (B) using the free type library. According to my requirements i want the bitmap to be anti-aliased. I also want to apply a stroke to the character and then dump the entire bitmap into a file. I am not able to get the desired output that i need. The following is the code that i have written. Could any one of you please help me in getting the correct output, please. Any help would be appreciated. int main() { FT_Library library; FT_UInt glyph_index; FT_Glyph glyph; FT_GlyphSlot slot; FT_Error error; FT_BitmapGlyph glyphBitmap; FT_Face face; FT_Stroker stroker; FT_Vector pen; unsigned char *bitmap; int bmp_width, bmp_height; int k,j,nPosX,nPosY; FILE *font_1, *outline_1; /**Allocate bitmap space*/ /*Allocate Bitmap buffer */ bitmap = (unsigned char *)malloc (sizeof(unsigned char)*MAX_HEIGHT*MAX_WIDTH); memset (bitmap,0x00,MAX_HEIGHT*MAX_WIDTH); /**Initialize the library */ error = FT_Init_FreeType(&library); if(error) { DBG(error initializing the library); } /* Open the font face */ error = FT_New_Face(library, FONT_PATH, 0, &face); if(error) { DBG(Error opening font face); } /*Initialize the stroker */ error = FT_Stroker_New(library, &stroker); if(error) { DBG(Error creating stroker); } FT_Stroker_Set(stroker, 40, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); error = FT_Set_Pixel_Sizes( face, /* handle to face object */ FONT_WIDTH , /* pixel_width */ FONT_HEIGHT ); /* pixel_height */ if(error) { DBG(set pixel size failed); } slot = face->glyph; /* Set pen position */ pen.x = 0; pen.y = pen.y = -( face->size->metrics.descender ) ; /* set transformation */ FT_Set_Transform( face, NULL, &pen ); /* retrieve glyph index from character code */ glyph_index = FT_Get_Char_Index(face, 66); /* load glyph image into the slot (erase previous one) */ error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); if(error) { DBG(could not load glyph to slot); } /**Get the glyph from slot */ error = FT_Get_Glyph(slot, &glyph); if(error) { DBG(Could not get the glyph image from slot); } error = FT_Glyph_Stroke(&glyph, stroker, 1); if(error) { DBG(Giving stroke failed ); } /**Convert the glyph to a bitmap object from glyph object */ error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1); if(error) { DBG(Could not convert to bitmap); } glyphBitmap = (FT_BitmapGlyph) glyph; // Compute contour glyph upper left corner nPosX =pen.x+ glyphBitmap->left; nPosY = pen.y + glyphBitmap->top; for(j=0 ; jbitmap.rows ; j++) { for(k=0 ; k < glyphBitmap->bitmap.width ; k++) { //bitmap[nPosY+j][nPosX+k] = //printf("%d ",glyphBitmap->bitmap.buffer[(j*(glyphBitmap->bitmap.width))+k]); } printf("\n"); } nPosX =pen.x+ slot->bitmap_left; nPosY = pen.y + slot->bitmap_top; for(j=0 ; j< slot->bitmap.rows ; j++) { for(k=0 ; k < slot->bitmap.width ; k++) { //bitmap[nPosY+j][nPosX+k] = printf("%d ",slot->bitmap.buffer[(j*(slot->bitmap.width))+k]); } printf("\n"); } return 0; } Also the glyph is currently present in two variables. It would be helpful if both the glyph and the outline are present in the same buffer. Please also help me in dumping the contents of the buffer. regards, Vishnu

View this message in context: rendering bitmap!!!
Sent from the Freetype - Dev mailing list archive at Nabble.com.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]