* src/truetype/ttgload.c (TT_Load_Composite_Glyph)

[FT_CONFIG_OPTION_BYTECODE_INTERPRETER]: Make it compilable again.


Formatting, documentation fixes.
This commit is contained in:
Werner Lemberg 2006-05-17 22:55:04 +00:00
parent 281679de85
commit 545c4e566e
12 changed files with 282 additions and 170 deletions

View File

@ -1,26 +1,69 @@
2006-05-18 Werner Lemberg <wl@gnu.org>
* src/truetype/ttgload.c (TT_Load_Composite_Glyph)
[FT_CONFIG_OPTION_BYTECODE_INTERPRETER]: Make it compilable again.
2006-05-17 David Turner <david@freetype.org>
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
This is a major patch used to drastically improve the performance of
loading glyphs. This both speeds up loading the glyph vectors
themselves and the auto-fitter module.
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
We now use inline assembler code with GCC to implement `FT_MulFix',
which is probably the most important function related to the
engine's performance.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
The resulting speed-up is about 25%.
* src/ftccmap.c (FTC_CMapCache_Lookup): changed the threshold
used to detect rogue clients from 4 to 16. This is to prevent
some segmentation faults with fonts like KozMinProVI-Regular.otf
which comes from the Japanese Adobe Reader Asian Font pack.
* include/freetype/internal/tttypes.h (TT_LoaderRec): Add fields
`cursor' and `limit'.
* src/autofit/afangles.c (af_corner_is_flat, af_corner_orientation):
New functions.
(AF_ATAN_BITS, af_arctan, af_angle_atan): Comment out.
[TEST]: Remove.
* src/autofit/afcjk.c (AF_Script_UniRangeRec): Comment out test
code.
* src/autofit/afhints.c (af_axis_hints_new_segment): Don't call
`FT_ZERO'
(af_direction_compute, af_glyph_hints_compute_inflections): Rewritten.
(af_glyph_hints_reload: Rewrite recognition of weak points.
* src/autofit/aflatin.c (af_latin_hints_compute_segments): Move
constant values out of the loops.
* src/autofit/aftypes.h: Updated.
* src/base/ftcalc.c (FT_MulFix): Use inline assembler code.
* src/base/ftoutln.c (FT_Outline_Get_Orientation): Use vector
product to get orientation.
* src/gzip/ftgzip.c (ft_get_uncompressed_size): New function.
(FT_Stream_OpenGzip): Use it to handle small files directly in
memory.
* src/psaux/psconv.c (PS_Conv_ASCIIHexDecode, PS_ConvEexecDecode):
Improve performance.
* src/truetype/ttgload.c (TT_Access_Glyph_Frame): Set `cursor' and
`limit'.
(TT_Load_Glyph_Header, TT_Load_Simple_Glyph,
TT_Load_Composite_Glyph): Updated. Add threshold to protect against
exceedingly large values of number of contours. Speed up by
reducing the number of loops.
* src/type1/t1gload.c (T1_Load_Glyph): Don't apply unit matrix.
* src/cache/ftccmap.c (FTC_CMapCache_Lookup): Change the threshold
used to detect rogue clients from 4 to 16. This is to prevent some
segmentation faults with fonts like `KozMinProVI-Regular.otf' which
comes from the Japanese Adobe Reader Asian Font pack.
2007-05-17 Werner Lemberg <wl@gnu.org>

View File

