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