freetype-devel
[Top][All Lists]
Advanced

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

[Devel] Developing a Freetype application


From: Ron Olson
Subject: [Devel] Developing a Freetype application
Date: Sat, 28 Sep 2002 09:20:35 -0500

Hey all-

 

I’m trying to integrate Freetype into my applications, but I don’t know how. What I mean to say is, I have been able to get Freetype-generated glyphs on the screen, but the quality is always very poor, which comes, of course, from my ignorance of how to use the library properly. Here is an example of the code I’ve been working on (windows-mfc):

 

void CFT3View::RenderText()

{

            FT_GlyphSlot slot = FTFace_->glyph;

 

            vector<COLORREF> colorvec;

            for ( int c = 255; c > 0; --c )

            {

                        colorvec.push_back(RGB(c,c,c));

            }

 

            FT_Error error;

            int offsetx(0);

            int offsety(0);

 

            for ( int x = 0; x < (signed int)Text_.GetLength(); ++x )

            {

                        // load the glyph image into the slot (and erase the previous one)

                        error = FT_Load_Char( FTFace_, Text_[x], FT_LOAD_RENDER );

 

                        FT_Byte* p = (FT_Byte*)slot->bitmap.buffer;

                       

                        for ( int yy = 0; yy < slot->bitmap.rows; ++yy )

                        {

                                    for ( int xx = 0; xx < slot->bitmap.width; ++xx )

                                    {

                                                BYTE pix = *p++;

 

                                                if ( pix > 255 )

                                                            pix = 255;

                                               

                                                MemDC_.SetPixelV(CPoint((xx + offsetx), ((yy - offsety))), colorvec[pix] );

                                    }

                        }

                       

                        offsetx += slot->advance.x >> 6;

                        offsety -= slot->advance.y >> 6;                         

            }

}

 

While this does render the text, performance is always very poor in redrawing (the library and the font face were initialized at the beginning of the application).

 

While I believe the fact that the characters are all flush against the top is because the coordinate system of Freetype assumes 0.0 is the bottom left corner, instead of the top left corner, I guess I’m stuck in terms of how to properly write code that would allow me to use Freetype at small point sizes as the default text-render in my app.

 

So, while I’m not asking “how do you use Freetype” exactly, I guess I’m asking, “how do you use Freetype well?” Clearly the KDE folks are doing something right as all their text is rendered quite nicely at small point sizes, but I’m basically lost in the woods here.

 

Thanks for any information,

 

Ron


reply via email to

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