1 /***************************************************************************/ |
|
2 /* */ |
|
3 /* t1driver.c */ |
|
4 /* */ |
|
5 /* Type 1 driver interface (body). */ |
|
6 /* */ |
|
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007, 2009 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 "t1driver.h" |
|
21 #include "t1gload.h" |
|
22 #include "t1load.h" |
|
23 |
|
24 #include "t1errors.h" |
|
25 |
|
26 #ifndef T1_CONFIG_OPTION_NO_AFM |
|
27 #include "t1afm.h" |
|
28 #endif |
|
29 |
|
30 #include FT_INTERNAL_DEBUG_H |
|
31 #include FT_INTERNAL_STREAM_H |
|
32 |
|
33 #include FT_SERVICE_MULTIPLE_MASTERS_H |
|
34 #include FT_SERVICE_GLYPH_DICT_H |
|
35 #include FT_SERVICE_XFREE86_NAME_H |
|
36 #include FT_SERVICE_POSTSCRIPT_NAME_H |
|
37 #include FT_SERVICE_POSTSCRIPT_CMAPS_H |
|
38 #include FT_SERVICE_POSTSCRIPT_INFO_H |
|
39 #include FT_SERVICE_KERNING_H |
|
40 |
|
41 |
|
42 /*************************************************************************/ |
|
43 /* */ |
|
44 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
|
45 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
|
46 /* messages during execution. */ |
|
47 /* */ |
|
48 #undef FT_COMPONENT |
|
49 #define FT_COMPONENT trace_t1driver |
|
50 |
|
51 /* |
|
52 * GLYPH DICT SERVICE |
|
53 * |
|
54 */ |
|
55 |
|
56 static FT_Error |
|
57 t1_get_glyph_name( T1_Face face, |
|
58 FT_UInt glyph_index, |
|
59 FT_Pointer buffer, |
|
60 FT_UInt buffer_max ) |
|
61 { |
|
62 FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max ); |
|
63 |
|
64 return T1_Err_Ok; |
|
65 } |
|
66 |
|
67 |
|
68 static FT_UInt |
|
69 t1_get_name_index( T1_Face face, |
|
70 FT_String* glyph_name ) |
|
71 { |
|
72 FT_Int i; |
|
73 FT_String* gname; |
|
74 |
|
75 |
|
76 for ( i = 0; i < face->type1.num_glyphs; i++ ) |
|
77 { |
|
78 gname = face->type1.glyph_names[i]; |
|
79 |
|
80 if ( !ft_strcmp( glyph_name, gname ) ) |
|
81 return (FT_UInt)i; |
|
82 } |
|
83 |
|
84 return 0; |
|
85 } |
|
86 |
|
87 |
|
88 static const FT_Service_GlyphDictRec t1_service_glyph_dict = |
|
89 { |
|
90 (FT_GlyphDict_GetNameFunc) t1_get_glyph_name, |
|
91 (FT_GlyphDict_NameIndexFunc)t1_get_name_index |
|
92 }; |
|
93 |
|
94 |
|
95 /* |
|
96 * POSTSCRIPT NAME SERVICE |
|
97 * |
|
98 */ |
|
99 |
|
100 static const char* |
|
101 t1_get_ps_name( T1_Face face ) |
|
102 { |
|
103 return (const char*) face->type1.font_name; |
|
104 } |
|
105 |
|
106 |
|
107 static const FT_Service_PsFontNameRec t1_service_ps_name = |
|
108 { |
|
109 (FT_PsName_GetFunc)t1_get_ps_name |
|
110 }; |
|
111 |
|
112 |
|
113 /* |
|
114 * MULTIPLE MASTERS SERVICE |
|
115 * |
|
116 */ |
|
117 |
|
118 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
|
119 static const FT_Service_MultiMastersRec t1_service_multi_masters = |
|
120 { |
|
121 (FT_Get_MM_Func) T1_Get_Multi_Master, |
|
122 (FT_Set_MM_Design_Func) T1_Set_MM_Design, |
|
123 (FT_Set_MM_Blend_Func) T1_Set_MM_Blend, |
|
124 (FT_Get_MM_Var_Func) T1_Get_MM_Var, |
|
125 (FT_Set_Var_Design_Func)T1_Set_Var_Design |
|
126 }; |
|
127 #endif |
|
128 |
|
129 |
|
130 /* |
|
131 * POSTSCRIPT INFO SERVICE |
|
132 * |
|
133 */ |
|
134 |
|
135 static FT_Error |
|
136 t1_ps_get_font_info( FT_Face face, |
|
137 PS_FontInfoRec* afont_info ) |
|
138 { |
|
139 *afont_info = ((T1_Face)face)->type1.font_info; |
|
140 |
|
141 return T1_Err_Ok; |
|
142 } |
|
143 |
|
144 |
|
145 static FT_Error |
|
146 t1_ps_get_font_extra( FT_Face face, |
|
147 PS_FontExtraRec* afont_extra ) |
|
148 { |
|
149 *afont_extra = ((T1_Face)face)->type1.font_extra; |
|
150 |
|
151 return T1_Err_Ok; |
|
152 } |
|
153 |
|
154 |
|
155 static FT_Int |
|
156 t1_ps_has_glyph_names( FT_Face face ) |
|
157 { |
|
158 FT_UNUSED( face ); |
|
159 |
|
160 return 1; |
|
161 } |
|
162 |
|
163 |
|
164 static FT_Error |
|
165 t1_ps_get_font_private( FT_Face face, |
|
166 PS_PrivateRec* afont_private ) |
|
167 { |
|
168 *afont_private = ((T1_Face)face)->type1.private_dict; |
|
169 |
|
170 return T1_Err_Ok; |
|
171 } |
|
172 |
|
173 |
|
174 static const FT_Service_PsInfoRec t1_service_ps_info = |
|
175 { |
|
176 (PS_GetFontInfoFunc) t1_ps_get_font_info, |
|
177 (PS_GetFontExtraFunc) t1_ps_get_font_extra, |
|
178 (PS_HasGlyphNamesFunc) t1_ps_has_glyph_names, |
|
179 (PS_GetFontPrivateFunc)t1_ps_get_font_private, |
|
180 }; |
|
181 |
|
182 |
|
183 #ifndef T1_CONFIG_OPTION_NO_AFM |
|
184 static const FT_Service_KerningRec t1_service_kerning = |
|
185 { |
|
186 T1_Get_Track_Kerning, |
|
187 }; |
|
188 #endif |
|
189 |
|
190 |
|
191 /* |
|
192 * SERVICE LIST |
|
193 * |
|
194 */ |
|
195 |
|
196 static const FT_ServiceDescRec t1_services[] = |
|
197 { |
|
198 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &t1_service_ps_name }, |
|
199 { FT_SERVICE_ID_GLYPH_DICT, &t1_service_glyph_dict }, |
|
200 { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TYPE_1 }, |
|
201 { FT_SERVICE_ID_POSTSCRIPT_INFO, &t1_service_ps_info }, |
|
202 |
|
203 #ifndef T1_CONFIG_OPTION_NO_AFM |
|
204 { FT_SERVICE_ID_KERNING, &t1_service_kerning }, |
|
205 #endif |
|
206 |
|
207 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
|
208 { FT_SERVICE_ID_MULTI_MASTERS, &t1_service_multi_masters }, |
|
209 #endif |
|
210 { NULL, NULL } |
|
211 }; |
|
212 |
|
213 |
|
214 static FT_Module_Interface |
|
215 Get_Interface( FT_Driver driver, |
|
216 const FT_String* t1_interface ) |
|
217 { |
|
218 FT_UNUSED( driver ); |
|
219 |
|
220 return ft_service_list_lookup( t1_services, t1_interface ); |
|
221 } |
|
222 |
|
223 |
|
224 #ifndef T1_CONFIG_OPTION_NO_AFM |
|
225 |
|
226 /*************************************************************************/ |
|
227 /* */ |
|
228 /* <Function> */ |
|
229 /* Get_Kerning */ |
|
230 /* */ |
|
231 /* <Description> */ |
|
232 /* A driver method used to return the kerning vector between two */ |
|
233 /* glyphs of the same face. */ |
|
234 /* */ |
|
235 /* <Input> */ |
|
236 /* face :: A handle to the source face object. */ |
|
237 /* */ |
|
238 /* left_glyph :: The index of the left glyph in the kern pair. */ |
|
239 /* */ |
|
240 /* right_glyph :: The index of the right glyph in the kern pair. */ |
|
241 /* */ |
|
242 /* <Output> */ |
|
243 /* kerning :: The kerning vector. This is in font units for */ |
|
244 /* scalable formats, and in pixels for fixed-sizes */ |
|
245 /* formats. */ |
|
246 /* */ |
|
247 /* <Return> */ |
|
248 /* FreeType error code. 0 means success. */ |
|
249 /* */ |
|
250 /* <Note> */ |
|
251 /* Only horizontal layouts (left-to-right & right-to-left) are */ |
|
252 /* supported by this function. Other layouts, or more sophisticated */ |
|
253 /* kernings are out of scope of this method (the basic driver */ |
|
254 /* interface is meant to be simple). */ |
|
255 /* */ |
|
256 /* They can be implemented by format-specific interfaces. */ |
|
257 /* */ |
|
258 static FT_Error |
|
259 Get_Kerning( T1_Face face, |
|
260 FT_UInt left_glyph, |
|
261 FT_UInt right_glyph, |
|
262 FT_Vector* kerning ) |
|
263 { |
|
264 kerning->x = 0; |
|
265 kerning->y = 0; |
|
266 |
|
267 if ( face->afm_data ) |
|
268 T1_Get_Kerning( (AFM_FontInfo)face->afm_data, |
|
269 left_glyph, |
|
270 right_glyph, |
|
271 kerning ); |
|
272 |
|
273 return T1_Err_Ok; |
|
274 } |
|
275 |
|
276 |
|
277 #endif /* T1_CONFIG_OPTION_NO_AFM */ |
|
278 |
|
279 |
|
280 FT_CALLBACK_TABLE_DEF |
|
281 const FT_Driver_ClassRec t1_driver_class = |
|
282 { |
|
283 { |
|
284 FT_MODULE_FONT_DRIVER | |
|
285 FT_MODULE_DRIVER_SCALABLE | |
|
286 FT_MODULE_DRIVER_HAS_HINTER, |
|
287 |
|
288 sizeof( FT_DriverRec ), |
|
289 |
|
290 "type1", |
|
291 0x10000L, |
|
292 0x20000L, |
|
293 |
|
294 0, /* format interface */ |
|
295 |
|
296 (FT_Module_Constructor)T1_Driver_Init, |
|
297 (FT_Module_Destructor) T1_Driver_Done, |
|
298 (FT_Module_Requester) Get_Interface, |
|
299 }, |
|
300 |
|
301 sizeof( T1_FaceRec ), |
|
302 sizeof( T1_SizeRec ), |
|
303 sizeof( T1_GlyphSlotRec ), |
|
304 |
|
305 (FT_Face_InitFunc) T1_Face_Init, |
|
306 (FT_Face_DoneFunc) T1_Face_Done, |
|
307 (FT_Size_InitFunc) T1_Size_Init, |
|
308 (FT_Size_DoneFunc) T1_Size_Done, |
|
309 (FT_Slot_InitFunc) T1_GlyphSlot_Init, |
|
310 (FT_Slot_DoneFunc) T1_GlyphSlot_Done, |
|
311 |
|
312 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS |
|
313 ft_stub_set_char_sizes, |
|
314 ft_stub_set_pixel_sizes, |
|
315 #endif |
|
316 (FT_Slot_LoadFunc) T1_Load_Glyph, |
|
317 |
|
318 #ifdef T1_CONFIG_OPTION_NO_AFM |
|
319 (FT_Face_GetKerningFunc) 0, |
|
320 (FT_Face_AttachFunc) 0, |
|
321 #else |
|
322 (FT_Face_GetKerningFunc) Get_Kerning, |
|
323 (FT_Face_AttachFunc) T1_Read_Metrics, |
|
324 #endif |
|
325 (FT_Face_GetAdvancesFunc) T1_Get_Advances, |
|
326 (FT_Size_RequestFunc) T1_Size_Request, |
|
327 (FT_Size_SelectFunc) 0 |
|
328 }; |
|
329 |
|
330 |
|
331 /* END */ |
|