[truetype] Some fixes and code refactoring in `ttgxvar.c'.

* src/truetype/ttgxvar.c (ft_var_readpackedpoints): Fix return value
of `point_cnt' if two bytes are read.
Use a more vertical coding style.
(ft_var_readpackeddeltas): Use FT_UInt for `delta_cnt' parameter.
Use a more vertical coding style.
This commit is contained in:
Werner Lemberg 2015-03-04 08:40:23 +01:00
parent a374c9cfe7
commit 328b792313
2 changed files with 65 additions and 49 deletions

View File

@ -1,3 +1,13 @@
2015-03-04 Werner Lemberg <wl@gnu.org>
[truetype] Some fixes and code refactoring in `ttgxvar.c'.
* src/truetype/ttgxvar.c (ft_var_readpackedpoints): Fix return value
of `point_cnt' if two bytes are read.
Use a more vertical coding style.
(ft_var_readpackeddeltas): Use FT_UInt for `delta_cnt' parameter.
Use a more vertical coding style.
2015-03-03 Werner Lemberg <wl@gnu.org> 2015-03-03 Werner Lemberg <wl@gnu.org>
[autofit] Fix Savannah bug #44241. [autofit] Fix Savannah bug #44241.

View File

@ -20,7 +20,7 @@
/* */ /* */
/* Apple documents the `fvar', `gvar', `cvar', and `avar' tables at */ /* Apple documents the `fvar', `gvar', `cvar', and `avar' tables at */
/* */ /* */
/* http://developer.apple.com/fonts/TTRefMan/RM06/Chap6[fgca]var.html */ /* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6[fgca]var.html */
/* */ /* */
/* The documentation for `fvar' is inconsistent. At one point it says */ /* The documentation for `fvar' is inconsistent. At one point it says */
/* that `countSizePairs' should be 3, at another point 2. It should */ /* that `countSizePairs' should be 3, at another point 2. It should */
@ -60,9 +60,9 @@
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
#define FT_Stream_FTell( stream ) \ #define FT_Stream_FTell( stream ) \
(FT_ULong)( (stream)->cursor - (stream)->base ) (FT_ULong)( (stream)->cursor - (stream)->base )
#define FT_Stream_SeekSet( stream, off ) \ #define FT_Stream_SeekSet( stream, off ) \
( (stream)->cursor = (stream)->base + (off) ) ( (stream)->cursor = (stream)->base + (off) )
@ -96,8 +96,8 @@
#define ALL_POINTS (FT_UShort*)~(FT_PtrDist)0 #define ALL_POINTS (FT_UShort*)~(FT_PtrDist)0
#define GX_PT_POINTS_ARE_WORDS 0x80 #define GX_PT_POINTS_ARE_WORDS 0x80U
#define GX_PT_POINT_RUN_COUNT_MASK 0x7F #define GX_PT_POINT_RUN_COUNT_MASK 0x7FU
/*************************************************************************/ /*************************************************************************/
@ -126,52 +126,67 @@
FT_UInt *point_cnt ) FT_UInt *point_cnt )
{ {
FT_UShort *points = NULL; FT_UShort *points = NULL;
FT_Int n; FT_UInt n;
FT_Int runcnt; FT_UInt runcnt;
FT_Int i; FT_UInt i, j;
FT_Int j; FT_UShort first;
FT_Int first;
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
FT_Error error = FT_Err_Ok; FT_Error error = FT_Err_Ok;
FT_UNUSED( error ); FT_UNUSED( error );
*point_cnt = n = FT_GET_BYTE(); *point_cnt = 0;
n = FT_GET_BYTE();
if ( n == 0 ) if ( n == 0 )
return ALL_POINTS; return ALL_POINTS;
if ( n & GX_PT_POINTS_ARE_WORDS ) if ( n & GX_PT_POINTS_ARE_WORDS )
n = FT_GET_BYTE() | ( ( n & GX_PT_POINT_RUN_COUNT_MASK ) << 8 ); {
n &= GX_PT_POINT_RUN_COUNT_MASK;
n <<= 8;
n |= FT_GET_BYTE();
}
if ( FT_NEW_ARRAY( points, n ) ) if ( FT_NEW_ARRAY( points, n ) )
return NULL; return NULL;
*point_cnt = n;
i = 0; i = 0;
while ( i < n ) while ( i < n )
{ {
runcnt = FT_GET_BYTE(); runcnt = FT_GET_BYTE();
if ( runcnt & GX_PT_POINTS_ARE_WORDS ) if ( runcnt & GX_PT_POINTS_ARE_WORDS )
{ {
runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; runcnt &= GX_PT_POINT_RUN_COUNT_MASK;
first = points[i++] = FT_GET_USHORT(); first = FT_GET_USHORT();
points[i++] = first;
if ( runcnt < 1 || i + runcnt >= n ) if ( runcnt < 1 || i + runcnt >= n )
goto Exit; goto Exit;
/* first point not included in runcount */ /* first point not included in run count */
for ( j = 0; j < runcnt; ++j ) for ( j = 0; j < runcnt; j++ )
points[i++] = (FT_UShort)( first += FT_GET_USHORT() ); {
first += FT_GET_USHORT();
points[i++] = first;
}
} }
else else
{ {
first = points[i++] = FT_GET_BYTE(); first = FT_GET_BYTE();
points[i++] = first;
if ( runcnt < 1 || i + runcnt >= n ) if ( runcnt < 1 || i + runcnt >= n )
goto Exit; goto Exit;
for ( j = 0; j < runcnt; ++j ) for ( j = 0; j < runcnt; j++ )
points[i++] = (FT_UShort)( first += FT_GET_BYTE() ); {
first += FT_GET_BYTE();
points[i++] = first;
}
} }
} }
@ -180,12 +195,9 @@
} }
enum #define GX_DT_DELTAS_ARE_ZERO 0x80U
{ #define GX_DT_DELTAS_ARE_WORDS 0x40U
GX_DT_DELTAS_ARE_ZERO = 0x80, #define GX_DT_DELTA_RUN_COUNT_MASK 0x3FU
GX_DT_DELTAS_ARE_WORDS = 0x40,
GX_DT_DELTA_RUN_COUNT_MASK = 0x3F
};
/*************************************************************************/ /*************************************************************************/
@ -200,7 +212,7 @@
/* <Input> */ /* <Input> */
/* stream :: The data stream. */ /* stream :: The data stream. */
/* */ /* */
/* delta_cnt :: The number of to be read. */ /* delta_cnt :: The number of deltas to be read. */
/* */ /* */
/* <Return> */ /* <Return> */
/* An array of FT_Short containing the deltas for the affected */ /* An array of FT_Short containing the deltas for the affected */
@ -210,12 +222,11 @@
/* */ /* */
static FT_Short* static FT_Short*
ft_var_readpackeddeltas( FT_Stream stream, ft_var_readpackeddeltas( FT_Stream stream,
FT_Offset delta_cnt ) FT_UInt delta_cnt )
{ {
FT_Short *deltas = NULL; FT_Short *deltas = NULL;
FT_UInt runcnt; FT_UInt runcnt, cnt;
FT_Offset i; FT_UInt i, j;
FT_UInt j;
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
FT_Error error = FT_Err_Ok; FT_Error error = FT_Err_Ok;
@ -229,34 +240,30 @@
while ( i < delta_cnt ) while ( i < delta_cnt )
{ {
runcnt = FT_GET_BYTE(); runcnt = FT_GET_BYTE();
cnt = runcnt & GX_DT_DELTA_RUN_COUNT_MASK;
if ( runcnt & GX_DT_DELTAS_ARE_ZERO ) if ( runcnt & GX_DT_DELTAS_ARE_ZERO )
{ {
/* runcnt zeroes get added */ /* `runcnt' zeroes get added */
for ( j = 0; for ( j = 0; j <= cnt && i < delta_cnt; j++ )
j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt;
++j )
deltas[i++] = 0; deltas[i++] = 0;
} }
else if ( runcnt & GX_DT_DELTAS_ARE_WORDS ) else if ( runcnt & GX_DT_DELTAS_ARE_WORDS )
{ {
/* runcnt shorts from the stack */ /* `runcnt' shorts from the stack */
for ( j = 0; for ( j = 0; j <= cnt && i < delta_cnt; j++ )
j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt;
++j )
deltas[i++] = FT_GET_SHORT(); deltas[i++] = FT_GET_SHORT();
} }
else else
{ {
/* runcnt signed bytes from the stack */ /* `runcnt' signed bytes from the stack */
for ( j = 0; for ( j = 0; j <= cnt && i < delta_cnt; j++ )
j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt;
++j )
deltas[i++] = FT_GET_CHAR(); deltas[i++] = FT_GET_CHAR();
} }
if ( j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) ) if ( j <= cnt )
{ {
/* Bad format */ /* bad format */
FT_FREE( deltas ); FT_FREE( deltas );
return NULL; return NULL;
} }
@ -330,10 +337,9 @@
for ( j = 0; j < segment->pairCount; ++j ) for ( j = 0; j < segment->pairCount; ++j )
{ {
segment->correspondence[j].fromCoord = /* convert to Fixed */
FT_GET_SHORT() << 2; /* convert to Fixed */ segment->correspondence[j].fromCoord = FT_GET_SHORT() << 2;
segment->correspondence[j].toCoord = segment->correspondence[j].toCoord = FT_GET_SHORT() << 2;
FT_GET_SHORT()<<2; /* convert to Fixed */
} }
} }