xujian | 1 Apr 14:06 2009

[ft] How to fast get the metrics value of one character

 

HI,

Now, I use freetype font engine on our embedded system. It works fine .but there is a question:

 

For displaying several characters for one time.  Firstly  I call:

/******************************/

    while(*string)

    {

        error = FT_Load_Char(pFTFace,*string, FT_LOAD_DEFAULT);

        string++;

        if(error){

            break;

        }

        pFtrect->right += slot->advance.x>>6;

        baseline_offset = (metrics->height-metrics->horiBearingY)>>6>baseline_offset?(metrics->height-metrics->horiBearingY)>>6:baseline_offset;

        pFtrect->top = (metrics->horiBearingY>>6)>pFtrect->top ?metrics->horiBearingY>>6:pFtrect->top;

 

    }

/****************/

To get the total w and h  of the whole strings. then  malloc  (w*h )  memory to store the bitmaps which will be rendered to.

 

Secondly:

Call :

        while(*str_temp)

        {

            error = FT_Load_Char(pFTFace,*str_temp, FT_LOAD_RENDER);

            str_temp++;

            align_top = h-rect.baseline-slot->bitmap_top;

            align_left = slot->bitmap_left;

            for(int i=0;i <slot->bitmap.rows;i++)

            {

                buf_temp =buf+x_offset+ (align_top+i)*w+align_left; 

                for(int j=0;j<slot->bitmap.width;j++)

                {

                    *buf_temp++ = slot->bitmap.buffer[i*slot->bitmap.width+j];

                   

                }

            }

            x_offset += slot->advance.x>>6;

 

      }

 I get the idea that the two  FT_Load_Char waste a lot of time.

How can I get the total w and h  of the whole strings  fast ?< metrics value>

 

Thanks

_______________________________________________
Freetype mailing list
Freetype <at> nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype
Werner LEMBERG | 1 Apr 18:37 2009
Picon

Re: [ft] How to fast get the metrics value of one character


> I get the idea that the two FT_Load_Char waste a lot of time.
> 
> How can I get the total w and h of the whole strings fast ? <metrics
> value>

It depends.  If you only need the metrics, have a look at
`FT_Get_Advance' and `FT_Get_Advances'.  If you need *exact* w and h,
you *must* render the glyph and cache the result (at least for
TrueType fonts).

BTW, caching is always a good thing.

    Werner
Brady Duga | 1 Apr 18:41 2009

Re: [ft] How to fast get the metrics value of one character


On Apr 1, 2009, at 9:37 AM, Werner LEMBERG wrote:

>
> BTW, caching is always a good thing.

And there is caching support built-in which works quite well.

--Brady
Werner LEMBERG | 2 Apr 18:21 2009
Picon

Re: [ft] freetype build failing when flow-tools is present


> [...] is there a way that we can have FreeType look for its
> ftconfig.h in the build directory anyway and not look to a possibly
> wrong one in the directory given in CPPFLAGS?

Yes.  You can change the `CFLAGS' variable as follows while calling `make':

   CFLAGS="$CFLAGS -UFT_CONFIG_CONFIG_H -DFT_CONFIG_CONFIG_H=..."

> The failing compile line is:
>
> libtool: compile: \
>   /usr/bin/gcc-4.0 \
>   -I/opt/local/include \
>   -I/opt/local/var/.../work/freetype-2.3.9/objs
>   -I./builds/unix \
>   -I/opt/local/var/.../work/freetype-2.3.9/include \
>   -c \
>   -O2 \
>   -DFT_CONFIG_OPTION_SYSTEM_ZLIB \
>   -DDARWIN_NO_CARBON
>   "-DFT_CONFIG_CONFIG_H=<ftconfig.h>" \
>   -DFT2_BUILD_LIBRARY
>   "-DFT_CONFIG_MODULES_H=<ftmodule.h>" \
>   builds/unix/ftsystem.c
>   -fno-common \
>   -DPIC \
>   -o /opt/local/var/.../work/freetype-2.3.9/objs/.libs/ftsystem.o
>
> I see -I/opt/local/include is first, hence that's where ftconfig.h
> is found first.  Perhaps that should be the last -I that's listed,
> instead of the first?

I don't think so.  The idea of `CPPFLAGS' is to override other
preprocessor flags.

    Werner
Ryan Schmidt | 3 Apr 00:58 2009

Re: [ft] freetype build failing when flow-tools is present


On Apr 2, 2009, at 11:21, Werner LEMBERG wrote:

>> [...] is there a way that we can have FreeType look for its
>> ftconfig.h in the build directory anyway and not look to a possibly
>> wrong one in the directory given in CPPFLAGS?
>
> Yes.  You can change the `CFLAGS' variable as follows while calling  
> `make':
>
>    CFLAGS="$CFLAGS -UFT_CONFIG_CONFIG_H -DFT_CONFIG_CONFIG_H=..."

Hmm. It just seems odd to me that I should have to tell freetype  
where its config file is, when it should already know this.

>> The failing compile line is:
>>
>> libtool: compile: \
>>   /usr/bin/gcc-4.0 \
>>   -I/opt/local/include \
>>   -I/opt/local/var/.../work/freetype-2.3.9/objs
>>   -I./builds/unix \
>>   -I/opt/local/var/.../work/freetype-2.3.9/include \
>>   -c \
>>   -O2 \
>>   -DFT_CONFIG_OPTION_SYSTEM_ZLIB \
>>   -DDARWIN_NO_CARBON
>>   "-DFT_CONFIG_CONFIG_H=<ftconfig.h>" \
>>   -DFT2_BUILD_LIBRARY
>>   "-DFT_CONFIG_MODULES_H=<ftmodule.h>" \
>>   builds/unix/ftsystem.c
>>   -fno-common \
>>   -DPIC \
>>   -o /opt/local/var/.../work/freetype-2.3.9/objs/.libs/ftsystem.o
>>
>> I see -I/opt/local/include is first, hence that's where ftconfig.h
>> is found first.  Perhaps that should be the last -I that's listed,
>> instead of the first?
>
> I don't think so.  The idea of `CPPFLAGS' is to override other
> preprocessor flags.

