1 /****************************************************************************
5 * Simple interface to access SFNT name tables (which are used
6 * to hold font names, copyright info, notices, etc.) (body).
8 * This is _not_ used to retrieve glyph names!
10 * Copyright (C) 1996-2023 by
11 * David Turner, Robert Wilhelm, and Werner Lemberg.
13 * This file is part of the FreeType project, and may only be used,
14 * modified, and distributed under the terms of the FreeType project
15 * license, LICENSE.TXT. By continuing to use, modify, or distribute
16 * this file you indicate that you have read the license and
17 * understand and accept it fully.
22 #include <freetype/internal/ftdebug.h>
24 #include <freetype/ftsnames.h>
25 #include <freetype/internal/tttypes.h>
26 #include <freetype/internal/ftstream.h>
29 #ifdef TT_CONFIG_OPTION_SFNT_NAMES
32 /* documentation is in ftsnames.h */
34 FT_EXPORT_DEF( FT_UInt )
35 FT_Get_Sfnt_Name_Count( FT_Face face )
37 return ( face && FT_IS_SFNT( face ) ) ? ((TT_Face)face)->num_names : 0;
41 /* documentation is in ftsnames.h */
43 FT_EXPORT_DEF( FT_Error )
44 FT_Get_Sfnt_Name( FT_Face face,
48 FT_Error error = FT_ERR( Invalid_Argument );
51 if ( aname && face && FT_IS_SFNT( face ) )
53 TT_Face ttface = (TT_Face)face;
56 if ( idx < (FT_UInt)ttface->num_names )
58 TT_Name entry = ttface->name_table.names + idx;
61 /* load name on demand */
62 if ( entry->stringLength > 0 && !entry->string )
64 FT_Memory memory = face->memory;
65 FT_Stream stream = face->stream;
68 if ( FT_QNEW_ARRAY ( entry->string, entry->stringLength ) ||
69 FT_STREAM_SEEK( entry->stringOffset ) ||
70 FT_STREAM_READ( entry->string, entry->stringLength ) )
72 FT_FREE( entry->string );
73 entry->stringLength = 0;
77 aname->platform_id = entry->platformID;
78 aname->encoding_id = entry->encodingID;
79 aname->language_id = entry->languageID;
80 aname->name_id = entry->nameID;
81 aname->string = (FT_Byte*)entry->string;
82 aname->string_len = entry->stringLength;
92 /* documentation is in ftsnames.h */
94 FT_EXPORT_DEF( FT_Error )
95 FT_Get_Sfnt_LangTag( FT_Face face,
97 FT_SfntLangTag *alangTag )
99 FT_Error error = FT_ERR( Invalid_Argument );
102 if ( alangTag && face && FT_IS_SFNT( face ) )
104 TT_Face ttface = (TT_Face)face;
107 if ( ttface->name_table.format != 1 )
108 return FT_THROW( Invalid_Table );
110 if ( langID > 0x8000U &&
111 langID - 0x8000U < ttface->name_table.numLangTagRecords )
113 TT_LangTag entry = ttface->name_table.langTags +
114 ( langID - 0x8000U );
117 /* load name on demand */
118 if ( entry->stringLength > 0 && !entry->string )
120 FT_Memory memory = face->memory;
121 FT_Stream stream = face->stream;
124 if ( FT_QNEW_ARRAY ( entry->string, entry->stringLength ) ||
125 FT_STREAM_SEEK( entry->stringOffset ) ||
126 FT_STREAM_READ( entry->string, entry->stringLength ) )
128 FT_FREE( entry->string );
129 entry->stringLength = 0;
133 alangTag->string = (FT_Byte*)entry->string;
134 alangTag->string_len = entry->stringLength;
144 #else /* !TT_CONFIG_OPTION_SFNT_NAMES */
147 FT_EXPORT_DEF( FT_UInt )
148 FT_Get_Sfnt_Name_Count( FT_Face face )
156 FT_EXPORT_DEF( FT_Error )
157 FT_Get_Sfnt_Name( FT_Face face,
165 return FT_THROW( Unimplemented_Feature );
169 FT_EXPORT_DEF( FT_Error )
170 FT_Get_Sfnt_LangTag( FT_Face face,
172 FT_SfntLangTag *alangTag )
176 FT_UNUSED( alangTag );
178 return FT_THROW( Unimplemented_Feature );
182 #endif /* !TT_CONFIG_OPTION_SFNT_NAMES */