1 /***************************************************************************/
5 /* CID objects manager (body). */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
19 #include <freetype/internal/ftdebug.h>
20 #include <freetype/internal/ftstream.h>
23 #ifdef FT_FLAT_COMPILE
30 #include <cid/cidgload.h>
31 #include <cid/cidload.h>
36 #include <freetype/internal/psnames.h>
39 /*************************************************************************/
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. */
46 #define FT_COMPONENT trace_cidobjs
49 /*************************************************************************/
53 /*************************************************************************/
56 /*************************************************************************/
62 /* Finalizes a given face object. */
65 /* face :: A pointer to the face object to destroy. */
68 void CID_Done_Face( CID_Face face
)
75 CID_Info
* cid
= &face
->cid
;
76 T1_FontInfo
* info
= &cid
->font_info
;
79 memory
= face
->root
.memory
;
81 /* release FontInfo strings */
82 FREE( info
->version
);
84 FREE( info
->full_name
);
85 FREE( info
->family_name
);
88 /* release font dictionaries */
89 FREE( cid
->font_dicts
);
92 /* release other strings */
93 FREE( cid
->cid_font_name
);
94 FREE( cid
->registry
);
95 FREE( cid
->ordering
);
97 face
->root
.family_name
= 0;
98 face
->root
.style_name
= 0;
103 /*************************************************************************/
109 /* Initializes a given CID face object. */
112 /* stream :: The source font stream. */
114 /* face_index :: The index of the font face in the resource. */
116 /* num_params :: Number of additional generic parameters. Ignored. */
118 /* params :: Additional generic parameters. Ignored. */
121 /* face :: The newly built face object. */
124 /* FreeType error code. 0 means success. */
127 FT_Error
CID_Init_Face( FT_Stream stream
,
131 FT_Parameter
* params
)
134 PSNames_Interface
* psnames
;
136 FT_UNUSED( num_params
);
138 FT_UNUSED( face_index
);
142 face
->root
.num_faces
= 1;
144 psnames
= (PSNames_Interface
*)face
->psnames
;
147 psnames
= (PSNames_Interface
*)FT_Get_Module_Interface(
148 FT_FACE_LIBRARY( face
), "psnames" );
150 face
->psnames
= psnames
;
153 /* open the tokenizer; this will also check the font format */
154 if ( FILE_Seek( 0 ) )
157 error
= CID_Open_Face( face
);
161 /* if we just wanted to check the format, leave successfully now */
162 if ( face_index
< 0 )
165 /* check the face index */
166 if ( face_index
!= 0 )
168 FT_ERROR(( "CID_Init_Face: invalid face index\n" ));
169 error
= T1_Err_Invalid_Argument
;
173 /* Now, load the font program into the face object */
175 /* Init the face object fields */
176 /* Now set up root face fields */
178 FT_Face root
= (FT_Face
)&face
->root
;
181 root
->num_glyphs
= face
->cid
.cid_count
;
182 root
->num_charmaps
= 0;
184 root
->face_index
= face_index
;
185 root
->face_flags
= FT_FACE_FLAG_SCALABLE
;
187 root
->face_flags
|= FT_FACE_FLAG_HORIZONTAL
;
189 if ( face
->cid
.font_info
.is_fixed_pitch
)
190 root
->face_flags
|= FT_FACE_FLAG_FIXED_WIDTH
;
192 /* XXX: TODO: add kerning with .afm support */
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
)
199 char* full
= face
->cid
.font_info
.full_name
;
200 char* family
= root
->family_name
;
202 while ( *family
&& *full
== *family
)
208 root
->style_name
= ( *full
== ' ' ) ? full
+ 1
213 /* do we have a `/FontName'? */
214 if ( face
->cid
.cid_font_name
)
216 root
->family_name
= face
->cid
.cid_font_name
;
217 root
->style_name
= "Regular";
221 /* no embedded bitmap support */
222 root
->num_fixed_sizes
= 0;
223 root
->available_sizes
= 0;
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 )
235 /* now compute the maximum advance width */
237 root
->max_advance_width
= face
->type1
.private_dict
.standard_width
[0];
239 /* compute max advance width for proportional fonts */
240 if ( !face
->type1
.font_info
.is_fixed_pitch
)
245 error
= CID_Compute_Max_Advance( face
, &max_advance
);
247 /* in case of error, keep the standard width */
249 root
->max_advance_width
= max_advance
;
251 error
= 0; /* clear error */
254 root
->max_advance_height
= root
->height
;
258 root
->underline_position
= face
->cid
.font_info
.underline_position
;
259 root
->underline_thickness
= face
->cid
.font_info
.underline_thickness
;
261 root
->max_points
= 0;
262 root
->max_contours
= 0;
268 /* charmap support - synthetize unicode charmap when possible */
270 FT_Face root
= &face
->root
;
271 FT_CharMap charmap
= face
->charmaprecs
;
274 /* synthesize a Unicode charmap if there is support in the `psnames' */
278 PSNames_Interface
* psnames
= (PSNames_Interface
*)face
->psnames
;
281 if ( psnames
->unicode_value
)
283 error
= psnames
->build_unicodes(
285 face
->type1
.num_glyphs
,
286 (const char**)face
->type1
.glyph_names
,
287 &face
->unicode_map
);
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;
298 /* simply clear the error in case of failure (which really */
299 /* means that out of memory or no unicode glyph names) */
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? */
308 switch ( face
->type1
.encoding_type
)
310 case t1_encoding_standard
:
311 charmap
->encoding
= ft_encoding_adobe_standard
;
312 charmap
->encoding_id
= 0;
315 case t1_encoding_expert
:
316 charmap
->encoding
= ft_encoding_adobe_expert
;
317 charmap
->encoding_id
= 1;
321 charmap
->encoding
= ft_encoding_adobe_custom
;
322 charmap
->encoding_id
= 2;
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];
339 /*************************************************************************/
342 /* CID_Init_Driver */
345 /* Initializes a given CID driver object. */
348 /* driver :: A handle to the target driver object. */
351 /* FreeType error code. 0 means success. */
354 FT_Error
CID_Init_Driver( CID_Driver driver
)
362 /*************************************************************************/
365 /* CID_Done_Driver */
368 /* Finalizes a given CID driver. */
371 /* driver :: A handle to the target CID driver. */
374 void CID_Done_Driver( CID_Driver driver
)