]> git.saurik.com Git - wxWidgets.git/blame - src/freetype/cid/cidobjs.c
added cw6 fixes and patrick's patches
[wxWidgets.git] / src / freetype / cid / cidobjs.c
CommitLineData
cabec872
RR
1/***************************************************************************/
2/* */
3/* cidobjs.c */
4/* */
5/* CID objects manager (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#include <freetype/internal/ftdebug.h>
20#include <freetype/internal/ftstream.h>
21
22
23#ifdef FT_FLAT_COMPILE
24
25#include "cidgload.h"
26#include "cidload.h"
27
28#else
29
30#include <cid/cidgload.h>
31#include <cid/cidload.h>
32
33#endif
34
35
36#include <freetype/internal/psnames.h>
37
38
39 /*************************************************************************/
40 /* */
41 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
42 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
43 /* messages during execution. */
44 /* */
45#undef FT_COMPONENT
46#define FT_COMPONENT trace_cidobjs
47
48
49 /*************************************************************************/
50 /* */
51 /* FACE FUNCTIONS */
52 /* */
53 /*************************************************************************/
54
55
56 /*************************************************************************/
57 /* */
58 /* <Function> */
59 /* CID_Done_Face */
60 /* */
61 /* <Description> */
62 /* Finalizes a given face object. */
63 /* */
64 /* <Input> */
65 /* face :: A pointer to the face object to destroy. */
66 /* */
67 LOCAL_FUNC
68 void CID_Done_Face( CID_Face face )
69 {
70 FT_Memory memory;
71
72
73 if ( face )
74 {
75 CID_Info* cid = &face->cid;
76 T1_FontInfo* info = &cid->font_info;
77
78
79 memory = face->root.memory;
80
81 /* release FontInfo strings */
82 FREE( info->version );
83 FREE( info->notice );
84 FREE( info->full_name );
85 FREE( info->family_name );
86 FREE( info->weight );
87
88 /* release font dictionaries */
89 FREE( cid->font_dicts );
90 cid->num_dicts = 0;
91
92 /* release other strings */
93 FREE( cid->cid_font_name );
94 FREE( cid->registry );
95 FREE( cid->ordering );
96
97 face->root.family_name = 0;
98 face->root.style_name = 0;
99 }
100 }
101
102
103 /*************************************************************************/
104 /* */
105 /* <Function> */
106 /* CID_Init_Face */
107 /* */
108 /* <Description> */
109 /* Initializes a given CID face object. */
110 /* */
111 /* <Input> */
112 /* stream :: The source font stream. */
113 /* */
114 /* face_index :: The index of the font face in the resource. */
115 /* */
116 /* num_params :: Number of additional generic parameters. Ignored. */
117 /* */
118 /* params :: Additional generic parameters. Ignored. */
119 /* */
120 /* <InOut> */
121 /* face :: The newly built face object. */
122 /* */
123 /* <Return> */
124 /* FreeType error code. 0 means success. */
125 /* */
126 LOCAL_FUNC
127 FT_Error CID_Init_Face( FT_Stream stream,
128 CID_Face face,
129 FT_Int face_index,
130 FT_Int num_params,
131 FT_Parameter* params )
132 {
133 FT_Error error;
134 PSNames_Interface* psnames;
135
136 FT_UNUSED( num_params );
137 FT_UNUSED( params );
138 FT_UNUSED( face_index );
139 FT_UNUSED( stream );
140
141
142 face->root.num_faces = 1;
143
144 psnames = (PSNames_Interface*)face->psnames;
145 if ( !psnames )
146 {
147 psnames = (PSNames_Interface*)FT_Get_Module_Interface(
148 FT_FACE_LIBRARY( face ), "psnames" );
149
150 face->psnames = psnames;
151 }
152
153 /* open the tokenizer; this will also check the font format */
154 if ( FILE_Seek( 0 ) )
155 goto Exit;
156
157 error = CID_Open_Face( face );
158 if ( error )
159 goto Exit;
160
161 /* if we just wanted to check the format, leave successfully now */
162 if ( face_index < 0 )
163 goto Exit;
164
165 /* check the face index */
166 if ( face_index != 0 )
167 {
168 FT_ERROR(( "CID_Init_Face: invalid face index\n" ));
169 error = T1_Err_Invalid_Argument;
170 goto Exit;
171 }
172
173 /* Now, load the font program into the face object */
174 {
175 /* Init the face object fields */
176 /* Now set up root face fields */
177 {
178 FT_Face root = (FT_Face)&face->root;
179
180
181 root->num_glyphs = face->cid.cid_count;
182 root->num_charmaps = 0;
183
184 root->face_index = face_index;
185 root->face_flags = FT_FACE_FLAG_SCALABLE;
186
187 root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
188
189 if ( face->cid.font_info.is_fixed_pitch )
190 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
191
192 /* XXX: TODO: add kerning with .afm support */
193
194 /* get style name -- be careful, some broken fonts only */
195 /* have a /FontName dictionary entry! */
196 root->family_name = face->cid.font_info.family_name;
197 if ( root->family_name )
198 {
199 char* full = face->cid.font_info.full_name;
200 char* family = root->family_name;
201
202 while ( *family && *full == *family )
203 {
204 family++;
205 full++;
206 }
207
208 root->style_name = ( *full == ' ' ) ? full + 1
209 : (char *)"Regular";
210 }
211 else
212 {
213 /* do we have a `/FontName'? */
214 if ( face->cid.cid_font_name )
215 {
216 root->family_name = face->cid.cid_font_name;
217 root->style_name = "Regular";
218 }
219 }
220
221 /* no embedded bitmap support */
222 root->num_fixed_sizes = 0;
223 root->available_sizes = 0;
224
225 root->bbox = face->cid.font_bbox;
226 root->units_per_EM = 1000;
227 root->ascender = (FT_Short)face->cid.font_bbox.yMax;
228 root->descender = -(FT_Short)face->cid.font_bbox.yMin;
229 root->height = ( ( root->ascender + root->descender ) * 12 )
230 / 10;
231
232
233#if 0
234
235 /* now compute the maximum advance width */
236
237 root->max_advance_width = face->type1.private_dict.standard_width[0];
238
239 /* compute max advance width for proportional fonts */
240 if ( !face->type1.font_info.is_fixed_pitch )
241 {
242 FT_Int max_advance;
243
244
245 error = CID_Compute_Max_Advance( face, &max_advance );
246
247 /* in case of error, keep the standard width */
248 if ( !error )
249 root->max_advance_width = max_advance;
250 else
251 error = 0; /* clear error */
252 }
253
254 root->max_advance_height = root->height;
255
256#endif /* 0 */
257
258 root->underline_position = face->cid.font_info.underline_position;
259 root->underline_thickness = face->cid.font_info.underline_thickness;
260
261 root->max_points = 0;
262 root->max_contours = 0;
263 }
264 }
265
266#if 0
267
268 /* charmap support - synthetize unicode charmap when possible */
269 {
270 FT_Face root = &face->root;
271 FT_CharMap charmap = face->charmaprecs;
272
273
274 /* synthesize a Unicode charmap if there is support in the `psnames' */
275 /* module */
276 if ( face->psnames )
277 {
278 PSNames_Interface* psnames = (PSNames_Interface*)face->psnames;
279
280
281 if ( psnames->unicode_value )
282 {
283 error = psnames->build_unicodes(
284 root->memory,
285 face->type1.num_glyphs,
286 (const char**)face->type1.glyph_names,
287 &face->unicode_map );
288 if ( !error )
289 {
290 root->charmap = charmap;
291 charmap->face = (FT_Face)face;
292 charmap->encoding = ft_encoding_unicode;
293 charmap->platform_id = 3;
294 charmap->encoding_id = 1;
295 charmap++;
296 }
297
298 /* simply clear the error in case of failure (which really */
299 /* means that out of memory or no unicode glyph names) */
300 error = 0;
301 }
302 }
303
304 /* now, support either the standard, expert, or custom encodings */
305 charmap->face = (FT_Face)face;
306 charmap->platform_id = 7; /* a new platform id for Adobe fonts? */
307
308 switch ( face->type1.encoding_type )
309 {
310 case t1_encoding_standard:
311 charmap->encoding = ft_encoding_adobe_standard;
312 charmap->encoding_id = 0;
313 break;
314
315 case t1_encoding_expert:
316 charmap->encoding = ft_encoding_adobe_expert;
317 charmap->encoding_id = 1;
318 break;
319
320 default:
321 charmap->encoding = ft_encoding_adobe_custom;
322 charmap->encoding_id = 2;
323 break;
324 }
325
326 root->charmaps = face->charmaps;
327 root->num_charmaps = charmap - face->charmaprecs + 1;
328 face->charmaps[0] = &face->charmaprecs[0];
329 face->charmaps[1] = &face->charmaprecs[1];
330 }
331
332#endif /* 0 */
333
334 Exit:
335 return error;
336 }
337
338
339 /*************************************************************************/
340 /* */
341 /* <Function> */
342 /* CID_Init_Driver */
343 /* */
344 /* <Description> */
345 /* Initializes a given CID driver object. */
346 /* */
347 /* <Input> */
348 /* driver :: A handle to the target driver object. */
349 /* */
350 /* <Return> */
351 /* FreeType error code. 0 means success. */
352 /* */
353 LOCAL_FUNC
354 FT_Error CID_Init_Driver( CID_Driver driver )
355 {
356 FT_UNUSED( driver );
357
358 return T1_Err_Ok;
359 }
360
361
362 /*************************************************************************/
363 /* */
364 /* <Function> */
365 /* CID_Done_Driver */
366 /* */
367 /* <Description> */
368 /* Finalizes a given CID driver. */
369 /* */
370 /* <Input> */
371 /* driver :: A handle to the target CID driver. */
372 /* */
373 LOCAL_DEF
374 void CID_Done_Driver( CID_Driver driver )
375 {
376 FT_UNUSED( driver );
377 }
378
379
380/* END */