@ -5,7 +5,7 @@
/* Routines used to compute vector angles with limited accuracy */
/* and very high speed. It also contains sorting routines (body). */
/* */
/* Copyright 2003, 2004, 2005 by */
/* Copyright 2003, 2004, 2005, 2006 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -31,16 +31,27 @@
FT_Pos d_in, d_out, d_corner;
if ( ax < 0 ) ax = -ax;
if ( ay < 0 ) ay = -ay;
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
d_in = ax + ay;
ax = x_out; if ( ax < 0 ) ax = -ax;
ay = y_out; if ( ay < 0 ) ay = -ay;
ax = x_out;
if ( ax < 0 )
ax = -ax;
ay = y_out;
if ( ay < 0 )
ay = -ay;
d_out = ax + ay;
ax = x_out + x_in; if ( ax < 0 ) ax = -ax;
ay = y_out + y_in; if ( ay < 0 ) ay = -ay;
ax = x_out + x_in;
if ( ax < 0 )
ax = -ax;
ay = y_out + y_in;
if ( ay < 0 )
ay = -ay;
d_corner = ax + ay;
return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
@ -55,6 +66,7 @@
{
FT_Pos delta;
delta = x_in * y_out - y_in * x_out;
if ( delta == 0 )
@ -64,18 +76,26 @@
}
/* we're not using af_angle_atan anymore, but we keep the source
* code below just in case :-)
/*
* We are not using `af_angle_atan' anymore, but we keep the source
* code below just in case...
*/
#if 0
/* the trick here is to realize that we don't need an very accurate
* angle approximation. We're going to use the result of af_angle_atan
* to only compare the sign of angle differences, or see if its magnitude
* is very small.
/*
* The trick here is to realize that we don't need a very accurate angle
* approximation. We are going to use the result of `af_angle_atan' to
* only compare the sign of angle differences, or check whether its
* magnitude is very small.
*
* the approximation (dy*PI/(|dx|+|dy|))) should be enough, and much
* faster to compute.
* The approximation
*
* dy * PI / (|dx|+|dy|)
*
* should be enough, and much faster to compute.
*/
FT_LOCAL_DEF( AF_Angle )
af_angle_atan( FT_Fixed dx,
@ -85,8 +105,11 @@
FT_Fixed ax = dx;
FT_Fixed ay = dy;
if ( ax < 0 ) ax = -ax;
if ( ay < 0 ) ay = -ay;
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
ax += ay;
@ -107,8 +130,10 @@
return angle;
}
#elif 0
/* the following table has been automatically generated with */
/* the `mather.py' Python script */
@ -211,7 +236,7 @@
}
#endif
#endif /* 0 */
FT_LOCAL_DEF( void )

View File

@ -1438,7 +1438,7 @@
static const AF_Script_UniRangeRec af_cjk_uniranges[] =
{
#if 0
{ 0x0100, 0xFFFF }, /* why ?? */
{ 0x0100, 0xFFFF }, /* why this? */
#endif
{ 0x2E80, 0x2EFF }, /* CJK Radicals Supplement */
{ 0x2F00, 0x2FDF }, /* Kangxi Radicals */

View File

@ -267,16 +267,18 @@
#endif /* AF_DEBUG */
/* compute the direction value of a given vector */
FT_LOCAL_DEF( AF_Direction )
af_direction_compute( FT_Pos dx,
FT_Pos dy )
{
#if 1
FT_Pos ll, ss; /* long and short arm lengths */
AF_Direction dir; /* candidate direction */
if ( dy >= dx )
{
if ( dy >= -dx )
@ -313,7 +315,9 @@
dir = AF_DIR_NONE;
return dir;
#else /* 0 */
AF_Direction dir;
FT_Pos ax = FT_ABS( dx );
FT_Pos ay = FT_ABS( dy );
@ -335,13 +339,16 @@
}
return dir;
#endif /* 0 */
}
/* compute all inflex points in a given glyph */
#if 1
static void
af_glyph_hints_compute_inflections( AF_GlyphHints hints )
{
@ -403,7 +410,7 @@
in_x = out_x;
in_y = out_y;
/* now, process all segments in the contour */
/* now process all segments in the contour */
do
{
/* first, extend current segment's end whenever possible */
@ -454,6 +461,7 @@
}
#else /* old code */
static void
af_glyph_hints_compute_inflections( AF_GlyphHints hints )
{
@ -560,6 +568,7 @@
;
}
}
#endif /* old code */
@ -809,7 +818,9 @@
}
else if ( point->out_dir == point->in_dir )
{
#if 1
if ( point->out_dir != AF_DIR_NONE )
goto Is_Weak_Point;
@ -817,6 +828,7 @@
goto Is_Weak_Point;
#else /* old code */
AF_Angle angle_in, angle_out, delta;
@ -830,7 +842,9 @@
if ( delta < 2 && delta > -2 )
goto Is_Weak_Point;
#endif /* old code */
}
else if ( point->in_dir == -point->out_dir )
goto Is_Weak_Point;

