freetype
[Top][All Lists]
Advanced

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

[Freetype] Rendering Fonts to Bitmap


From: Dexter
Subject: [Freetype] Rendering Fonts to Bitmap
Date: Sun, 1 Sep 2002 23:17:26 +0200

Hello Everyone!

I'm really begging for help, i tried everything i could but nope :| I wrote
the following code
to draw a simple character in a bitmap:

I noticed that when i set   i.bmiColors[h].rgbBlue to any value
glyph_bitmap->bitmap.buffer becomes
NULL!!!!!!!

 FT_Glyph     glyph;
 FT_BitmapGlyph glyph_bitmap;
 FT_UInt  glyph_index;
 int            pen_x = 0, pen_y = 0;

 // -> Creates a generic bitmap
 HDC dc = CreateCompatibleDC(NULL);

 BITMAPINFO i;
 ZeroMemory( &i.bmiHeader, sizeof(BITMAPINFOHEADER));

 i.bmiHeader.biPlanes  = 1;
 i.bmiHeader.biBitCount  = 1;
 i.bmiHeader.biSizeImage = 0;
 i.bmiHeader.biSize   = sizeof(BITMAPINFOHEADER);
 i.bmiHeader.biClrUsed  = 0;
 i.bmiHeader.biClrImportant = 0;
 i.bmiHeader.biCompression  = BI_RGB;
 i.bmiHeader.biXPelsPerMeter = i.bmiHeader.biYPelsPerMeter = 2954;

 char c = '4';
 glyph_index = FT_Get_Char_Index(m_FaceArray[iIndex], (int)c);

 m_fntError  = FT_Load_Glyph(m_FaceArray[iIndex], glyph_index,
FT_LOAD_RENDER);
 m_fntError  = FT_Get_Glyph(m_FaceArray[iIndex]->glyph, &glyph);

 // convert to a bitmap (default render mode + destroy old)
 if(glyph->format != ft_glyph_format_bitmap)
 {
  m_fntError = FT_Glyph_To_Bitmap(&glyph, ft_render_mode_mono, 0, false);
 }


 // access bitmap content by typecasting
 glyph_bitmap = (FT_BitmapGlyph)glyph;

 i.bmiHeader.biWidth = glyph_bitmap->bitmap.width;
 i.bmiHeader.biHeight = glyph_bitmap->bitmap.rows;

 void *pvBits;
 HBITMAP hbmp = CreateDIBSection(dc,&i,DIB_RGB_COLORS,&pvBits,NULL,0);
 if(!hbmp)
 {
 m_fntError = FT_Err_Missing_Bbx_Field + 1;
 return NULL;
 }

 for(int h = 0;h < 2;h++)
 {
  i.bmiColors[h].rgbBlue   = h;
  i.bmiColors[h].rgbGreen  = 0;
  i.bmiColors[h].rgbRed    = 0;
 }


SetDIBits(dc,hbmp,0,glyph_bitmap->bitmap.rows,&glyph_bitmap->bitmap.buffer,&
i,DIB_RGB_COLORS);

Thank you all!




reply via email to

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