freetype
[Top][All Lists]
Advanced

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

Re: [ft] Stroker and glyph border


From: Fred408
Subject: Re: [ft] Stroker and glyph border
Date: Tue, 21 Nov 2006 23:38:51 -0800 (PST)

Hello,

I just found out that I had to use the "top" and "left" fields of the
GlyphBitmap structure
to place the black border around the white glyph. However I still have some
rendering quality 
problems at very low sizes. How can I improve the quality of the rendering
using the #defines 
of the lib ?



Fred408 wrote:
> 
> Hello,
> 
> I'm using freetype to render subtitles to display in video. All the glyphs
> look
> really great with the anti-aliasing and everything seems to work fine. 
> 
> However, I am now trying to add a black border (contour) to the glyph
> shapes so that
> they remain visible in most background video. I use the stroker to create
> the
> contour but I can't manage to adjust the contour position so that it fits
> perfectly
> the edge of the shape. 
>   
> Once I have rendered the contour to a bitmap, how can I position it so
> that it fits
> perfectly with the white glyph shapes edges ?
> 
> My code is just below.
> 
> Thanks alot for the help,
> 
> Fred
> 
> 
> Here is my code : (in bold are passages I'm unsure about)
> _____________________________________________________________
> 
> 
>    // Init freeType
> error = FT_Init_FreeType(&library);
>    // Create Face
> error = FT_New_Face(library, "arial.ttf", 0, &face);
>    // Set Pixel size
> error = FT_Set_Pixel_Sizes(face, 256, 0);
>    // Shortcut to glyph slot
> pSlot = (face->glyph);
> 
> 
>    // for each character in the string
> for(i=0 ; i<strlen(text) ; i++){
> 
>        // load the glyph in the glyphSlot
>    error = FT_Load_Char(face, text[i], FT_LOAD_RENDER);
>       // compute the upper left corner of the glyph
>    nPosX = penx + pSlot->metrics.horiBearingX/64+1;
>    nPosY = peny - pSlot->metrics.horiBearingY/64+1;
>       // draw the glyph to the bitmap
>    for(j=0 ; j<pSlot->bitmap.rows ; j++){
>       for(k=0 ; k<pSlot->bitmap.width ; k++){
>          bitmap[nPosY+j][nPosX+k] =
> pSlot->bitmap.buffer[(j*(pSlot->bitmap.width))+k];
>       }
>    }
> 
> 
>       // Up to here everything looks great.
>       // Now lets add some nice black contour to the glyph shapes.
> 
> 
>       // load the glyph once again but without rendering it
>    error = FT_Load_Char(face, text[i], FT_LOAD_DEFAULT);
>       // copy from glyphSlot to glyph
>    error = FT_Get_Glyph( pSlot, &glyph );
>       // create stroker
>    FT_Stroker_New(library, &stroker);
> 
> 
>       // Configure stroker (how to choose radius ?)
>    FT_Stroker_Set(stroker, 
>      16, // ?? 
>      FT_STROKER_LINECAP_ROUND,
>      FT_STROKER_LINEJOIN_ROUND,
>      0 
>    );
> 
> 
>       // Apply stroke to the glyph to create the contour
>    error = FT_Glyph_Stroke( &glyph, stroker, 0 );
>       // Render the contour glyph to the bitmap
>    error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, &origin, 0
> );
> 
>       // cast the contour glyph to a bitmapGlyph
>    glyphBitmap = (FT_BitmapGlyph)glyph;
> 
>       // Compute contour glyph upper left corner
>    nPosX = penx + pSlot->metrics.horiBearingX/64;//+?
>    nPosY = peny - pSlot->metrics.horiBearingY/64;//+?
> 
>       // Draw the contour to another bitmap
>    for(j=0 ; j<glyphBitmap->bitmap.rows ; j++){
>       for(k=0 ; k<glyphBitmap->bitmap.width ; k++){
>           bitmap2[nPosY+j][nPosX+k] =
>       glyphBitmap->bitmap.buffer[(j*(glyphBitmap->bitmap.width))+k];
>       }
>    }
>  
> 
>       // update the penX coordinate with the glyph or with the contour
>       // glyph horiAdvance ? (if the contour is very thick we have to take
>       // it into account in the pen update)
>    penx += pSlot->metrics.horiAdvance/64; // ?
> }
> 
> _________________________________________________________
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Stroker-and-glyph-border-tf2668115.html#a7486396
Sent from the Freetype - User mailing list archive at Nabble.com.





reply via email to

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