[pcf] Massive unsigning (part 1).

Unofficial specifications hesitate to use unsigned 32-bit integers.
Negative values caused a lot of trouble in the past and it is safer
and easier to treat some properties as unsigned.

* src/pcf/pcf.h (PCF_AccelRec): Use unsigned values for `fontAscent',
`fontDescent', and `maxOverlap'.
* src/pcf/pcfread.c (pcf_load_font, pcf_get_accel): Updated.
* src/pcf/pcfdrivr.c (PCF_Glyph_Load, PCF_Size_Select,
PCF_Size_Request): Updated.
This commit is contained in:
Alexei Podtelezhnikov 2018-08-08 00:09:16 -04:00
parent 705bac50d3
commit 3d4ab6bac1
4 changed files with 40 additions and 38 deletions

View File

@ -1,4 +1,18 @@
2018-08-06 Alexei Podtelezhnikov <apodtele@gmail.com> 2018-08-08 Alexei Podtelezhnikov <apodtele@gmail.com>
[pcf] Massive unsigning (part 1).
Unofficial specifications hesitate to use unsigned 32-bit integers.
Negative values caused a lot of trouble in the past and it is safer
and easier to treat some properties as unsigned.
* src/pcf/pcf.h (PCF_AccelRec): Use unsigned values for `fontAscent',
`fontDescent', and `maxOverlap'.
* src/pcf/pcfread.c (pcf_load_font, pcf_get_accel): Updated.
* src/pcf/pcfdrivr.c (PCF_Glyph_Load, PCF_Size_Select,
PCF_Size_Request): Updated.
2018-08-07 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/pcf/pcfread.c (pcf_get_bitmaps): Unsign `offsets' and * src/pcf/pcfread.c (pcf_get_bitmaps): Unsign `offsets' and
`bitmapSizes'. `bitmapSizes'.

View File

@ -113,9 +113,9 @@ FT_BEGIN_HEADER
FT_Byte inkInside; FT_Byte inkInside;
FT_Byte inkMetrics; FT_Byte inkMetrics;
FT_Byte drawDirection; FT_Byte drawDirection;
FT_Long fontAscent; FT_ULong fontAscent;
FT_Long fontDescent; FT_ULong fontDescent;
FT_Long maxOverlap; FT_ULong maxOverlap;
PCF_MetricRec minbounds; PCF_MetricRec minbounds;
PCF_MetricRec maxbounds; PCF_MetricRec maxbounds;
PCF_MetricRec ink_minbounds; PCF_MetricRec ink_minbounds;

View File

@ -441,8 +441,8 @@ THE SOFTWARE.
FT_Select_Metrics( size->face, strike_index ); FT_Select_Metrics( size->face, strike_index );
size->metrics.ascender = accel->fontAscent * 64; size->metrics.ascender = (FT_Pos)accel->fontAscent * 64;
size->metrics.descender = -accel->fontDescent * 64; size->metrics.descender = -(FT_Pos)accel->fontDescent * 64;
size->metrics.max_advance = accel->maxbounds.characterWidth * 64; size->metrics.max_advance = accel->maxbounds.characterWidth * 64;
return FT_Err_Ok; return FT_Err_Ok;
@ -470,8 +470,8 @@ THE SOFTWARE.
break; break;
case FT_SIZE_REQUEST_TYPE_REAL_DIM: case FT_SIZE_REQUEST_TYPE_REAL_DIM:
if ( height == ( face->accel.fontAscent + if ( (FT_ULong)height == ( face->accel.fontAscent +
face->accel.fontDescent ) ) face->accel.fontDescent ) )
error = FT_Err_Ok; error = FT_Err_Ok;
break; break;
@ -560,8 +560,8 @@ THE SOFTWARE.
slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); slot->metrics.height = (FT_Pos)( bitmap->rows * 64 );
ft_synthesize_vertical_metrics( &slot->metrics, ft_synthesize_vertical_metrics( &slot->metrics,
( face->accel.fontAscent + (FT_Pos)( face->accel.fontAscent +
face->accel.fontDescent ) * 64 ); face->accel.fontDescent ) * 64 );
if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
goto Exit; goto Exit;

View File