View File

@ -602,6 +602,7 @@
FT_Pos max_coord = -32000;
#endif
FT_ZERO( &seg0 );
seg0.score = 32000;
seg0.flags = AF_EDGE_NORMAL;

View File

@ -137,9 +137,10 @@ FT_BEGIN_HEADER
#endif /* 0 */
/* return TRUE if a corner is flat, or nearly flat, this is equivalent
* to say that the angle difference between the 'in' and 'out' vectors is
* very small
/*
* Return TRUE if a corner is flat or nearly flat. This is equivalent to
* saying that the angle difference between the `in' and `out' vectors is
* very small.
*/
FT_LOCAL( FT_Int )
af_corner_is_flat( FT_Pos x_in,
@ -147,10 +148,11 @@ FT_BEGIN_HEADER
FT_Pos x_out,
FT_Pos y_out );
/* return a value that can be -1, 0 or +1 depending on the orientation
* of a given corner. We're using the Cartesian coordinate system,
* with positive Ys going upwards. The function returns +1 when
* the corner turns to the left, -1 to the right, and 0 for undecided
/*
* Return -1, 0, or +1, depending on the orientation of a given corner.
* We use the Cartesian coordinate system, with positive vertical values
* going upwards. The function returns +1 when the corner turns to the
* left, -1 to the right, and 0 for undecided.
*/
FT_LOCAL( FT_Int )
af_corner_orientation( FT_Pos x_in,
@ -158,6 +160,7 @@ FT_BEGIN_HEADER
FT_Pos x_out,
FT_Pos y_out );
#define AF_ANGLE_DIFF( result, angle1, angle2 ) \
FT_BEGIN_STMNT \
AF_Angle _delta = (angle2) - (angle1); \

View File

@ -396,11 +396,13 @@
FT_MulFix( FT_Long a,
FT_Long b )
{
/* let's use inline assembly to speed things a bit */
/* use inline assembly to speed up things a bit */
#if defined( __GNUC__ ) && defined( i386 )
FT_Long result;
__asm__ __volatile__ (
"imul %%edx\n"
"movl %%edx, %%ecx\n"
@ -419,6 +421,7 @@
return result;
#elif 1
FT_Long sa, sb;
FT_ULong ua, ub;
@ -435,16 +438,14 @@
ub = (FT_ULong)b;
if ( ua <= 2048 && ub <= 1048576L )
{
ua = ( ua * ub + 0x8000 ) >> 16;
}
ua = ( ua * ub + 0x8000U ) >> 16;
else
{
FT_ULong al = ua & 0xFFFF;
FT_ULong al = ua & 0xFFFFU;
ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
( ( al * ( ub & 0xFFFF ) + 0x8000 ) >> 16 );
( ( al * ( ub & 0xFFFFU ) + 0x8000U ) >> 16 );
}
sa ^= sb,
@ -468,16 +469,14 @@
ub = (FT_ULong)b;
if ( ua <= 2048 && ub <= 1048576L )
{
ua = ( ua * ub + 0x8000L ) >> 16;
}
ua = ( ua * ub + 0x8000UL ) >> 16;
else
{
FT_ULong al = ua & 0xFFFFL;
FT_ULong al = ua & 0xFFFFUL;
ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
( ( al * ( ub & 0xFFFFL ) + 0x8000L ) >> 16 );
( ( al * ( ub & 0xFFFFUL ) + 0x8000UL ) >> 16 );
}
return ( s < 0 ? -(FT_Long)ua : (FT_Long)ua );

View File

@ -1013,24 +1013,29 @@
}
#if 1
{
FT_Pos dx1 = prev->x - xmin_point->x;
FT_Pos dy1 = prev->y - xmin_point->y;
FT_Pos dx2 = next->x - xmin_point->x;
FT_Pos dy2 = next->y - xmin_point->y;
if ( dy1 * dx2 > dy2 * dx1 )
return FT_ORIENTATION_POSTSCRIPT;
else
return FT_ORIENTATION_TRUETYPE;
}
#else
#else /* 0 */
if ( FT_Atan2( prev->x - xmin_point->x, prev->y - xmin_point->y ) >
FT_Atan2( next->x - xmin_point->x, next->y - xmin_point->y ) )
return FT_ORIENTATION_POSTSCRIPT;
else
return FT_ORIENTATION_TRUETYPE;
#endif
#endif /* 0 */
}

