diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2017-09-16 22:12:39 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2017-09-16 22:12:39 +0000 |
commit | 3613f8e4f3d3ffeb2b3e68126369e9463d4df65a (patch) | |
tree | 7970b602298d68e874ff225be9ae95c93df4d2d9 /Build/source/libs/freetype2/freetype-src/src/cff | |
parent | 12b257238b111240034611a07690f2c023973d87 (diff) |
freetype 2.8.1
git-svn-id: svn://tug.org/texlive/trunk@45324 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/freetype2/freetype-src/src/cff')
10 files changed, 432 insertions, 304 deletions
diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.c b/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.c index 250f89e0df4..c491f2f9e5c 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.c @@ -194,8 +194,8 @@ blues->zone[blues->count].csTopEdge = cf2_blueToFixed( blueValues[i + 1] ); - zoneHeight = blues->zone[blues->count].csTopEdge - - blues->zone[blues->count].csBottomEdge; + zoneHeight = SUB_INT32( blues->zone[blues->count].csTopEdge, + blues->zone[blues->count].csBottomEdge ); if ( zoneHeight < 0 ) { @@ -243,8 +243,8 @@ blues->zone[blues->count].csTopEdge = cf2_blueToFixed( otherBlues[i + 1] ); - zoneHeight = blues->zone[blues->count].csTopEdge - - blues->zone[blues->count].csBottomEdge; + zoneHeight = SUB_INT32( blues->zone[blues->count].csTopEdge, + blues->zone[blues->count].csBottomEdge ); if ( zoneHeight < 0 ) { @@ -301,7 +301,7 @@ /* top edge */ flatFamilyEdge = cf2_blueToFixed( familyOtherBlues[j + 1] ); - diff = cf2_fixedAbs( flatEdge - flatFamilyEdge ); + diff = cf2_fixedAbs( SUB_INT32( flatEdge, flatFamilyEdge ) ); if ( diff < minDiff && diff < csUnitsPerPixel ) { @@ -319,7 +319,7 @@ /* top edge */ flatFamilyEdge = cf2_blueToFixed( familyBlues[1] ); - diff = cf2_fixedAbs( flatEdge - flatFamilyEdge ); + diff = cf2_fixedAbs( SUB_INT32( flatEdge, flatFamilyEdge ) ); if ( diff < minDiff && diff < csUnitsPerPixel ) blues->zone[i].csFlatEdge = flatFamilyEdge; @@ -342,7 +342,7 @@ /* adjust edges of top zone upward by twice darkening amount */ flatFamilyEdge += 2 * font->darkenY; /* bottom edge */ - diff = cf2_fixedAbs( flatEdge - flatFamilyEdge ); + diff = cf2_fixedAbs( SUB_INT32( flatEdge, flatFamilyEdge ) ); if ( diff < minDiff && diff < csUnitsPerPixel ) { @@ -408,8 +408,8 @@ /* Note: constant changed from 0.5 to 0.6 to avoid a problem with */ /* 10ppem Arial */ - blues->boost = cf2_floatToFixed( .6 ) - - FT_MulDiv( cf2_floatToFixed ( .6 ), + blues->boost = cf2_doubleToFixed( .6 ) - + FT_MulDiv( cf2_doubleToFixed ( .6 ), blues->scale, blues->blueScale ); if ( blues->boost > 0x7FFF ) @@ -489,17 +489,18 @@ if ( blues->zone[i].bottomZone && cf2_hint_isBottom( bottomHintEdge ) ) { - if ( ( blues->zone[i].csBottomEdge - csFuzz ) <= - bottomHintEdge->csCoord && + if ( SUB_INT32( blues->zone[i].csBottomEdge, csFuzz ) <= + bottomHintEdge->csCoord && bottomHintEdge->csCoord <= - ( blues->zone[i].csTopEdge + csFuzz ) ) + ADD_INT32( blues->zone[i].csTopEdge, csFuzz ) ) { /* bottom edge captured by bottom zone */ if ( blues->suppressOvershoot ) dsNew = blues->zone[i].dsFlatEdge; - else if ( ( blues->zone[i].csTopEdge - bottomHintEdge->csCoord ) >= + else if ( SUB_INT32( blues->zone[i].csTopEdge, + bottomHintEdge->csCoord ) >= blues->blueShift ) { /* guarantee minimum of 1 pixel overshoot */ @@ -514,7 +515,7 @@ dsNew = cf2_fixedRound( bottomHintEdge->dsCoord ); } - dsMove = dsNew - bottomHintEdge->dsCoord; + dsMove = SUB_INT32( dsNew, bottomHintEdge->dsCoord ); captured = TRUE; break; @@ -523,17 +524,18 @@ if ( !blues->zone[i].bottomZone && cf2_hint_isTop( topHintEdge ) ) { - if ( ( blues->zone[i].csBottomEdge - csFuzz ) <= - topHintEdge->csCoord && + if ( SUB_INT32( blues->zone[i].csBottomEdge, csFuzz ) <= + topHintEdge->csCoord && topHintEdge->csCoord <= - ( blues->zone[i].csTopEdge + csFuzz ) ) + ADD_INT32( blues->zone[i].csTopEdge, csFuzz ) ) { /* top edge captured by top zone */ if ( blues->suppressOvershoot ) dsNew = blues->zone[i].dsFlatEdge; - else if ( ( topHintEdge->csCoord - blues->zone[i].csBottomEdge ) >= + else if ( SUB_INT32( topHintEdge->csCoord, + blues->zone[i].csBottomEdge ) >= blues->blueShift ) { /* guarantee minimum of 1 pixel overshoot */ @@ -548,7 +550,7 @@ dsNew = cf2_fixedRound( topHintEdge->dsCoord ); } - dsMove = dsNew - topHintEdge->dsCoord; + dsMove = SUB_INT32( dsNew, topHintEdge->dsCoord ); captured = TRUE; break; @@ -561,13 +563,14 @@ /* move both edges and flag them `locked' */ if ( cf2_hint_isValid( bottomHintEdge ) ) { - bottomHintEdge->dsCoord += dsMove; + bottomHintEdge->dsCoord = ADD_INT32( bottomHintEdge->dsCoord, + dsMove ); cf2_hint_lock( bottomHintEdge ); } if ( cf2_hint_isValid( topHintEdge ) ) { - topHintEdge->dsCoord += dsMove; + topHintEdge->dsCoord = ADD_INT32( topHintEdge->dsCoord, dsMove ); cf2_hint_lock( topHintEdge ); } } diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.h b/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.h index 96fb60f38dc..a6bcd9de578 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.h +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2blues.h @@ -111,7 +111,7 @@ FT_BEGIN_HEADER * Constant used for hint adjustment and for synthetic em box hint * placement. */ -#define CF2_MIN_COUNTER cf2_floatToFixed( 0.5 ) +#define CF2_MIN_COUNTER cf2_doubleToFixed( 0.5 ) /* shared typedef is in cf2glue.h */ diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2fixed.h b/Build/source/libs/freetype2/freetype-src/src/cff/cf2fixed.h index 2e4b5032fa7..a041184bda8 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2fixed.h +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2fixed.h @@ -63,10 +63,10 @@ FT_BEGIN_HEADER ( (FT_Short)( ( (FT_UInt32)(x) + 0x8000U ) >> 16 ) ) #define cf2_fixedRound( x ) \ ( (CF2_Fixed)( ( (FT_UInt32)(x) + 0x8000U ) & 0xFFFF0000UL ) ) -#define cf2_floatToFixed( f ) \ +#define cf2_doubleToFixed( f ) \ ( (CF2_Fixed)( (f) * 65536.0 + 0.5 ) ) #define cf2_fixedAbs( x ) \ - ( (x) < 0 ? -(x) : (x) ) + ( (x) < 0 ? NEG_INT32( x ) : (x) ) #define cf2_fixedFloor( x ) \ ( (CF2_Fixed)( (FT_UInt32)(x) & 0xFFFF0000UL ) ) #define cf2_fixedFraction( x ) \ diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2font.c b/Build/source/libs/freetype2/freetype-src/src/cff/cf2font.c index a86e3619b46..4ac71a8d715 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2font.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2font.c @@ -117,7 +117,7 @@ return; /* protect against range problems and divide by zero */ - if ( emRatio < cf2_floatToFixed( .01 ) ) + if ( emRatio < cf2_doubleToFixed( .01 ) ) return; if ( stemDarkened ) @@ -447,7 +447,7 @@ /* choose a constant for StdHW that depends on font contrast */ stdHW = cf2_getStdHW( decoder ); - if ( stdHW > 0 && font->stdVW > 2 * stdHW ) + if ( stdHW > 0 && font->stdVW > MUL_INT32( 2, stdHW ) ) font->stdHW = FT_DivFix( cf2_intToFixed( 75 ), emRatio ); else { diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2ft.c b/Build/source/libs/freetype2/freetype-src/src/cff/cf2ft.c index eb8472f119a..c6c00d16239 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2ft.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2ft.c @@ -267,8 +267,8 @@ if ( *hinted ) { - *x_scale = ( decoder->builder.glyph->x_scale + 32 ) / 64; - *y_scale = ( decoder->builder.glyph->y_scale + 32 ) / 64; + *x_scale = ADD_INT32( decoder->builder.glyph->x_scale, 32 ) / 64; + *y_scale = ADD_INT32( decoder->builder.glyph->y_scale, 32 ) / 64; } else { diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2hints.c b/Build/source/libs/freetype2/freetype-src/src/cff/cf2hints.c index c8f7dfeba6d..656eb2cff17 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2hints.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2hints.c @@ -74,8 +74,8 @@ /* cross product of pt1 position from origin with pt2 position from */ /* pt1; we reduce the precision so that the result fits into 32 bits */ - return ( x1 >> 16 ) * ( ( y2 - y1 ) >> 16 ) - - ( y1 >> 16 ) * ( ( x2 - x1 ) >> 16 ); + return ( x1 >> 16 ) * ( SUB_INT32( y2, y1 ) >> 16 ) - + ( y1 >> 16 ) * ( SUB_INT32( x2, x1 ) >> 16 ); } @@ -105,7 +105,7 @@ stemHintArray, indexStemHint ); - width = stemHint->max - stemHint->min; + width = SUB_INT32( stemHint->max, stemHint->min ); if ( width == cf2_intToFixed( -21 ) ) { @@ -185,11 +185,11 @@ /* darkening. Bottoms are not changed; tops are incremented by twice */ /* `darkenY'. */ if ( cf2_hint_isTop( hint ) ) - hint->csCoord += 2 * font->darkenY; + hint->csCoord = ADD_INT32( hint->csCoord, 2 * font->darkenY ); - hint->csCoord += hintOrigin; - hint->scale = scale; - hint->index = indexStemHint; /* index in original stem hint array */ + hint->csCoord = ADD_INT32( hint->csCoord, hintOrigin ); + hint->scale = scale; + hint->index = indexStemHint; /* index in original stem hint array */ /* if original stem hint has been used, use the same position */ if ( hint->flags != 0 && stemHint->used ) @@ -314,6 +314,7 @@ /* start linear search from last hit */ CF2_UInt i = hintmap->lastIndex; + FT_ASSERT( hintmap->lastIndex < CF2_MAX_HINT_EDGES ); /* search up */ @@ -330,9 +331,10 @@ if ( i == 0 && csCoord < hintmap->edge[0].csCoord ) { /* special case for points below first edge: use uniform scale */ - return FT_MulFix( csCoord - hintmap->edge[0].csCoord, - hintmap->scale ) + - hintmap->edge[0].dsCoord; + return ADD_INT32( FT_MulFix( SUB_INT32( csCoord, + hintmap->edge[0].csCoord ), + hintmap->scale ), + hintmap->edge[0].dsCoord ); } else { @@ -340,9 +342,10 @@ * Note: entries with duplicate csCoord are allowed. * Use edge[i], the highest entry where csCoord >= entry[i].csCoord */ - return FT_MulFix( csCoord - hintmap->edge[i].csCoord, - hintmap->edge[i].scale ) + - hintmap->edge[i].dsCoord; + return ADD_INT32( FT_MulFix( SUB_INT32( csCoord, + hintmap->edge[i].csCoord ), + hintmap->edge[i].scale ), + hintmap->edge[i].dsCoord ); } } } @@ -437,14 +440,16 @@ /* is there room to move up? */ /* there is if we are at top of array or the next edge is at or */ /* beyond proposed move up? */ - if ( j >= hintmap->count - 1 || + if ( j >= hintmap->count - 1 || hintmap->edge[j + 1].dsCoord >= - hintmap->edge[j].dsCoord + moveUp + upMinCounter ) + ADD_INT32( hintmap->edge[j].dsCoord, + moveUp + upMinCounter ) ) { /* there is room to move up; is there also room to move down? */ - if ( i == 0 || + if ( i == 0 || hintmap->edge[i - 1].dsCoord <= - hintmap->edge[i].dsCoord + moveDown - downMinCounter ) + ADD_INT32( hintmap->edge[i].dsCoord, + moveDown - downMinCounter ) ) { /* move smaller absolute amount */ move = ( -moveDown < moveUp ) ? moveDown : moveUp; /* optimum */ @@ -455,9 +460,10 @@ else { /* is there room to move down? */ - if ( i == 0 || + if ( i == 0 || hintmap->edge[i - 1].dsCoord <= - hintmap->edge[i].dsCoord + moveDown - downMinCounter ) + ADD_INT32( hintmap->edge[i].dsCoord, + moveDown - downMinCounter ) ) { move = moveDown; /* true if non-optimum move */ @@ -491,9 +497,11 @@ } /* move the edge(s) */ - hintmap->edge[i].dsCoord += move; + hintmap->edge[i].dsCoord = ADD_INT32( hintmap->edge[i].dsCoord, + move ); if ( isPair ) - hintmap->edge[j].dsCoord += move; + hintmap->edge[j].dsCoord = ADD_INT32( hintmap->edge[j].dsCoord, + move ); } /* assert there are no overlaps in device space */ @@ -507,18 +515,20 @@ { if ( hintmap->edge[i].csCoord != hintmap->edge[i - 1].csCoord ) hintmap->edge[i - 1].scale = - FT_DivFix( - hintmap->edge[i].dsCoord - hintmap->edge[i - 1].dsCoord, - hintmap->edge[i].csCoord - hintmap->edge[i - 1].csCoord ); + FT_DivFix( SUB_INT32( hintmap->edge[i].dsCoord, + hintmap->edge[i - 1].dsCoord ), + SUB_INT32( hintmap->edge[i].csCoord, + hintmap->edge[i - 1].csCoord ) ); } if ( isPair ) { if ( hintmap->edge[j].csCoord != hintmap->edge[j - 1].csCoord ) hintmap->edge[j - 1].scale = - FT_DivFix( - hintmap->edge[j].dsCoord - hintmap->edge[j - 1].dsCoord, - hintmap->edge[j].csCoord - hintmap->edge[j - 1].csCoord ); + FT_DivFix( SUB_INT32( hintmap->edge[j].dsCoord, + hintmap->edge[j - 1].dsCoord ), + SUB_INT32( hintmap->edge[j].csCoord, + hintmap->edge[j - 1].csCoord ) ); i += 1; /* skip upper edge on next loop */ } @@ -539,15 +549,18 @@ /* is there room to move up? */ if ( hintmap->edge[j + 1].dsCoord >= - hintmap->edge[j].dsCoord + hintMove->moveUp + CF2_MIN_COUNTER ) + ADD_INT32( hintmap->edge[j].dsCoord, + hintMove->moveUp + CF2_MIN_COUNTER ) ) { /* there is more room now, move edge up */ - hintmap->edge[j].dsCoord += hintMove->moveUp; + hintmap->edge[j].dsCoord = ADD_INT32( hintmap->edge[j].dsCoord, + hintMove->moveUp ); if ( cf2_hint_isPair( &hintmap->edge[j] ) ) { FT_ASSERT( j > 0 ); - hintmap->edge[j - 1].dsCoord += hintMove->moveUp; + hintmap->edge[j - 1].dsCoord = + ADD_INT32( hintmap->edge[j - 1].dsCoord, hintMove->moveUp ); } } } @@ -635,18 +648,19 @@ { /* Use hint map to position the center of stem, and nominal scale */ /* to position the two edges. This preserves the stem width. */ - CF2_Fixed midpoint = cf2_hintmap_map( - hintmap->initialHintMap, - ( secondHintEdge->csCoord + - firstHintEdge->csCoord ) / 2 ); - CF2_Fixed halfWidth = FT_MulFix( - ( secondHintEdge->csCoord - - firstHintEdge->csCoord ) / 2, - hintmap->scale ); - - - firstHintEdge->dsCoord = midpoint - halfWidth; - secondHintEdge->dsCoord = midpoint + halfWidth; + CF2_Fixed midpoint = + cf2_hintmap_map( + hintmap->initialHintMap, + ADD_INT32( secondHintEdge->csCoord, + firstHintEdge->csCoord ) / 2 ); + CF2_Fixed halfWidth = + FT_MulFix( SUB_INT32( secondHintEdge->csCoord, + firstHintEdge->csCoord ) / 2, + hintmap->scale ); + + + firstHintEdge->dsCoord = SUB_INT32( midpoint, halfWidth ); + secondHintEdge->dsCoord = ADD_INT32( midpoint, halfWidth ); } else firstHintEdge->dsCoord = cf2_hintmap_map( hintmap->initialHintMap, @@ -715,7 +729,7 @@ /* insert first edge */ hintmap->edge[indexInsert] = *firstHintEdge; /* copy struct */ - hintmap->count += 1; + hintmap->count += 1; if ( isPair ) { @@ -781,7 +795,7 @@ cf2_arrstack_size( hStemHintArray ) + cf2_arrstack_size( vStemHintArray ) ); if ( !cf2_hintmask_isValid( hintMask ) ) - return; /* too many stem hints */ + return; /* too many stem hints */ } /* begin by clearing the map */ @@ -797,7 +811,7 @@ /* Defense-in-depth. Should never return here. */ if ( bitCount > hintMask->bitCount ) - return; + return; /* synthetic embox hints get highest priority */ if ( font->blues.doEmBoxHints ) @@ -1063,7 +1077,7 @@ cf2_fixedAbs( glyphpath->yOffset ) ); /* .1 character space unit */ - glyphpath->snapThreshold = cf2_floatToFixed( 0.1f ); + glyphpath->snapThreshold = cf2_doubleToFixed( 0.1 ); glyphpath->moveIsPending = TRUE; glyphpath->pathIsOpen = FALSE; @@ -1095,16 +1109,20 @@ FT_Vector pt; /* hinted point in upright DS */ - pt.x = FT_MulFix( glyphpath->scaleX, x ) + - FT_MulFix( glyphpath->scaleC, y ); + pt.x = ADD_INT32( FT_MulFix( glyphpath->scaleX, x ), + FT_MulFix( glyphpath->scaleC, y ) ); pt.y = cf2_hintmap_map( hintmap, y ); - ppt->x = FT_MulFix( glyphpath->font->outerTransform.a, pt.x ) + - FT_MulFix( glyphpath->font->outerTransform.c, pt.y ) + - glyphpath->fractionalTranslation.x; - ppt->y = FT_MulFix( glyphpath->font->outerTransform.b, pt.x ) + - FT_MulFix( glyphpath->font->outerTransform.d, pt.y ) + - glyphpath->fractionalTranslation.y; + ppt->x = ADD_INT32( + FT_MulFix( glyphpath->font->outerTransform.a, pt.x ), + ADD_INT32( + FT_MulFix( glyphpath->font->outerTransform.c, pt.y ), + glyphpath->fractionalTranslation.x ) ); + ppt->y = ADD_INT32( + FT_MulFix( glyphpath->font->outerTransform.b, pt.x ), + ADD_INT32( + FT_MulFix( glyphpath->font->outerTransform.d, pt.y ), + glyphpath->fractionalTranslation.y ) ); } @@ -1154,12 +1172,12 @@ CF2_Fixed denominator, s; - u.x = CF2_CS_SCALE( u2->x - u1->x ); - u.y = CF2_CS_SCALE( u2->y - u1->y ); - v.x = CF2_CS_SCALE( v2->x - v1->x ); - v.y = CF2_CS_SCALE( v2->y - v1->y ); - w.x = CF2_CS_SCALE( v1->x - u1->x ); - w.y = CF2_CS_SCALE( v1->y - u1->y ); + u.x = CF2_CS_SCALE( SUB_INT32( u2->x, u1->x ) ); + u.y = CF2_CS_SCALE( SUB_INT32( u2->y, u1->y ) ); + v.x = CF2_CS_SCALE( SUB_INT32( v2->x, v1->x ) ); + v.y = CF2_CS_SCALE( SUB_INT32( v2->y, v1->y ) ); + w.x = CF2_CS_SCALE( SUB_INT32( v1->x, u1->x ) ); + w.y = CF2_CS_SCALE( SUB_INT32( v1->y, u1->y ) ); denominator = cf2_perp( u, v ); @@ -1168,8 +1186,11 @@ s = FT_DivFix( cf2_perp( w, v ), denominator ); - intersection->x = u1->x + FT_MulFix( s, u2->x - u1->x ); - intersection->y = u1->y + FT_MulFix( s, u2->y - u1->y ); + intersection->x = ADD_INT32( u1->x, + FT_MulFix( s, SUB_INT32( u2->x, u1->x ) ) ); + intersection->y = ADD_INT32( u1->y, + FT_MulFix( s, SUB_INT32( u2->y, u1->y ) ) ); + /* * Special case snapping for horizontal and vertical lines. @@ -1180,25 +1201,29 @@ * */ - if ( u1->x == u2->x && - cf2_fixedAbs( intersection->x - u1->x ) < glyphpath->snapThreshold ) + if ( u1->x == u2->x && + cf2_fixedAbs( SUB_INT32( intersection->x, + u1->x ) ) < glyphpath->snapThreshold ) intersection->x = u1->x; - if ( u1->y == u2->y && - cf2_fixedAbs( intersection->y - u1->y ) < glyphpath->snapThreshold ) + if ( u1->y == u2->y && + cf2_fixedAbs( SUB_INT32( intersection->y, + u1->y ) ) < glyphpath->snapThreshold ) intersection->y = u1->y; - if ( v1->x == v2->x && - cf2_fixedAbs( intersection->x - v1->x ) < glyphpath->snapThreshold ) + if ( v1->x == v2->x && + cf2_fixedAbs( SUB_INT32( intersection->x, + v1->x ) ) < glyphpath->snapThreshold ) intersection->x = v1->x; - if ( v1->y == v2->y && - cf2_fixedAbs( intersection->y - v1->y ) < glyphpath->snapThreshold ) + if ( v1->y == v2->y && + cf2_fixedAbs( SUB_INT32( intersection->y, + v1->y ) ) < glyphpath->snapThreshold ) intersection->y = v1->y; /* limit the intersection distance from midpoint of u2 and v1 */ - if ( cf2_fixedAbs( intersection->x - ( u2->x + v1->x ) / 2 ) > - glyphpath->miterLimit || - cf2_fixedAbs( intersection->y - ( u2->y + v1->y ) / 2 ) > - glyphpath->miterLimit ) + if ( cf2_fixedAbs( intersection->x - ADD_INT32( u2->x, v1->x ) / 2 ) > + glyphpath->miterLimit || + cf2_fixedAbs( intersection->y - ADD_INT32( u2->y, v1->y ) / 2 ) > + glyphpath->miterLimit ) return FALSE; return TRUE; @@ -1446,16 +1471,16 @@ CF2_Fixed* x, CF2_Fixed* y ) { - CF2_Fixed dx = x2 - x1; - CF2_Fixed dy = y2 - y1; + CF2_Fixed dx = SUB_INT32( x2, x1 ); + CF2_Fixed dy = SUB_INT32( y2, y1 ); /* note: negative offsets don't work here; negate deltas to change */ /* quadrants, below */ if ( glyphpath->font->reverseWinding ) { - dx = -dx; - dy = -dy; + dx = NEG_INT32( dx ); + dy = NEG_INT32( dy ); } *x = *y = 0; @@ -1464,8 +1489,9 @@ return; /* add momentum for this path element */ - glyphpath->callbacks->windingMomentum += - cf2_getWindingMomentum( x1, y1, x2, y2 ); + glyphpath->callbacks->windingMomentum = + ADD_INT32( glyphpath->callbacks->windingMomentum, + cf2_getWindingMomentum( x1, y1, x2, y2 ) ); /* note: allow mixed integer and fixed multiplication here */ if ( dx >= 0 ) @@ -1474,13 +1500,13 @@ { /* first quadrant, +x +y */ - if ( dx > 2 * dy ) + if ( dx > MUL_INT32( 2, dy ) ) { /* +x */ *x = 0; *y = 0; } - else if ( dy > 2 * dx ) + else if ( dy > MUL_INT32( 2, dx ) ) { /* +y */ *x = glyphpath->xOffset; @@ -1489,9 +1515,9 @@ else { /* +x +y */ - *x = FT_MulFix( cf2_floatToFixed( 0.7 ), + *x = FT_MulFix( cf2_doubleToFixed( 0.7 ), glyphpath->xOffset ); - *y = FT_MulFix( cf2_floatToFixed( 1.0 - 0.7 ), + *y = FT_MulFix( cf2_doubleToFixed( 1.0 - 0.7 ), glyphpath->yOffset ); } } @@ -1499,24 +1525,24 @@ { /* fourth quadrant, +x -y */ - if ( dx > -2 * dy ) + if ( dx > MUL_INT32( -2, dy ) ) { /* +x */ *x = 0; *y = 0; } - else if ( -dy > 2 * dx ) + else if ( NEG_INT32( dy ) > MUL_INT32( 2, dx ) ) { /* -y */ - *x = -glyphpath->xOffset; + *x = NEG_INT32( glyphpath->xOffset ); *y = glyphpath->yOffset; } else { /* +x -y */ - *x = FT_MulFix( cf2_floatToFixed( -0.7 ), + *x = FT_MulFix( cf2_doubleToFixed( -0.7 ), glyphpath->xOffset ); - *y = FT_MulFix( cf2_floatToFixed( 1.0 - 0.7 ), + *y = FT_MulFix( cf2_doubleToFixed( 1.0 - 0.7 ), glyphpath->yOffset ); } } @@ -1527,13 +1553,13 @@ { /* second quadrant, -x +y */ - if ( -dx > 2 * dy ) + if ( NEG_INT32( dx ) > MUL_INT32( 2, dy ) ) { /* -x */ *x = 0; - *y = 2 * glyphpath->yOffset; + *y = MUL_INT32( 2, glyphpath->yOffset ); } - else if ( dy > -2 * dx ) + else if ( dy > MUL_INT32( -2, dx ) ) { /* +y */ *x = glyphpath->xOffset; @@ -1542,9 +1568,9 @@ else { /* -x +y */ - *x = FT_MulFix( cf2_floatToFixed( 0.7 ), + *x = FT_MulFix( cf2_doubleToFixed( 0.7 ), glyphpath->xOffset ); - *y = FT_MulFix( cf2_floatToFixed( 1.0 + 0.7 ), + *y = FT_MulFix( cf2_doubleToFixed( 1.0 + 0.7 ), glyphpath->yOffset ); } } @@ -1552,24 +1578,24 @@ { /* third quadrant, -x -y */ - if ( -dx > -2 * dy ) + if ( NEG_INT32( dx ) > MUL_INT32( -2, dy ) ) { /* -x */ *x = 0; - *y = 2 * glyphpath->yOffset; + *y = MUL_INT32( 2, glyphpath->yOffset ); } - else if ( -dy > -2 * dx ) + else if ( NEG_INT32( dy ) > MUL_INT32( -2, dx ) ) { /* -y */ - *x = -glyphpath->xOffset; + *x = NEG_INT32( glyphpath->xOffset ); *y = glyphpath->yOffset; } else { /* -x -y */ - *x = FT_MulFix( cf2_floatToFixed( -0.7 ), + *x = FT_MulFix( cf2_doubleToFixed( -0.7 ), glyphpath->xOffset ); - *y = FT_MulFix( cf2_floatToFixed( 1.0 + 0.7 ), + *y = FT_MulFix( cf2_doubleToFixed( 1.0 + 0.7 ), glyphpath->yOffset ); } } @@ -1675,10 +1701,10 @@ &yOffset ); /* construct offset points */ - P0.x = glyphpath->currentCS.x + xOffset; - P0.y = glyphpath->currentCS.y + yOffset; - P1.x = x + xOffset; - P1.y = y + yOffset; + P0.x = ADD_INT32( glyphpath->currentCS.x, xOffset ); + P0.y = ADD_INT32( glyphpath->currentCS.y, yOffset ); + P1.x = ADD_INT32( x, xOffset ); + P1.y = ADD_INT32( y, yOffset ); if ( glyphpath->moveIsPending ) { @@ -1753,19 +1779,20 @@ &yOffset3 ); /* add momentum from the middle segment */ - glyphpath->callbacks->windingMomentum += - cf2_getWindingMomentum( x1, y1, x2, y2 ); + glyphpath->callbacks->windingMomentum = + ADD_INT32( glyphpath->callbacks->windingMomentum, + cf2_getWindingMomentum( x1, y1, x2, y2 ) ); /* construct offset points */ - P0.x = glyphpath->currentCS.x + xOffset1; - P0.y = glyphpath->currentCS.y + yOffset1; - P1.x = x1 + xOffset1; - P1.y = y1 + yOffset1; + P0.x = ADD_INT32( glyphpath->currentCS.x, xOffset1 ); + P0.y = ADD_INT32( glyphpath->currentCS.y, yOffset1 ); + P1.x = ADD_INT32( x1, xOffset1 ); + P1.y = ADD_INT32( y1, yOffset1 ); /* note: preserve angle of final segment by using offset3 at both ends */ - P2.x = x2 + xOffset3; - P2.y = y2 + yOffset3; - P3.x = x3 + xOffset3; - P3.y = y3 + yOffset3; + P2.x = ADD_INT32( x2, xOffset3 ); + P2.y = ADD_INT32( y2, yOffset3 ); + P3.x = ADD_INT32( x3, xOffset3 ); + P3.y = ADD_INT32( y3, yOffset3 ); if ( glyphpath->moveIsPending ) { diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cf2intrp.c b/Build/source/libs/freetype2/freetype-src/src/cff/cf2intrp.c index 40bd9059a13..a8162807485 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cf2intrp.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cf2intrp.c @@ -304,10 +304,12 @@ CF2_StemHintRec stemhint; - stemhint.min = - position += cf2_stack_getReal( opStack, i ); - stemhint.max = - position += cf2_stack_getReal( opStack, i + 1 ); + stemhint.min = + position = ADD_INT32( position, + cf2_stack_getReal( opStack, i ) ); + stemhint.max = + position = ADD_INT32( position, + cf2_stack_getReal( opStack, i + 1 ) ); stemhint.used = FALSE; stemhint.maxDS = @@ -348,7 +350,8 @@ { vals[i + 2] = vals[i]; if ( readFromStack[i] ) - vals[i + 2] += cf2_stack_getReal( opStack, idx++ ); + vals[i + 2] = ADD_INT32( vals[i + 2], cf2_stack_getReal( opStack, + idx++ ) ); } if ( isHFlex ) @@ -356,31 +359,34 @@ if ( doConditionalLastRead ) { - FT_Bool lastIsX = (FT_Bool)( cf2_fixedAbs( vals[10] - *curX ) > - cf2_fixedAbs( vals[11] - *curY ) ); + 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 ); if ( lastIsX ) { - vals[12] = vals[10] + lastVal; + vals[12] = ADD_INT32( vals[10], lastVal ); vals[13] = *curY; } else { vals[12] = *curX; - vals[13] = vals[11] + lastVal; + vals[13] = ADD_INT32( vals[11], lastVal ); } } else { if ( readFromStack[10] ) - vals[12] = vals[10] + cf2_stack_getReal( opStack, idx++ ); + vals[12] = ADD_INT32( vals[10], + cf2_stack_getReal( opStack, idx++ ) ); else vals[12] = *curX; if ( readFromStack[11] ) - vals[13] = vals[11] + cf2_stack_getReal( opStack, idx ); + vals[13] = ADD_INT32( vals[11], + cf2_stack_getReal( opStack, idx ) ); else vals[13] = *curY; } @@ -426,7 +432,10 @@ for ( j = 1; j < blend->lenBV; j++ ) - sum += FT_MulFix( *weight++, cf2_stack_getReal( opStack, delta++ ) ); + sum = ADD_INT32( sum, + FT_MulFix( *weight++, + cf2_stack_getReal( opStack, + delta++ ) ) ); /* store blended result */ cf2_stack_setReal( opStack, i + base, sum ); @@ -759,7 +768,8 @@ FT_TRACE4(( " vmoveto\n" )); if ( cf2_stack_count( opStack ) > 1 && !haveWidth ) - *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX; + *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), + nominalWidthX ); /* width is defined or default after this */ haveWidth = TRUE; @@ -767,7 +777,7 @@ if ( font->decoder->width_only ) goto exit; - curY += cf2_stack_popFixed( opStack ); + curY = ADD_INT32( curY, cf2_stack_popFixed( opStack ) ); cf2_glyphpath_moveTo( &glyphPath, curX, curY ); @@ -783,8 +793,10 @@ for ( idx = 0; idx < count; idx += 2 ) { - curX += cf2_stack_getReal( opStack, idx + 0 ); - curY += cf2_stack_getReal( opStack, idx + 1 ); + curX = ADD_INT32( curX, cf2_stack_getReal( opStack, + idx + 0 ) ); + curY = ADD_INT32( curY, cf2_stack_getReal( opStack, + idx + 1 ) ); cf2_glyphpath_lineTo( &glyphPath, curX, curY ); } @@ -810,9 +822,9 @@ if ( isX ) - curX += v; + curX = ADD_INT32( curX, v ); else - curY += v; + curY = ADD_INT32( curY, v ); isX = !isX; @@ -835,13 +847,15 @@ while ( idx + 6 <= count ) { - CF2_Fixed x1 = cf2_stack_getReal( opStack, idx + 0 ) + curX; - CF2_Fixed y1 = cf2_stack_getReal( opStack, idx + 1 ) + curY; - CF2_Fixed x2 = cf2_stack_getReal( opStack, idx + 2 ) + x1; - CF2_Fixed y2 = cf2_stack_getReal( opStack, idx + 3 ) + y1; - CF2_Fixed x3 = cf2_stack_getReal( opStack, idx + 4 ) + x2; - CF2_Fixed y3 = cf2_stack_getReal( opStack, idx + 5 ) + y2; + CF2_Fixed x1, y1, x2, y2, x3, y3; + + x1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 0 ), curX ); + y1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 1 ), curY ); + x2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 2 ), x1 ); + y2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 3 ), y1 ); + x3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 4 ), x2 ); + y3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 5 ), y2 ); cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 ); @@ -852,8 +866,10 @@ if ( op1 == cf2_cmdRCURVELINE ) { - curX += cf2_stack_getReal( opStack, idx + 0 ); - curY += cf2_stack_getReal( opStack, idx + 1 ); + curX = ADD_INT32( curX, cf2_stack_getReal( opStack, + idx + 0 ) ); + curY = ADD_INT32( curY, cf2_stack_getReal( opStack, + idx + 1 ) ); cf2_glyphpath_lineTo( &glyphPath, curX, curY ); } @@ -1129,7 +1145,10 @@ arg = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, FT_ABS( arg ) ); + if ( arg < -CF2_FIXED_MAX ) + cf2_stack_pushFixed( opStack, CF2_FIXED_MAX ); + else + cf2_stack_pushFixed( opStack, FT_ABS( arg ) ); } continue; /* do not clear the stack */ @@ -1144,7 +1163,9 @@ summand2 = cf2_stack_popFixed( opStack ); summand1 = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, summand1 + summand2 ); + cf2_stack_pushFixed( opStack, + ADD_INT32( summand1, + summand2 ) ); } continue; /* do not clear the stack */ @@ -1159,7 +1180,8 @@ subtrahend = cf2_stack_popFixed( opStack ); minuend = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, minuend - subtrahend ); + cf2_stack_pushFixed( opStack, + SUB_INT32( minuend, subtrahend ) ); } continue; /* do not clear the stack */ @@ -1174,7 +1196,8 @@ divisor = cf2_stack_popFixed( opStack ); dividend = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, FT_DivFix( dividend, divisor ) ); + cf2_stack_pushFixed( opStack, + FT_DivFix( dividend, divisor ) ); } continue; /* do not clear the stack */ @@ -1187,7 +1210,10 @@ arg = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, -arg ); + if ( arg < -CF2_FIXED_MAX ) + cf2_stack_pushFixed( opStack, CF2_FIXED_MAX ); + else + cf2_stack_pushFixed( opStack, -arg ); } continue; /* do not clear the stack */ @@ -1257,7 +1283,8 @@ arg2 = cf2_stack_popFixed( opStack ); arg1 = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, cond1 <= cond2 ? arg1 : arg2 ); + cf2_stack_pushFixed( opStack, + cond1 <= cond2 ? arg1 : arg2 ); } continue; /* do not clear the stack */ @@ -1291,7 +1318,8 @@ factor2 = cf2_stack_popFixed( opStack ); factor1 = cf2_stack_popFixed( opStack ); - cf2_stack_pushFixed( opStack, FT_MulFix( factor1, factor2 ) ); + cf2_stack_pushFixed( opStack, + FT_MulFix( factor1, factor2 ) ); } continue; /* do not clear the stack */ @@ -1305,7 +1333,9 @@ arg = cf2_stack_popFixed( opStack ); if ( arg > 0 ) { - FT_Fixed root = arg; + /* use a start value that doesn't make */ + /* the algorithm's addition overflow */ + FT_Fixed root = arg < 10 ? arg : arg >> 1; FT_Fixed new_root; @@ -1369,7 +1399,8 @@ if ( size > 0 ) { - /* for `cf2_stack_getReal', index 0 is bottom of stack */ + /* for `cf2_stack_getReal', */ + /* index 0 is bottom of stack */ CF2_UInt gr_idx; @@ -1381,7 +1412,8 @@ gr_idx = size - 1 - (CF2_UInt)idx; cf2_stack_pushFixed( opStack, - cf2_stack_getReal( opStack, gr_idx ) ); + cf2_stack_getReal( opStack, + gr_idx ) ); } } continue; /* do not clear the stack */ @@ -1416,7 +1448,8 @@ cf2_stack_count( opStack ) == 5 ) { if ( !haveWidth ) - *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX; + *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), + nominalWidthX ); } /* width is defined or default after this */ @@ -1564,7 +1597,8 @@ FT_TRACE4(( " rmoveto\n" )); if ( cf2_stack_count( opStack ) > 2 && !haveWidth ) - *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX; + *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), + nominalWidthX ); /* width is defined or default after this */ haveWidth = TRUE; @@ -1572,8 +1606,8 @@ if ( font->decoder->width_only ) goto exit; - curY += cf2_stack_popFixed( opStack ); - curX += cf2_stack_popFixed( opStack ); + curY = ADD_INT32( curY, cf2_stack_popFixed( opStack ) ); + curX = ADD_INT32( curX, cf2_stack_popFixed( opStack ) ); cf2_glyphpath_moveTo( &glyphPath, curX, curY ); @@ -1583,7 +1617,8 @@ FT_TRACE4(( " hmoveto\n" )); if ( cf2_stack_count( opStack ) > 1 && !haveWidth ) - *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX; + *width = ADD_INT32( cf2_stack_getReal( opStack, 0 ), + nominalWidthX ); /* width is defined or default after this */ haveWidth = TRUE; @@ -1591,7 +1626,7 @@ if ( font->decoder->width_only ) goto exit; - curX += cf2_stack_popFixed( opStack ); + curX = ADD_INT32( curX, cf2_stack_popFixed( opStack ) ); cf2_glyphpath_moveTo( &glyphPath, curX, curY ); @@ -1607,8 +1642,10 @@ while ( idx + 6 < count ) { - curX += cf2_stack_getReal( opStack, idx + 0 ); - curY += cf2_stack_getReal( opStack, idx + 1 ); + curX = ADD_INT32( curX, cf2_stack_getReal( opStack, + idx + 0 ) ); + curY = ADD_INT32( curY, cf2_stack_getReal( opStack, + idx + 1 ) ); cf2_glyphpath_lineTo( &glyphPath, curX, curY ); idx += 2; @@ -1616,13 +1653,15 @@ while ( idx < count ) { - CF2_Fixed x1 = cf2_stack_getReal( opStack, idx + 0 ) + curX; - CF2_Fixed y1 = cf2_stack_getReal( opStack, idx + 1 ) + curY; - CF2_Fixed x2 = cf2_stack_getReal( opStack, idx + 2 ) + x1; - CF2_Fixed y2 = cf2_stack_getReal( opStack, idx + 3 ) + y1; - CF2_Fixed x3 = cf2_stack_getReal( opStack, idx + 4 ) + x2; - CF2_Fixed y3 = cf2_stack_getReal( opStack, idx + 5 ) + y2; + CF2_Fixed x1, y1, x2, y2, x3, y3; + + x1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 0 ), curX ); + y1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 1 ), curY ); + x2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 2 ), x1 ); + y2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 3 ), y1 ); + x3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 4 ), x2 ); + y3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 5 ), y2 ); cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 ); @@ -1656,18 +1695,18 @@ if ( ( count - idx ) & 1 ) { - x1 = cf2_stack_getReal( opStack, idx ) + curX; + x1 = ADD_INT32( cf2_stack_getReal( opStack, idx ), curX ); idx++; } else x1 = curX; - y1 = cf2_stack_getReal( opStack, idx + 0 ) + curY; - x2 = cf2_stack_getReal( opStack, idx + 1 ) + x1; - y2 = cf2_stack_getReal( opStack, idx + 2 ) + y1; + y1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 0 ), curY ); + x2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 1 ), x1 ); + y2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 2 ), y1 ); x3 = x2; - y3 = cf2_stack_getReal( opStack, idx + 3 ) + y2; + y3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 3 ), y2 ); cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 ); @@ -1701,17 +1740,17 @@ if ( ( count - idx ) & 1 ) { - y1 = cf2_stack_getReal( opStack, idx ) + curY; + y1 = ADD_INT32( cf2_stack_getReal( opStack, idx ), curY ); idx++; } else y1 = curY; - x1 = cf2_stack_getReal( opStack, idx + 0 ) + curX; - x2 = cf2_stack_getReal( opStack, idx + 1 ) + x1; - y2 = cf2_stack_getReal( opStack, idx + 2 ) + y1; - x3 = cf2_stack_getReal( opStack, idx + 3 ) + x2; + x1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 0 ), curX ); + x2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 1 ), x1 ); + y2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 2 ), y1 ); + x3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 3 ), x2 ); y3 = y2; cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 ); @@ -1750,15 +1789,15 @@ if ( alternate ) { - x1 = cf2_stack_getReal( opStack, idx + 0 ) + curX; + x1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 0 ), curX ); y1 = curY; - x2 = cf2_stack_getReal( opStack, idx + 1 ) + x1; - y2 = cf2_stack_getReal( opStack, idx + 2 ) + y1; - y3 = cf2_stack_getReal( opStack, idx + 3 ) + y2; + x2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 1 ), x1 ); + y2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 2 ), y1 ); + y3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 3 ), y2 ); if ( count - idx == 5 ) { - x3 = cf2_stack_getReal( opStack, idx + 4 ) + x2; + x3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 4 ), x2 ); idx++; } @@ -1770,14 +1809,14 @@ else { x1 = curX; - y1 = cf2_stack_getReal( opStack, idx + 0 ) + curY; - x2 = cf2_stack_getReal( opStack, idx + 1 ) + x1; - y2 = cf2_stack_getReal( opStack, idx + 2 ) + y1; - x3 = cf2_stack_getReal( opStack, idx + 3 ) + x2; + y1 = ADD_INT32( cf2_stack_getReal( opStack, idx + 0 ), curY ); + x2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 1 ), x1 ); + y2 = ADD_INT32( cf2_stack_getReal( opStack, idx + 2 ), y1 ); + x3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 3 ), x2 ); if ( count - idx == 5 ) { - y3 = cf2_stack_getReal( opStack, idx + 4 ) + y2; + y3 = ADD_INT32( cf2_stack_getReal( opStack, idx + 4 ), y2 ); idx++; } diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cffgload.c b/Build/source/libs/freetype2/freetype-src/src/cff/cffgload.c index 940804850e8..20f3a2c28e9 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cffgload.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cffgload.c @@ -20,6 +20,7 @@ #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_SFNT_H +#include FT_INTERNAL_CALC_H #include FT_OUTLINE_H #include FT_CFF_DRIVER_H @@ -1450,8 +1451,8 @@ cff_builder_close_contour( builder ); builder->path_begun = 0; - x += args[-2]; - y += args[-1]; + x = ADD_LONG( x, args[-2] ); + y = ADD_LONG( y, args[-1] ); args = stack; break; @@ -1460,7 +1461,7 @@ cff_builder_close_contour( builder ); builder->path_begun = 0; - y += args[-1]; + y = ADD_LONG( y, args[-1] ); args = stack; break; @@ -1469,7 +1470,7 @@ cff_builder_close_contour( builder ); builder->path_begun = 0; - x += args[-1]; + x = ADD_LONG( x, args[-1] ); args = stack; break; @@ -1486,8 +1487,8 @@ args -= num_args & ~1; while ( args < decoder->top ) { - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 1 ); args += 2; } @@ -1519,9 +1520,9 @@ while ( args < decoder->top ) { if ( phase ) - x += args[0]; + x = ADD_LONG( x, args[0] ); else - y += args[0]; + y = ADD_LONG( y, args[0] ); if ( cff_builder_add_point1( builder, x, y ) ) goto Fail; @@ -1552,15 +1553,18 @@ args -= nargs; while ( args < decoder->top ) { - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[2]; - y += args[3]; + + x = ADD_LONG( x, args[2] ); + y = ADD_LONG( y, args[3] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[4]; - y += args[5]; + + x = ADD_LONG( x, args[4] ); + y = ADD_LONG( y, args[5] ); cff_builder_add_point( builder, x, y, 1 ); + args += 6; } args = stack; @@ -1589,7 +1593,7 @@ if ( nargs & 1 ) { - x += args[0]; + x = ADD_LONG( x, args[0] ); args++; nargs--; } @@ -1599,13 +1603,16 @@ while ( args < decoder->top ) { - y += args[0]; + y = ADD_LONG( y, args[0] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[1]; - y += args[2]; + + x = ADD_LONG( x, args[1] ); + y = ADD_LONG( y, args[2] ); cff_builder_add_point( builder, x, y, 0 ); - y += args[3]; + + y = ADD_LONG( y, args[3] ); cff_builder_add_point( builder, x, y, 1 ); + args += 4; } args = stack; @@ -1633,7 +1640,7 @@ args -= nargs; if ( nargs & 1 ) { - y += args[0]; + y = ADD_LONG( y, args[0] ); args++; nargs--; } @@ -1643,13 +1650,16 @@ while ( args < decoder->top ) { - x += args[0]; + x = ADD_LONG( x, args[0] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[1]; - y += args[2]; + + x = ADD_LONG( x, args[1] ); + y = ADD_LONG( y, args[2] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[3]; + + x = ADD_LONG( x, args[3] ); cff_builder_add_point( builder, x, y, 1 ); + args += 4; } args = stack; @@ -1688,26 +1698,30 @@ nargs -= 4; if ( phase ) { - x += args[0]; + x = ADD_LONG( x, args[0] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[1]; - y += args[2]; + + x = ADD_LONG( x, args[1] ); + y = ADD_LONG( y, args[2] ); cff_builder_add_point( builder, x, y, 0 ); - y += args[3]; + + y = ADD_LONG( y, args[3] ); if ( nargs == 1 ) - x += args[4]; + x = ADD_LONG( x, args[4] ); cff_builder_add_point( builder, x, y, 1 ); } else { - y += args[0]; + y = ADD_LONG( y, args[0] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[1]; - y += args[2]; + + x = ADD_LONG( x, args[1] ); + y = ADD_LONG( y, args[2] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[3]; + + x = ADD_LONG( x, args[3] ); if ( nargs == 1 ) - y += args[4]; + y = ADD_LONG( y, args[4] ); cff_builder_add_point( builder, x, y, 1 ); } args += 4; @@ -1740,23 +1754,27 @@ /* first, add the line segments */ while ( num_lines > 0 ) { - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 1 ); + args += 2; num_lines--; } /* then the curve */ - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[2]; - y += args[3]; + + x = ADD_LONG( x, args[2] ); + y = ADD_LONG( y, args[3] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[4]; - y += args[5]; + + x = ADD_LONG( x, args[4] ); + y = ADD_LONG( y, args[5] ); cff_builder_add_point( builder, x, y, 1 ); + args = stack; } break; @@ -1785,23 +1803,27 @@ /* first, add the curves */ while ( num_curves > 0 ) { - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[2]; - y += args[3]; + + x = ADD_LONG( x, args[2] ); + y = ADD_LONG( y, args[3] ); cff_builder_add_point( builder, x, y, 0 ); - x += args[4]; - y += args[5]; + + x = ADD_LONG( x, args[4] ); + y = ADD_LONG( y, args[5] ); cff_builder_add_point( builder, x, y, 1 ); + args += 6; num_curves--; } /* then the final line */ - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 1 ); + args = stack; } break; @@ -1824,33 +1846,33 @@ start_y = y; /* first control point */ - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, 0 ); /* second control point */ - x += args[2]; - y += args[3]; + x = ADD_LONG( x, args[2] ); + y = ADD_LONG( y, args[3] ); cff_builder_add_point( builder, x, y, 0 ); /* join point; on curve, with y-value the same as the last */ /* control point's y-value */ - x += args[4]; + x = ADD_LONG( x, args[4] ); cff_builder_add_point( builder, x, y, 1 ); /* third control point, with y-value the same as the join */ /* point's y-value */ - x += args[5]; + x = ADD_LONG( x, args[5] ); cff_builder_add_point( builder, x, y, 0 ); /* fourth control point */ - x += args[6]; - y += args[7]; + x = ADD_LONG( x, args[6] ); + y = ADD_LONG( y, args[7] ); cff_builder_add_point( builder, x, y, 0 ); /* ending point, with y-value the same as the start */ - x += args[8]; - y = start_y; + x = ADD_LONG( x, args[8] ); + y = start_y; cff_builder_add_point( builder, x, y, 1 ); args = stack; @@ -1873,32 +1895,32 @@ start_y = y; /* first control point */ - x += args[0]; + x = ADD_LONG( x, args[0] ); cff_builder_add_point( builder, x, y, 0 ); /* second control point */ - x += args[1]; - y += args[2]; + x = ADD_LONG( x, args[1] ); + y = ADD_LONG( y, args[2] ); cff_builder_add_point( builder, x, y, 0 ); /* join point; on curve, with y-value the same as the last */ /* control point's y-value */ - x += args[3]; + x = ADD_LONG( x, args[3] ); cff_builder_add_point( builder, x, y, 1 ); /* third control point, with y-value the same as the join */ /* point's y-value */ - x += args[4]; + x = ADD_LONG( x, args[4] ); cff_builder_add_point( builder, x, y, 0 ); /* fourth control point */ - x += args[5]; - y = start_y; + x = ADD_LONG( x, args[5] ); + y = start_y; cff_builder_add_point( builder, x, y, 0 ); /* ending point, with y-value the same as the start point's */ /* y-value -- we don't add this point, though */ - x += args[6]; + x = ADD_LONG( x, args[6] ); cff_builder_add_point( builder, x, y, 1 ); args = stack; @@ -1934,8 +1956,8 @@ /* grab up to the last argument */ for ( count = 5; count > 0; count-- ) { - dx += temp[0]; - dy += temp[1]; + dx = ADD_LONG( dx, temp[0] ); + dy = ADD_LONG( dy, temp[1] ); temp += 2; } @@ -1949,8 +1971,8 @@ for ( count = 5; count > 0; count-- ) { - x += args[0]; - y += args[1]; + x = ADD_LONG( x, args[0] ); + y = ADD_LONG( y, args[1] ); cff_builder_add_point( builder, x, y, (FT_Bool)( count == 3 ) ); args += 2; @@ -1959,13 +1981,13 @@ /* is last operand an x- or y-delta? */ if ( horizontal ) { - x += args[0]; - y = start_y; + x = ADD_LONG( x, args[0] ); + y = start_y; } else { - x = start_x; - y += args[0]; + x = start_x; + y = ADD_LONG( y, args[0] ); } cff_builder_add_point( builder, x, y, 1 ); @@ -1987,8 +2009,8 @@ for ( count = 6; count > 0; count-- ) { - x += args[0]; - y += args[1]; + 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 ) ); args += 2; @@ -2066,21 +2088,26 @@ FT_TRACE4(( " abs\n" )); if ( args[0] < 0 ) - args[0] = -args[0]; + { + if ( args[0] == FT_LONG_MIN ) + args[0] = FT_LONG_MAX; + else + args[0] = -args[0]; + } args++; break; case cff_op_add: FT_TRACE4(( " add\n" )); - args[0] += args[1]; + args[0] = ADD_LONG( args[0], args[1] ); args++; break; case cff_op_sub: FT_TRACE4(( " sub\n" )); - args[0] -= args[1]; + args[0] = SUB_LONG( args[0], args[1] ); args++; break; @@ -2094,6 +2121,8 @@ case cff_op_neg: FT_TRACE4(( " neg\n" )); + if ( args[0] == FT_LONG_MIN ) + args[0] = FT_LONG_MAX; args[0] = -args[0]; args++; break; @@ -2350,12 +2379,13 @@ FT_TRACE4(( " hsbw (invalid op)\n" )); - decoder->glyph_width = decoder->nominal_width + ( args[1] >> 16 ); + decoder->glyph_width = + ADD_LONG( decoder->nominal_width, ( args[1] >> 16 ) ); decoder->builder.left_bearing.x = args[0]; decoder->builder.left_bearing.y = 0; - x = decoder->builder.pos_x + args[0]; + x = ADD_LONG( decoder->builder.pos_x, args[0] ); y = decoder->builder.pos_y; args = stack; break; @@ -2367,13 +2397,14 @@ FT_TRACE4(( " sbw (invalid op)\n" )); - decoder->glyph_width = decoder->nominal_width + ( args[2] >> 16 ); + decoder->glyph_width = + ADD_LONG( decoder->nominal_width, ( args[2] >> 16 ) ); decoder->builder.left_bearing.x = args[0]; decoder->builder.left_bearing.y = args[1]; - x = decoder->builder.pos_x + args[0]; - y = decoder->builder.pos_y + args[1]; + x = ADD_LONG( decoder->builder.pos_x, args[0] ); + y = ADD_LONG( decoder->builder.pos_y, args[1] ); args = stack; break; @@ -2384,8 +2415,8 @@ FT_TRACE4(( " setcurrentpoint (invalid op)\n" )); - x = decoder->builder.pos_x + args[0]; - y = decoder->builder.pos_y + args[1]; + x = ADD_LONG( decoder->builder.pos_x, args[0] ); + y = ADD_LONG( decoder->builder.pos_y, args[1] ); args = stack; break; diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cffload.c b/Build/source/libs/freetype2/freetype-src/src/cff/cffload.c index 3beaeb1c8e7..12420384af2 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cffload.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cffload.c @@ -1352,9 +1352,12 @@ sum = cff_parse_num( parser, &parser->stack[i + base] ) * 65536; for ( j = 1; j < blend->lenBV; j++ ) - sum += FT_MulFix( *weight++, - cff_parse_num( parser, - &parser->stack[delta++] ) * 65536 ); + sum = ADD_INT32( + sum, + FT_MulFix( + *weight++, + cff_parse_num( parser, + &parser->stack[delta++] ) * 65536 ) ); /* point parser stack to new value on blend_stack */ parser->stack[i + base] = subFont->blend_top; diff --git a/Build/source/libs/freetype2/freetype-src/src/cff/cffparse.c b/Build/source/libs/freetype2/freetype-src/src/cff/cffparse.c index e1511bdbd17..9d7bf6d22c8 100644 --- a/Build/source/libs/freetype2/freetype-src/src/cff/cffparse.c +++ b/Build/source/libs/freetype2/freetype-src/src/cff/cffparse.c @@ -20,6 +20,7 @@ #include "cffparse.h" #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_DEBUG_H +#include FT_INTERNAL_CALC_H #include "cfferrs.h" #include "cffpic.h" @@ -156,6 +157,22 @@ 1000000000L }; + /* maximum values allowed for multiplying */ + /* with the corresponding `power_tens' element */ + static const FT_Long power_ten_limits[] = + { + FT_LONG_MAX / 1L, + FT_LONG_MAX / 10L, + FT_LONG_MAX / 100L, + FT_LONG_MAX / 1000L, + FT_LONG_MAX / 10000L, + FT_LONG_MAX / 100000L, + FT_LONG_MAX / 1000000L, + FT_LONG_MAX / 10000000L, + FT_LONG_MAX / 100000000L, + FT_LONG_MAX / 1000000000L, + }; + /* read a real */ static FT_Fixed @@ -484,7 +501,15 @@ if ( scaling ) + { + if ( FT_ABS( val ) > power_ten_limits[scaling] ) + { + val = val > 0 ? 0x7FFFFFFFL : -0x7FFFFFFFL; + goto Overflow; + } + val *= power_tens[scaling]; + } if ( val > 0x7FFF ) { @@ -1585,7 +1610,7 @@ val = 0; while ( num_args > 0 ) { - val += cff_parse_num( parser, data++ ); + val = ADD_LONG( val, cff_parse_num( parser, data++ ) ); switch ( field->size ) { case (8 / FT_CHAR_BIT): |