freetype
[Top][All Lists]
Advanced

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

Re: [ft] Question about font size


From: LonelyStar
Subject: Re: [ft] Question about font size
Date: Sat, 9 Sep 2006 15:43:45 -0700 (PDT)



Werner LEMBERG wrote:
> 
> 
>> I am using freetype to load fonts and read vectorize them with
>> FT_Outline_Decompose.
>>
>> I want to have exact controll over how many pixels the characters
>> are in height.  The FT_Vector I get during decomposing I am dividing
>> by face->size->metrics.height and storing as a float.
>>
>> I was expecting to get characters with height 1, so that I can just
>> multiply by my wanted pixel height.
>>
>> Doing so gives me characters half the height I want.
>> 
>> What am I doing wrong?
> 
> Small (compilable) code sample, please.
> 
> 
>     Werner
> 
> 
My "short" code example, I hope it's self explaining.
I would expect to get a character size around 1.0. For 'j' I get 0.485149 :(

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include FT_OUTLINE_H

//Our Face
FT_Face face;
//Current glyph
FT_Glyph glyph;
FT_Library library;

/* In my code the following functions do of course something completly
different.
 * These functions just finds the highest and lowest point of the Decomposed
 * character, so that we can measure its size afterwards.
 */
float highest_y=0.0f;
float lowest_y=0.0f;

int line_to(FT_Vector* to,void* p)
{
        float h=face->size->metrics.height;
        if(to->y/h > highest_y)
                highest_y=to->y/h;
        if(to->y/h < highest_y)
                highest_y=to->y/h;
        return 0;
}

int move_to(FT_Vector* to,void *p)
{
        //Do the same as line_to
        return line_to(to,p);
}

int conic_to(FT_Vector* control,FT_Vector* to,void *p)
{
        //Smae as line_to for both points
        line_to(control,p);
        line_to(to,p);
        return 0;
}

int cubic_to(FT_Vector* control1,FT_Vector* control2,FT_Vector* to,void *p)
{
        //Smae as line_to for all points
        line_to(control1,p);
        line_to(control2,p);
        line_to(to,p);
        return 0;
}

int main()
{
        if(FT_Init_FreeType(&library))
        {
                printf("Unable to init Freetype\n");
                return -1;
        }
        //Load font.ttf. In my case its a very plain Arial-like font.
        if(FT_New_Face(library,"font.ttf",0,&face))
        {
                printf("Unable to load font.ttf\n");
                return -1;
        }
        //If I understand correctly (and I am not sure I do), it should not 
matter
which size we set here
        FT_Set_Char_Size(face,0,16*64,300,300);

        //Load the glyph. I choose "j" because it should occupy the whole font
height
        int glyph_index=FT_Get_Char_Index(face,'j');
        if(FT_Load_Glyph(face,glyph_index,FT_LOAD_DEFAULT))
        {
                printf("Unable to load glyph\n");
                return -1;
        }
        
        //Decompose glyph
        FT_Outline_Funcs of;
        of.move_to=&move_to;
        of.line_to=&line_to;
        of.conic_to=&conic_to;
        of.cubic_to=&cubic_to;
        of.shift=0;
        of.delta=0;
        FT_Outline_Decompose(&(face->glyph->outline),&of,0);

        //print the height of the character. I am expecting a height of 1
        printf("The Y-Expansion of the character begins at %f and ends at %f.
Therefor its height is %f\n",lowest_y,highest_y,highest_y-lowest_y);
        
        return 0;
}

-- 
View this message in context: 
http://www.nabble.com/Question-about-font-size-tf2245239.html#a6228899
Sent from the Freetype - User forum at Nabble.com.





reply via email to

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