1 | /**************************************************************************** |
2 | * |
3 | * ftsnames.c |
4 | * |
5 | * Simple interface to access SFNT name tables (which are used |
6 | * to hold font names, copyright info, notices, etc.) (body). |
7 | * |
8 | * This is _not_ used to retrieve glyph names! |
9 | * |
10 | * Copyright (C) 1996-2023 by |
11 | * David Turner, Robert Wilhelm, and Werner Lemberg. |
12 | * |
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. |
18 | * |
19 | */ |
20 | |
21 | |
22 | #include <freetype/internal/ftdebug.h> |
23 | |
24 | #include <freetype/ftsnames.h> |
25 | #include <freetype/internal/tttypes.h> |
26 | #include <freetype/internal/ftstream.h> |
27 | |
28 | |
29 | #ifdef TT_CONFIG_OPTION_SFNT_NAMES |
30 | |
31 | |
32 | /* documentation is in ftsnames.h */ |
33 | |
34 | FT_EXPORT_DEF( FT_UInt ) |
35 | FT_Get_Sfnt_Name_Count( FT_Face face ) |
36 | { |
37 | return ( face && FT_IS_SFNT( face ) ) ? ((TT_Face)face)->num_names : 0; |
38 | } |
39 | |
40 | |
41 | /* documentation is in ftsnames.h */ |
42 | |
43 | FT_EXPORT_DEF( FT_Error ) |
44 | FT_Get_Sfnt_Name( FT_Face face, |
45 | FT_UInt idx, |
46 | FT_SfntName *aname ) |
47 | { |
48 | FT_Error error = FT_ERR( Invalid_Argument ); |
49 | |
50 | |
51 | if ( aname && face && FT_IS_SFNT( face ) ) |
52 | { |
53 | TT_Face ttface = (TT_Face)face; |
54 | |
55 | |
56 | if ( idx < (FT_UInt)ttface->num_names ) |
57 | { |
58 | TT_Name entry = ttface->name_table.names + idx; |
59 | |
60 | |
61 | /* load name on demand */ |
62 | if ( entry->stringLength > 0 && !entry->string ) |
63 | { |
64 | FT_Memory memory = face->memory; |
65 | FT_Stream stream = face->stream; |
66 | |
67 | |
68 | if ( FT_QNEW_ARRAY ( entry->string, entry->stringLength ) || |
69 | FT_STREAM_SEEK( entry->stringOffset ) || |
70 | FT_STREAM_READ( entry->string, entry->stringLength ) ) |
71 | { |
72 | FT_FREE( entry->string ); |
73 | entry->stringLength = 0; |
74 | } |
75 | } |
76 | |
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; |
83 | |
84 | error = FT_Err_Ok; |
85 | } |
86 | } |
87 | |
88 | return error; |
89 | } |
90 | |
91 | |
92 | /* documentation is in ftsnames.h */ |
93 | |
94 | FT_EXPORT_DEF( FT_Error ) |
95 | FT_Get_Sfnt_LangTag( FT_Face face, |
96 | FT_UInt langID, |
97 | FT_SfntLangTag *alangTag ) |
98 | { |
99 | FT_Error error = FT_ERR( Invalid_Argument ); |
100 | |
101 | |
102 | if ( alangTag && face && FT_IS_SFNT( face ) ) |
103 | { |
104 | TT_Face ttface = (TT_Face)face; |
105 | |
106 | |
107 | if ( ttface->name_table.format != 1 ) |
108 | return FT_THROW( Invalid_Table ); |
109 | |
110 | if ( langID > 0x8000U && |
111 | langID - 0x8000U < ttface->name_table.numLangTagRecords ) |
112 | { |
113 | TT_LangTag entry = ttface->name_table.langTags + |
114 | ( langID - 0x8000U ); |
115 | |
116 | |
117 | /* load name on demand */ |
118 | if ( entry->stringLength > 0 && !entry->string ) |
119 | { |
120 | FT_Memory memory = face->memory; |
121 | FT_Stream stream = face->stream; |
122 | |
123 | |
124 | if ( FT_QNEW_ARRAY ( entry->string, entry->stringLength ) || |
125 | FT_STREAM_SEEK( entry->stringOffset ) || |
126 | FT_STREAM_READ( entry->string, entry->stringLength ) ) |
127 | { |
128 | FT_FREE( entry->string ); |
129 | entry->stringLength = 0; |
130 | } |
131 | } |
132 | |
133 | alangTag->string = (FT_Byte*)entry->string; |
134 | alangTag->string_len = entry->stringLength; |
135 | |
136 | error = FT_Err_Ok; |
137 | } |
138 | } |
139 | |
140 | return error; |
141 | } |
142 | |
143 | |
144 | #else /* !TT_CONFIG_OPTION_SFNT_NAMES */ |
145 | |
146 | |
147 | FT_EXPORT_DEF( FT_UInt ) |
148 | FT_Get_Sfnt_Name_Count( FT_Face face ) |
149 | { |
150 | FT_UNUSED( face ); |
151 | |
152 | return 0; |
153 | } |
154 | |
155 | |
156 | FT_EXPORT_DEF( FT_Error ) |
157 | FT_Get_Sfnt_Name( FT_Face face, |
158 | FT_UInt idx, |
159 | FT_SfntName *aname ) |
160 | { |
161 | FT_UNUSED( face ); |
162 | FT_UNUSED( idx ); |
163 | FT_UNUSED( aname ); |
164 | |
165 | return FT_THROW( Unimplemented_Feature ); |
166 | } |
167 | |
168 | |
169 | FT_EXPORT_DEF( FT_Error ) |
170 | FT_Get_Sfnt_LangTag( FT_Face face, |
171 | FT_UInt langID, |
172 | FT_SfntLangTag *alangTag ) |
173 | { |
174 | FT_UNUSED( face ); |
175 | FT_UNUSED( langID ); |
176 | FT_UNUSED( alangTag ); |
177 | |
178 | return FT_THROW( Unimplemented_Feature ); |
179 | } |
180 | |
181 | |
182 | #endif /* !TT_CONFIG_OPTION_SFNT_NAMES */ |
183 | |
184 | |
185 | /* END */ |
186 | |