6
src/cache/ftccmap.c vendored
View File

@ -307,9 +307,9 @@
* It is also very unlikely that a rogue client is interested
* in Unicode values 0 to 15.
*
* NOTE: The original threshold was 4, but we found a font
* from the Adobe Acrobat Reader Pack, named
* "KozMinProVI-Regular.otf" which contained more than 5 charmaps.
* NOTE: The original threshold was 4, but we found a font from the
* Adobe Acrobat Reader Pack, named `KozMinProVI-Regular.otf',
* which contains more than 5 charmaps.
*/
if ( cmap_index >= 16 )
{

View File

@ -561,6 +561,7 @@
FT_ULong old_pos;
FT_ULong result = 0;
old_pos = stream->pos;
if ( !FT_Stream_Seek( stream, stream->size - 4 ) )
{
@ -607,24 +608,28 @@
stream->descriptor.pointer = zip;
}
/* ok, here's a trick to try to dramatically improve the performance
* of dealing with small files. If the original stream size is less
* than a certain threshold, we try to load the whole font file in
* memory. this saves us from the 32KB buffer needed to inflate the
* file anyway, plus the two 4KB intermediate input/output buffers
* used in the FT_GZipFile structure.
/*
* We use the following trick to try to dramatically improve the
* performance while dealing with small files. If the original stream
* size is less than a certain threshold, we try to load the whole font
* file into memory. This saves us from using the 32KB buffer needed
* to inflate the file, plus the two 4KB intermediate input/output
* buffers used in the `FT_GZipFile' structure.
*/
{
FT_ULong zip_size = ft_gzip_get_uncompressed_size( source );
if ( zip_size != 0 && zip_size < 40 * 1024 )
{
FT_Byte* zip_buff;
if ( !FT_ALLOC( zip_buff, zip_size ) )
{
FT_ULong count;
count = ft_gzip_file_io( zip, 0, zip_buff, zip_size );
if ( count == zip_size )
{
@ -641,6 +646,7 @@
goto Exit;
}
ft_gzip_file_io( zip, 0, NULL, 0 );
FT_FREE( zip_buff );
}

View File

@ -337,17 +337,19 @@
n *= 2;
#if 1
p = *cursor;
if ( n > (FT_UInt)( limit - p ) )
n = (FT_UInt)( limit - p );
/* we try to process two nibbles at a time to be as fast as possible
*/
/* we try to process two nibbles at a time to be as fast as possible */
for ( ; r < n; r++ )
{
FT_UInt c = p[r];
if ( IS_PS_SPACE( c ) )
continue;
@ -370,8 +372,11 @@
buffer[w++] = (FT_Byte)( pad << 4 );
*cursor = p + r;
return w;
#else
#else /* 0 */
for ( r = 0; r < n; r++ )
{
FT_Char c;
@ -402,7 +407,9 @@
*cursor = p;
return ( r + 1 ) / 2;
#endif
#endif /* 0 */
}
@ -417,7 +424,9 @@
FT_UInt r;
FT_UInt s = *seed;
#if 1
p = *cursor;
if ( n > (FT_UInt)(limit - p) )
n = (FT_UInt)(limit - p);
@ -427,13 +436,16 @@
FT_UInt val = p[r];
FT_UInt b = ( val ^ ( s >> 8 ) );
s = ( (val + s)*52845U + 22719 ) & 0xFFFFU;
buffer[r] = (FT_Byte) b;
}
*cursor = p + n;
*seed = (FT_UShort)s;
#else
#else /* 0 */
for ( r = 0, p = *cursor; r < n && p < limit; r++, p++ )
{
FT_Byte b = (FT_Byte)( *p ^ ( s >> 8 ) );
@ -444,7 +456,8 @@
}
*cursor = p;
*seed = s;
#endif
#endif /* 0 */
return r;
}

View File

@ -531,6 +531,9 @@
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
{
FT_Stream stream = loader->stream;
/* we must undo the FT_FRAME_ENTER in order to point to the */
/* composite instructions, if we find some. */
/* we will process them later... */