[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
diff --git a/ChangeLog b/ChangeLog
index b9576d8..bbe07ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
`bitmapSizes'.
diff --git a/src/pcf/pcf.h b/src/pcf/pcf.h
index 3c4eb6a..a4f6d24 100644
--- a/src/pcf/pcf.h
+++ b/src/pcf/pcf.h
@@ -113,9 +113,9 @@ FT_BEGIN_HEADER
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;
diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c
index e2f7e7c..90fb896 100644
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -441,8 +441,8 @@ THE SOFTWARE.
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 @@ THE SOFTWARE.
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 @@ THE SOFTWARE.
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;
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 14cce67..493c159 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -1139,9 +1139,9 @@ THE SOFTWARE.
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 @@ THE SOFTWARE.
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 @@ THE SOFTWARE.
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 @@ THE SOFTWARE.
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 @@ THE SOFTWARE.
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 )