]> git.saurik.com Git - wxWidgets.git/blame - src/freetype/type1z/z1objs.c
AddBook ignores wxMac paths (still won't work)
[wxWidgets.git] / src / freetype / type1z / z1objs.c
CommitLineData
cabec872
RR
1/***************************************************************************/
2/* */
3/* z1objs.c */
4/* */
5/* Experimental Type 1 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 "z1gload.h"
26#include "z1load.h"
27#include "z1afm.h"
28
29#else
30
31#include <type1z/z1gload.h>
32#include <type1z/z1load.h>
33#include <type1z/z1afm.h>
34
35#endif
36
37
38#include <freetype/internal/psnames.h>
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_z1objs
49
50
51 /*************************************************************************/
52 /* */
53 /* FACE FUNCTIONS */
54 /* */
55 /*************************************************************************/
56
57
58 /*************************************************************************/
59 /* */
60 /* <Function> */
61 /* Z1_Done_Face */
62 /* */
63 /* <Description> */
64 /* The face object destructor. */
65 /* */
66 /* <Input> */
67 /* face :: A typeless pointer to the face object to destroy. */
68 /* */
69 LOCAL_FUNC
70 void Z1_Done_Face( T1_Face face )
71 {
72 FT_Memory memory;
73 T1_Font* type1 = &face->type1;
74
75
76 if ( face )
77 {
78 memory = face->root.memory;
79
80#ifndef Z1_CONFIG_OPTION_NO_MM_SUPPORT
81 /* release multiple masters information */
82 Z1_Done_Blend( face );
83 face->blend = 0;
84#endif
85
86 /* release font info strings */
87 {
88 T1_FontInfo* info = &type1->font_info;
89
90
91 FREE( info->version );
92 FREE( info->notice );
93 FREE( info->full_name );
94 FREE( info->family_name );
95 FREE( info->weight );
96 }
97
98 /* release top dictionary */
99 FREE( type1->charstrings_len );
100 FREE( type1->charstrings );
101 FREE( type1->glyph_names );
102
103 FREE( type1->subrs );
104 FREE( type1->subrs_len );
105
106 FREE( type1->subrs_block );
107 FREE( type1->charstrings_block );
108 FREE( type1->glyph_names_block );
109
110 FREE( type1->encoding.char_index );
111 FREE( type1->font_name );
112
113#ifndef Z1_CONFIG_OPTION_NO_AFM
114 /* release afm data if present */
115 if ( face->afm_data )
116 Z1_Done_AFM( memory, (Z1_AFM*)face->afm_data );
117#endif
118
119 /* release unicode map, if any */
120 FREE( face->unicode_map.maps );
121 face->unicode_map.num_maps = 0;
122
123 face->root.family_name = 0;
124 face->root.style_name = 0;
125 }
126 }
127
128
129 /*************************************************************************/
130 /* */
131 /* <Function> */
132 /* Z1_Init_Face */
133 /* */
134 /* <Description> */
135 /* The face object constructor. */
136 /* */
137 /* <Input> */
138 /* stream :: input stream where to load font data. */
139 /* */
140 /* face_index :: The index of the font face in the resource. */
141 /* */
142 /* num_params :: Number of additional generic parameters. Ignored. */
143 /* */
144 /* params :: Additional generic parameters. Ignored. */
145 /* */
146 /* <InOut> */
147 /* face :: The face record to build. */
148 /* */
149 /* <Return> */
150 /* FreeType error code. 0 means success. */
151 /* */
152 LOCAL_FUNC
153 FT_Error Z1_Init_Face( FT_Stream stream,
154 T1_Face face,
155 FT_Int face_index,
156 FT_Int num_params,
157 FT_Parameter* params )
158 {
159 FT_Error error;
160 PSNames_Interface* psnames;
161
162 FT_UNUSED( num_params );
163 FT_UNUSED( params );
164 FT_UNUSED( face_index );
165 FT_UNUSED( stream );
166
167
168 face->root.num_faces = 1;
169
170 psnames = (PSNames_Interface*)face->psnames;
171 if ( !psnames )
172 {
173 psnames = (PSNames_Interface*)
174 FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psnames" );
175
176 face->psnames = psnames;
177 }
178
179 /* open the tokenizer, this will also check the font format */
180 error = Z1_Open_Face( face );
181 if ( error )
182 goto Exit;
183
184 /* if we just wanted to check the format, leave successfully now */
185 if ( face_index < 0 )
186 goto Exit;
187
188 /* check the face index */
189 if ( face_index != 0 )
190 {
191 FT_ERROR(( "Z1_Init_Face: invalid face index\n" ));
192 error = T1_Err_Invalid_Argument;
193 goto Exit;
194 }
195
196 /* Now, load the font program into the face object */
197
198 /* Init the face object fields */
199 /* Now set up root face fields */
200 {
201 FT_Face root = (FT_Face)&face->root;
202
203
204 root->num_glyphs = face->type1.num_glyphs;
205 root->num_charmaps = 1;
206
207 root->face_index = face_index;
208 root->face_flags = FT_FACE_FLAG_SCALABLE;
209
210 root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
211
212 root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
213
214 if ( face->type1.font_info.is_fixed_pitch )
215 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
216
217 if ( face->blend )
218 root->face_flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;
219
220 /* XXX: TODO -- add kerning with .afm support */
221
222 /* get style name -- be careful, some broken fonts only */
223 /* have a `/FontName' dictionary entry! */
224 root->family_name = face->type1.font_info.family_name;
225 if ( root->family_name )
226 {
227 char* full = face->type1.font_info.full_name;
228 char* family = root->family_name;
229
230
231 while ( *family && *full == *family )
232 {
233 family++;
234 full++;
235 }
236
237 root->style_name = ( *full == ' ' ? full + 1
238 : (char *)"Regular" );
239 }
240 else
241 {
242 /* do we have a `/FontName'? */
243 if ( face->type1.font_name )
244 {
245 root->family_name = face->type1.font_name;
246 root->style_name = "Regular";
247 }
248 }
249
250 /* no embedded bitmap support */
251 root->num_fixed_sizes = 0;
252 root->available_sizes = 0;
253
254 root->bbox = face->type1.font_bbox;
255 root->units_per_EM = 1000;
256 root->ascender = (FT_Short)face->type1.font_bbox.yMax;
257 root->descender = -(FT_Short)face->type1.font_bbox.yMin;
258 root->height = ( ( root->ascender + root->descender ) * 12 ) / 10;
259
260 /* now compute the maximum advance width */
261
262 root->max_advance_width = face->type1.private_dict.standard_width[0];
263
264 /* compute max advance width for proportional fonts */
265 if ( !face->type1.font_info.is_fixed_pitch )
266 {
267 FT_Int max_advance;
268
269
270 error = Z1_Compute_Max_Advance( face, &max_advance );
271
272 /* in case of error, keep the standard width */
273 if ( !error )
274 root->max_advance_width = max_advance;
275 else
276 error = 0; /* clear error */
277 }
278
279 root->max_advance_height = root->height;
280
281 root->underline_position = face->type1.font_info.underline_position;
282 root->underline_thickness = face->type1.font_info.underline_thickness;
283
284 root->max_points = 0;
285 root->max_contours = 0;
286 }
287
288 /* charmap support -- synthetize unicode charmap if possible */
289 {
290 FT_Face root = &face->root;
291 FT_CharMap charmap = face->charmaprecs;
292
293
294 /* synthesize a Unicode charmap if there is support in the `PSNames' */
295 /* module */
296 if ( face->psnames )
297 {
298 PSNames_Interface* psnames = (PSNames_Interface*)face->psnames;
299
300
301 if ( psnames->unicode_value )
302 {
303 error = psnames->build_unicodes(
304 root->memory,
305 face->type1.num_glyphs,
306 (const char**)face->type1.glyph_names,
307 &face->unicode_map );
308 if ( !error )
309 {
310 root->charmap = charmap;
311 charmap->face = (FT_Face)face;
312 charmap->encoding = ft_encoding_unicode;
313 charmap->platform_id = 3;
314 charmap->encoding_id = 1;
315 charmap++;
316 }
317
318 /* simply clear the error in case of failure (which really) */
319 /* means that out of memory or no unicode glyph names */
320 error = FT_Err_Ok;
321 }
322 }
323
324 /* now, support either the standard, expert, or custom encoding */
325 charmap->face = (FT_Face)face;
326 charmap->platform_id = 7; /* a new platform id for Adobe fonts? */
327
328 switch ( face->type1.encoding_type )
329 {
330 case t1_encoding_standard:
331 charmap->encoding = ft_encoding_adobe_standard;
332 charmap->encoding_id = 0;
333 break;
334
335 case t1_encoding_expert:
336 charmap->encoding = ft_encoding_adobe_expert;
337 charmap->encoding_id = 1;
338 break;
339
340 default:
341 charmap->encoding = ft_encoding_adobe_custom;
342 charmap->encoding_id = 2;
343 break;
344 }
345
346 root->charmaps = face->charmaps;
347 root->num_charmaps = charmap - face->charmaprecs + 1;
348 face->charmaps[0] = &face->charmaprecs[0];
349 face->charmaps[1] = &face->charmaprecs[1];
350 }
351
352 Exit:
353 return error;
354 }
355
356
357 /*************************************************************************/
358 /* */
359 /* <Function> */
360 /* Z1_Init_Driver */
361 /* */
362 /* <Description> */
363 /* Initializes a given Type 1 driver object. */
364 /* */
365 /* <Input> */
366 /* driver :: A handle to the target driver object. */
367 /* */
368 /* <Return> */
369 /* FreeType error code. 0 means success. */
370 /* */
371 LOCAL_FUNC
372 FT_Error Z1_Init_Driver( Z1_Driver driver )
373 {
374 FT_UNUSED( driver );
375
376 return T1_Err_Ok;
377 }
378
379
380 /*************************************************************************/
381 /* */
382 /* <Function> */
383 /* Z1_Done_Driver */
384 /* */
385 /* <Description> */
386 /* Finalizes a given Type 1 driver. */
387 /* */
388 /* <Input> */
389 /* driver :: A handle to the target Type 1 driver. */
390 /* */
391 LOCAL_DEF
392 void Z1_Done_Driver( Z1_Driver driver )
393 {
394 FT_UNUSED( driver );
395 }
396
397
398/* END */