Fix handing of `FT_Bool'.

Before this commit we had code like

  (FT_Bool)( globals->glyph_styles[gindex] & 0x8000)

Since `FT_Bool' is defined to be an `unsigned char', the code
evaluated to something like

  (unsigned char)( 0x8532 & 0x8000)

which in turn expanded to

  (unsigned char)( 0x8000)

and finally yielded 0x00 – i.e., false – not as expected.

Problem reported and analyzed by Tony Smith <tony.smith@macro4.com>.

* include/freetype/fttypes.h (FT_BOOL): Add a comparison against
zero so that we always have a Boolean expression.

*/*: Replace castings to `FT_Bool' with calls to `FT_BOOL' where
possible.
This commit is contained in:
Werner Lemberg 2018-09-25 09:10:09 +02:00
parent 0f122fef34
commit a9af691481
19 changed files with 73 additions and 50 deletions

View File

@ -1,3 +1,30 @@
2018-09-25 Werner Lemberg <wl@gnu.org>
Fix handing of `FT_Bool'.
Before this commit we had code like
(FT_Bool)( globals->glyph_styles[gindex] & 0x8000)
Since `FT_Bool' is defined to be an `unsigned char', the code
evaluated to something like
(unsigned char)( 0x8532 & 0x8000)
which in turn expanded to
(unsigned char)( 0x8000)
and finally yielded 0x00 i.e., false not as expected.
Problem reported and analyzed by Tony Smith <tony.smith@macro4.com>.
* include/freetype/fttypes.h (FT_BOOL): Add a comparison against
zero so that we always have a Boolean expression.
*/*: Replace castings to `FT_Bool' with calls to `FT_BOOL' where
possible.
2018-09-23 Alexei Podtelezhnikov <apodtele@gmail.com>
[bdf] Speed up charmap access.

View File

@ -588,7 +588,7 @@ FT_BEGIN_HEADER
#define FT_IS_EMPTY( list ) ( (list).head == 0 )
#define FT_BOOL( x ) ( (FT_Bool)( x ) )
#define FT_BOOL( x ) ( (FT_Bool)( (x) != 0 ) )
/* concatenate C tokens */
#define FT_ERR_XCAT( x, y ) x ## y

View File

@ -1198,7 +1198,7 @@
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
is_serif = (FT_Bool)( seg->serif && seg->serif->edge != edge );
is_serif = FT_BOOL( seg->serif && seg->serif->edge != edge );
if ( seg->link || is_serif )
{

View File

@ -489,9 +489,9 @@
FT_UInt gindex )
{
if ( gindex < (FT_ULong)globals->glyph_count )
return (FT_Bool)( globals->glyph_styles[gindex] & AF_DIGIT );
return FT_BOOL( globals->glyph_styles[gindex] & AF_DIGIT );
return (FT_Bool)0;
return FT_BOOL( 0 );
}

View File

@ -549,7 +549,7 @@
*offset = ( dim == AF_DIMENSION_HORZ ) ? seg->first->fx
: seg->first->fy;
if ( seg->edge )
*is_blue = (FT_Bool)( seg->edge->blue_edge != 0 );
*is_blue = FT_BOOL( seg->edge->blue_edge );
else
*is_blue = FALSE;

View File

