[sfnt] Consolidate POST version 2.0 and 2.5 (pt 2). * src/sfnt/ttpost.c (load_format_20, load_format_25): Update arguments and move shared calls and checks upstream to... (load_post_names): ... this function. (tt_face_free_ps_names, tt_face_get_ps_name): 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 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
diff --git a/src/sfnt/ttpost.c b/src/sfnt/ttpost.c
index 25643cb..aa51276 100644
--- a/src/sfnt/ttpost.c
+++ b/src/sfnt/ttpost.c
@@ -156,64 +156,51 @@
static FT_Error
- load_format_20( TT_Face face,
- FT_Stream stream,
- FT_ULong post_len )
+ load_format_20( TT_Post_Names names,
+ FT_Stream stream,
+ FT_UShort num_glyphs,
+ FT_ULong post_len )
{
FT_Memory memory = stream->memory;
FT_Error error;
- FT_UShort num_glyphs;
+ FT_UShort n;
FT_UShort num_names = 0;
FT_UShort* glyph_indices = NULL;
FT_Byte** name_strings = NULL;
- if ( FT_READ_USHORT( num_glyphs ) )
- goto Exit;
-
- /* UNDOCUMENTED! The number of glyphs in this table can be smaller */
- /* than the value in the maxp table (cf. cyberbit.ttf). */
-
- /* There already exist fonts which have more than 32768 glyph names */
- /* in this table, so the test for this threshold has been dropped. */
-
- if ( num_glyphs > face->max_profile.numGlyphs ||
- (FT_ULong)num_glyphs * 2 > post_len )
+ if ( (FT_ULong)num_glyphs * 2 > post_len )
{
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* load the indices and note their maximum */
- {
- FT_UShort n;
- FT_UShort idx;
-
+ if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) ||
+ FT_FRAME_ENTER( num_glyphs * 2 ) )
+ goto Fail;
- if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) ||
- FT_FRAME_ENTER( num_glyphs * 2 ) )
- goto Fail;
+ for ( n = 0; n < num_glyphs; n++ )
+ {
+ FT_UShort idx = FT_GET_USHORT();
- for ( n = 0; n < num_glyphs; n++ )
- {
- glyph_indices[n] = idx = FT_GET_USHORT();
- if ( idx > num_names )
- num_names = idx;
- }
+ if ( idx > num_names )
+ num_names = idx;
- FT_FRAME_EXIT();
+ glyph_indices[n] = idx;
}
+ FT_FRAME_EXIT();
+
/* compute number of names stored in table */
num_names = num_names > 257 ? num_names - 257 : 0;
/* now load the name strings */
if ( num_names )
{
- FT_UShort n;
FT_ULong p;
FT_Byte* strings;
@@ -258,15 +245,11 @@
}
/* all right, set table fields and exit successfully */
- {
- TT_Post_Names table = &face->postscript_names;
+ names->num_glyphs = num_glyphs;
+ names->num_names = num_names;
+ names->glyph_indices = glyph_indices;
+ names->glyph_names = name_strings;
-
- table->num_glyphs = num_glyphs;
- table->num_names = num_names;
- table->glyph_indices = glyph_indices;
- table->glyph_names = name_strings;
- }
return FT_Err_Ok;
Fail:
@@ -279,24 +262,21 @@
static FT_Error
- load_format_25( TT_Face face,
- FT_Stream stream,
- FT_ULong post_len )
+ load_format_25( TT_Post_Names names,
+ FT_Stream stream,
+ FT_UShort num_glyphs,
+ FT_ULong post_len )
{
FT_Memory memory = stream->memory;
FT_Error error;
- FT_UShort n, num_glyphs;
+ FT_UShort n;
FT_UShort* glyph_indices = NULL;
- if ( FT_READ_USHORT( num_glyphs ) )
- goto Exit;
-
/* check the number of glyphs, including the theoretical limit */
- if ( num_glyphs > face->max_profile.numGlyphs ||
- num_glyphs > post_len ||
- num_glyphs > 257 + 128 )
+ if ( num_glyphs > post_len ||
+ num_glyphs > 258 + 128 )
{
error = FT_THROW( Invalid_File_Format );
goto Exit;
@@ -324,13 +304,8 @@
FT_FRAME_EXIT();
/* OK, set table fields and exit successfully */
- {
- TT_Post_Names table = &face->postscript_names;
-
-
- table->num_glyphs = num_glyphs;
- table->glyph_indices = glyph_indices;
- }
+ names->num_glyphs = num_glyphs;
+ names->glyph_indices = glyph_indices;
return FT_Err_Ok;
@@ -345,37 +320,37 @@
static FT_Error
load_post_names( TT_Face face )
{
- FT_Stream stream;
- FT_Error error;
- FT_Fixed format;
+ FT_Error error = FT_Err_Ok;
+ FT_Stream stream = face->root.stream;
+ FT_Fixed format = face->postscript.FormatType;
FT_ULong post_len;
+ FT_UShort num_glyphs;
- /* get a stream for the face's resource */
- stream = face->root.stream;
-
/* seek to the beginning of the PS names table */
error = face->goto_table( face, TTAG_post, stream, &post_len );
if ( error )
goto Exit;
- format = face->postscript.FormatType;
-
- /* go to beginning of subtable */
- if ( FT_STREAM_SKIP( 32 ) )
+ /* UNDOCUMENTED! The number of glyphs in this table can be smaller */
+ /* than the value in the maxp table (cf. cyberbit.ttf). */
+ if ( post_len < 34 ||
+ FT_STREAM_SKIP( 32 ) ||
+ FT_READ_USHORT( num_glyphs ) ||
+ num_glyphs > face->max_profile.numGlyphs ||
+ num_glyphs == 0 )
goto Exit;
- /* now read postscript table */
- if ( format == 0x00020000L && post_len >= 34 )
- error = load_format_20( face, stream, post_len - 34 );
- else if ( format == 0x00025000L && post_len >= 34 )
- error = load_format_25( face, stream, post_len - 34 );
- else
- error = FT_THROW( Invalid_File_Format );
-
- face->postscript_names.loaded = 1;
+ /* now read postscript names data */
+ if ( format == 0x00020000L )
+ error = load_format_20( &face->postscript_names, stream,
+ num_glyphs, post_len - 34 );
+ else if ( format == 0x00025000L )
+ error = load_format_25( &face->postscript_names, stream,
+ num_glyphs, post_len - 34 );
Exit:
+ face->postscript_names.loaded = 1; /* even if failed */
return error;
}
@@ -385,30 +360,20 @@
{
FT_Memory memory = face->root.memory;
TT_Post_Names names = &face->postscript_names;
- FT_Fixed format;
- if ( names->loaded )
+ if ( names->num_glyphs )
{
- format = face->postscript.FormatType;
-
- if ( format == 0x00020000L )
- {
- FT_FREE( names->glyph_indices );
- names->num_glyphs = 0;
+ FT_FREE( names->glyph_indices );
+ names->num_glyphs = 0;
+ }
- if ( names->num_names )
- {
- FT_FREE( names->glyph_names );
- names->num_names = 0;
- }
- }
- else if ( format == 0x00025000L )
- {
- FT_FREE( names->glyph_indices );
- names->num_glyphs = 0;
- }
+ if ( names->num_names )
+ {
+ FT_FREE( names->glyph_names );
+ names->num_names = 0;
}
+
names->loaded = 0;
}
@@ -476,7 +441,8 @@
if ( idx < 258 ) /* paranoid checking */
*PSname = MAC_NAME( idx );
}
- else if ( format == 0x00020000L )
+ else if ( format == 0x00020000L ||
+ format == 0x00025000L )
{
if ( !names->loaded )
{
@@ -492,22 +458,10 @@
if ( name_index < 258 )
*PSname = MAC_NAME( name_index );
- else
+ else /* only for version 2.0 */
*PSname = (FT_String*)names->glyph_names[name_index - 258];
}
}
- else if ( format == 0x00025000L )
- {
- if ( !names->loaded )
- {
- error = load_post_names( face );
- if ( error )
- goto End;
- }
-
- if ( idx < (FT_UInt)names->num_glyphs ) /* paranoid checking */
- *PSname = MAC_NAME( names->glyph_indices[idx] );
- }
/* nothing to do for format == 0x00030000L */