Search code examples
c++freetypefreetype2

FreeType2 FT_Outline_Decompose returns huge numbers


I am trying to read glyph outline for a character using FreeType lib.I load font from a standard .ttf file.Till now I was using outline tags to convert outline to path elements like segments and bezier curves.Then I found FT_Outline_Decompose which is a part of the lib.But when I am using it,the decomposed data values are huge.Every point on the path as a value of ~ 859722XXX .So even the down-scaling with factor of 64 as it's suggested by examples doesn't help to get pixel size values.

My code goes like this:

    const char* fontFile ="fonts/Verdana.ttf";
std::string chars("Uta \n");

char charcode = chars[0];

FT_Library defLibHandle;
FT_Error err = FT_Init_FreeType(&defLibHandle);
if(err){
    printf(ft_errors[err].err_msg);
    throw;
}
FT_Face faceHandle;
err = FT_New_Face(defLibHandle,fontFile,0,&faceHandle);

if(err){
    printf(ft_errors[err].err_msg);
    throw;
}


FT_Glyph glyph;

// load glyph

err = FT_Load_Char(faceHandle,
                    charcode,
                       FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE);
if (err) {
    std::cout << "FT_Load_Glyph: error\n";
}

//FT_Get_Glyph(faceHandle->glyph, &glyph);
FT_Outline  outline = faceHandle->glyph->outline;

if (faceHandle->glyph->format != ft_glyph_format_outline) {
    std::cout << "not an outline font\n";
}


FT_Outline_Funcs funcs;
funcs.move_to =  (FT_Outline_MoveTo_Func)&moveTo;
funcs.line_to =  (FT_Outline_LineTo_Func)&lineTo;
funcs.conic_to = (FT_Outline_ConicTo_Func)&conicTo;
funcs.cubic_to = (FT_Outline_CubicTo_Func)&cubicTo;
// trace outline of the glyph
err = FT_Outline_Decompose(&outline,
                             &funcs, nullptr);
 if (err) {
    std::cout <<ft_errors[err].err_msg ;
 }

Now, in the callbacks like moveTo() I attempt to resize:

int moveTo(FT_Vector* to, void* fp) {

pathRef->moveTo(ftVecToFloat(to)); ///
  // ftVecToFloat is "float(f) / 64.0f" ///

    return 0;
}

But the initial FT_Vector value is so huge that the division by 64.0 still doesn't matters.


Solution

  • set funcs.shift = 0; funcs.delta = 0; will work