]> git.saurik.com Git - wxWidgets.git/blob - src/freetype/type1/t1driver.c
Added FreeType II beta 8.
[wxWidgets.git] / src / freetype / type1 / t1driver.c
1 /***************************************************************************/
2 /* */
3 /* t1driver.c */
4 /* */
5 /* 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 "t1driver.h"
22 #include "t1gload.h"
23 #include "t1afm.h"
24
25 #else
26
27 #include <type1/t1driver.h>
28 #include <type1/t1gload.h>
29 #include <type1/t1afm.h>
30
31 #endif
32
33
34 #include <freetype/internal/ftdebug.h>
35 #include <freetype/internal/ftstream.h>
36 #include <freetype/internal/psnames.h>
37
38 #include <string.h> /* for strcmp() */
39
40
41 /*************************************************************************/
42 /* */
43 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
44 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
45 /* messages during execution. */
46 /* */
47 #undef FT_COMPONENT
48 #define FT_COMPONENT trace_t1driver
49
50
51 #ifndef T1_CONFIG_OPTION_NO_AFM
52
53
54 /*************************************************************************/
55 /* */
56 /* <Function> */
57 /* Get_Kerning */
58 /* */
59 /* <Description> */
60 /* A driver method used to return the kerning vector between two */
61 /* glyphs of the same face. */
62 /* */
63 /* <Input> */
64 /* face :: A handle to the source face object. */
65 /* */
66 /* left_glyph :: The index of the left glyph in the kern pair. */
67 /* */
68 /* right_glyph :: The index of the right glyph in the kern pair. */
69 /* */
70 /* <Output> */
71 /* kerning :: The kerning vector. This is in font units for */
72 /* scalable formats, and in pixels for fixed-sizes */
73 /* formats. */
74 /* */
75 /* <Return> */
76 /* FreeType error code. 0 means success. */
77 /* */
78 /* <Note> */
79 /* Only horizontal layouts (left-to-right & right-to-left) are */
80 /* supported by this function. Other layouts, or more sophisticated */
81 /* kernings are out of scope of this method (the basic driver */
82 /* interface is meant to be simple). */
83 /* */
84 /* They can be implemented by format-specific interfaces. */
85 /* */
86 static
87 FT_Error Get_Kerning( T1_Face face,
88 FT_UInt left_glyph,
89 FT_UInt right_glyph,
90 FT_Vector* kerning )
91 {
92 T1_AFM* afm;
93
94
95 kerning->x = 0;
96 kerning->y = 0;
97
98 afm = (T1_AFM*)face->afm_data;
99 if ( afm )
100 T1_Get_Kerning( afm, left_glyph, right_glyph, kerning );
101
102 return T1_Err_Ok;
103 }
104
105
106 #endif /* T1_CONFIG_OPTION_NO_AFM */
107
108
109 static
110 FT_Error get_t1_glyph_name( T1_Face face,
111 FT_UInt glyph_index,
112 FT_Pointer buffer,
113 FT_UInt buffer_max )
114 {
115 FT_String* gname;
116
117
118 gname = face->type1.glyph_names[glyph_index];
119
120 if ( buffer_max > 0 )
121 {
122 FT_UInt len = strlen( gname );
123
124
125 if ( len >= buffer_max )
126 len = buffer_max - 1;
127
128 MEM_Copy( buffer, gname, len );
129 ((FT_Byte*)buffer)[len] = 0;
130 }
131
132 return T1_Err_Ok;
133 }
134
135
136 static
137 FT_Module_Interface T1_Get_Interface( FT_Module module,
138 const char* interface )
139 {
140 FT_UNUSED( module );
141
142 if ( strcmp( interface, "glyph_name" ) == 0 )
143 return (FT_Module_Interface)get_t1_glyph_name;
144
145 return 0;
146 }
147
148
149
150 /*************************************************************************/
151 /* */
152 /* <Function> */
153 /* Set_Char_Sizes */
154 /* */
155 /* <Description> */
156 /* A driver method used to reset a size's character sizes (horizontal */
157 /* and vertical) expressed in fractional points. */
158 /* */
159 /* <Input> */
160 /* char_width :: The character width expressed in 26.6 */
161 /* fractional points. */
162 /* */
163 /* char_height :: The character height expressed in 26.6 */
164 /* fractional points. */
165 /* */
166 /* horz_resolution :: The horizontal resolution of the output device. */
167 /* */
168 /* vert_resolution :: The vertical resolution of the output device. */
169 /* */
170 /* <InOut> */
171 /* size :: A handle to the target size object. */
172 /* */
173 /* <Return> */
174 /* FreeType error code. 0 means success. */
175 /* */
176 static
177 FT_Error Set_Char_Sizes( T1_Size size,
178 FT_F26Dot6 char_width,
179 FT_F26Dot6 char_height,
180 FT_UInt horz_resolution,
181 FT_UInt vert_resolution )
182 {
183 FT_UNUSED( char_width );
184 FT_UNUSED( char_height );
185 FT_UNUSED( horz_resolution );
186 FT_UNUSED( vert_resolution );
187
188 size->valid = FALSE;
189
190 return T1_Reset_Size( size );
191 }
192
193
194 /*************************************************************************/
195 /* */
196 /* <Function> */
197 /* Set_Pixel_Sizes */
198 /* */
199 /* <Description> */
200 /* A driver method used to reset a size's character sizes (horizontal */
201 /* and vertical) expressed in integer pixels. */
202 /* */
203 /* <Input> */
204 /* pixel_width :: The character width expressed in integer pixels. */
205 /* */
206 /* pixel_height :: The character height expressed in integer pixels. */
207 /* */
208 /* <InOut> */
209 /* size :: A handle to the target size object. */
210 /* */
211 /* <Return> */
212 /* FreeType error code. 0 means success. */
213 /* */
214 static
215 FT_Error Set_Pixel_Sizes( T1_Size size,
216 FT_Int pixel_width,
217 FT_Int pixel_height )
218 {
219 FT_UNUSED( pixel_width );
220 FT_UNUSED( pixel_height );
221
222 size->valid = FALSE;
223
224 return T1_Reset_Size( size );
225 }
226
227
228 /*************************************************************************/
229 /* */
230 /* <Function> */
231 /* Get_Char_Index */
232 /* */
233 /* <Description> */
234 /* Uses a charmap to return a given character code's glyph index. */
235 /* */
236 /* <Input> */
237 /* charmap :: A handle to the source charmap object. */
238 /* charcode :: The character code. */
239 /* */
240 /* <Return> */
241 /* Glyph index. 0 means `undefined character code'. */
242 /* */
243 static
244 FT_UInt Get_Char_Index( FT_CharMap charmap,
245 FT_Long charcode )
246 {
247 T1_Face face;
248 FT_UInt result = 0;
249 PSNames_Interface* psnames;
250
251
252 face = (T1_Face)charmap->face;
253 psnames = (PSNames_Interface*)face->psnames;
254 if ( psnames )
255 switch ( charmap->encoding )
256 {
257 /*******************************************************************/
258 /* */
259 /* Unicode encoding support */
260 /* */
261 case ft_encoding_unicode:
262 /* use the `PSNames' module to synthetize the Unicode charmap */
263 result = psnames->lookup_unicode( &face->unicode_map,
264 (FT_ULong)charcode );
265
266 /* the function returns 0xFFFF if the Unicode charcode has */
267 /* no corresponding glyph */
268 if ( result == 0xFFFF )
269 result = 0;
270 goto Exit;
271
272 /*******************************************************************/
273 /* */
274 /* Custom Type 1 encoding */
275 /* */
276 case ft_encoding_adobe_custom:
277 {
278 T1_Encoding* encoding = &face->type1.encoding;
279
280
281 if ( charcode >= encoding->code_first &&
282 charcode <= encoding->code_last )
283 result = encoding->char_index[charcode];
284 goto Exit;
285 }
286
287 /*******************************************************************/
288 /* */
289 /* Adobe Standard & Expert encoding support */
290 /* */
291 default:
292 if ( charcode < 256 )
293 {
294 FT_UInt code;
295 FT_Int n;
296 const char* glyph_name;
297
298
299 code = psnames->adobe_std_encoding[charcode];
300 if ( charmap->encoding == ft_encoding_adobe_expert )
301 code = psnames->adobe_expert_encoding[charcode];
302
303 glyph_name = psnames->adobe_std_strings( code );
304 if ( !glyph_name )
305 break;
306
307 for ( n = 0; n < face->type1.num_glyphs; n++ )
308 {
309 const char* gname = face->type1.glyph_names[n];
310
311
312 if ( gname && gname[0] == glyph_name[0] &&
313 strcmp( gname, glyph_name ) == 0 )
314 {
315 result = n;
316 break;
317 }
318 }
319 }
320 }
321 Exit:
322 return result;
323 }
324
325
326
327 const FT_Driver_Class t1_driver_class =
328 {
329 {
330 ft_module_font_driver | ft_module_driver_scalable,
331 sizeof( FT_DriverRec ),
332
333 "type1", /* driver name */
334 0x10000L, /* driver version 1.0 */
335 0x20000L, /* driver requires FreeType 2.0 or above */
336
337 0, /* module specific interface */
338
339 (FT_Module_Constructor)0,
340 (FT_Module_Destructor) 0,
341 (FT_Module_Requester) T1_Get_Interface
342 },
343
344 sizeof( T1_FaceRec ),
345 sizeof( T1_SizeRec ),
346 sizeof( T1_GlyphSlotRec ),
347
348 (FTDriver_initFace) T1_Init_Face,
349 (FTDriver_doneFace) T1_Done_Face,
350 (FTDriver_initSize) T1_Init_Size,
351 (FTDriver_doneSize) T1_Done_Size,
352 (FTDriver_initGlyphSlot)T1_Init_GlyphSlot,
353 (FTDriver_doneGlyphSlot)T1_Done_GlyphSlot,
354
355 (FTDriver_setCharSizes) Set_Char_Sizes,
356 (FTDriver_setPixelSizes)Set_Pixel_Sizes,
357 (FTDriver_loadGlyph) T1_Load_Glyph,
358 (FTDriver_getCharIndex) Get_Char_Index,
359
360 #ifdef T1_CONFIG_OPTION_NO_AFM
361 (FTDriver_getKerning) 0,
362 (FTDriver_attachFile) 0,
363 #else
364 (FTDriver_getKerning) Get_Kerning,
365 (FTDriver_attachFile) T1_Read_AFM,
366 #endif
367 (FTDriver_getAdvances) 0
368 };
369
370
371 #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
372
373 EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void )
374 {
375 return &t1_driver_class;
376 }
377
378 #endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */
379
380
381 /* END */