freetype
[Top][All Lists]
Advanced

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

[Freetype] Type1 Font Char -> Bitmap Troubles


From: misza
Subject: [Freetype] Type1 Font Char -> Bitmap Troubles
Date: Sat, 21 Feb 2004 05:25:50 GMT

Hi Everyone!
I'm trying to access characters from a type1 font and place them into a bitmap
ready for drawing and have not been sucessful despite reading carefully the
glyph guidlines, the tutorial and many bits and pieces in the api reference(all
of which I found were a bit ambiguous/inadequate towards what I'm trying to
accomplish). I run the BeOS ( http://wiki.bebits.com/page/NewbieInfo ) and I'm
trying to place the char into a BBitmap (reference here:
http://bebook.beunited.org/The%20Interface%20Kit/Bitmap.html ). I have posted my
code below. The font I am accessing is rtxmi.pfb (a font included with tetex)
and I have selected the charmap with the greek symbols on it (I suspect). I
suspect the rendering of the FT_Bitmap is fine, but when I go to inspect the
bits.buffer, it is really, really large, ~200,000 characters, surely not just
one character.

I have the following questions:
-Should the BBitmap that I want to place the rendered bitmap into be 12 by 12
pixels?
-Why is the bits.buffer so large, shouldn't it be only for one char? If not,
what offset in this data can I use to get the character at index i out of it.
-What is the length of the data I want for the character (needed for SetBits()).
-Do I need to do any fancy transforms (to the origin) or anything? This was
particularly ambiguous in the tutorial!

Thankyou very much for your time, this problem has been eating away at me for
nearly two weeks now.
It is very much appreciated.

        FT_Library library;     
        int error;
        if(!FT_Init_FreeType(&library))
        {
                FT_Face face;
                if(!(error =
FT_New_Face(library,"/boot/home/config/fonts/psfonts/rtxmi.pfb",0,&face)))
                {
                        PS_FontInfoRec finfo;
                        if(!(error = FT_Get_PS_Font_Info(face,&finfo)))
                        {
                                printf("Version = %s\n Notice = %s\n FullName = 
%s\n FamilyName = %s\n
Weight = %s\n",
                                
finfo.version,finfo.notice,finfo.full_name,finfo.family_name,finfo.weight);
                        }
                        
                                int NumGlyphs = face->num_glyphs;
                                cout << "NumGlyphs = " << NumGlyphs << endl;
                                cout << "NumFaces = " << face->num_faces << 
endl;
                        
                        FT_CharMap map = face->charmaps[1];
                        if(!(error = FT_Set_Charmap(face,map)))
                        {
                                        for(int i=1;i<NumGlyphs;i++)    //start 
at 1, 0 == missing glyph
                                        {
                                                if(!(error = 
FT_Set_Pixel_Sizes(face,12,12)))
                                                {
                                                if(!(error = 
FT_Load_Char(face,i,FT_LOAD_RENDER)))
                                                {
                                                                        
FT_GlyphSlot slot = face->glyph;
                                                                        
FT_Bitmap bits = slot->bitmap;
                                                                        int 
width=bits.width;
                                                                        int 
height=bits.rows;
                                                                        
                                                                        int 
pitch = abs(bits.pitch);
                                                                        int 
length=width*height*pitch;
                                                                        short 
numofgrays=bits.num_grays;
                                                                        char 
pixmode = bits.pixel_mode;
                                                                        
                                                                        
if(width > 0 && height > 0)
                                                                        {
                                                                                
printf("FT_PIXEL_MODE_GRAY: %s\n",(pixmode == FT_PIXEL_MODE_GRAY) ?
"true" : "false");
                                                                                
cout << "width: " << width << "\nheight = " << height <<
"\nlength:length = " << length
                                                                                
<< "\nnumofgreys = " << numofgrays << "\npitch: " << pitch <<
"\nbitmap_left = " << slot->bitmap_left
                                                                                
<< "\nbitmap_top = " <<  slot->bitmap_top << endl;
                                                                                
                                                                                
FT_Glyph_Metrics metrics = slot->metrics;
                                                                                
printf("Glyph Metrics:\nWidth: %d\nHeight:
%d\n",metrics.width,metrics.height);
                                                                                
printf("Glyph Metrics:\nWidth/64: %d\nHeight/64:
%d\n",metrics.width/64,metrics.height/64);
                                                                                
                                        FT_Size fsize= face->size;
                                        FT_Size_Metrics fszm= fsize->metrics;
                                                                                
cout << "x_ppem: " << fszm.x_ppem << '\n' << "y_ppem: " <<
fszm.y_ppem<< '\n' 
                                                                                
<< "x_scale: " << fszm.x_scale<< '\n' <<"y_scale: " <<   fszm.y_scale<<
                                                                                
'\n' << "ascender: " << fszm.ascender<< '\n' << "descender: " <<
fszm.descender<< 
                                                                                
'\n' <<"height: " <<  fszm.height<< '\n' << "max_advance: " <<
fszm.max_advance << endl;
                                                                                
                                                                                
BBitmap* mybitmap = new BBitmap(BRect(0,0,11,11),B_GRAY8);
                                                                                
mybitmap->SetBits(bits.buffer,12*12,0,B_GRAY8);
                                                                                
                                                                                
DrawBitmap(mybitmap);
                                                                                
MovePenBy(20,20);
                                                                                
//unsigned char* p = bits.buffer;
                                                                                
                                                                                
/*
                                                                                
int k=0;                                                                
                                                                                
while(k < 100000)
                                                                                
{
                                                                                
        printf("[%x](%d)",p[k],k);
                                                                                
        k++;
                                                                                
}
                                                                                
printf("\nk = %d\n",k);
                                                                                
*/
                                                                                
break;
                                                                }}}}}}
                else if(error == FT_Err_Unknown_File_Format)
                {
                        cout << "unknown font format" << endl;
                }
                
        
        }
This is some sample output:

$ obj.x86/FontTester
Version = 3.1
 Notice = Version 3.1, GPL
 FullName = rtxmi
 FamilyName = rtxmi
 Weight = Medium
NumGlyphs = 81
NumFaces = 1
FT_PIXEL_MODE_GRAY: true
width: 8
height = 9
length:length = 576
numofgreys = 256
pitch: 8
bitmap_left = -1
bitmap_top = 9
Glyph Metrics:
Width: 512
Height: 576
Glyph Metrics:
Width/64: 8
Height/64: 9
x_ppem: 12
y_ppem: 12
x_scale: 50332
y_scale: 50332
ascender: 640
descender: -192
height: 896
max_advance: 768    

Thanks for your time,
Brent Miszalski.







reply via email to

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