freetype
[Top][All Lists]
Advanced

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

[ft] Freetype 2.4.4 -> freetype 2.4.12: FT_Get_Advance changed behaviour


From: Gregor Mückl
Subject: [ft] Freetype 2.4.4 -> freetype 2.4.12: FT_Get_Advance changed behaviour?
Date: Sun, 02 Jun 2013 18:13:51 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6

Hi!

I've upgraded a project of mine from using freetype 2.4.4 to freetype 2.4.12 and now I experience totally broken text layouting (the layouting code is my own). Horizontal spacings between characters are now either far too large or far too small, depending on the font. In one case the glyph distances are at least double what they should be. None of the tested fonts give anything close to believable reasults. Linking against the old version of freetype without any further code changes fixes this issue.

I seem to get vastly different values for the horizontal advance. If I uncommend the if block around FT_HAS_KERNING in the code below, the result does not change noticably. This is the code I use to compute the horizontal layout of a string of glyphs:

typedef struct {
        unsigned int glyph;
        float posX;
        float posY;
        int lineNumber;
        int font;
        int size;
} TL_GlyphPosition;

void _TL_ActivateFontSize(int font, int size)
{
        if(TL_Globals.fonts[font].currentSize==size) {
                return;
        }

        FT_Set_Pixel_Sizes(TL_Globals.fonts[font].face,0,size);
        TL_Globals.fonts[font].currentSize=size;

        int height=TL_Globals.fonts[font].face->size->metrics.height;
        
if(height<TL_Globals.fonts[font].face->size->metrics.ascender+TL_Globals.fonts[font].face->size->metrics.descender)
 {
height=TL_Globals.fonts[font].face->size->metrics.ascender+TL_Globals.fonts[font].face->size->metrics.descender;
        }
        TL_Globals.fonts[font].currentLineHeight=height;
}

int _TL_CalculateRunWidth(TL_GlyphPosition *glyphs, int length, bool firstInLine)
{
        int width=0;
        FT_Vector kerning;
        FT_Fixed advance;
        int i;

        for(i=0;i<length;i++) {
                glyphs[i].posX=(float)width;
                glyphs[i].posY=0;

                // get character width of current character
                _TL_ActivateFontSize(glyphs[i].font,glyphs[i].size);
FT_Get_Advance(TL_Globals.fonts[glyphs[i].font].face,glyphs[i].glyph,FT_LOAD_DEFAULT,&advance); advance=(FT_Fixed)(64*advance/(float)TL_Globals.fonts[glyphs[i].font].face->size->metrics.x_scale);
                width+=advance;

                // check whether this is the first character in the string/line
                if((i==0 && !firstInLine) || i!=0) {
// respect proper kerning (if possible, i.e. both glyphs are from the same font and size) if(FT_HAS_KERNING(TL_Globals.fonts[glyphs[i].font].face) && glyphs[i-1].font==glyphs[i].font && glyphs[i-1].size==glyphs[i].size) {
                                // Note: glyphs[i-1] may point beyond start of 
passed glyphs array,
// but it's only a section of a larger string, so this unchecked i-1 is fine FT_Get_Kerning(TL_Globals.fonts[glyphs[i].font].face,glyphs[i-1].glyph,glyphs[i].glyph,FT_KERNING_UNFITTED,&kerning);
                                width+=kerning.x;
                        }
                }

        }

        return width;
}

Am I doing something obviously wrong in this snippet? Was there an interface change in freetype that I should be aware of?

Regards,
Gregor



reply via email to

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