freetype
[Top][All Lists]
Advanced

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

Re: [ft] How to get Horizontal Advance on Stroked Glyph


From: Infro
Subject: Re: [ft] How to get Horizontal Advance on Stroked Glyph
Date: Fri, 18 May 2012 19:11:09 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

On 5/18/2012 1:21 AM, johnpf74 wrote:
Hello,

I am trying to get the advance amount for a stroked glyph. I cannot find it
anywhere in the documentation. I have a code snippet below. Basically when I
do the algorithm, the advance amount is not accounting for the width of the
outline, so the next character's outline overlaps the previous character.

Any suggestions?

Thanks,
John

// set the stroker with a 3 pixel stroke
FT_Stroker_Set(stroker,
                 static_cast<  FT_Fixed>( 3 * 0x40),
                 FT_STROKER_LINECAP_ROUND,
                 FT_STROKER_LINEJOIN_ROUND,
                 0);

FT_Glyph outlineGlyph = NULL;

// Load the glyph
FT_UInt glyphIndex = FT_Get_Char_Index( *face, chr );
FT_Load_Glyph( *face, glyphIndex, FT_LOAD_NO_BITMAP );
FT_Get_Glyph( (*face)->glyph,&outlineGlyph );

// stroke it
FT_Glyph_Stroke(&outlineGlyph, stroker, false );

// copy to bitmap
FT_Glyph_To_Bitmap(&outlineGlyph, FT_RENDER_MODE_NORMAL, NULL, true );
FT_BitmapGlyph outlineBitmap = (FT_BitmapGlyph)outlineGlyph;

// get metrics - chrDef is my own struct where I am storing per character
metrics
chrDef->m_bearingX = (*face)->glyph->metrics.horiBearingX>>  6;
chrDef->m_bearingY = (*face)->glyph->metrics.horiBearingY>>  6;

// ???? this advance does not account for extra width of outline in advance
chrDef->m_advance = (*face)->glyph->metrics.horiAdvance>>  6;
// I also tried this and got similar results
//chrDef->m_advance = outlineGlyph->advance.x>>  16;

FT_Glyph interiorGlyph = NULL;
FT_Load_Glyph( *face, glyphIndex, FT_LOAD_NO_BITMAP );
FT_Get_Glyph( (*face)->glyph,&interiorGlyph );
FT_Glyph_To_Bitmap(&interiorGlyph, FT_RENDER_MODE_NORMAL, NULL, true );



===
Although I'm not very familiar with freetype, I don't see any faults in your code.
Best I can do is offer some of my code.  Perhaps it will be of some help.
Typically I don't get to respond to this board cause someone else beats me too it, so someone else respond who knows better too.
-------------------
CurrentGlyph->GlyphIndex = FT_Get_Char_Index(FreeTypeFace, Letter); FT_Load_Glyph(FreeTypeFace, CurrentGlyph->GlyphIndex, FT_LOAD_DEFAULT);
                GlyphPointer = &CurrentGlyph->Glyph;
                FT_Get_Glyph(FreeTypeFace->glyph, GlyphPointer);
                PenPointer = CurrentGlyph->Pen;

                if(Kerning && Prev_Glyph && CurrentGlyph->GlyphIndex)
                {
                    FT_Get_Kerning(
                        FreeTypeFace,
                        Prev_Glyph,
                        CurrentGlyph->GlyphIndex,
                        FT_KERNING_DEFAULT,
                        KernVectorPointer );
                    Pen_X += KernVector.x;
                }
                if(Prev_Glyph && CurrentGlyph->GlyphIndex)
                {
                    if((Prev_RSB - FreeTypeFace->glyph->lsb_delta) >= 32)
                        Pen_X-=64;
else if ((Prev_RSB - FreeTypeFace->glyph->lsb_delta) <= -32)
                        Pen_X+=64;
                }
                Prev_RSB = FreeTypeFace->glyph->rsb_delta;

                CurrentGlyph->Pen->x = FT_PIX_CEIL(Pen_X);
                CurrentGlyph->Pen->y = FT_PIX_CEIL(Pen_Y);
//if(Prev_Advance >= (CurrentGlyph->Glyph->advance.x>>10 + Pen_X)) Pen_X = Prev_Advance
                Pen_X += CurrentGlyph->Glyph->advance.x>>10;



reply via email to

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