@ -1139,9 +1139,9 @@ THE SOFTWARE.
FT_FRAME_BYTE ( inkMetrics ), FT_FRAME_BYTE ( inkMetrics ),
FT_FRAME_BYTE ( drawDirection ), FT_FRAME_BYTE ( drawDirection ),
FT_FRAME_SKIP_BYTES( 1 ), FT_FRAME_SKIP_BYTES( 1 ),
FT_FRAME_LONG_LE ( fontAscent ), FT_FRAME_ULONG_LE ( fontAscent ),
FT_FRAME_LONG_LE ( fontDescent ), FT_FRAME_ULONG_LE ( fontDescent ),
FT_FRAME_LONG_LE ( maxOverlap ), FT_FRAME_ULONG_LE ( maxOverlap ),
FT_FRAME_END FT_FRAME_END
}; };
@ -1161,9 +1161,9 @@ THE SOFTWARE.
FT_FRAME_BYTE ( inkMetrics ), FT_FRAME_BYTE ( inkMetrics ),
FT_FRAME_BYTE ( drawDirection ), FT_FRAME_BYTE ( drawDirection ),
FT_FRAME_SKIP_BYTES( 1 ), FT_FRAME_SKIP_BYTES( 1 ),
FT_FRAME_LONG ( fontAscent ), FT_FRAME_ULONG ( fontAscent ),
FT_FRAME_LONG ( fontDescent ), FT_FRAME_ULONG ( fontDescent ),
FT_FRAME_LONG ( maxOverlap ), FT_FRAME_ULONG ( maxOverlap ),
FT_FRAME_END FT_FRAME_END
}; };
@ -1217,7 +1217,7 @@ THE SOFTWARE.
FT_TRACE5(( " noOverlap=%s, constantMetrics=%s," FT_TRACE5(( " noOverlap=%s, constantMetrics=%s,"
" terminalFont=%s, constantWidth=%s\n" " terminalFont=%s, constantWidth=%s\n"
" inkInside=%s, inkMetrics=%s, drawDirection=%s\n" " inkInside=%s, inkMetrics=%s, drawDirection=%s\n"
" fontAscent=%ld, fontDescent=%ld, maxOverlap=%ld\n", " fontAscent=%lu, fontDescent=%lu, maxOverlap=%lu\n",
accel->noOverlap ? "yes" : "no", accel->noOverlap ? "yes" : "no",
accel->constantMetrics ? "yes" : "no", accel->constantMetrics ? "yes" : "no",
accel->terminalFont ? "yes" : "no", accel->terminalFont ? "yes" : "no",
@ -1229,17 +1229,17 @@ THE SOFTWARE.
accel->fontDescent, accel->fontDescent,
accel->maxOverlap )); accel->maxOverlap ));
/* sanity checks */ /* sanity checks so that combined height can fit short */
if ( FT_ABS( accel->fontAscent ) > 0x7FFF ) if ( accel->fontAscent > 0x3FFFU )
{ {
accel->fontAscent = accel->fontAscent < 0 ? -0x7FFF : 0x7FFF; accel->fontAscent = 0x3FFFU;
FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %d\n", FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %u\n",
accel->fontAscent )); accel->fontAscent ));
} }
if ( FT_ABS( accel->fontDescent ) > 0x7FFF ) if ( accel->fontDescent > 0x3FFFU )
{ {
accel->fontDescent = accel->fontDescent < 0 ? -0x7FFF : 0x7FFF; accel->fontDescent = 0x3FFFU;
FT_TRACE0(( "pfc_get_accel: clamping font descent to value %d\n", FT_TRACE0(( "pfc_get_accel: clamping font descent to value %u\n",
accel->fontDescent )); accel->fontDescent ));
} }
@ -1565,20 +1565,8 @@ THE SOFTWARE.
bsize->height = face->accel.maxbounds.ascent << 6; bsize->height = face->accel.maxbounds.ascent << 6;
#endif #endif
#ifdef FT_DEBUG_LEVEL_TRACE bsize->height = (FT_Short)( face->accel.fontAscent +
if ( face->accel.fontAscent + face->accel.fontDescent < 0 ) face->accel.fontDescent );
FT_TRACE0(( "pcf_load_font: negative height\n" ));
#endif
if ( FT_ABS( face->accel.fontAscent +
face->accel.fontDescent ) > 0x7FFF )
{
bsize->height = 0x7FFF;
FT_TRACE0(( "pcf_load_font: clamping height to value %d\n",
bsize->height ));
}
else
bsize->height = FT_ABS( (FT_Short)( face->accel.fontAscent +
face->accel.fontDescent ) );
prop = pcf_find_property( face, "AVERAGE_WIDTH" ); prop = pcf_find_property( face, "AVERAGE_WIDTH" );
if ( prop ) if ( prop )