[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.
This commit is contained in:
Alexei Podtelezhnikov 2023-04-01 22:34:30 -04:00
parent 6d7b8b22c4
commit 9597a62bac
2 changed files with 40 additions and 107 deletions

View File

@ -779,13 +779,15 @@ FT_BEGIN_HEADER
/************************************************************************** /**************************************************************************
* *
* @struct: * @struct:
* TT_Post_20Rec * TT_Post_NamesRec
* *
* @description: * @description:
* Postscript names sub-table, format 2.0. Stores the PS name of each * Postscript names table, either format 2.0 or 2.5.
* glyph in the font face.
* *
* @fields: * @fields:
* loaded ::
* A flag to indicate whether the PS names are loaded.
*
* num_glyphs :: * num_glyphs ::
* The number of named glyphs in the table. * The number of named glyphs in the table.
* *
@ -798,69 +800,14 @@ FT_BEGIN_HEADER
* glyph_names :: * glyph_names ::
* The PS names not in Mac Encoding. * 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_glyphs;
FT_UShort num_names; FT_UShort num_names;
FT_UShort* glyph_indices; FT_UShort* glyph_indices;
FT_Byte** glyph_names; 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; } TT_Post_NamesRec, *TT_Post_Names;

View File

@ -259,7 +259,7 @@
/* all right, set table fields and exit successfully */ /* 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; table->num_glyphs = num_glyphs;
@ -286,8 +286,8 @@
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
FT_Error error; FT_Error error;
FT_UShort num_glyphs; FT_UShort n, num_glyphs;
FT_Char* offset_table = NULL; FT_UShort* glyph_indices = NULL;
if ( FT_READ_USHORT( num_glyphs ) ) if ( FT_READ_USHORT( num_glyphs ) )
@ -302,42 +302,40 @@
goto Exit; goto Exit;
} }
if ( num_glyphs ) /* 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_UShort n; FT_Int idx = n + FT_GET_CHAR();
if ( FT_QNEW_ARRAY( offset_table, num_glyphs ) || if ( idx < 0 || idx > 257 )
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++ )
{ {
FT_Int idx = n + offset_table[n]; error = FT_THROW( Invalid_File_Format );
goto Fail;
if ( idx < 0 || idx > 257 )
{
error = FT_THROW( Invalid_File_Format );
goto Fail;
}
} }
glyph_indices[n] = (FT_UShort)idx;
} }
FT_FRAME_EXIT();
/* OK, set table fields and exit successfully */ /* 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->num_glyphs = num_glyphs;
table->offsets = offset_table; table->glyph_indices = glyph_indices;
} }
return FT_Err_Ok; return FT_Err_Ok;
Fail: Fail:
FT_FREE( offset_table ); FT_FREE( glyph_indices );
Exit: Exit:
return error; return error;
@ -396,25 +394,19 @@
if ( format == 0x00020000L ) if ( format == 0x00020000L )
{ {
TT_Post_20 table = &names->names.format_20; FT_FREE( names->glyph_indices );
names->num_glyphs = 0;
if ( names->num_names )
FT_FREE( table->glyph_indices );
table->num_glyphs = 0;
if ( table->num_names )
{ {
FT_FREE( table->glyph_names ); FT_FREE( names->glyph_names );
table->num_names = 0; names->num_names = 0;
} }
} }
else if ( format == 0x00025000L ) else if ( format == 0x00025000L )
{ {
TT_Post_25 table = &names->names.format_25; FT_FREE( names->glyph_indices );
names->num_glyphs = 0;
FT_FREE( table->offsets );
table->num_glyphs = 0;
} }
} }
names->loaded = 0; names->loaded = 0;
@ -486,9 +478,6 @@
} }
else if ( format == 0x00020000L ) else if ( format == 0x00020000L )
{ {
TT_Post_20 table = &names->names.format_20;
if ( !names->loaded ) if ( !names->loaded )
{ {
error = load_post_names( face ); error = load_post_names( face );
@ -496,22 +485,19 @@
goto End; 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 ) if ( name_index < 258 )
*PSname = MAC_NAME( name_index ); *PSname = MAC_NAME( name_index );
else else
*PSname = (FT_String*)table->glyph_names[name_index - 258]; *PSname = (FT_String*)names->glyph_names[name_index - 258];
} }
} }
else if ( format == 0x00025000L ) else if ( format == 0x00025000L )
{ {
TT_Post_25 table = &names->names.format_25;
if ( !names->loaded ) if ( !names->loaded )
{ {
error = load_post_names( face ); error = load_post_names( face );
@ -519,8 +505,8 @@
goto End; goto End;
} }
if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */ if ( idx < (FT_UInt)names->num_glyphs ) /* paranoid checking */
*PSname = MAC_NAME( (FT_Int)idx + table->offsets[idx] ); *PSname = MAC_NAME( names->glyph_indices[idx] );
} }
/* nothing to do for format == 0x00030000L */ /* nothing to do for format == 0x00030000L */