From:
address@hidden
[mailto:address@hidden On Behalf Of David
Turner
Sent: Tuesday, September 02, 2008 9:32 AM
To: address@hidden
Subject: [ft-devel] new API introduced (FT_Get_Advances)
Hello
everyone,
just to let you know that I just introduced in the CVS depot a new API (and
corresponding header)
to be able to more quickly retrieve the advance width of individual glyphs
without loading their
outlines.
the new header file if FT_ADVANCES_H (a.k.a. freetype/ftadvanc.h) and
provides two new APIs
(see copy of the header file with docs below).
the 'ftbench' demo program has also been updated with a new test that exercise
the new APIs
in both "normal" and "fast" mode (see below).
this works as follows:
when using a strongly hinted mode (either auto-hinted or bytecoded), this does
perform the hinting
and retrieves the advance(s) after that. this is slightly faster (about 10-20%)
than doing successive
FT_Load_Glyph() calls, depending on the font backend being used.
however, when using no scaling, no hinting or even the "light hinting
mode" (which only hints in the
vertical dimension), the function can return results *immediately* simply
looking the values in the font
file itself, if the font driver supports it. I have added support for this in
the TrueType / Type1 and CFF
font drivers. I still need to add CID and PFR support (I really don't think
Type42 is needed)
here are some runs of the new 'ftbench' on one of my work machines:
$
objs/ftbench /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf
Load
: 19.415 us/op
Load_Advances (Normal) : 16.327 us/op
Load_Advances
(Fast) : 0.034 us/op
Render
: 6.285 us/op
Get_Glyph
: 1.077 us/op
Get_CBox
: 0.539 us/op
Get_Char_Index
: 0.074 us/op
Iterate
CMap
: 35.950 us/op
New_Face
: 100.482 us/op
Embolden
: 0.000 us/op
$ objs/ftbench /usr/share/fonts/type1/t1-xfree86-nonfree/cour.pfa
Load
: 21.810 us/op
Load_Advances (Normal) : 13.508 us/op
Load_Advances
(Fast) : 0.080 us/op
Render
: 8.756 us/op
Get_Glyph
: 1.190 us/op
Get_CBox
: 0.118 us/op
Get_Char_Index
: 0.057 us/op
Iterate
CMap
: 31.968 us/op
New_Face
: 1855.956 us/op
Embolden
: 0.222 us/op
feel free to comment on the API and suggest improvements if you see any problem
here.
Regards,
- David
copy of the new header file below:
/*************************************************************************/
/*
*/
/*
<Const>
*/
/*
FT_ADVANCE_FLAG_FAST_ONLY
*/
/*
*/
/*
<Description>
*/
/* a bit-flag to be or-ed to the 'flags' parameter of
the */
/* @FT_Get_Advance and
@FT_Get_Advances.
*/
/*
*/
/* when set, it indicates that you want these
functions to fail */
/* if the corresponding hinting mode or font driver
doesn't */
/* allow for very quick advance
computation.
*/
/*
*/
/* typically, unscaled, unhinted, bitmapped and
light-hinted glyphs */
/* can have their advance width(s) computed very
quickly.
*/
/*
*/
/* not so for normal and bytecode hinted modes, which
require */
/* loading/scaling/hinting the glyph outline instead,
which is */
/* extremely slow by
comparison
*/
/*
*/
#define FT_ADVANCE_FLAG_FAST_ONLY 0x20000000U
/*************************************************************************/
/*
*/
/*
<Function>
*/
/*
FT_Get_Advance
*/
/*
*/
/*
<Description>
*/
/* Retrieve the advance of a given glyph outline in a
@FT_Face. */
/* by default, the unhinted advance is returned in
font units */
/*
*/
/*
<Input>
*/
/* face :: source
@FT_Face
handle
*/
/* gindex :: glyph
index
*/
/* load_flags :: a set of bit-flags similar to those
used */
/*
when calling @FT_Load_Glyph, used to
determine */
/*
what kind of advances you
need.
*/
/*
<Output>
*/
/* padvance :: the advance value, in either font units
or 16.16 */
/*
format.
*/
/*
*/
/*
if @FT_LOAD_VERTICAL_LAYOUT is set, this is
the */
/*
vertical advance corresponding to a vertical layout. */
/*
otherwise, it's the horizontal advance in
an */
/*
horizontal
layout.
*/
/*
<Return>
*/
/* FreeType error code. 0 means
success.
*/
/*
*/
/*
<Note>
*/
/* This function may fail if you use @FT_ADVANCE_FLAG_FAST_ONLY
and */
/* if the corresponding's font backend doesn't have a
quick way to */
/* retrieve the
advances.
*/
/*
*/
/* A scaled advance is returned in 16.16 format, but
isn't */
/* transformed by the affine transform specified by
@FT_Set_Transform */
/*
*/
FT_EXPORT( FT_Error )
FT_Get_Advance( FT_Face face,
FT_UInt gindex,
FT_UInt load_flags,
FT_Fixed *padvance );
/*************************************************************************/
/*
*/
/*
<Function>
*/
/*
FT_Get_Advances
*/
/*
*/
/*
<Description>
*/
/* Retrieve the advance of several glyph outlines in a
@FT_Face. */
/* by default, the unhinted advances are returned in
font units */
/*
*/
/*
<Input>
*/
/* face ::
source @FT_Face
handle
*/
/* start :: first
glyph
index
*/
/* count :: number
of advances you want to
retrieve
*/
/* load_flags :: a set of bit-flags similar to
those used when */
/*
calling @FT_Load_Glyph.
*/
/*
*/
/*
<Output>
*/
/* padvance :: the advances, in either font units or
16.16 format. */
/*
this array must contain at least 'count' elements
*/
/*
*/
/*
if @FT_LOAD_VERTICAL_LAYOUT is set, these are the
*/
/*
vertical advances corresponding to a vertical layout. */
/*
otherwise, they are the horizontal advances in an
*/
/*
horizontal
layout.
*/
/* <Return>
*/
/* FreeType error code. 0 means
success.
*/
/*
*/
/*
<Note>
*/
/* This function may fail if you use
@FT_ADVANCE_FLAG_FAST_ONLY and */
/* if the corresponding's font backend doesn't have a
quick way to */
/* retrieve the
advances.
*/
/*
*/
/* Scaled advances are returned in 16.16 format, but
aren't */
/* transformed by the affine transform specified by
@FT_Set_Transform */
/*
*/
FT_EXPORT( FT_Error )
FT_Get_Advances( FT_Face face,
FT_UInt start,
FT_UInt count,
FT_UInt load_flags,
FT_Fixed *padvances );