1 /***************************************************************************/
2 /* */
3 /* sfdriver.c */
4 /* */
5 /* High-level SFNT driver interface (body). */
6 /* */
7 /* Copyright 1996-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
19 #include <ft2build.h>
20 #include FT_INTERNAL_SFNT_H
21 #include FT_INTERNAL_OBJECTS_H
23 #include "sfdriver.h"
24 #include "ttload.h"
25 #include "ttcmap.h"
26 #include "sfobjs.h"
28 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
29 #include "ttsbit.h"
30 #endif
32 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
33 #include "ttpost.h"
34 #endif
36 #include <string.h> /* for strcmp() */
39 static void*
40 get_sfnt_table( TT_Face face,
41 FT_Sfnt_Tag tag )
42 {
43 void* table;
46 switch ( tag )
47 {
48 case ft_sfnt_head:
49 table = &face->header;
50 break;
52 case ft_sfnt_hhea:
53 table = &face->horizontal;
54 break;
56 case ft_sfnt_vhea:
57 table = face->vertical_info ? &face->vertical : 0;
58 break;
60 case ft_sfnt_os2:
61 table = face->os2.version == 0xFFFF ? 0 : &face->os2;
62 break;
64 case ft_sfnt_post:
65 table = &face->postscript;
66 break;
68 case ft_sfnt_maxp:
69 table = &face->max_profile;
70 break;
72 case ft_sfnt_pclt:
73 table = face->pclt.Version ? &face->pclt : 0;
74 break;
76 default:
77 table = 0;
78 }
80 return table;
81 }
84 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
87 static FT_Error
88 get_sfnt_glyph_name( TT_Face face,
89 FT_UInt glyph_index,
90 FT_Pointer buffer,
91 FT_UInt buffer_max )
92 {
93 FT_String* gname;
94 FT_Error error;
97 error = TT_Get_PS_Name( face, glyph_index, &gname );
98 if ( !error && buffer_max > 0 )
99 {
100 FT_UInt len = (FT_UInt)( strlen( gname ) );
103 if ( len >= buffer_max )
104 len = buffer_max - 1;
106 MEM_Copy( buffer, gname, len );
107 ((FT_Byte*)buffer)[len] = 0;
108 }
110 return error;
111 }
114 static const char*
115 get_sfnt_postscript_name( TT_Face face )
116 {
117 FT_Int n;
119 /* shouldn't happen, but just in case to avoid memory leaks */
120 if ( face->root.internal->postscript_name )
121 return face->root.internal->postscript_name;
123 /* scan the name table to see if we have a Postscript name here, either */
124 /* in Macintosh or Windows platform encodings.. */
125 for ( n = 0; n < face->num_names; n++ )
126 {
127 TT_NameRec* name = face->name_table.names + n;
129 if ( name->nameID == 6 )
130 {
131 if ( ( name->platformID == 3 &&
132 name->encodingID == 1 &&
133 name->languageID == 0x409 ) ||
135 ( name->platformID == 1 &&
136 name->encodingID == 0 &&
137 name->languageID == 0 ) )
138 {
139 FT_UInt len = name->stringLength;
140 FT_Error error;
141 FT_Memory memory = face->root.memory;
142 FT_String* result;
144 if ( !ALLOC( result, len+1 ) )
145 {
146 memcpy( result, name->string, len );
147 result[len] = '\0';
149 face->root.internal->postscript_name = result;
150 }
151 return result;
152 }
153 }
154 }
156 return NULL;
157 }
160 #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
163 FT_CALLBACK_DEF( FT_Module_Interface )
164 SFNT_Get_Interface( FT_Module module,
165 const char* interface )
166 {
167 FT_UNUSED( module );
169 if ( strcmp( interface, "get_sfnt" ) == 0 )
170 return (FT_Module_Interface)get_sfnt_table;
172 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
173 if ( strcmp( interface, "glyph_name" ) == 0 )
174 return (FT_Module_Interface)get_sfnt_glyph_name;
175 #endif
177 if ( strcmp( interface, "postscript_name" ) == 0 )
178 return (FT_Module_Interface)get_sfnt_postscript_name;
180 return 0;
181 }
184 static
185 const SFNT_Interface sfnt_interface =
186 {
187 TT_Goto_Table,
189 SFNT_Init_Face,
190 SFNT_Load_Face,
191 SFNT_Done_Face,
192 SFNT_Get_Interface,
194 TT_Load_Any,
195 TT_Load_SFNT_Header,
196 TT_Load_Directory,
198 TT_Load_Header,
199 TT_Load_Metrics_Header,
200 TT_Load_CMap,
201 TT_Load_MaxProfile,
202 TT_Load_OS2,
203 TT_Load_PostScript,
205 TT_Load_Names,
206 TT_Free_Names,
208 TT_Load_Hdmx,
209 TT_Free_Hdmx,
211 TT_Load_Kern,
212 TT_Load_Gasp,
213 TT_Load_PCLT,
215 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
217 /* see `ttload.h' */
218 TT_Load_Bitmap_Header,
220 /* see `ttsbit.h' */
221 TT_Set_SBit_Strike,
222 TT_Load_SBit_Strikes,
223 TT_Load_SBit_Image,
224 TT_Free_SBit_Strikes,
226 #else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
228 0,
229 0,
230 0,
231 0,
232 0,
234 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
236 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
238 /* see `ttpost.h' */
239 TT_Get_PS_Name,
240 TT_Free_Post_Names,
242 #else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
244 0,
245 0,
247 #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
249 /* see `ttcmap.h' */
250 TT_CharMap_Load,
251 TT_CharMap_Free,
252 };
255 FT_CALLBACK_TABLE_DEF
256 const FT_Module_Class sfnt_module_class =
257 {
258 0, /* not a font driver or renderer */
259 sizeof( FT_ModuleRec ),
261 "sfnt", /* driver name */
262 0x10000L, /* driver version 1.0 */
263 0x20000L, /* driver requires FreeType 2.0 or higher */
265 (const void*)&sfnt_interface, /* module specific interface */
267 (FT_Module_Constructor)0,
268 (FT_Module_Destructor) 0,
269 (FT_Module_Requester) SFNT_Get_Interface
270 };
273 /* END */