I see. So what you're saying is, freetype knows where its config file  
is, but by using CPPFLAGS in this way, we are telling freetype that  
we know better? I think we don't know better. :)

Should MacPorts be using a different mechanism, then? I'm not an  
expert at compiling things. Someone suggested we change CPPFLAGS="-I$ 
{prefix}/include" to CPPFLAGS="-isystem${prefix}/include", and this  
does seem to work, for freetype, so I committed that change  
yesterday, for freetype. Does that seem reasonable?

What we need in MacPorts is a way to tell all ports "When you need  
extra includes and libraries from other software, look for them in  
the following prefix before looking in /, /usr, and /usr/local." For  
some time we have been using CPPFLAGS="-I${prefix}/include" and  
LDFLAGS="-L${prefix}/lib" to do this. Is this not a good way? We do  
not want these includes and libraries to override the ones being  
created by the package being built.
Werner LEMBERG | 3 Apr 01:14 2009
Picon

Re: [ft] freetype build failing when flow-tools is present


>>    CFLAGS="$CFLAGS -UFT_CONFIG_CONFIG_H -DFT_CONFIG_CONFIG_H=..."
> 
> Hmm.  It just seems odd to me that I should have to tell freetype
> where its config file is, when it should already know this.

Well, you do something completely non-standard ...

> Someone suggested we change CPPFLAGS="-I${prefix}/include" to
> CPPFLAGS="-isystem${prefix}/include", and this does seem to work
> [...]
> 
> What we need in MacPorts is a way to tell all ports "When you need
> extra includes and libraries from other software, look for them in
> the following prefix before looking in /, /usr, and /usr/local." For
> some time we have been using CPPFLAGS="-I${prefix}/include" and
> LDFLAGS="-L${prefix}/lib" to do this.

Yes.  Looking at the info pages of `cpp', `-isystem' seems to be
exactly the right thing.

    Werner
Stoiko Todorov | 4 Apr 18:05 2009
Picon

[ft] Galette kerning issues

Hi everyone.

I'm working on an sdl+opengl+freetype project. I'm using the Galette face (galette-med.otf OpenType font) and I have issues with kerning. Here is an image taken from my application:
http://picasaweb.google.com/lh/photo/TZl7LHGaFVfF-wOWA_q-Mw?feat=directlink

And here is an image taken from gimp using the same font and the same text.
http://picasaweb.google.com/lh/photo/K-ifF9MnGu9UFJu4U1h7Sw?feat=directlink

Obviously my kerning is wrong.
here is my code (taken almost 1:1 from the freetype tutorial )

...
        glyphIndex = FT_Get_Char_Index( ftFace, c );

        if ( FT_HAS_KERNING( ftFace ) && previous && glyphIndex ) {
            FT_Vector delta;
           
            FT_Get_Kerning( ftFace, previous, glyphIndex, FT_KERNING_DEFAULT, &delta );
            x += delta.x >> 6;
        }

        error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_RENDER );
        if ( error )
            ...;

       // my draw-to-texture is here
      
        x += slot->advance.x >> 6;

        previous = glyphIndex;
...

Any ideas?

_______________________________________________
Freetype mailing list
Freetype <at> nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype
Werner LEMBERG | 4 Apr 18:26 2009
Picon

Re: [ft] Galette kerning issues


> I'm working on an sdl+opengl+freetype project. I'm using the Galette
> face (galette-med.otf OpenType font) and I have issues with
> kerning. Here is an image taken from my application:
> http://picasaweb.google.com/lh/photo/TZl7LHGaFVfF-wOWA_q-Mw?feat=directlink
> 
> And here is an image taken from gimp using the same font and the
> same text.
> http://picasaweb.google.com/lh/photo/K-ifF9MnGu9UFJu4U1h7Sw?feat=directlink
> 
> Obviously my kerning is wrong.  [...]

I suspect that this font contains no `kern' table at all -- the
kerning is probably contained in the `GPOS' table.  This is not
covered by FreeType's API.  You should use a higher-level library to
access it, say, Pango or ICU.

    Werner
Werner LEMBERG | 4 Apr 18:41 2009
Picon

Re: [ft] Galette kerning issues


> I suspect that this font contains no `kern' table at all -- the
> kerning is probably contained in the `GPOS' table.  This is not
> covered by FreeType's API.  You should use a higher-level library to
> access it, say, Pango or ICU.

I've updated the tutorial to reflect this.

    Werner
Pierre Marchand | 6 Apr 11:01 2009

Re: [ft] Galette kerning issues

Vous avez écrit :
> Hi everyone.
>
> I'm working on an sdl+opengl+freetype project. I'm using the Galette face
> (galette-med.otf OpenType font) 
>[…]
> Any ideas?

As already said, kerning is likely to lie into kern feature rather than a kern 
table. I recently wrote some code (warn you, it’s heavily Qt based) which 
could help if you don’t want to use an OpenType processor (which is the right 
thing to do in fact (the one in Harfbuzz  working well AFAICS)). The code 
itself you can see there:
<http://svn.gna.org/viewcvs/undertype/trunk/tools/typotek/src/fmkernfeat.h?rev=911&view=markup>
<http://svn.gna.org/viewcvs/undertype/trunk/tools/typotek/src/fmkernfeat.cpp?rev=911&view=markup>

my 2¢

--

-- 
Pierre Marchand
http://www.oep-h.com

Gmane