summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/truetype/ttgxvar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/truetype/ttgxvar.c')
-rw-r--r--src/3rdparty/freetype/src/truetype/ttgxvar.c130
1 files changed, 59 insertions, 71 deletions
diff --git a/src/3rdparty/freetype/src/truetype/ttgxvar.c b/src/3rdparty/freetype/src/truetype/ttgxvar.c
index ef25aafb5b..1b35539fe1 100644
--- a/src/3rdparty/freetype/src/truetype/ttgxvar.c
+++ b/src/3rdparty/freetype/src/truetype/ttgxvar.c
@@ -4,7 +4,7 @@
/* */
/* TrueType GX Font Variation loader */
/* */
-/* Copyright 2004, 2005, 2006, 2007, 2008, 2009 by */
+/* Copyright 2004-2014 by */
/* David Turner, Robert Wilhelm, Werner Lemberg, and George Williams. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -61,9 +61,9 @@
#define FT_Stream_FTell( stream ) \
- ( (stream)->cursor - (stream)->base )
+ (FT_ULong)( (stream)->cursor - (stream)->base )
#define FT_Stream_SeekSet( stream, off ) \
- ( (stream)->cursor = (stream)->base+(off) )
+ ( (stream)->cursor = (stream)->base + (off) )
/*************************************************************************/
@@ -91,7 +91,9 @@
/* indicates that there is a delta for every point without needing to */
/* enumerate all of them. */
/* */
-#define ALL_POINTS (FT_UShort*)( -1 )
+
+ /* ensure that value `0' has the same width as a pointer */
+#define ALL_POINTS (FT_UShort*)~(FT_PtrDist)0
#define GX_PT_POINTS_ARE_WORDS 0x80
@@ -123,14 +125,14 @@
ft_var_readpackedpoints( FT_Stream stream,
FT_UInt *point_cnt )
{
- FT_UShort *points;
+ FT_UShort *points = NULL;
FT_Int n;
FT_Int runcnt;
FT_Int i;
FT_Int j;
FT_Int first;
FT_Memory memory = stream->memory;
- FT_Error error = TT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
FT_UNUSED( error );
@@ -154,7 +156,7 @@
runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK;
first = points[i++] = FT_GET_USHORT();
- if ( runcnt < 1 )
+ if ( runcnt < 1 || i + runcnt >= n )
goto Exit;
/* first point not included in runcount */
@@ -165,7 +167,7 @@
{
first = points[i++] = FT_GET_BYTE();
- if ( runcnt < 1 )
+ if ( runcnt < 1 || i + runcnt >= n )
goto Exit;
for ( j = 0; j < runcnt; ++j )
@@ -210,12 +212,12 @@
ft_var_readpackeddeltas( FT_Stream stream,
FT_Offset delta_cnt )
{
- FT_Short *deltas;
+ FT_Short *deltas = NULL;
FT_UInt runcnt;
FT_Offset i;
FT_UInt j;
FT_Memory memory = stream->memory;
- FT_Error error = TT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
FT_UNUSED( error );
@@ -283,7 +285,7 @@
FT_Memory memory = stream->memory;
GX_Blend blend = face->blend;
GX_AVarSegment segment;
- FT_Error error = TT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
FT_ULong version;
FT_Long axisCount;
FT_Int i, j;
@@ -412,7 +414,7 @@
if ( gvar_head.version != (FT_Long)0x00010000L ||
gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis )
{
- error = TT_Err_Invalid_Table;
+ error = FT_THROW( Invalid_Table );
goto Exit;
}
@@ -501,11 +503,9 @@
FT_Fixed* im_end_coords )
{
FT_UInt i;
- FT_Fixed apply;
- FT_Fixed temp;
+ FT_Fixed apply = 0x10000L;
- apply = 0x10000L;
for ( i = 0; i < blend->num_axis; ++i )
{
if ( tuple_coords[i] == 0 )
@@ -525,11 +525,10 @@
else if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) )
/* not an intermediate tuple */
- apply = FT_MulDiv( apply,
+ apply = FT_MulFix( apply,
blend->normalizedcoords[i] > 0
? blend->normalizedcoords[i]
- : -blend->normalizedcoords[i],
- 0x10000L );
+ : -blend->normalizedcoords[i] );
else if ( blend->normalizedcoords[i] <= im_start_coords[i] ||
blend->normalizedcoords[i] >= im_end_coords[i] )
@@ -539,20 +538,14 @@
}
else if ( blend->normalizedcoords[i] < tuple_coords[i] )
- {
- temp = FT_MulDiv( blend->normalizedcoords[i] - im_start_coords[i],
- 0x10000L,
- tuple_coords[i] - im_start_coords[i]);
- apply = FT_MulDiv( apply, temp, 0x10000L );
- }
+ apply = FT_MulDiv( apply,
+ blend->normalizedcoords[i] - im_start_coords[i],
+ tuple_coords[i] - im_start_coords[i] );
else
- {
- temp = FT_MulDiv( im_end_coords[i] - blend->normalizedcoords[i],
- 0x10000L,
- im_end_coords[i] - tuple_coords[i] );
- apply = FT_MulDiv( apply, temp, 0x10000L );
- }
+ apply = FT_MulDiv( apply,
+ im_end_coords[i] - blend->normalizedcoords[i],
+ im_end_coords[i] - tuple_coords[i] );
}
return apply;
@@ -619,10 +612,10 @@
FT_Stream stream = face->root.stream;
FT_Memory memory = face->root.memory;
FT_ULong table_len;
- FT_Error error = TT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
FT_ULong fvar_start;
FT_Int i, j;
- FT_MM_Var* mmvar;
+ FT_MM_Var* mmvar = NULL;
FT_Fixed* next_coords;
FT_String* next_name;
FT_Var_Axis* a;
@@ -682,18 +675,22 @@
if ( fvar_head.version != (FT_Long)0x00010000L ||
fvar_head.countSizePairs != 2 ||
fvar_head.axisSize != 20 ||
+ /* axisCount limit implied by 16-bit instanceSize */
+ fvar_head.axisCount > 0x3FFE ||
fvar_head.instanceSize != 4 + 4 * fvar_head.axisCount ||
+ /* instanceCount limit implied by limited range of name IDs */
+ fvar_head.instanceCount > 0x7EFF ||
fvar_head.offsetToData + fvar_head.axisCount * 20U +
fvar_head.instanceCount * fvar_head.instanceSize > table_len )
{
- error = TT_Err_Invalid_Table;
+ error = FT_THROW( Invalid_Table );
goto Exit;
}
if ( FT_NEW( face->blend ) )
goto Exit;
- /* XXX: TODO - check for overflows */
+ /* cannot overflow 32-bit arithmetic because of limits above */
face->blend->mmvar_len =
sizeof ( FT_MM_Var ) +
fvar_head.axisCount * sizeof ( FT_Var_Axis ) +
@@ -708,7 +705,7 @@
mmvar->num_axis =
fvar_head.axisCount;
mmvar->num_designs =
- (FT_UInt)-1; /* meaningless in this context; each glyph */
+ ~0U; /* meaningless in this context; each glyph */
/* may have a different number of designs */
/* (or tuples, as called by Apple) */
mmvar->num_namedstyles =
@@ -852,7 +849,7 @@
FT_UInt num_coords,
FT_Fixed* coords )
{
- FT_Error error = TT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
GX_Blend blend;
FT_MM_Var* mmvar;
FT_UInt i;
@@ -880,14 +877,14 @@
if ( num_coords != mmvar->num_axis )
{
- error = TT_Err_Invalid_Argument;
+ error = FT_THROW( Invalid_Argument );
goto Exit;
}
for ( i = 0; i < num_coords; ++i )
if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L )
{
- error = TT_Err_Invalid_Argument;
+ error = FT_THROW( Invalid_Argument );
goto Exit;
}
@@ -941,13 +938,13 @@
FT_FREE( face->cvt );
face->cvt = NULL;
- tt_face_load_cvt( face, face->root.stream );
+ error = tt_face_load_cvt( face, face->root.stream );
break;
case mcvt_modify:
/* The original cvt table is in memory. All we need to do is */
/* apply the `cvar' table (if any). */
- tt_face_vary_cvt( face, face->root.stream );
+ error = tt_face_vary_cvt( face, face->root.stream );
break;
case mcvt_retain:
@@ -988,7 +985,7 @@
FT_UInt num_coords,
FT_Fixed* coords )
{
- FT_Error error = TT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
FT_Fixed* normalized = NULL;
GX_Blend blend;
FT_MM_Var* mmvar;
@@ -1009,7 +1006,7 @@
if ( num_coords != mmvar->num_axis )
{
- error = TT_Err_Invalid_Argument;
+ error = FT_THROW( Invalid_Argument );
goto Exit;
}
@@ -1025,24 +1022,16 @@
{
if ( coords[i] > a->maximum || coords[i] < a->minimum )
{
- error = TT_Err_Invalid_Argument;
+ error = FT_THROW( Invalid_Argument );
goto Exit;
}
if ( coords[i] < a->def )
- {
- normalized[i] = -FT_MulDiv( coords[i] - a->def,
- 0x10000L,
- a->minimum - a->def );
- }
+ normalized[i] = -FT_DivFix( coords[i] - a->def, a->minimum - a->def );
else if ( a->maximum == a->def )
normalized[i] = 0;
else
- {
- normalized[i] = FT_MulDiv( coords[i] - a->def,
- 0x10000L,
- a->maximum - a->def );
- }
+ normalized[i] = FT_DivFix( coords[i] - a->def, a->maximum - a->def );
}
if ( !blend->avar_checked )
@@ -1057,15 +1046,11 @@
if ( normalized[i] < av->correspondence[j].fromCoord )
{
normalized[i] =
- FT_MulDiv(
- FT_MulDiv(
- normalized[i] - av->correspondence[j - 1].fromCoord,
- 0x10000L,
- av->correspondence[j].fromCoord -
- av->correspondence[j - 1].fromCoord ),
- av->correspondence[j].toCoord -
- av->correspondence[j - 1].toCoord,
- 0x10000L ) +
+ FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord,
+ av->correspondence[j].toCoord -
+ av->correspondence[j - 1].toCoord,
+ av->correspondence[j].fromCoord -
+ av->correspondence[j - 1].fromCoord ) +
av->correspondence[j - 1].toCoord;
break;
}
@@ -1137,7 +1122,7 @@
{
FT_TRACE2(( "tt_face_vary_cvt: no blend specified\n" ));
- error = TT_Err_Ok;
+ error = FT_Err_Ok;
goto Exit;
}
@@ -1145,7 +1130,7 @@
{
FT_TRACE2(( "tt_face_vary_cvt: no `cvt ' table\n" ));
- error = TT_Err_Ok;
+ error = FT_Err_Ok;
goto Exit;
}
@@ -1154,13 +1139,13 @@
{
FT_TRACE2(( "is missing\n" ));
- error = TT_Err_Ok;
+ error = FT_Err_Ok;
goto Exit;
}
if ( FT_FRAME_ENTER( table_len ) )
{
- error = TT_Err_Ok;
+ error = FT_Err_Ok;
goto Exit;
}
@@ -1169,7 +1154,7 @@
{
FT_TRACE2(( "bad table version\n" ));
- error = TT_Err_Ok;
+ error = FT_Err_Ok;
goto FExit;
}
@@ -1321,7 +1306,7 @@
FT_Stream stream = face->root.stream;
FT_Memory memory = stream->memory;
GX_Blend blend = face->blend;
- FT_Vector* delta_xy;
+ FT_Vector* delta_xy = NULL;
FT_Error error;
FT_ULong glyph_start;
@@ -1340,7 +1325,7 @@
if ( !face->doblend || blend == NULL )
- return TT_Err_Invalid_Argument;
+ return FT_THROW( Invalid_Argument );
/* to be freed by the caller */
if ( FT_NEW_ARRAY( delta_xy, n_points ) )
@@ -1350,7 +1335,7 @@
if ( glyph_index >= blend->gv_glyphcnt ||
blend->glyphoffsets[glyph_index] ==
blend->glyphoffsets[glyph_index + 1] )
- return TT_Err_Ok; /* no variation data for this glyph */
+ return FT_Err_Ok; /* no variation data for this glyph */
if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) ||
FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] -
@@ -1400,7 +1385,7 @@
}
else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount )
{
- error = TT_Err_Invalid_Table;
+ error = FT_THROW( Invalid_Table );
goto Fail3;
}
else
@@ -1470,6 +1455,9 @@
{
for ( j = 0; j < point_count; ++j )
{
+ if ( localpoints[j] >= n_points )
+ continue;
+
delta_xy[localpoints[j]].x += FT_MulFix( deltas_x[j], apply );
delta_xy[localpoints[j]].y += FT_MulFix( deltas_y[j], apply );
}