[sfnt] Consolidate POST version 2.0 and 2.5 (pt 1). The deprecated POST version 2.5 can be handled using the data structures of version 2.0. The goal is to reduce the footprint. * include/freetype/internal/tttypes.h (TT_Post_Names): Absorb and... (TT_Post_20, TT_Post_25): ... remove these structures. src/sfnt/ttpost.c (load_post_names, tt_face_get_ps_name, tt_face_free_ps_names, load_format_20): Updated accordingly. (load_format_25): ditto and convert offsets to glyph indices.
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
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index fee036b..dc790f9 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -779,13 +779,15 @@ FT_BEGIN_HEADER
/**************************************************************************
*
* @struct:
- * TT_Post_20Rec
+ * TT_Post_NamesRec
*
* @description:
- * Postscript names sub-table, format 2.0. Stores the PS name of each
- * glyph in the font face.
+ * Postscript names table, either format 2.0 or 2.5.
*
* @fields:
+ * loaded ::
+ * A flag to indicate whether the PS names are loaded.
+ *
* num_glyphs ::
* The number of named glyphs in the table.
*
@@ -798,69 +800,14 @@ FT_BEGIN_HEADER
* glyph_names ::
* The PS names not in Mac Encoding.
*/
- typedef struct TT_Post_20Rec_
+ typedef struct TT_Post_NamesRec_
{
+ FT_Bool loaded;
FT_UShort num_glyphs;
FT_UShort num_names;
FT_UShort* glyph_indices;
FT_Byte** glyph_names;
- } TT_Post_20Rec, *TT_Post_20;
-
-
- /**************************************************************************
- *
- * @struct:
- * TT_Post_25Rec
- *
- * @description:
- * Postscript names sub-table, format 2.5. Stores the PS name of each
- * glyph in the font face.
- *
- * @fields:
- * num_glyphs ::
- * The number of glyphs in the table.
- *
- * offsets ::
- * An array of signed offsets in a normal Mac Postscript name encoding.
- */
- typedef struct TT_Post_25_
- {
- FT_UShort num_glyphs;
- FT_Char* offsets;
-
- } TT_Post_25Rec, *TT_Post_25;
-
-
- /**************************************************************************
- *
- * @struct:
- * TT_Post_NamesRec
- *
- * @description:
- * Postscript names table, either format 2.0 or 2.5.
- *
- * @fields:
- * loaded ::
- * A flag to indicate whether the PS names are loaded.
- *
- * format_20 ::
- * The sub-table used for format 2.0.
- *
- * format_25 ::
- * The sub-table used for format 2.5.
- */
- typedef struct TT_Post_NamesRec_
- {
- FT_Bool loaded;
-
- union
- {
- TT_Post_20Rec format_20;
- TT_Post_25Rec format_25;
-
- } names;
-
} TT_Post_NamesRec, *TT_Post_Names;
diff --git a/src/sfnt/ttpost.c b/src/sfnt/ttpost.c
index 40435c2..25643cb 100644
--- a/src/sfnt/ttpost.c
+++ b/src/sfnt/ttpost.c
@@ -259,7 +259,7 @@
/* all right, set table fields and exit successfully */
{
- TT_Post_20 table = &face->postscript_names.names.format_20;
+ TT_Post_Names table = &face->postscript_names;
table->num_glyphs = num_glyphs;
@@ -286,8 +286,8 @@
FT_Memory memory = stream->memory;
FT_Error error;
- FT_UShort num_glyphs;
- FT_Char* offset_table = NULL;
+ FT_UShort n, num_glyphs;
+ FT_UShort* glyph_indices = NULL;
if ( FT_READ_USHORT( num_glyphs ) )
@@ -302,42 +302,40 @@
goto Exit;
}
- if ( num_glyphs )
- {
- FT_UShort n;
+ /* load the indices and note their maximum */
+ if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) ||
+ FT_FRAME_ENTER( num_glyphs ) )
+ goto Fail;
+ for ( n = 0; n < num_glyphs; n++ )
+ {
+ FT_Int idx = n + FT_GET_CHAR();
- if ( FT_QNEW_ARRAY( offset_table, num_glyphs ) ||
- FT_STREAM_READ( offset_table, num_glyphs ) )
- goto Fail;
- /* now check the offset table for out-of-range values */
- for ( n = 0; n < num_glyphs; n++ )
+ if ( idx < 0 || idx > 257 )
{
- FT_Int idx = n + offset_table[n];
-
-
- if ( idx < 0 || idx > 257 )
- {
- error = FT_THROW( Invalid_File_Format );
- goto Fail;
- }
+ error = FT_THROW( Invalid_File_Format );
+ goto Fail;
}
+
+ glyph_indices[n] = (FT_UShort)idx;
}
+ FT_FRAME_EXIT();
+
/* OK, set table fields and exit successfully */
{
- TT_Post_25 table = &face->postscript_names.names.format_25;
+ TT_Post_Names table = &face->postscript_names;
- table->num_glyphs = num_glyphs;
- table->offsets = offset_table;
+ table->num_glyphs = num_glyphs;
+ table->glyph_indices = glyph_indices;
}
return FT_Err_Ok;
Fail:
- FT_FREE( offset_table );
+ FT_FREE( glyph_indices );
Exit:
return error;
@@ -396,25 +394,19 @@
if ( format == 0x00020000L )
{
- TT_Post_20 table = &names->names.format_20;
-
-
- FT_FREE( table->glyph_indices );
- table->num_glyphs = 0;
+ FT_FREE( names->glyph_indices );
+ names->num_glyphs = 0;
- if ( table->num_names )
+ if ( names->num_names )
{
- FT_FREE( table->glyph_names );
- table->num_names = 0;
+ FT_FREE( names->glyph_names );
+ names->num_names = 0;
}
}
else if ( format == 0x00025000L )
{
- TT_Post_25 table = &names->names.format_25;
-
-
- FT_FREE( table->offsets );
- table->num_glyphs = 0;
+ FT_FREE( names->glyph_indices );
+ names->num_glyphs = 0;
}
}
names->loaded = 0;
@@ -486,9 +478,6 @@
}
else if ( format == 0x00020000L )
{
- TT_Post_20 table = &names->names.format_20;
-
-
if ( !names->loaded )
{
error = load_post_names( face );
@@ -496,22 +485,19 @@
goto End;
}
- if ( idx < (FT_UInt)table->num_glyphs )
+ if ( idx < (FT_UInt)names->num_glyphs )
{
- FT_UShort name_index = table->glyph_indices[idx];
+ FT_UShort name_index = names->glyph_indices[idx];
if ( name_index < 258 )
*PSname = MAC_NAME( name_index );
else
- *PSname = (FT_String*)table->glyph_names[name_index - 258];
+ *PSname = (FT_String*)names->glyph_names[name_index - 258];
}
}
else if ( format == 0x00025000L )
{
- TT_Post_25 table = &names->names.format_25;
-
-
if ( !names->loaded )
{
error = load_post_names( face );
@@ -519,8 +505,8 @@
goto End;
}
- if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */
- *PSname = MAC_NAME( (FT_Int)idx + table->offsets[idx] );
+ if ( idx < (FT_UInt)names->num_glyphs ) /* paranoid checking */
+ *PSname = MAC_NAME( names->glyph_indices[idx] );
}
/* nothing to do for format == 0x00030000L */