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-2019 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 <ft2build.h> |
23 | #include FT_INTERNAL_DEBUG_H |
24 | |
25 | #include FT_SFNT_NAMES_H |
26 | #include FT_INTERNAL_TRUETYPE_TYPES_H |
27 | #include FT_INTERNAL_STREAM_H |
28 | |
29 | |
30 | #ifdef TT_CONFIG_OPTION_SFNT_NAMES |
31 | |
32 | |
33 | /* documentation is in ftsnames.h */ |
34 | |
35 | FT_EXPORT_DEF( FT_UInt ) |
36 | FT_Get_Sfnt_Name_Count( FT_Face face ) |
37 | { |
38 | return ( face && FT_IS_SFNT( face ) ) ? ((TT_Face)face)->num_names : 0; |
39 | } |
40 | |
41 | |
42 | /* documentation is in ftsnames.h */ |
43 | |
44 | FT_EXPORT_DEF( FT_Error ) |
45 | FT_Get_Sfnt_Name( FT_Face face, |
46 | FT_UInt idx, |
47 | FT_SfntName *aname ) |
48 | { |
49 | FT_Error error = FT_ERR( Invalid_Argument ); |
50 | |
51 | |
52 | if ( aname && face && FT_IS_SFNT( face ) ) |
53 | { |
54 | TT_Face ttface = (TT_Face)face; |
55 | |
56 | |
57 | if ( idx < (FT_UInt)ttface->num_names ) |
58 | { |
59 | TT_Name entry = ttface->name_table.names + idx; |
60 | |
61 | |
62 | /* load name on demand */ |
63 | if ( entry->stringLength > 0 && !entry->string ) |
64 | { |
65 | FT_Memory memory = face->memory; |
66 | FT_Stream stream = face->stream; |
67 | |
68 | |
69 | if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) || |
70 | FT_STREAM_SEEK( entry->stringOffset ) || |
71 | FT_STREAM_READ( entry->string, entry->stringLength ) ) |
72 | { |
73 | FT_FREE( entry->string ); |
74 | entry->stringLength = 0; |
75 | } |
76 | } |
77 | |
78 | aname->platform_id = entry->platformID; |
79 | aname->encoding_id = entry->encodingID; |
80 | aname->language_id = entry->languageID; |
81 | aname->name_id = entry->nameID; |
82 | aname->string = (FT_Byte*)entry->string; |
83 | aname->string_len = entry->stringLength; |
84 | |
85 | error = FT_Err_Ok; |
86 | } |
87 | } |
88 | |
89 | return error; |
90 | } |
91 | |
92 | |
93 | /* documentation is in ftsnames.h */ |
94 | |
95 | FT_EXPORT_DEF( FT_Error ) |
96 | FT_Get_Sfnt_LangTag( FT_Face face, |
97 | FT_UInt langID, |
98 | FT_SfntLangTag *alangTag ) |
99 | { |
100 | FT_Error error = FT_ERR( Invalid_Argument ); |
101 | |
102 | |
103 | if ( alangTag && face && FT_IS_SFNT( face ) ) |
104 | { |
105 | TT_Face ttface = (TT_Face)face; |
106 | |
107 | |
108 | if ( ttface->name_table.format != 1 ) |
109 | return FT_THROW( Invalid_Table ); |
110 | |
111 | if ( langID > 0x8000U && |
112 | langID - 0x8000U < ttface->name_table.numLangTagRecords ) |
113 | { |
114 | TT_LangTag entry = ttface->name_table.langTags + |
115 | ( langID - 0x8000U ); |
116 | |
117 | |
118 | /* load name on demand */ |
119 | if ( entry->stringLength > 0 && !entry->string ) |
120 | { |
121 | FT_Memory memory = face->memory; |
122 | FT_Stream stream = face->stream; |
123 | |
124 | |
125 | if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) || |
126 | FT_STREAM_SEEK( entry->stringOffset ) || |
127 | FT_STREAM_READ( entry->string, entry->stringLength ) ) |
128 | { |
129 | FT_FREE( entry->string ); |
130 | entry->stringLength = 0; |
131 | } |
132 | } |
133 | |
134 | alangTag->string = (FT_Byte*)entry->string; |
135 | alangTag->string_len = entry->stringLength; |
136 | |
137 | error = FT_Err_Ok; |
138 | } |
139 | } |
140 | |
141 | return error; |
142 | } |
143 | |
144 | |
145 | #else /* !TT_CONFIG_OPTION_SFNT_NAMES */ |
146 | |
147 | |
148 | FT_EXPORT_DEF( FT_UInt ) |
149 | FT_Get_Sfnt_Name_Count( FT_Face face ) |
150 | { |
151 | FT_UNUSED( face ); |
152 | |
153 | return 0; |
154 | } |
155 | |
156 | |
157 | FT_EXPORT_DEF( FT_Error ) |
158 | FT_Get_Sfnt_Name( FT_Face face, |
159 | FT_UInt idx, |
160 | FT_SfntName *aname ) |
161 | { |
162 | FT_UNUSED( face ); |
163 | FT_UNUSED( idx ); |
164 | FT_UNUSED( aname ); |
165 | |
166 | return FT_THROW( Unimplemented_Feature ); |
167 | } |
168 | |
169 | |
170 | FT_EXPORT_DEF( FT_Error ) |
171 | FT_Get_Sfnt_LangTag( FT_Face face, |
172 | FT_UInt langID, |
173 | FT_SfntLangTag *alangTag ) |
174 | { |
175 | FT_UNUSED( face ); |
176 | FT_UNUSED( langID ); |
177 | FT_UNUSED( alangTag ); |
178 | |
179 | return FT_THROW( Unimplemented_Feature ); |
180 | } |
181 | |
182 | |
183 | #endif /* !TT_CONFIG_OPTION_SFNT_NAMES */ |
184 | |
185 | |
186 | /* END */ |
187 | |