ref: 3d4ab6bac14c28dcbce00dd57bb30b0bbc4937db
parent: 705bac50d3ade49188e05018ede2072e4d1e1788
author: Alexei Podtelezhnikov <[email protected]>
date: Tue Aug 7 20:09:16 EDT 2018
[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.
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,18 @@
-2018-08-06 Alexei Podtelezhnikov <[email protected]>
+2018-08-08 Alexei Podtelezhnikov <[email protected]>
+
+ [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 <[email protected]>
* src/pcf/pcfread.c (pcf_get_bitmaps): Unsign `offsets' and
`bitmapSizes'.
--- a/src/pcf/pcf.h
+++ b/src/pcf/pcf.h
@@ -113,9 +113,9 @@
FT_Byte inkInside;
FT_Byte inkMetrics;
FT_Byte drawDirection;
- FT_Long fontAscent;
- FT_Long fontDescent;
- FT_Long maxOverlap;
+ FT_ULong fontAscent;
+ FT_ULong fontDescent;
+ FT_ULong maxOverlap;
PCF_MetricRec minbounds;
PCF_MetricRec maxbounds;
PCF_MetricRec ink_minbounds;
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -441,8 +441,8 @@
FT_Select_Metrics( size->face, strike_index );
- size->metrics.ascender = accel->fontAscent * 64;
- size->metrics.descender = -accel->fontDescent * 64;
+ size->metrics.ascender = (FT_Pos)accel->fontAscent * 64;
+ size->metrics.descender = -(FT_Pos)accel->fontDescent * 64;
size->metrics.max_advance = accel->maxbounds.characterWidth * 64;
return FT_Err_Ok;
@@ -470,8 +470,8 @@
break;
case FT_SIZE_REQUEST_TYPE_REAL_DIM:
- if ( height == ( face->accel.fontAscent +
- face->accel.fontDescent ) )
+ if ( (FT_ULong)height == ( face->accel.fontAscent +
+ face->accel.fontDescent ) )
error = FT_Err_Ok;
break;
@@ -560,8 +560,8 @@
slot->metrics.height = (FT_Pos)( bitmap->rows * 64 );
ft_synthesize_vertical_metrics( &slot->metrics,
- ( face->accel.fontAscent +
- face->accel.fontDescent ) * 64 );
+ (FT_Pos)( face->accel.fontAscent +
+ face->accel.fontDescent ) * 64 );
if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
goto Exit;
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -1139,9 +1139,9 @@
FT_FRAME_BYTE ( inkMetrics ),
FT_FRAME_BYTE ( drawDirection ),
FT_FRAME_SKIP_BYTES( 1 ),
- FT_FRAME_LONG_LE ( fontAscent ),
- FT_FRAME_LONG_LE ( fontDescent ),
- FT_FRAME_LONG_LE ( maxOverlap ),
+ FT_FRAME_ULONG_LE ( fontAscent ),
+ FT_FRAME_ULONG_LE ( fontDescent ),
+ FT_FRAME_ULONG_LE ( maxOverlap ),
FT_FRAME_END
};
@@ -1161,9 +1161,9 @@
FT_FRAME_BYTE ( inkMetrics ),
FT_FRAME_BYTE ( drawDirection ),
FT_FRAME_SKIP_BYTES( 1 ),
- FT_FRAME_LONG ( fontAscent ),
- FT_FRAME_LONG ( fontDescent ),
- FT_FRAME_LONG ( maxOverlap ),
+ FT_FRAME_ULONG ( fontAscent ),
+ FT_FRAME_ULONG ( fontDescent ),
+ FT_FRAME_ULONG ( maxOverlap ),
FT_FRAME_END
};
@@ -1217,7 +1217,7 @@
FT_TRACE5(( " noOverlap=%s, constantMetrics=%s,"
" terminalFont=%s, constantWidth=%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->constantMetrics ? "yes" : "no",
accel->terminalFont ? "yes" : "no",
@@ -1229,17 +1229,17 @@
accel->fontDescent,
accel->maxOverlap ));
- /* sanity checks */
- if ( FT_ABS( accel->fontAscent ) > 0x7FFF )
+ /* sanity checks so that combined height can fit short */
+ if ( accel->fontAscent > 0x3FFFU )
{
- accel->fontAscent = accel->fontAscent < 0 ? -0x7FFF : 0x7FFF;
- FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %d\n",
+ accel->fontAscent = 0x3FFFU;
+ FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %u\n",
accel->fontAscent ));
}
- if ( FT_ABS( accel->fontDescent ) > 0x7FFF )
+ if ( accel->fontDescent > 0x3FFFU )
{
- accel->fontDescent = accel->fontDescent < 0 ? -0x7FFF : 0x7FFF;
- FT_TRACE0(( "pfc_get_accel: clamping font descent to value %d\n",
+ accel->fontDescent = 0x3FFFU;
+ FT_TRACE0(( "pfc_get_accel: clamping font descent to value %u\n",
accel->fontDescent ));
}
@@ -1565,20 +1565,8 @@
bsize->height = face->accel.maxbounds.ascent << 6;
#endif
-#ifdef FT_DEBUG_LEVEL_TRACE
- if ( face->accel.fontAscent + face->accel.fontDescent < 0 )
- 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 ) );
+ bsize->height = (FT_Short)( face->accel.fontAscent +
+ face->accel.fontDescent );
prop = pcf_find_property( face, "AVERAGE_WIDTH" );
if ( prop )