@ -1307,7 +1307,7 @@
/* an extra-light axis corresponds to a standard width that is */
/* smaller than 5/8 pixels */
axis->extra_light =
(FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
FT_BOOL( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
#ifdef FT_DEBUG_LEVEL_TRACE
if ( axis->extra_light )
@ -2328,9 +2328,9 @@
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
is_serif = (FT_Bool)( seg->serif &&
seg->serif->edge &&
seg->serif->edge != edge );
is_serif = FT_BOOL( seg->serif &&
seg->serif->edge &&
seg->serif->edge != edge );
if ( ( seg->link && seg->link->edge ) || is_serif )
{

View File

@ -632,7 +632,7 @@
/* an extra-light axis corresponds to a standard width that is */
/* smaller than 5/8 pixels */
axis->extra_light =
(FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
FT_BOOL( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
if ( dim == AF_DIMENSION_VERT )
{
@ -1302,9 +1302,9 @@
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
is_serif = (FT_Bool)( seg->serif &&
seg->serif->edge &&
seg->serif->edge != edge );
is_serif = FT_BOOL( seg->serif &&
seg->serif->edge &&
seg->serif->edge != edge );
if ( ( seg->link && seg->link->edge ) || is_serif )
{

View File

@ -962,8 +962,9 @@
#ifdef GRID_FIT_METRICS
if ( !( load_flags & FT_LOAD_NO_HINTING ) )
ft_glyphslot_grid_fit_metrics( slot,
FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
ft_glyphslot_grid_fit_metrics(
slot,
FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
#endif
}
}
@ -2736,8 +2737,8 @@
/* close the attached stream */
FT_Stream_Free( stream,
(FT_Bool)( parameters->stream &&
( parameters->flags & FT_OPEN_STREAM ) ) );
FT_BOOL( parameters->stream &&
( parameters->flags & FT_OPEN_STREAM ) ) );
Exit:
return error;
@ -5154,9 +5155,9 @@
service = (FT_Service_Properties)interface;
if ( set )
missing_func = (FT_Bool)( !service->set_property );
missing_func = FT_BOOL( !service->set_property );
else
missing_func = (FT_Bool)( !service->get_property );
missing_func = FT_BOOL( !service->get_property );
if ( missing_func )
{

View File

@ -414,7 +414,7 @@
decoder.width_only = TRUE;
decoder.builder.no_recurse =
(FT_Bool)( load_flags & FT_LOAD_NO_RECURSE );
FT_BOOL( load_flags & FT_LOAD_NO_RECURSE );
/* now load the unscaled outline */
error = cff_get_glyph_data( face, glyph_index,

View File

@ -393,8 +393,7 @@
must_finish_decoder = TRUE;
/* set up the decoder */
decoder.builder.no_recurse = FT_BOOL(
( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ) );
decoder.builder.no_recurse = FT_BOOL( load_flags & FT_LOAD_NO_RECURSE );
error = cid_load_glyph( &decoder, glyph_index );
if ( error )

View File

@ -122,7 +122,7 @@
stream,
(FT_UInt)( face_index & 0xFFFF ),
face->header.log_dir_offset,
FT_BOOL( face->header.phy_font_max_size_high != 0 ) );
FT_BOOL( face->header.phy_font_max_size_high ) );
if ( error )
goto Exit;
@ -370,7 +370,7 @@
FT_Bool scaling;
scaling = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 );
scaling = FT_BOOL( !( load_flags & FT_LOAD_NO_SCALE ) );
/* copy outline data */
*outline = slot->glyph.loader->base.outline;

View File

@ -1568,7 +1568,7 @@
x = ADD_LONG( x, args[0] );
y = ADD_LONG( y, args[1] );
cff_builder_add_point( builder, x, y,
(FT_Bool)( count == 3 ) );
FT_BOOL( count == 3 ) );
args += 2;
}
@ -1606,7 +1606,7 @@
x = ADD_LONG( x, args[0] );
y = ADD_LONG( y, args[1] );
cff_builder_add_point( builder, x, y,
(FT_Bool)( count == 4 || count == 1 ) );
FT_BOOL( count == 4 || count == 1 ) );
args += 2;
}

View File

@ -331,7 +331,7 @@
}
/* copy hinted flag on each call */
font->hinted = (FT_Bool)( font->renderingFlags & CF2_FlagsHinted );
font->hinted = FT_BOOL( font->renderingFlags & CF2_FlagsHinted );
/* determine if transform has changed; */
/* include Fontmatrix but ignore translation */
@ -366,7 +366,7 @@
if ( font->stemDarkened != ( font->renderingFlags & CF2_FlagsDarkened ) )
{
font->stemDarkened =
(FT_Bool)( font->renderingFlags & CF2_FlagsDarkened );
FT_BOOL( font->renderingFlags & CF2_FlagsDarkened );
/* blue zones depend on darkened flag */
needExtraSetup = TRUE;

View File

@ -217,52 +217,49 @@
FT_LOCAL_DEF( FT_Bool )
cf2_hint_isValid( const CF2_Hint hint )
{
return (FT_Bool)( hint->flags != 0 );
return FT_BOOL( hint->flags );
}
static FT_Bool
cf2_hint_isPair( const CF2_Hint hint )
{
return (FT_Bool)( ( hint->flags &
( CF2_PairBottom | CF2_PairTop ) ) != 0 );
return FT_BOOL( hint->flags & ( CF2_PairBottom | CF2_PairTop ) );
}
static FT_Bool
cf2_hint_isPairTop( const CF2_Hint hint )
{
return (FT_Bool)( ( hint->flags & CF2_PairTop ) != 0 );
return FT_BOOL( hint->flags & CF2_PairTop );
}
FT_LOCAL_DEF( FT_Bool )
cf2_hint_isTop( const CF2_Hint hint )
{
return (FT_Bool)( ( hint->flags &
( CF2_PairTop | CF2_GhostTop ) ) != 0 );
return FT_BOOL( hint->flags & ( CF2_PairTop | CF2_GhostTop ) );
}
FT_LOCAL_DEF( FT_Bool )
cf2_hint_isBottom( const CF2_Hint hint )
{
return (FT_Bool)( ( hint->flags &
( CF2_PairBottom | CF2_GhostBottom ) ) != 0 );
return FT_BOOL( hint->flags & ( CF2_PairBottom | CF2_GhostBottom ) );
}
static FT_Bool
cf2_hint_isLocked( const CF2_Hint hint )
{
return (FT_Bool)( ( hint->flags & CF2_Locked ) != 0 );
return FT_BOOL( hint->flags & CF2_Locked );
}
static FT_Bool
cf2_hint_isSynthetic( const CF2_Hint hint )
{
return (FT_Bool)( ( hint->flags & CF2_Synthetic ) != 0 );
return FT_BOOL( hint->flags & CF2_Synthetic );
}
@ -497,7 +494,7 @@
{
move = moveDown;
/* true if non-optimum move */
saveEdge = (FT_Bool)( moveUp < -moveDown );
saveEdge = FT_BOOL( moveUp < -moveDown );
}
else
{

View File

@ -287,7 +287,7 @@
{
CF2_UInt i;
CF2_UInt count = cf2_stack_count( opStack );
FT_Bool hasWidthArg = (FT_Bool)( count & 1 );
FT_Bool hasWidthArg = FT_BOOL( count & 1 );
/* variable accumulates delta values from operand stack */
CF2_Fixed position = hintOffset;
@ -364,7 +364,7 @@
if ( doConditionalLastRead )
{
FT_Bool lastIsX = (FT_Bool)(
FT_Bool lastIsX = FT_BOOL(
cf2_fixedAbs( SUB_INT32( vals[10], *curX ) ) >
cf2_fixedAbs( SUB_INT32( vals[11], *curY ) ) );
CF2_Fixed lastVal = cf2_stack_getReal( opStack, idx );

View File

@ -105,7 +105,7 @@
FT_LOCAL_DEF( FT_Bool )
cf2_buf_isEnd( CF2_Buffer buf )
{
return (FT_Bool)( buf->ptr >= buf->end );
return FT_BOOL( buf->ptr >= buf->end );
}

View File

@ -1479,7 +1479,7 @@
}
#endif
use_aw_2 = (FT_Bool)( subpixel_hinting && grayscale );
use_aw_2 = FT_BOOL( subpixel_hinting && grayscale );
loader->pp1.x = loader->bbox.xMin - loader->left_bearing;
loader->pp1.y = 0;

View File

@ -402,9 +402,9 @@
t1glyph->outline.n_points = 0;
t1glyph->outline.n_contours = 0;
hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 &&
( load_flags & FT_LOAD_NO_HINTING ) == 0 );
scaled = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 );
hinting = FT_BOOL( !( load_flags & FT_LOAD_NO_SCALE ) &&
!( load_flags & FT_LOAD_NO_HINTING ) );
scaled = FT_BOOL( !( load_flags & FT_LOAD_NO_SCALE ) );
glyph->hint = hinting;
glyph->scaled = scaled;
@ -416,7 +416,7 @@
t1glyph,
(FT_Byte**)type1->glyph_names,
face->blend,
FT_BOOL( hinting ),
hinting,
FT_LOAD_TARGET_MODE( load_flags ),
T1_Parse_Glyph );
if ( error )
@ -424,8 +424,7 @@
must_finish_decoder = TRUE;
decoder.builder.no_recurse = FT_BOOL(
( load_flags & FT_LOAD_NO_RECURSE ) != 0 );
decoder.builder.no_recurse = FT_BOOL( load_flags & FT_LOAD_NO_RECURSE );
decoder.num_subrs = type1->num_subrs;
decoder.subrs = type1->subrs;

View File

@ -73,7 +73,7 @@
#ifdef FT_CONFIG_OPTION_INCREMENTAL
#define IS_INCREMENTAL (FT_Bool)( face->root.internal->incremental_interface != 0 )
#define IS_INCREMENTAL FT_BOOL( face->root.internal->incremental_interface )
#else
#define IS_INCREMENTAL 0
#endif