The BIG graph update
[rrdtool.git] / libraries / freetype-2.0.5 / sfdriver.c
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 /***************************************************************************/
17
18
19 #include <ft2build.h>
20 #include FT_INTERNAL_SFNT_H
21 #include FT_INTERNAL_OBJECTS_H
22
23 #include "sfdriver.h"
24 #include "ttload.h"
25 #include "ttcmap.h"
26 #include "sfobjs.h"
27
28 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
29 #include "ttsbit.h"
30 #endif
31
32 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
33 #include "ttpost.h"
34 #endif
35
36 #include <string.h>     /* for strcmp() */
37
38
39   static void*
40   get_sfnt_table( TT_Face      face,
41                   FT_Sfnt_Tag  tag )
42   {
43     void*  table;
44
45
46     switch ( tag )
47     {
48     case ft_sfnt_head:
49       table = &face->header;
50       break;
51
52     case ft_sfnt_hhea:
53       table = &face->horizontal;
54       break;
55
56     case ft_sfnt_vhea:
57       table = face->vertical_info ? &face->vertical : 0;
58       break;
59
60     case ft_sfnt_os2:
61       table = face->os2.version == 0xFFFF ? 0 : &face->os2;
62       break;
63
64     case ft_sfnt_post:
65       table = &face->postscript;
66       break;
67
68     case ft_sfnt_maxp:
69       table = &face->max_profile;
70       break;
71
72     case ft_sfnt_pclt:
73       table = face->pclt.Version ? &face->pclt : 0;
74       break;
75
76     default:
77       table = 0;
78     }
79
80     return table;
81   }
82
83
84 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
85
86
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;
95
96
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 ) );
101
102
103       if ( len >= buffer_max )
104         len = buffer_max - 1;
105
106       MEM_Copy( buffer, gname, len );
107       ((FT_Byte*)buffer)[len] = 0;
108     }
109
110     return error;
111   }
112
113
114   static const char*
115   get_sfnt_postscript_name( TT_Face  face )
116   {
117     FT_Int  n;
118
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;
122
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;
128       
129       if ( name->nameID == 6 )
130       {
131         if ( ( name->platformID == 3 &&
132                name->encodingID == 1 &&
133                name->languageID == 0x409 ) ||
134                
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;
143           
144           if ( !ALLOC( result, len+1 ) )
145           {
146             memcpy( result, name->string, len );
147             result[len] = '\0';
148             
149             face->root.internal->postscript_name = result;
150           }
151           return result;
152         }
153       }
154     }
155     
156     return NULL;
157   }
158
159
160 #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
161
162
163   FT_CALLBACK_DEF( FT_Module_Interface )
164   SFNT_Get_Interface( FT_Module    module,
165                       const char*  interface )
166   {
167     FT_UNUSED( module );
168
169     if ( strcmp( interface, "get_sfnt" ) == 0 )
170       return (FT_Module_Interface)get_sfnt_table;
171
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
176
177     if ( strcmp( interface, "postscript_name" ) == 0 )
178       return (FT_Module_Interface)get_sfnt_postscript_name;
179
180     return 0;
181   }
182
183
184   static
185   const SFNT_Interface  sfnt_interface =
186   {
187     TT_Goto_Table,
188
189     SFNT_Init_Face,
190     SFNT_Load_Face,
191     SFNT_Done_Face,
192     SFNT_Get_Interface,
193
194     TT_Load_Any,
195     TT_Load_SFNT_Header,
196     TT_Load_Directory,
197
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,
204
205     TT_Load_Names,
206     TT_Free_Names,
207
208     TT_Load_Hdmx,
209     TT_Free_Hdmx,
210
211     TT_Load_Kern,
212     TT_Load_Gasp,
213     TT_Load_PCLT,
214
215 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
216
217     /* see `ttload.h' */
218     TT_Load_Bitmap_Header,
219
220     /* see `ttsbit.h' */
221     TT_Set_SBit_Strike,
222     TT_Load_SBit_Strikes,
223     TT_Load_SBit_Image,
224     TT_Free_SBit_Strikes,
225
226 #else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
227
228     0,
229     0,
230     0,
231     0,
232     0,
233
234 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
235
236 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
237
238     /* see `ttpost.h' */
239     TT_Get_PS_Name,
240     TT_Free_Post_Names,
241
242 #else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
243
244     0,
245     0,
246
247 #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
248
249     /* see `ttcmap.h' */
250     TT_CharMap_Load,
251     TT_CharMap_Free,
252   };
253
254
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 ),
260
261     "sfnt",     /* driver name                            */
262     0x10000L,   /* driver version 1.0                     */
263     0x20000L,   /* driver requires FreeType 2.0 or higher */
264
265     (const void*)&sfnt_interface,  /* module specific interface */
266
267     (FT_Module_Constructor)0,
268     (FT_Module_Destructor) 0,
269     (FT_Module_Requester)  SFNT_Get_Interface
270   };
271
272
273 /* END */