* 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:
parent
281679de85
commit
545c4e566e
77
ChangeLog
77
ChangeLog
@ -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>
|
||||
|
||||
|
@ -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, */
|
||||
@ -21,29 +21,40 @@
|
||||
|
||||
|
||||
FT_LOCAL_DEF( FT_Int )
|
||||
af_corner_is_flat( FT_Pos x_in,
|
||||
FT_Pos y_in,
|
||||
FT_Pos x_out,
|
||||
FT_Pos y_out )
|
||||
af_corner_is_flat( FT_Pos x_in,
|
||||
FT_Pos y_in,
|
||||
FT_Pos x_out,
|
||||
FT_Pos y_out )
|
||||
{
|
||||
FT_Pos ax = x_in;
|
||||
FT_Pos ay = y_in;
|
||||
|
||||
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;
|
||||
d_out = ax+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;
|
||||
d_corner = ax+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);
|
||||
return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
|
||||
}
|
||||
|
||||
|
||||
@ -53,30 +64,39 @@
|
||||
FT_Pos x_out,
|
||||
FT_Pos y_out )
|
||||
{
|
||||
FT_Pos delta;
|
||||
FT_Pos delta;
|
||||
|
||||
delta = x_in*y_out - y_in*x_out;
|
||||
|
||||
delta = x_in * y_out - y_in * x_out;
|
||||
|
||||
if ( delta == 0 )
|
||||
return 0;
|
||||
else
|
||||
return 1 - 2*(delta < 0);
|
||||
return 1 - 2 * ( delta < 0 );
|
||||
}
|
||||
|
||||
|
||||
/* 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 approximation (dy*PI/(|dx|+|dy|))) should be enough, and much
|
||||
* faster to compute.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
FT_LOCAL_DEF( AF_Angle )
|
||||
af_angle_atan( FT_Fixed dx,
|
||||
FT_Fixed dy )
|
||||
@ -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;
|
||||
|
||||
@ -94,7 +117,7 @@
|
||||
angle = 0;
|
||||
else
|
||||
{
|
||||
angle = (AF_ANGLE_PI2*dy)/(ax+ay);
|
||||
angle = ( AF_ANGLE_PI2 * dy ) / ( ax + ay );
|
||||
if ( dx < 0 )
|
||||
{
|
||||
if ( angle >= 0 )
|
||||
@ -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 )
|
||||
|
@ -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 */
|
||||
|
@ -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 )
|
||||
@ -309,11 +311,13 @@
|
||||
}
|
||||
|
||||
ss *= 12;
|
||||
if ( ll <= FT_ABS(ss) )
|
||||
if ( ll <= FT_ABS( ss ) )
|
||||
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 */
|
||||
@ -439,8 +446,8 @@
|
||||
start->flags |= AF_FLAG_INFLECTION;
|
||||
}
|
||||
|
||||
start = end;
|
||||
end = after;
|
||||
start = end;
|
||||
end = after;
|
||||
|
||||
orient_prev = orient_cur;
|
||||
in_x = out_x;
|
||||
@ -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;
|
||||
|
@ -602,6 +602,7 @@
|
||||
FT_Pos max_coord = -32000;
|
||||
#endif
|
||||
|
||||
|
||||
FT_ZERO( &seg0 );
|
||||
seg0.score = 32000;
|
||||
seg0.flags = AF_EDGE_NORMAL;
|
||||
|
@ -137,27 +137,30 @@ 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,
|
||||
FT_Pos y_in,
|
||||
FT_Pos x_out,
|
||||
FT_Pos y_out );
|
||||
af_corner_is_flat( FT_Pos x_in,
|
||||
FT_Pos y_in,
|
||||
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,
|
||||
FT_Pos y_in,
|
||||
FT_Pos x_out,
|
||||
FT_Pos y_out );
|
||||
|
||||
|
||||
#define AF_ANGLE_DIFF( result, angle1, angle2 ) \
|
||||
FT_BEGIN_STMNT \
|
||||
AF_Angle _delta = (angle2) - (angle1); \
|
||||
|
@ -396,29 +396,32 @@
|
||||
FT_MulFix( FT_Long a,
|
||||
FT_Long b )
|
||||
{
|
||||
/* let's use inline assembly to speed things a bit */
|
||||
#if defined(__GNUC__) && defined(i386)
|
||||
/* 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"
|
||||
"sarl $31, %%ecx\n"
|
||||
"addl $0x8000, %%ecx\n"
|
||||
"addl %%ecx, %%eax\n"
|
||||
"adcl $0, %%edx\n"
|
||||
"shrl $16, %%eax\n"
|
||||
"shll $16, %%edx\n"
|
||||
"addl %%edx, %%eax\n"
|
||||
"mov %%eax, %0\n"
|
||||
: "=r"(result)
|
||||
: "a"(a), "d"(b)
|
||||
: "%ecx"
|
||||
);
|
||||
return result;
|
||||
"imul %%edx\n"
|
||||
"movl %%edx, %%ecx\n"
|
||||
"sarl $31, %%ecx\n"
|
||||
"addl $0x8000, %%ecx\n"
|
||||
"addl %%ecx, %%eax\n"
|
||||
"adcl $0, %%edx\n"
|
||||
"shrl $16, %%eax\n"
|
||||
"shll $16, %%edx\n"
|
||||
"addl %%edx, %%eax\n"
|
||||
"mov %%eax, %0\n"
|
||||
: "=r"(result)
|
||||
: "a"(a), "d"(b)
|
||||
: "%ecx"
|
||||
);
|
||||
return result;
|
||||
|
||||
#elif 1
|
||||
|
||||
FT_Long sa, sb;
|
||||
FT_ULong ua, ub;
|
||||
|
||||
@ -427,24 +430,22 @@
|
||||
return a;
|
||||
|
||||
sa = ( a >> ( sizeof ( a ) * 8 - 1 ) );
|
||||
a = ( a ^ sa ) - sa;
|
||||
a = ( a ^ sa ) - sa;
|
||||
sb = ( b >> ( sizeof ( b ) * 8 - 1 ) );
|
||||
b = ( b ^ sb ) - sb;
|
||||
b = ( b ^ sb ) - sb;
|
||||
|
||||
ua = (FT_ULong)a;
|
||||
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,
|
||||
@ -461,23 +462,21 @@
|
||||
if ( a == 0 || b == 0x10000L )
|
||||
return a;
|
||||
|
||||
s = a; a = FT_ABS(a);
|
||||
s ^= b; b = FT_ABS(b);
|
||||
s = a; a = FT_ABS( a );
|
||||
s ^= b; b = FT_ABS( b );
|
||||
|
||||
ua = (FT_ULong)a;
|
||||
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 );
|
||||
|
@ -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 )
|
||||
|
||||
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
6
src/cache/ftccmap.c
vendored
@ -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 )
|
||||
{
|
||||
|
@ -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 );
|
||||
FT_ULong zip_size = ft_gzip_get_uncompressed_size( source );
|
||||
|
||||
if ( zip_size != 0 && zip_size < 40*1024 )
|
||||
|
||||
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 );
|
||||
}
|
||||
|
@ -337,28 +337,30 @@
|
||||
|
||||
|
||||
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
|
||||
*/
|
||||
#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 */
|
||||
for ( ; r < n; r++ )
|
||||
{
|
||||
FT_UInt c = p[r];
|
||||
|
||||
if ( IS_PS_SPACE(c) )
|
||||
|
||||
if ( IS_PS_SPACE( c ) )
|
||||
continue;
|
||||
|
||||
if ( c OP 0x80 )
|
||||
break;
|
||||
|
||||
c = ft_char_table[ c & 0x7F ];
|
||||
c = ft_char_table[c & 0x7F];
|
||||
if ( (unsigned)c >= 16 )
|
||||
break;
|
||||
|
||||
pad = (pad << 4) | c;
|
||||
pad = ( pad << 4 ) | c;
|
||||
if ( pad & 0x100 )
|
||||
{
|
||||
buffer[w++] = (FT_Byte)pad;
|
||||
@ -367,11 +369,14 @@
|
||||
}
|
||||
|
||||
if ( pad != 0x01 )
|
||||
buffer[w++] = (FT_Byte)(pad << 4);
|
||||
buffer[w++] = (FT_Byte)( pad << 4 );
|
||||
|
||||
*cursor = p + r;
|
||||
|
||||
*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 */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -413,11 +420,13 @@
|
||||
FT_UInt n,
|
||||
FT_UShort* seed )
|
||||
{
|
||||
FT_Byte* p;
|
||||
FT_UInt r;
|
||||
FT_UInt s = *seed;
|
||||
FT_Byte* p;
|
||||
FT_UInt r;
|
||||
FT_UInt s = *seed;
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
p = *cursor;
|
||||
if ( n > (FT_UInt)(limit - p) )
|
||||
n = (FT_UInt)(limit - p);
|
||||
@ -425,7 +434,8 @@
|
||||
for ( r = 0; r < n; r++ )
|
||||
{
|
||||
FT_UInt val = p[r];
|
||||
FT_UInt b = ( val ^ (s >> 8) );
|
||||
FT_UInt b = ( val ^ ( s >> 8 ) );
|
||||
|
||||
|
||||
s = ( (val + s)*52845U + 22719 ) & 0xFFFFU;
|
||||
buffer[r] = (FT_Byte) b;
|
||||
@ -433,7 +443,9 @@
|
||||
|
||||
*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;
|
||||
}
|
||||
|
@ -208,19 +208,19 @@
|
||||
FT_CALLBACK_DEF( FT_Error )
|
||||
TT_Load_Glyph_Header( TT_Loader loader )
|
||||
{
|
||||
FT_Byte* p = loader->cursor;
|
||||
FT_Byte* limit = loader->limit;
|
||||
FT_Byte* p = loader->cursor;
|
||||
FT_Byte* limit = loader->limit;
|
||||
|
||||
|
||||
if ( p + 10 > limit )
|
||||
return TT_Err_Invalid_Outline;
|
||||
|
||||
loader->n_contours = FT_NEXT_SHORT(p);
|
||||
loader->n_contours = FT_NEXT_SHORT( p );
|
||||
|
||||
loader->bbox.xMin = FT_NEXT_SHORT(p);
|
||||
loader->bbox.yMin = FT_NEXT_SHORT(p);
|
||||
loader->bbox.xMax = FT_NEXT_SHORT(p);
|
||||
loader->bbox.yMax = FT_NEXT_SHORT(p);
|
||||
loader->bbox.xMin = FT_NEXT_SHORT( p );
|
||||
loader->bbox.yMin = FT_NEXT_SHORT( p );
|
||||
loader->bbox.xMax = FT_NEXT_SHORT( p );
|
||||
loader->bbox.yMax = FT_NEXT_SHORT( p );
|
||||
|
||||
FT_TRACE5(( " # of contours: %d\n", loader->n_contours ));
|
||||
FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin,
|
||||
@ -263,11 +263,11 @@
|
||||
cont_limit = cont + n_contours;
|
||||
|
||||
/* check space for contours array + instructions count */
|
||||
if ( n_contours >= 0xFFF || p + (n_contours+1)*2 > limit )
|
||||
if ( n_contours >= 0xFFF || p + (n_contours + 1) * 2 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
for ( ; cont < cont_limit; cont++ )
|
||||
cont[0] = FT_NEXT_USHORT(p);
|
||||
cont[0] = FT_NEXT_USHORT( p );
|
||||
|
||||
n_points = 0;
|
||||
if ( n_contours > 0 )
|
||||
@ -289,10 +289,10 @@
|
||||
load->glyph->control_len = 0;
|
||||
load->glyph->control_data = 0;
|
||||
|
||||
if ( p+2 > limit )
|
||||
if ( p + 2 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
n_ins = FT_NEXT_USHORT(p);
|
||||
n_ins = FT_NEXT_USHORT( p );
|
||||
|
||||
FT_TRACE5(( " Instructions size: %u\n", n_ins ));
|
||||
|
||||
@ -303,7 +303,7 @@
|
||||
goto Fail;
|
||||
}
|
||||
|
||||
if ( (limit - p) < n_ins )
|
||||
if ( ( limit - p ) < n_ins )
|
||||
{
|
||||
FT_TRACE0(( "TT_Load_Simple_Glyph: Instruction count mismatch!\n" ));
|
||||
error = TT_Err_Too_Many_Hints;
|
||||
@ -332,16 +332,16 @@
|
||||
|
||||
while ( flag < flag_limit )
|
||||
{
|
||||
if ( p+1 > limit )
|
||||
if ( p + 1 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
*flag++ = c = FT_NEXT_BYTE(p);
|
||||
*flag++ = c = FT_NEXT_BYTE( p );
|
||||
if ( c & 8 )
|
||||
{
|
||||
if ( p+1 > limit )
|
||||
if ( p + 1 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
count = FT_NEXT_BYTE(p);
|
||||
count = FT_NEXT_BYTE( p );
|
||||
if ( flag + (FT_Int)count > flag_limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
@ -364,19 +364,19 @@
|
||||
|
||||
if ( *flag & 2 )
|
||||
{
|
||||
if ( p+1 > limit )
|
||||
if ( p + 1 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
y = (FT_Pos)FT_NEXT_BYTE(p);
|
||||
y = (FT_Pos)FT_NEXT_BYTE( p );
|
||||
if ( ( *flag & 16 ) == 0 )
|
||||
y = -y;
|
||||
}
|
||||
else if ( ( *flag & 16 ) == 0 )
|
||||
{
|
||||
if ( p+2 > limit )
|
||||
if ( p + 2 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
y = (FT_Pos)FT_NEXT_SHORT(p);
|
||||
y = (FT_Pos)FT_NEXT_SHORT( p );
|
||||
}
|
||||
|
||||
x += y;
|
||||
@ -397,19 +397,19 @@
|
||||
|
||||
if ( *flag & 4 )
|
||||
{
|
||||
if ( p+1 > limit )
|
||||
if ( p +1 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
y = (FT_Pos)FT_NEXT_BYTE(p);
|
||||
y = (FT_Pos)FT_NEXT_BYTE( p );
|
||||
if ( ( *flag & 32 ) == 0 )
|
||||
y = -y;
|
||||
}
|
||||
else if ( ( *flag & 32 ) == 0 )
|
||||
{
|
||||
if ( p+2 > limit )
|
||||
if ( p + 2 > limit )
|
||||
goto Invalid_Outline;
|
||||
|
||||
y = (FT_Pos)FT_NEXT_SHORT(p);
|
||||
y = (FT_Pos)FT_NEXT_SHORT( p );
|
||||
}
|
||||
|
||||
x += y;
|
||||
@ -459,15 +459,15 @@
|
||||
goto Fail;
|
||||
|
||||
/* check space */
|
||||
if ( p+4 > limit )
|
||||
if ( p + 4 > limit )
|
||||
goto Invalid_Composite;
|
||||
|
||||
subglyph = gloader->current.subglyphs + num_subglyphs;
|
||||
|
||||
subglyph->arg1 = subglyph->arg2 = 0;
|
||||
|
||||
subglyph->flags = FT_NEXT_USHORT(p);
|
||||
subglyph->index = FT_NEXT_USHORT(p);
|
||||
subglyph->flags = FT_NEXT_USHORT( p );
|
||||
subglyph->index = FT_NEXT_USHORT( p );
|
||||
|
||||
/* check space */
|
||||
count = 2;
|
||||
@ -486,13 +486,13 @@
|
||||
/* read arguments */
|
||||
if ( subglyph->flags & ARGS_ARE_WORDS )
|
||||
{
|
||||
subglyph->arg1 = FT_NEXT_SHORT(p);
|
||||
subglyph->arg2 = FT_NEXT_SHORT(p);
|
||||
subglyph->arg1 = FT_NEXT_SHORT( p );
|
||||
subglyph->arg2 = FT_NEXT_SHORT( p );
|
||||
}
|
||||
else
|
||||
{
|
||||
subglyph->arg1 = FT_NEXT_CHAR(p);
|
||||
subglyph->arg2 = FT_NEXT_CHAR(p);
|
||||
subglyph->arg1 = FT_NEXT_CHAR( p );
|
||||
subglyph->arg2 = FT_NEXT_CHAR( p );
|
||||
}
|
||||
|
||||
/* read transform */
|
||||
@ -501,20 +501,20 @@
|
||||
|
||||
if ( subglyph->flags & WE_HAVE_A_SCALE )
|
||||
{
|
||||
xx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
yy = xx;
|
||||
}
|
||||
else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
|
||||
{
|
||||
xx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
yy = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
}
|
||||
else if ( subglyph->flags & WE_HAVE_A_2X2 )
|
||||
{
|
||||
xx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
yx = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
xy = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
yy = (FT_Fixed)FT_NEXT_SHORT(p) << 2;
|
||||
xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
yx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
xy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
|
||||
}
|
||||
|
||||
subglyph->transform.xx = xx;
|
||||
@ -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... */
|
||||
|
Loading…
Reference in New Issue
Block a user