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