[pcf] Massive unsigning (part 2). Treat all size related properties as unsigned values. * src/pcf/pcf.h (PCF_ParsePropertyRec): Use unsigned `name' and `value'. * src/pcf/pcfread.c (pcf_get_propeerties, pcf_load_font): Updated parsing code and handling of AVERAGE_WIDTH, POINT_SIZE, PIXEL_SIZE, RESOLUTION_X and RESOLUTION_Y.
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
diff --git a/ChangeLog b/ChangeLog
index bbe07ee..268420e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2018-08-08 Alexei Podtelezhnikov <apodtele@gmail.com>
+ [pcf] Massive unsigning (part 2).
+
+ Treat all size related properties as unsigned values.
+
+ * src/pcf/pcf.h (PCF_ParsePropertyRec): Use unsigned `name' and
+ `value'.
+ * src/pcf/pcfread.c (pcf_get_propeerties, pcf_load_font): Updated
+ parsing code and handling of AVERAGE_WIDTH, POINT_SIZE, PIXEL_SIZE,
+ RESOLUTION_X and RESOLUTION_Y.
+
+2018-08-08 Alexei Podtelezhnikov <apodtele@gmail.com>
+
[pcf] Massive unsigning (part 1).
Unofficial specifications hesitate to use unsigned 32-bit integers.
diff --git a/src/pcf/pcf.h b/src/pcf/pcf.h
index a4f6d24..ce5df0b 100644
--- a/src/pcf/pcf.h
+++ b/src/pcf/pcf.h
@@ -57,9 +57,9 @@ FT_BEGIN_HEADER
typedef struct PCF_ParsePropertyRec_
{
- FT_Long name;
- FT_Byte isString;
- FT_Long value;
+ FT_ULong name;
+ FT_Byte isString;
+ FT_ULong value;
} PCF_ParsePropertyRec, *PCF_ParseProperty;
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 493c159..6b28c04 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -239,7 +239,7 @@ THE SOFTWARE.
{
for ( j = 0; j < sizeof ( tableNames ) / sizeof ( tableNames[0] );
j++ )
- if ( tables[i].type == (FT_UInt)( 1 << j ) )
+ if ( tables[i].type == ( 1U << j ) )
name = tableNames[j];
FT_TRACE4(( " %d: type=%s, format=0x%X,"
@@ -433,9 +433,9 @@ THE SOFTWARE.
#define FT_STRUCTURE PCF_ParsePropertyRec
FT_FRAME_START( PCF_PROPERTY_SIZE ),
- FT_FRAME_LONG_LE( name ),
- FT_FRAME_BYTE ( isString ),
- FT_FRAME_LONG_LE( value ),
+ FT_FRAME_ULONG_LE( name ),
+ FT_FRAME_BYTE ( isString ),
+ FT_FRAME_ULONG_LE( value ),
FT_FRAME_END
};
@@ -447,9 +447,9 @@ THE SOFTWARE.
#define FT_STRUCTURE PCF_ParsePropertyRec
FT_FRAME_START( PCF_PROPERTY_SIZE ),
- FT_FRAME_LONG( name ),
- FT_FRAME_BYTE( isString ),
- FT_FRAME_LONG( value ),
+ FT_FRAME_ULONG( name ),
+ FT_FRAME_BYTE ( isString ),
+ FT_FRAME_ULONG( value ),
FT_FRAME_END
};
@@ -623,11 +623,10 @@ THE SOFTWARE.
FT_TRACE4(( "\n" ));
for ( i = 0; i < nprops; i++ )
{
- FT_Long name_offset = props[i].name;
+ FT_ULong name_offset = props[i].name;
- if ( ( name_offset < 0 ) ||
- ( (FT_ULong)name_offset > string_size ) )
+ if ( name_offset > string_size )
{
error = FT_THROW( Invalid_Offset );
goto Bail;
@@ -642,11 +641,10 @@ THE SOFTWARE.
if ( props[i].isString )
{
- FT_Long value_offset = props[i].value;
+ FT_ULong value_offset = props[i].value;
- if ( ( value_offset < 0 ) ||
- ( (FT_ULong)value_offset > string_size ) )
+ if ( value_offset > string_size )
{
error = FT_THROW( Invalid_Offset );
goto Bail;
@@ -659,7 +657,7 @@ THE SOFTWARE.
}
else
{
- properties[i].value.l = props[i].value;
+ properties[i].value.ul = props[i].value;
FT_TRACE4(( " %d\n", properties[i].value.l ));
}
@@ -1571,94 +1569,72 @@ THE SOFTWARE.
prop = pcf_find_property( face, "AVERAGE_WIDTH" );
if ( prop )
{
-#ifdef FT_DEBUG_LEVEL_TRACE
- if ( prop->value.l < 0 )
- FT_TRACE0(( "pcf_load_font: negative average width\n" ));
-#endif
- if ( ( FT_ABS( prop->value.l ) > 0x7FFFL * 10 - 5 ) )
+ if ( prop->value.ul > 0x7FFFUL * 10 - 5 )
{
bsize->width = 0x7FFF;
- FT_TRACE0(( "pcf_load_font: clamping average width to value %d\n",
+ FT_TRACE0(( "pcf_load_font: clamping average width to value %hd\n",
bsize->width ));
}
else
- bsize->width = FT_ABS( (FT_Short)( ( prop->value.l + 5 ) / 10 ) );
+ bsize->width = (FT_Short)( ( prop->value.ul + 5 ) / 10 );
}
else
{
/* this is a heuristical value */
- bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 );
+ bsize->width = bsize->height - bsize->height / 3;
}
prop = pcf_find_property( face, "POINT_SIZE" );
if ( prop )
{
-#ifdef FT_DEBUG_LEVEL_TRACE
- if ( prop->value.l < 0 )
- FT_TRACE0(( "pcf_load_font: negative point size\n" ));
-#endif
/* convert from 722.7 decipoints to 72 points per inch */
- if ( FT_ABS( prop->value.l ) > 0x504C2L ) /* 0x7FFF * 72270/7200 */
+ if ( prop->value.ul > 0x504C2UL ) /* 0x7FFF * 72270/7200 */
{
bsize->size = 0x7FFF;
FT_TRACE0(( "pcf_load_font: clamping point size to value %d\n",
bsize->size ));
}
else
- bsize->size = FT_MulDiv( FT_ABS( prop->value.l ),
- 64 * 7200,
- 72270L );
+ bsize->size = FT_MulDiv( prop->value.l, 64 * 7200, 72270L );
}
prop = pcf_find_property( face, "PIXEL_SIZE" );
if ( prop )
{
-#ifdef FT_DEBUG_LEVEL_TRACE
- if ( prop->value.l < 0 )
- FT_TRACE0(( "pcf_load_font: negative pixel size\n" ));
-#endif
- if ( FT_ABS( prop->value.l ) > 0x7FFF )
+ if ( prop->value.ul > 0x7FFFU )
{
- bsize->y_ppem = 0x7FFF << 6;
+ bsize->y_ppem = 0x7FFF * 64;
FT_TRACE0(( "pcf_load_font: clamping pixel size to value %d\n",
bsize->y_ppem ));
}
else
- bsize->y_ppem = FT_ABS( (FT_Short)prop->value.l ) << 6;
+ bsize->y_ppem = (FT_Pos)prop->value.ul * 64;
}
prop = pcf_find_property( face, "RESOLUTION_X" );
if ( prop )
{
-#ifdef FT_DEBUG_LEVEL_TRACE
- if ( prop->value.l < 0 )
- FT_TRACE0(( "pcf_load_font: negative X resolution\n" ));
-#endif
- if ( FT_ABS( prop->value.l ) > 0x7FFF )
+ if ( prop->value.ul > 0x7FFFU )
{
resolution_x = 0x7FFF;
- FT_TRACE0(( "pcf_load_font: clamping X resolution to value %d\n",
+ FT_TRACE0(( "pcf_load_font: clamping X resolution to value %hd\n",
resolution_x ));
}
else
- resolution_x = FT_ABS( (FT_Short)prop->value.l );
+ resolution_x = (FT_Short)prop->value.ul;
}
prop = pcf_find_property( face, "RESOLUTION_Y" );
if ( prop )
{
-#ifdef FT_DEBUG_LEVEL_TRACE
- if ( prop->value.l < 0 )
- FT_TRACE0(( "pcf_load_font: negative Y resolution\n" ));
-#endif
- if ( FT_ABS( prop->value.l ) > 0x7FFF )
+ if ( prop->value.ul > 0x7FFFU )
{
resolution_y = 0x7FFF;
FT_TRACE0(( "pcf_load_font: clamping Y resolution to value %d\n",
resolution_y ));
}
else
- resolution_y = FT_ABS( (FT_Short)prop->value.l );
+ resolution_y = (FT_Short)prop->value.ul;
}
if ( bsize->y_ppem == 0 )