]> git.saurik.com Git - wxWidgets.git/blob - src/freetype/type1z/z1driver.c
removed old xpm code
[wxWidgets.git] / src / freetype / type1z / z1driver.c
1 /***************************************************************************/
2 /* */
3 /* z1driver.c */
4 /* */
5 /* Experimental Type 1 driver interface (body). */
6 /* */
7 /* Copyright 1996-2000 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 #ifdef FT_FLAT_COMPILE
20
21 #include "z1driver.h"
22 #include "z1gload.h"
23 #include "z1load.h"
24 #include "z1afm.h"
25
26 #else
27
28 #include <type1z/z1driver.h>
29 #include <type1z/z1gload.h>
30 #include <type1z/z1load.h>
31 #include <type1z/z1afm.h>
32
33 #endif
34
35
36 #include <freetype/internal/ftdebug.h>
37 #include <freetype/internal/ftstream.h>
38 #include <freetype/internal/psnames.h>
39
40 #include <string.h> /* for strcmp() */
41
42
43 /*************************************************************************/
44 /* */
45 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
46 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
47 /* messages during execution. */
48 /* */
49 #undef FT_COMPONENT
50 #define FT_COMPONENT trace_z1driver
51
52
53 static
54 FT_Error get_z1_glyph_name( T1_Face face,
55 FT_UInt glyph_index,
56 FT_Pointer buffer,
57 FT_UInt buffer_max )
58 {
59 FT_String* gname;
60
61
62 gname = face->type1.glyph_names[glyph_index];
63
64 if ( buffer_max > 0 )
65 {
66 FT_UInt len = strlen( gname );
67
68
69 if (len >= buffer_max)
70 len = buffer_max - 1;
71
72 MEM_Copy( buffer, gname, len );
73 ((FT_Byte*)buffer)[len] = 0;
74 }
75
76 return T1_Err_Ok;
77 }
78
79
80 /*************************************************************************/
81 /* */
82 /* <Function> */
83 /* Get_Interface */
84 /* */
85 /* <Description> */
86 /* Each driver can provide one or more extensions to the base */
87 /* FreeType API. These can be used to access format specific */
88 /* features (e.g., all TrueType/OpenType resources share a common */
89 /* file structure and common tables which can be accessed through the */
90 /* `sfnt' interface), or more simply generic ones (e.g., the */
91 /* `postscript names' interface which can be used to retrieve the */
92 /* PostScript name of a given glyph index). */
93 /* */
94 /* <InOut> */
95 /* driver :: A handle to a driver object. */
96 /* */
97 /* <Input> */
98 /* interface :: A string designing the interface. Examples are */
99 /* `sfnt', `post_names', `charmaps', etc. */
100 /* */
101 /* <Return> */
102 /* A typeless pointer to the extension's interface (normally a table */
103 /* of function pointers). Returns NULL if the requested extension */
104 /* isn't available (i.e., wasn't compiled in the driver at build */
105 /* time). */
106 /* */
107 static
108 FT_Module_Interface Get_Interface( FT_Driver driver,
109 const FT_String* interface )
110 {
111 FT_UNUSED( driver );
112 FT_UNUSED( interface );
113
114 if ( strcmp( (const char*)interface, "glyph_name" ) == 0 )
115 return (FT_Module_Interface)get_z1_glyph_name;
116
117 #ifndef Z1_CONFIG_OPTION_NO_MM_SUPPORT
118 if ( strcmp( (const char*)interface, "get_mm" ) == 0 )
119 return (FT_Module_Interface)Z1_Get_Multi_Master;
120
121 if ( strcmp( (const char*)interface, "set_mm_design") == 0 )
122 return (FT_Module_Interface)Z1_Set_MM_Design;
123
124 if ( strcmp( (const char*)interface, "set_mm_blend") == 0 )
125 return (FT_Module_Interface)Z1_Set_MM_Blend;
126 #endif
127 return 0;
128 }
129
130
131 #ifndef Z1_CONFIG_OPTION_NO_AFM
132
133 /*************************************************************************/
134 /* */
135 /* <Function> */
136 /* Get_Kerning */
137 /* */
138 /* <Description> */
139 /* A driver method used to return the kerning vector between two */
140 /* glyphs of the same face. */
141 /* */
142 /* <Input> */
143 /* face :: A handle to the source face object. */
144 /* */
145 /* left_glyph :: The index of the left glyph in the kern pair. */
146 /* */
147 /* right_glyph :: The index of the right glyph in the kern pair. */
148 /* */
149 /* <Output> */
150 /* kerning :: The kerning vector. This is in font units for */
151 /* scalable formats, and in pixels for fixed-sizes */
152 /* formats. */
153 /* */
154 /* <Return> */
155 /* FreeType error code. 0 means success. */
156 /* */
157 /* <Note> */
158 /* Only horizontal layouts (left-to-right & right-to-left) are */
159 /* supported by this function. Other layouts, or more sophisticated */
160 /* kernings are out of scope of this method (the basic driver */
161 /* interface is meant to be simple). */
162 /* */
163 /* They can be implemented by format-specific interfaces. */
164 /* */
165 static
166 FT_Error Get_Kerning( T1_Face face,
167 FT_UInt left_glyph,
168 FT_UInt right_glyph,
169 FT_Vector* kerning )
170 {
171 Z1_AFM* afm;
172
173
174 kerning->x = 0;
175 kerning->y = 0;
176
177 afm = (Z1_AFM*)face->afm_data;
178 if ( afm )
179 Z1_Get_Kerning( afm, left_glyph, right_glyph, kerning );
180
181 return T1_Err_Ok;
182 }
183
184
185 #endif /* T1_CONFIG_OPTION_NO_AFM */
186
187
188 /*************************************************************************/
189 /* */
190 /* <Function> */
191 /* Get_Char_Index */
192 /* */
193 /* <Description> */
194 /* Uses a charmap to return a given character code's glyph index. */
195 /* */
196 /* <Input> */
197 /* charmap :: A handle to the source charmap object. */
198 /* charcode :: The character code. */
199 /* */
200 /* <Return> */
201 /* Glyph index. 0 means `undefined character code'. */
202 /* */
203 static
204 FT_UInt Get_Char_Index( FT_CharMap charmap,
205 FT_Long charcode )
206 {
207 T1_Face face;
208 FT_UInt result = 0;
209 PSNames_Interface* psnames;
210
211
212 face = (T1_Face)charmap->face;
213 psnames = (PSNames_Interface*)face->psnames;
214 if ( psnames )
215 switch ( charmap->encoding )
216 {
217 /*******************************************************************/
218 /* */
219 /* Unicode encoding support */
220 /* */
221 case ft_encoding_unicode:
222 /* use the `PSNames' module to synthetize the Unicode charmap */
223 result = psnames->lookup_unicode( &face->unicode_map,
224 (FT_ULong)charcode );
225
226 /* the function returns 0xFFFF if the Unicode charcode has */
227 /* no corresponding glyph */
228 if ( result == 0xFFFF )
229 result = 0;
230 goto Exit;
231
232 /*******************************************************************/
233 /* */
234 /* Custom Type 1 encoding */
235 /* */
236 case ft_encoding_adobe_custom:
237 {
238 T1_Encoding* encoding = &face->type1.encoding;
239
240
241 if ( charcode >= encoding->code_first &&
242 charcode <= encoding->code_last )
243 result = encoding->char_index[charcode];
244 goto Exit;
245 }
246
247 /*******************************************************************/
248 /* */
249 /* Adobe Standard & Expert encoding support */
250 /* */
251 default:
252 if ( charcode < 256 )
253 {
254 FT_UInt code;
255 FT_Int n;
256 const char* glyph_name;
257
258
259 code = psnames->adobe_std_encoding[charcode];
260 if ( charmap->encoding == ft_encoding_adobe_expert )
261 code = psnames->adobe_expert_encoding[charcode];
262
263 glyph_name = psnames->adobe_std_strings( code );
264 if ( !glyph_name )
265 break;
266
267 for ( n = 0; n < face->type1.num_glyphs; n++ )
268 {
269 const char* gname = face->type1.glyph_names[n];
270
271
272 if ( gname && gname[0] == glyph_name[0] &&
273 strcmp( gname, glyph_name ) == 0 )
274 {
275 result = n;
276 break;
277 }
278 }
279 }
280 }
281 Exit:
282 return result;
283 }
284
285
286 const FT_Driver_Class t1_driver_class =
287 {
288 {
289 ft_module_font_driver | ft_module_driver_scalable,
290 sizeof( FT_DriverRec ),
291
292 "type1",
293 0x10000L,
294 0x20000L,
295
296 0, /* format interface */
297
298 (FT_Module_Constructor)Z1_Init_Driver,
299 (FT_Module_Destructor) Z1_Done_Driver,
300 (FT_Module_Requester) Get_Interface,
301 },
302
303 sizeof( T1_FaceRec ),
304 sizeof( Z1_SizeRec ),
305 sizeof( Z1_GlyphSlotRec ),
306
307 (FTDriver_initFace) Z1_Init_Face,
308 (FTDriver_doneFace) Z1_Done_Face,
309 (FTDriver_initSize) 0,
310 (FTDriver_doneSize) 0,
311 (FTDriver_initGlyphSlot)0,
312 (FTDriver_doneGlyphSlot)0,
313
314 (FTDriver_setCharSizes) 0,
315 (FTDriver_setPixelSizes)0,
316 (FTDriver_loadGlyph) Z1_Load_Glyph,
317 (FTDriver_getCharIndex) Get_Char_Index,
318
319 #ifdef Z1_CONFIG_OPTION_NO_AFM
320 (FTDriver_getKerning) 0,
321 (FTDriver_attachFile) 0,
322 #else
323 (FTDriver_getKerning) Get_Kerning,
324 (FTDriver_attachFile) Z1_Read_AFM,
325 #endif
326 (FTDriver_getAdvances) 0
327 };
328
329
330 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
331
332 EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void )
333 {
334 return &t1z_driver_class;
335 }
336
337 #endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */
338
339
340 /* END */