[cff] Fix Savannah bug #43271.
* src/cff/cf2font.c (cf2_computeDarkening): Change overflow detection to use logarithms and clamp `scaledStem'.
This commit is contained in:
parent
74d0aad22c
commit
537c55d39d
|
@ -1,3 +1,10 @@
|
||||||
|
2014-10-02 Dave Arnold <darnold@adobe.com>
|
||||||
|
|
||||||
|
[cff] Fix Savannah bug #43271.
|
||||||
|
|
||||||
|
* src/cff/cf2font.c (cf2_computeDarkening): Change overflow
|
||||||
|
detection to use logarithms and clamp `scaledStem'.
|
||||||
|
|
||||||
2014-10-01 Alexei Podtelezhnikov <apodtele@gmail.com>
|
2014-10-01 Alexei Podtelezhnikov <apodtele@gmail.com>
|
||||||
|
|
||||||
* src/base/ftcalc.c: Remove miscellaneous type casts.
|
* src/base/ftcalc.c: Remove miscellaneous type casts.
|
||||||
|
|
|
@ -105,6 +105,7 @@
|
||||||
/* adjusting for emRatio converts darkenAmount to character */
|
/* adjusting for emRatio converts darkenAmount to character */
|
||||||
/* space (font units). */
|
/* space (font units). */
|
||||||
CF2_Fixed stemWidthPer1000, scaledStem;
|
CF2_Fixed stemWidthPer1000, scaledStem;
|
||||||
|
FT_Int logBase2;
|
||||||
|
|
||||||
|
|
||||||
*darkenAmount = 0;
|
*darkenAmount = 0;
|
||||||
|
@ -131,25 +132,32 @@
|
||||||
/* convert from true character space to 1000 unit character space; */
|
/* convert from true character space to 1000 unit character space; */
|
||||||
/* add synthetic emboldening effect */
|
/* add synthetic emboldening effect */
|
||||||
|
|
||||||
/* we have to assure that the computation of `scaledStem' */
|
/* `stemWidthPer1000' will not overflow for a legitimate font */
|
||||||
/* and `stemWidthPer1000' don't overflow */
|
|
||||||
|
|
||||||
stemWidthPer1000 = FT_MulFix( stemWidth + boldenAmount, emRatio );
|
stemWidthPer1000 = FT_MulFix( stemWidth + boldenAmount, emRatio );
|
||||||
|
|
||||||
if ( emRatio > CF2_FIXED_ONE &&
|
/* `scaledStem' can easily overflow, so we must clamp its maximum */
|
||||||
stemWidthPer1000 <= ( stemWidth + boldenAmount ) )
|
/* value; the test doesn't need to be precise, but must be */
|
||||||
{
|
/* conservative. The clamp value (default 2333) where */
|
||||||
stemWidthPer1000 = 0; /* to pacify compiler */
|
/* `darkenAmount' is zero is well below the overflow value of */
|
||||||
scaledStem = cf2_intToFixed( x4 );
|
/* 32767. */
|
||||||
}
|
/* */
|
||||||
else
|
/* FT_MSB computes the integer part of the base 2 logarithm. The */
|
||||||
{
|
/* number of bits for the product is 1 or 2 more than the sum of */
|
||||||
scaledStem = FT_MulFix( stemWidthPer1000, ppem );
|
/* logarithms; remembering that the 16 lowest bits of the fraction */
|
||||||
|
/* are dropped this is correct to within a factor of almost 4. */
|
||||||
|
/* For example, 0x80.0000 * 0x80.0000 = 0x4000.0000 is 23+23 and */
|
||||||
|
/* is flagged as possible overflow because 0xff.ffff * 0xff.ffff = */
|
||||||
|
/* 0xffff.fe00 is also 23+23. */
|
||||||
|
|
||||||
if ( ppem > CF2_FIXED_ONE &&
|
logBase2 = FT_MSB( (FT_UInt32)stemWidthPer1000 ) +
|
||||||
scaledStem <= stemWidthPer1000 )
|
FT_MSB( (FT_UInt32)ppem );
|
||||||
scaledStem = cf2_intToFixed( x4 );
|
|
||||||
}
|
if ( logBase2 >= 46 )
|
||||||
|
/* possible overflow */
|
||||||
|
scaledStem = cf2_intToFixed( x4 );
|
||||||
|
else
|
||||||
|
scaledStem = FT_MulFix( stemWidthPer1000, ppem );
|
||||||
|
|
||||||
/* now apply the darkening parameters */
|
/* now apply the darkening parameters */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue