blob: 82eb0ba1e0a835f9ea879fa939c208ec332dec8a [file] [log] [blame]
Werner Lemberg8c90c222002-06-08 06:47:18 +00001/***************************************************************************/
2/* */
3/* t42drivr.c */
4/* */
5/* High-level Type 42 driver interface (body). */
6/* */
Werner Lembergf1c2b912006-01-13 14:53:28 +00007/* Copyright 2002, 2003, 2004, 2006 by Roberto Alameda. */
Werner Lemberg8c90c222002-06-08 06:47:18 +00008/* */
9/* This file is part of the FreeType project, and may only be used, */
10/* modified, and distributed under the terms of the FreeType project */
11/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
12/* this file you indicate that you have read the license and */
13/* understand and accept it fully. */
14/* */
15/***************************************************************************/
16
17
Werner Lemberg0657a8a2002-06-19 19:43:15 +000018 /*************************************************************************/
19 /* */
20 /* This driver implements Type42 fonts as described in the */
21 /* Technical Note #5012 from Adobe, with these limitations: */
22 /* */
23 /* 1) CID Fonts are not currently supported. */
24 /* 2) Incremental fonts making use of the GlyphDirectory keyword */
25 /* will be loaded, but the rendering will be using the TrueType */
26 /* tables. */
Werner Lemberge3f41982003-10-16 15:48:39 +000027 /* 3) As for Type1 fonts, CDevProc is not supported. */
28 /* 4) The Metrics dictionary is not supported. */
29 /* 5) AFM metrics are not supported. */
Werner Lemberg0657a8a2002-06-19 19:43:15 +000030 /* */
31 /* In other words, this driver supports Type42 fonts derived from */
32 /* TrueType fonts in a non-CID manner, as done by usual conversion */
33 /* programs. */
34 /* */
35 /*************************************************************************/
36
37
David Turner9f95bab2002-06-07 07:23:06 +000038#include "t42drivr.h"
39#include "t42objs.h"
Werner Lemberg8c90c222002-06-08 06:47:18 +000040#include "t42error.h"
Werner Lemberg347a7142002-05-15 06:16:57 +000041#include FT_INTERNAL_DEBUG_H
Werner Lemberg347a7142002-05-15 06:16:57 +000042
David Turnerc313c502003-09-11 19:51:54 +000043#include FT_SERVICE_XFREE86_NAME_H
44#include FT_SERVICE_GLYPH_DICT_H
45#include FT_SERVICE_POSTSCRIPT_NAME_H
David Turner77605952003-10-29 21:43:52 +000046#include FT_SERVICE_POSTSCRIPT_INFO_H
Werner Lemberg8c90c222002-06-08 06:47:18 +000047
Werner Lemberg7cf4d372002-05-21 14:13:01 +000048#undef FT_COMPONENT
49#define FT_COMPONENT trace_t42
50
Werner Lemberg8c90c222002-06-08 06:47:18 +000051
David Turnerc313c502003-09-11 19:51:54 +000052 /*
53 *
54 * GLYPH DICT SERVICE
55 *
56 */
David Turnerb72d8a82003-09-29 20:33:37 +000057
Werner Lemberg347a7142002-05-15 06:16:57 +000058 static FT_Error
59 t42_get_glyph_name( T42_Face face,
60 FT_UInt glyph_index,
61 FT_Pointer buffer,
62 FT_UInt buffer_max )
63 {
64 FT_String* gname;
65
66
David Turner9f95bab2002-06-07 07:23:06 +000067 gname = face->type1.glyph_names[glyph_index];
Werner Lemberg347a7142002-05-15 06:16:57 +000068
69 if ( buffer_max > 0 )
70 {
71 FT_UInt len = (FT_UInt)( ft_strlen( gname ) );
72
David Turner3e19d852002-07-17 21:52:20 +000073
Werner Lemberg347a7142002-05-15 06:16:57 +000074 if ( len >= buffer_max )
75 len = buffer_max - 1;
David Turner3e19d852002-07-17 21:52:20 +000076
Werner Lemberg347a7142002-05-15 06:16:57 +000077 FT_MEM_COPY( buffer, gname, len );
78 ((FT_Byte*)buffer)[len] = 0;
79 }
80
Werner Lemberg8c90c222002-06-08 06:47:18 +000081 return T42_Err_Ok;
Werner Lemberg347a7142002-05-15 06:16:57 +000082 }
83
84
Werner Lemberg347a7142002-05-15 06:16:57 +000085 static FT_UInt
86 t42_get_name_index( T42_Face face,
87 FT_String* glyph_name )
88 {
89 FT_Int i;
90 FT_String* gname;
91
92
David Turner9f95bab2002-06-07 07:23:06 +000093 for ( i = 0; i < face->type1.num_glyphs; i++ )
Werner Lemberg347a7142002-05-15 06:16:57 +000094 {
David Turner9f95bab2002-06-07 07:23:06 +000095 gname = face->type1.glyph_names[i];
Werner Lemberg347a7142002-05-15 06:16:57 +000096
97 if ( !ft_strcmp( glyph_name, gname ) )
Werner Lembergef512e32004-01-23 19:52:40 +000098 return (FT_UInt)ft_atol( (const char *)face->type1.charstrings[i] );
Werner Lemberg347a7142002-05-15 06:16:57 +000099 }
100
101 return 0;
102 }
103
104
David Turner10bf05a2004-04-21 14:30:37 +0000105 static const FT_Service_GlyphDictRec t42_service_glyph_dict =
David Turnerc313c502003-09-11 19:51:54 +0000106 {
Werner Lemberg013efd12003-09-17 05:26:33 +0000107 (FT_GlyphDict_GetNameFunc) t42_get_glyph_name,
108 (FT_GlyphDict_NameIndexFunc)t42_get_name_index
David Turnerc313c502003-09-11 19:51:54 +0000109 };
110
111
112 /*
113 *
114 * POSTSCRIPT NAME SERVICE
115 *
116 */
117
118 static const char*
David Turnerb72d8a82003-09-29 20:33:37 +0000119 t42_get_ps_font_name( T42_Face face )
David Turnerc313c502003-09-11 19:51:54 +0000120 {
121 return (const char*)face->type1.font_name;
122 }
123
124
David Turner10bf05a2004-04-21 14:30:37 +0000125 static const FT_Service_PsFontNameRec t42_service_ps_font_name =
David Turnerc313c502003-09-11 19:51:54 +0000126 {
David Turnerb72d8a82003-09-29 20:33:37 +0000127 (FT_PsName_GetFunc)t42_get_ps_font_name
David Turnerc313c502003-09-11 19:51:54 +0000128 };
129
130
131 /*
Werner Lemberg40bb0962003-11-01 14:36:20 +0000132 *
David Turner77605952003-10-29 21:43:52 +0000133 * POSTSCRIPT INFO SERVICE
134 *
135 */
136
137 static FT_Error
138 t42_ps_get_font_info( FT_Face face,
139 PS_FontInfoRec* afont_info )
140 {
141 *afont_info = ((T42_Face)face)->type1.font_info;
Werner Lemberg3605e472004-11-12 07:02:45 +0000142 return T42_Err_Ok;
David Turner77605952003-10-29 21:43:52 +0000143 }
144
Werner Lemberg40bb0962003-11-01 14:36:20 +0000145
David Turner77605952003-10-29 21:43:52 +0000146 static FT_Int
147 t42_ps_has_glyph_names( FT_Face face )
148 {
149 FT_UNUSED( face );
150 return 1;
151 }
152
Werner Lemberg40bb0962003-11-01 14:36:20 +0000153
Werner Lemberg3605e472004-11-12 07:02:45 +0000154 static FT_Error
155 t42_ps_get_font_private( FT_Face face,
156 PS_PrivateRec* afont_private )
157 {
158 *afont_private = ((T42_Face)face)->type1.private_dict;
159 return T42_Err_Ok;
160 }
161
162
David Turner77605952003-10-29 21:43:52 +0000163 static const FT_Service_PsInfoRec t42_service_ps_info =
164 {
Werner Lemberg3605e472004-11-12 07:02:45 +0000165 (PS_GetFontInfoFunc) t42_ps_get_font_info,
166 (PS_HasGlyphNamesFunc) t42_ps_has_glyph_names,
167 (PS_GetFontPrivateFunc)t42_ps_get_font_private
David Turner77605952003-10-29 21:43:52 +0000168 };
169
170
171 /*
David Turnerc313c502003-09-11 19:51:54 +0000172 *
173 * SERVICE LIST
174 *
175 */
176
177 static const FT_ServiceDescRec t42_services[] =
178 {
David Turnerb72d8a82003-09-29 20:33:37 +0000179 { FT_SERVICE_ID_GLYPH_DICT, &t42_service_glyph_dict },
180 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &t42_service_ps_font_name },
Werner Lemberg40bb0962003-11-01 14:36:20 +0000181 { FT_SERVICE_ID_POSTSCRIPT_INFO, &t42_service_ps_info },
Werner Lemberg1c0b8e92003-10-23 04:54:14 +0000182 { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TYPE_42 },
David Turnerc313c502003-09-11 19:51:54 +0000183 { NULL, NULL }
184 };
185
Werner Lemberg013efd12003-09-17 05:26:33 +0000186
Werner Lemberg347a7142002-05-15 06:16:57 +0000187 static FT_Module_Interface
David Turner9f95bab2002-06-07 07:23:06 +0000188 T42_Get_Interface( FT_Driver driver,
189 const FT_String* t42_interface )
Werner Lemberg347a7142002-05-15 06:16:57 +0000190 {
191 FT_UNUSED( driver );
192
David Turnerc313c502003-09-11 19:51:54 +0000193 return ft_service_list_lookup( t42_services, t42_interface );
Werner Lemberg347a7142002-05-15 06:16:57 +0000194 }
195
196
197 const FT_Driver_ClassRec t42_driver_class =
198 {
199 {
Werner Lemberg052904e2003-06-17 10:42:27 +0000200 FT_MODULE_FONT_DRIVER |
201 FT_MODULE_DRIVER_SCALABLE |
David Turner6aa260c2006-08-25 22:45:13 +0000202#ifdef TT_USE_BYTECODE_INTERPRETER
Werner Lemberg052904e2003-06-17 10:42:27 +0000203 FT_MODULE_DRIVER_HAS_HINTER,
Werner Lemberg7cf4d372002-05-21 14:13:01 +0000204#else
205 0,
206#endif
Werner Lemberg347a7142002-05-15 06:16:57 +0000207
208 sizeof ( T42_DriverRec ),
209
210 "type42",
211 0x10000L,
212 0x20000L,
213
214 0, /* format interface */
215
216 (FT_Module_Constructor)T42_Driver_Init,
217 (FT_Module_Destructor) T42_Driver_Done,
David Turner9f95bab2002-06-07 07:23:06 +0000218 (FT_Module_Requester) T42_Get_Interface,
Werner Lemberg347a7142002-05-15 06:16:57 +0000219 },
220
221 sizeof ( T42_FaceRec ),
222 sizeof ( T42_SizeRec ),
223 sizeof ( T42_GlyphSlotRec ),
224
225 (FT_Face_InitFunc) T42_Face_Init,
226 (FT_Face_DoneFunc) T42_Face_Done,
227 (FT_Size_InitFunc) T42_Size_Init,
228 (FT_Size_DoneFunc) T42_Size_Done,
229 (FT_Slot_InitFunc) T42_GlyphSlot_Init,
230 (FT_Slot_DoneFunc) T42_GlyphSlot_Done,
231
David Turnercda2d952006-02-16 22:45:31 +0000232#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
233 ft_stub_set_char_sizes,
234 ft_stub_set_pixel_sizes,
235#endif
David Turner9f95bab2002-06-07 07:23:06 +0000236 (FT_Slot_LoadFunc) T42_GlyphSlot_Load,
Werner Lemberg347a7142002-05-15 06:16:57 +0000237
238 (FT_Face_GetKerningFunc) 0,
239 (FT_Face_AttachFunc) 0,
240
David Turnercda2d952006-02-16 22:45:31 +0000241 (FT_Face_GetAdvancesFunc) 0,
242 (FT_Size_RequestFunc) T42_Size_Request,
243 (FT_Size_SelectFunc) T42_Size_Select
Werner Lemberg347a7142002-05-15 06:16:57 +0000244 };
245
Werner Lemberg8c90c222002-06-08 06:47:18 +0000246
247/* END */