freetype
[Top][All Lists]
Advanced

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

[ft] Monochrome Bitmap Trouble


From: Paresh Deshmukh
Subject: [ft] Monochrome Bitmap Trouble
Date: Wed, 14 Sep 2005 14:49:21 UT

Hi,

I am trying to generate a monochrome bitmap using Freetype version 2.1.7 for
a string and trying to print it on a 300 dpi printer.
I am able to get the proper bitmap only for certain characters, the other
characters are giving me garbage or distorted bitmap. I tried this with
different ttf files (for Arial and Vera fonts) but the result is the same.
I am working on Debian 3.1.

Here is my code please tell me if I am doing something wrong. Also if you could
provide me with a sample code to get monochrome bitmap for a given ttf file I
would be obliged.


#define SETPOINT 64
#define HEIGHT 1200
#define WIDTH 226
unsigned char image[HEIGHT][WIDTH];

FT_Face Face;
FT_GlyphSlot Slot;
FT_Matrix Matrix; /*Transformation matrix */
FT_Vector Pen; /*Untransformed origin */
FT_Error Error; /*Erro Handler for lib*/

/*Initiate Library*/
Error = FT_Init_FreeType( &m_Library );
/* create face object FT_New_Face()*/
Error = FT_New_Face(
m_Library,
"/arial.ttf",/*Path and file name*/
0,
&Face );
/*call FT_Set_Char_Size. character size is set to Height*Width for a
300×300 dpi device*/
Error = FT_Set_Char_Size(
Face,
iCharWidth * SETPOINT,
iCharHight* SETPOINT,
iHorzRes,
iHorzRes);

/*Setting Solt*/
Slot = Face->glyph;

/* set up matrix */
/*Value of iAngle is 0*/
double dAngle = ( iAngle / 360 ) * 3.14159 * 2; /* convert to radian*/
Matrix.xx = (FT_Fixed)( cos( dAngle ) * 0x10000L );
Matrix.xy = (FT_Fixed)(-sin( dAngle ) * 0x10000L );
Matrix.yx = (FT_Fixed)( sin( dAngle ) * 0x10000L );
Matrix.yy = (FT_Fixed)( cos( dAngle ) * 0x10000L );

/* the pen position in 26.6 cartesian space coordinates; */
Pen.x = 100
Pen.y = 100;
Slot->advance.x = iInterCharSpace;

for ( int iCountChar = 0; iCountChar < strInputString.size(); iCountChar++ )
{
FT_UInt Glyph_Index;

/* retrieve glyph index from character code */
Glyph_Index = FT_Get_Char_Index( Face, strInputString[iCountChar]);


/* set transformation */
FT_Set_Transform( Face, &Matrix, &Pen );
/* load glyph image into the slot (erase previous one) */
/*Error = FT_Load_Glyph( Face, Glyph_Index,
FT_LOAD_TARGET_MONO|FT_LOAD_FORCE_AUTOHINT);*/

Error = FT_Load_Char( Face, strInputString[iCountChar],
FT_LOAD_RENDER|FT_LOAD_TARGET_MONO /*|FT_LOAD_FORCE_AUTOHINT*/);
if ( Error )
continue; /* ignore errors */
/*FT_Glyph glyph;
Error = FT_Get_Glyph(Face->glyph,&glyph);
if ( Error )
continue;
// Convert The Glyph To A Bitmap.
FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_MONO, 0, 1 );
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;

// This Reference Will Make Accessing The Bitmap Easier.
FT_Bitmap& bitmap=bitmap_glyph->bitmap;*/

/*convert to an anti-aliased bitmap*/
Error = FT_Render_Glyph( Face->glyph, FT_RENDER_MODE_MONO);
if ( Error )
continue;

int iImageX,iImageY;
/* now, draw target surface */

if(!CreateFont(&Slot->bitmap,Slot->bitmap_left,Slot->bitmap_top,iImageX,iIma
geY))
{
FT_Done_Face (Face);
return false;
}
}

function Createfont is just copying the bitmap buffer to other buffer,
image[HEIGHT][WIDTH].

CreateFontRaster(FT_Bitmap* bitmap, FT_Int left, FT_Int
top,int&iImageIndexX,int&iImageIndexY )
{
int iIndexRow = 0;
int iIndexColumn = 0;
iImageIndexX =0;
iImageIndexY =0;
for(iImageIndexX =0,iIndexRow =0;iIndexRow <
bitmap->rows;iIndexRow++,iImageIndexX++)
{
for(iImageIndexY =0,iIndexColumn = 0;iIndexColumn < bitmap->pitch;
iIndexColumn++,iImageIndexY++)
{
image[iImageIndexX][iImageIndexY] |=
bitmap->buffer[iIndexRow*bitmap->width + iIndexColumn];
}
}
return true;
}


I also want to know if there is any install option needed to enable Monochrome
option or we have to do it programmatically. Is there something wrong with my
configuration?
I am going through tutorials and found FT_Get_Glyph_Bitmap() but its not
available with freetype2.1.7. Is it available with later version or some similar
implementation?

I am stuck at this point and am running out of ideas, please help!

Thanks
Paresh





reply via email to

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