~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/src/cff/cffobjs.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************/
 
2
/*                                                                         */
 
3
/*  cffobjs.c                                                              */
 
4
/*                                                                         */
 
5
/*    OpenType objects manager (body).                                     */
 
6
/*                                                                         */
 
7
/*  Copyright 1996-2001, 2002, 2003, 2004 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_CALC_H
 
22
#include FT_INTERNAL_STREAM_H
 
23
#include FT_ERRORS_H
 
24
#include FT_TRUETYPE_IDS_H
 
25
#include FT_TRUETYPE_TAGS_H
 
26
#include FT_INTERNAL_SFNT_H
 
27
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
 
28
#include FT_INTERNAL_POSTSCRIPT_HINTS_H
 
29
#include "cffobjs.h"
 
30
#include "cffload.h"
 
31
#include "cffcmap.h"
 
32
#include "cfferrs.h"
 
33
 
 
34
 
 
35
  /*************************************************************************/
 
36
  /*                                                                       */
 
37
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
 
38
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
 
39
  /* messages during execution.                                            */
 
40
  /*                                                                       */
 
41
#undef  FT_COMPONENT
 
42
#define FT_COMPONENT  trace_cffobjs
 
43
 
 
44
 
 
45
  /*************************************************************************/
 
46
  /*                                                                       */
 
47
  /*                            SIZE FUNCTIONS                             */
 
48
  /*                                                                       */
 
49
  /*  Note that we store the global hints in the size's `internal' root    */
 
50
  /*  field.                                                               */
 
51
  /*                                                                       */
 
52
  /*************************************************************************/
 
53
 
 
54
 
 
55
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
 
56
 
 
57
  static FT_Error
 
58
  sbit_size_reset( CFF_Size  size )
 
59
  {
 
60
    CFF_Face          face;
 
61
    FT_Error          error = CFF_Err_Ok;
 
62
 
 
63
    FT_ULong          strike_index;
 
64
    FT_Size_Metrics*  metrics;
 
65
    FT_Size_Metrics*  sbit_metrics;
 
66
    SFNT_Service      sfnt;
 
67
 
 
68
 
 
69
    metrics = &size->root.metrics;
 
70
 
 
71
    face = (CFF_Face)size->root.face;
 
72
    sfnt = (SFNT_Service)face->sfnt;
 
73
 
 
74
    sbit_metrics = &size->strike_metrics;
 
75
 
 
76
    error = sfnt->set_sbit_strike( face,
 
77
                                   metrics->x_ppem, metrics->y_ppem,
 
78
                                   &strike_index );
 
79
 
 
80
    if ( !error )
 
81
    {
 
82
      TT_SBit_Strike  strike = face->sbit_strikes + strike_index;
 
83
 
 
84
 
 
85
      sbit_metrics->x_ppem = metrics->x_ppem;
 
86
      sbit_metrics->y_ppem = metrics->y_ppem;
 
87
 
 
88
      sbit_metrics->ascender  = strike->hori.ascender << 6;
 
89
      sbit_metrics->descender = strike->hori.descender << 6;
 
90
 
 
91
      /* XXX: Is this correct? */
 
92
      sbit_metrics->height = sbit_metrics->ascender -
 
93
                             sbit_metrics->descender;
 
94
 
 
95
      /* XXX: Is this correct? */
 
96
      sbit_metrics->max_advance = ( strike->hori.min_origin_SB  +
 
97
                                    strike->hori.max_width      +
 
98
                                    strike->hori.min_advance_SB ) << 6;
 
99
 
 
100
      size->strike_index = (FT_UInt)strike_index;
 
101
    }
 
102
    else
 
103
    {
 
104
      size->strike_index = 0xFFFFU;
 
105
 
 
106
      sbit_metrics->x_ppem      = 0;
 
107
      sbit_metrics->y_ppem      = 0;
 
108
      sbit_metrics->ascender    = 0;
 
109
      sbit_metrics->descender   = 0;
 
110
      sbit_metrics->height      = 0;
 
111
      sbit_metrics->max_advance = 0;
 
112
    }
 
113
 
 
114
    return error;
 
115
  }
 
116
 
 
117
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
 
118
 
 
119
 
 
120
  static PSH_Globals_Funcs
 
121
  cff_size_get_globals_funcs( CFF_Size  size )
 
122
  {
 
123
    CFF_Face          face     = (CFF_Face)size->root.face;
 
124
    CFF_Font          font     = (CFF_FontRec *)face->extra.data;
 
125
    PSHinter_Service  pshinter = (PSHinter_Service)font->pshinter;
 
126
    FT_Module         module;
 
127
 
 
128
 
 
129
    module = FT_Get_Module( size->root.face->driver->root.library,
 
130
                            "pshinter" );
 
131
    return ( module && pshinter && pshinter->get_globals_funcs )
 
132
           ? pshinter->get_globals_funcs( module )
 
133
           : 0;
 
134
  }
 
135
 
 
136
 
 
137
  FT_LOCAL_DEF( void )
 
138
  cff_size_done( FT_Size  cffsize )        /* CFF_Size */
 
139
  {
 
140
    CFF_Size  size = (CFF_Size)cffsize;
 
141
 
 
142
 
 
143
    if ( cffsize->internal )
 
144
    {
 
145
      PSH_Globals_Funcs  funcs;
 
146
 
 
147
 
 
148
      funcs = cff_size_get_globals_funcs( size );
 
149
      if ( funcs )
 
150
        funcs->destroy( (PSH_Globals)cffsize->internal );
 
151
 
 
152
      cffsize->internal = 0;
 
153
    }
 
154
  }
 
155
 
 
156
 
 
157
  FT_LOCAL_DEF( FT_Error )
 
158
  cff_size_init( FT_Size  cffsize )         /* CFF_Size */
 
159
  {
 
160
    CFF_Size           size  = (CFF_Size)cffsize;
 
161
    FT_Error           error = CFF_Err_Ok;
 
162
    PSH_Globals_Funcs  funcs = cff_size_get_globals_funcs( size );
 
163
 
 
164
 
 
165
    if ( funcs )
 
166
    {
 
167
      PSH_Globals    globals;
 
168
      CFF_Face       face    = (CFF_Face)cffsize->face;
 
169
      CFF_Font       font    = (CFF_FontRec *)face->extra.data;
 
170
      CFF_SubFont    subfont = &font->top_font;
 
171
 
 
172
      CFF_Private    cpriv   = &subfont->private_dict;
 
173
      PS_PrivateRec  priv;
 
174
 
 
175
 
 
176
      /* IMPORTANT: The CFF and Type1 private dictionaries have    */
 
177
      /*            slightly different structures; we need to      */
 
178
      /*            synthetize a type1 dictionary on the fly here. */
 
179
 
 
180
      {
 
181
        FT_UInt  n, count;
 
182
 
 
183
 
 
184
        FT_MEM_ZERO( &priv, sizeof ( priv ) );
 
185
 
 
186
        count = priv.num_blue_values = cpriv->num_blue_values;
 
187
        for ( n = 0; n < count; n++ )
 
188
          priv.blue_values[n] = (FT_Short)cpriv->blue_values[n];
 
189
 
 
190
        count = priv.num_other_blues = cpriv->num_other_blues;
 
191
        for ( n = 0; n < count; n++ )
 
192
          priv.other_blues[n] = (FT_Short)cpriv->other_blues[n];
 
193
 
 
194
        count = priv.num_family_blues = cpriv->num_family_blues;
 
195
        for ( n = 0; n < count; n++ )
 
196
          priv.family_blues[n] = (FT_Short)cpriv->family_blues[n];
 
197
 
 
198
        count = priv.num_family_other_blues = cpriv->num_family_other_blues;
 
199
        for ( n = 0; n < count; n++ )
 
200
          priv.family_other_blues[n] = (FT_Short)cpriv->family_other_blues[n];
 
201
 
 
202
        priv.blue_scale = cpriv->blue_scale;
 
203
        priv.blue_shift = (FT_Int)cpriv->blue_shift;
 
204
        priv.blue_fuzz  = (FT_Int)cpriv->blue_fuzz;
 
205
 
 
206
        priv.standard_width[0]  = (FT_UShort)cpriv->standard_width;
 
207
        priv.standard_height[0] = (FT_UShort)cpriv->standard_height;
 
208
 
 
209
        count = priv.num_snap_widths = cpriv->num_snap_widths;
 
210
        for ( n = 0; n < count; n++ )
 
211
          priv.snap_widths[n] = (FT_Short)cpriv->snap_widths[n];
 
212
 
 
213
        count = priv.num_snap_heights = cpriv->num_snap_heights;
 
214
        for ( n = 0; n < count; n++ )
 
215
          priv.snap_heights[n] = (FT_Short)cpriv->snap_heights[n];
 
216
 
 
217
        priv.force_bold     = cpriv->force_bold;
 
218
        priv.language_group = cpriv->language_group;
 
219
        priv.lenIV          = cpriv->lenIV;
 
220
      }
 
221
 
 
222
      error = funcs->create( cffsize->face->memory, &priv, &globals );
 
223
      if ( !error )
 
224
        cffsize->internal = (FT_Size_Internal)(void*)globals;
 
225
    }
 
226
 
 
227
    return error;
 
228
  }
 
229
 
 
230
 
 
231
  FT_LOCAL_DEF( FT_Error )
 
232
  cff_size_reset( FT_Size  cffsize,         /* CFF_Size */
 
233
                  FT_UInt  char_width,
 
234
                  FT_UInt  char_height )
 
235
  {
 
236
    CFF_Size           size  = (CFF_Size)cffsize;
 
237
    PSH_Globals_Funcs  funcs = cff_size_get_globals_funcs( size );
 
238
    FT_Error           error = CFF_Err_Ok;
 
239
    FT_Face            face  = cffsize->face;
 
240
 
 
241
    FT_UNUSED( char_width );
 
242
    FT_UNUSED( char_height );
 
243
 
 
244
 
 
245
    if ( funcs )
 
246
      error = funcs->set_scale( (PSH_Globals)cffsize->internal,
 
247
                                 cffsize->metrics.x_scale,
 
248
                                 cffsize->metrics.y_scale,
 
249
                                 0, 0 );
 
250
 
 
251
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
 
252
 
 
253
    if ( face->face_flags & FT_FACE_FLAG_FIXED_SIZES )
 
254
    {
 
255
      error = sbit_size_reset( size );
 
256
 
 
257
      if ( !error && !( face->face_flags & FT_FACE_FLAG_SCALABLE ) )
 
258
        cffsize->metrics = size->strike_metrics;
 
259
    }
 
260
 
 
261
#endif
 
262
 
 
263
    if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
 
264
      return CFF_Err_Ok;
 
265
    else
 
266
      return error;
 
267
  }
 
268
 
 
269
 
 
270
  FT_LOCAL_DEF( FT_Error )
 
271
  cff_point_size_reset( FT_Size     cffsize,
 
272
                        FT_F26Dot6  char_width,
 
273
                        FT_F26Dot6  char_height,
 
274
                        FT_UInt     horz_resolution,
 
275
                        FT_UInt     vert_resolution )
 
276
  {
 
277
    FT_UNUSED( char_width );
 
278
    FT_UNUSED( char_height );
 
279
    FT_UNUSED( horz_resolution );
 
280
    FT_UNUSED( vert_resolution );
 
281
 
 
282
    return cff_size_reset( cffsize, 0, 0 );
 
283
  }
 
284
 
 
285
 
 
286
  /*************************************************************************/
 
287
  /*                                                                       */
 
288
  /*                            SLOT  FUNCTIONS                            */
 
289
  /*                                                                       */
 
290
  /*************************************************************************/
 
291
 
 
292
  FT_LOCAL_DEF( void )
 
293
  cff_slot_done( FT_GlyphSlot  slot )
 
294
  {
 
295
    slot->internal->glyph_hints = 0;
 
296
  }
 
297
 
 
298
 
 
299
  FT_LOCAL_DEF( FT_Error )
 
300
  cff_slot_init( FT_GlyphSlot  slot )
 
301
  {
 
302
    CFF_Face          face     = (CFF_Face)slot->face;
 
303
    CFF_Font          font     = (CFF_FontRec *)face->extra.data;
 
304
    PSHinter_Service  pshinter = (PSHinter_Service)font->pshinter;
 
305
 
 
306
 
 
307
    if ( pshinter )
 
308
    {
 
309
      FT_Module  module;
 
310
 
 
311
 
 
312
      module = FT_Get_Module( slot->face->driver->root.library,
 
313
                              "pshinter" );
 
314
      if ( module )
 
315
      {
 
316
        T2_Hints_Funcs  funcs;
 
317
 
 
318
 
 
319
        funcs = pshinter->get_t2_funcs( module );
 
320
        slot->internal->glyph_hints = (void*)funcs;
 
321
      }
 
322
    }
 
323
 
 
324
    return 0;
 
325
  }
 
326
 
 
327
 
 
328
  /*************************************************************************/
 
329
  /*                                                                       */
 
330
  /*                           FACE  FUNCTIONS                             */
 
331
  /*                                                                       */
 
332
  /*************************************************************************/
 
333
 
 
334
  static FT_String*
 
335
  cff_strcpy( FT_Memory         memory,
 
336
              const FT_String*  source )
 
337
  {
 
338
    FT_Error    error;
 
339
    FT_String*  result = 0;
 
340
    FT_Int      len = (FT_Int)ft_strlen( source );
 
341
 
 
342
 
 
343
    if ( !FT_ALLOC( result, len + 1 ) )
 
344
    {
 
345
      FT_MEM_COPY( result, source, len );
 
346
      result[len] = 0;
 
347
    }
 
348
 
 
349
    FT_UNUSED( error );
 
350
 
 
351
    return result;
 
352
  }
 
353
 
 
354
 
 
355
  FT_LOCAL_DEF( FT_Error )
 
356
  cff_face_init( FT_Stream      stream,
 
357
                 FT_Face        cffface,        /* CFF_Face */
 
358
                 FT_Int         face_index,
 
359
                 FT_Int         num_params,
 
360
                 FT_Parameter*  params )
 
361
  {
 
362
    CFF_Face            face = (CFF_Face)cffface;
 
363
    FT_Error            error;
 
364
    SFNT_Service        sfnt;
 
365
    FT_Service_PsCMaps  psnames;
 
366
    PSHinter_Service    pshinter;
 
367
    FT_Bool             pure_cff    = 1;
 
368
    FT_Bool             sfnt_format = 0;
 
369
 
 
370
#if 0
 
371
    FT_FACE_FIND_GLOBAL_SERVICE( face, sfnt,     SFNT );
 
372
    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames,  POSTSCRIPT_NAMES );
 
373
    FT_FACE_FIND_GLOBAL_SERVICE( face, pshinter, POSTSCRIPT_HINTER );
 
374
 
 
375
    if ( !sfnt )
 
376
      goto Bad_Format;
 
377
#else
 
378
    sfnt = (SFNT_Service)FT_Get_Module_Interface(
 
379
             cffface->driver->root.library, "sfnt" );
 
380
    if ( !sfnt )
 
381
      goto Bad_Format;
 
382
 
 
383
    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
 
384
 
 
385
    pshinter = (PSHinter_Service)FT_Get_Module_Interface(
 
386
                 cffface->driver->root.library, "pshinter" );
 
387
#endif
 
388
 
 
389
    /* create input stream from resource */
 
390
    if ( FT_STREAM_SEEK( 0 ) )
 
391
      goto Exit;
 
392
 
 
393
    /* check whether we have a valid OpenType file */
 
394
    error = sfnt->init_face( stream, face, face_index, num_params, params );
 
395
    if ( !error )
 
396
    {
 
397
      if ( face->format_tag != 0x4F54544FL )  /* `OTTO'; OpenType/CFF font */
 
398
      {
 
399
        FT_TRACE2(( "[not a valid OpenType/CFF font]\n" ));
 
400
        goto Bad_Format;
 
401
      }
 
402
 
 
403
      /* if we are performing a simple font format check, exit immediately */
 
404
      if ( face_index < 0 )
 
405
        return CFF_Err_Ok;
 
406
 
 
407
      sfnt_format = 1;
 
408
 
 
409
      /* now, the font can be either an OpenType/CFF font, or an SVG CEF */
 
410
      /* font; in the latter case it doesn't have a `head' table         */
 
411
      error = face->goto_table( face, TTAG_head, stream, 0 );
 
412
      if ( !error )
 
413
      {
 
414
        pure_cff = 0;
 
415
 
 
416
        /* load font directory */
 
417
        error = sfnt->load_face( stream, face,
 
418
                                 face_index, num_params, params );
 
419
        if ( error )
 
420
          goto Exit;
 
421
      }
 
422
      else
 
423
      {
 
424
        /* load the `cmap' table explicitly */
 
425
        error = sfnt->load_charmaps( face, stream );
 
426
        if ( error )
 
427
          goto Exit;
 
428
 
 
429
        /* XXX: we don't load the GPOS table, as OpenType Layout     */
 
430
        /* support will be added later to a layout library on top of */
 
431
        /* FreeType 2                                                */
 
432
      }
 
433
 
 
434
      /* now load the CFF part of the file */
 
435
      error = face->goto_table( face, TTAG_CFF, stream, 0 );
 
436
      if ( error )
 
437
        goto Exit;
 
438
    }
 
439
    else
 
440
    {
 
441
      /* rewind to start of file; we are going to load a pure-CFF font */
 
442
      if ( FT_STREAM_SEEK( 0 ) )
 
443
        goto Exit;
 
444
      error = CFF_Err_Ok;
 
445
    }
 
446
 
 
447
    /* now load and parse the CFF table in the file */
 
448
    {
 
449
      CFF_Font         cff;
 
450
      CFF_FontRecDict  dict;
 
451
      FT_Memory        memory = cffface->memory;
 
452
      FT_Int32         flags;
 
453
 
 
454
 
 
455
      if ( FT_NEW( cff ) )
 
456
        goto Exit;
 
457
 
 
458
      face->extra.data = cff;
 
459
      error = cff_font_load( stream, face_index, cff );
 
460
      if ( error )
 
461
        goto Exit;
 
462
 
 
463
      cff->pshinter = pshinter;
 
464
      cff->psnames  = (void*)psnames;
 
465
 
 
466
      /* Complement the root flags with some interesting information. */
 
467
      /* Note that this is only necessary for pure CFF and CEF fonts. */
 
468
 
 
469
      cffface->num_glyphs = cff->num_glyphs;
 
470
 
 
471
      dict = &cff->top_font.font_dict;
 
472
 
 
473
      /* we need the `PSNames' module for CFF and CEF formats */
 
474
      /* which aren't CID-keyed                               */
 
475
      if ( dict->cid_registry == 0xFFFFU && !psnames )
 
476
      {
 
477
        FT_ERROR(( "cff_face_init:" ));
 
478
        FT_ERROR(( " cannot open CFF & CEF fonts\n" ));
 
479
        FT_ERROR(( "              " ));
 
480
        FT_ERROR(( " without the `PSNames' module\n" ));
 
481
        goto Bad_Format;
 
482
      }
 
483
 
 
484
      if ( pure_cff )
 
485
      {
 
486
        char*  style_name = NULL;
 
487
 
 
488
 
 
489
        /* Set up num_faces. */
 
490
        cffface->num_faces = cff->num_faces;
 
491
 
 
492
        /* compute number of glyphs */
 
493
        if ( dict->cid_registry != 0xFFFFU )
 
494
          cffface->num_glyphs = dict->cid_count;
 
495
        else
 
496
          cffface->num_glyphs = cff->charstrings_index.count;
 
497
 
 
498
        /* set global bbox, as well as EM size */
 
499
        cffface->bbox.xMin =   dict->font_bbox.xMin             >> 16;
 
500
        cffface->bbox.yMin =   dict->font_bbox.yMin             >> 16;
 
501
        cffface->bbox.xMax = ( dict->font_bbox.xMax + 0xFFFFU ) >> 16;
 
502
        cffface->bbox.yMax = ( dict->font_bbox.yMax + 0xFFFFU ) >> 16;
 
503
 
 
504
        cffface->ascender  = (FT_Short)( cffface->bbox.yMax );
 
505
        cffface->descender = (FT_Short)( cffface->bbox.yMin );
 
506
        cffface->height    = (FT_Short)(
 
507
          ( ( cffface->ascender - cffface->descender ) * 12 ) / 10 );
 
508
 
 
509
        if ( dict->units_per_em )
 
510
          cffface->units_per_EM = dict->units_per_em;
 
511
        else
 
512
          cffface->units_per_EM = 1000;
 
513
 
 
514
        cffface->underline_position  =
 
515
          (FT_Short)( dict->underline_position >> 16 );
 
516
        cffface->underline_thickness =
 
517
          (FT_Short)( dict->underline_thickness >> 16 );
 
518
 
 
519
        /* retrieve font family & style name */
 
520
        cffface->family_name = cff_index_get_name( &cff->name_index,
 
521
                                                   face_index );
 
522
 
 
523
        if ( cffface->family_name )
 
524
        {
 
525
          char*  full   = cff_index_get_sid_string( &cff->string_index,
 
526
                                                    dict->full_name,
 
527
                                                    psnames );
 
528
          char*  fullp  = full;
 
529
          char*  family = cffface->family_name;
 
530
 
 
531
          /* We try to extract the style name from the full name.   */
 
532
          /* We need to ignore spaces and dashes during the search. */
 
533
          if ( full )
 
534
          {
 
535
            while ( *fullp )
 
536
            {
 
537
              /* skip common characters at the start of both strings */
 
538
              if ( *fullp == *family )
 
539
              {
 
540
                family++;
 
541
                fullp++;
 
542
                continue;
 
543
              }
 
544
 
 
545
              /* ignore spaces and dashes in full name during comparison */
 
546
              if ( *fullp == ' ' || *fullp == '-' )
 
547
              {
 
548
                fullp++;
 
549
                continue;
 
550
              }
 
551
 
 
552
              /* ignore spaces and dashes in family name during comparison */
 
553
              if ( *family == ' ' || *family == '-' )
 
554
              {
 
555
                family++;
 
556
                continue;
 
557
              }
 
558
 
 
559
              if ( !*family && *fullp )
 
560
              {
 
561
                /* Rhe full name begins with the same characters as the  */
 
562
                /* family name, with spaces and dashes removed.  In this */
 
563
                /* case, the remaining string in `fullp' will be used as */
 
564
                /* the style name.                                       */
 
565
                style_name = cff_strcpy( memory, fullp );
 
566
              }
 
567
              break;
 
568
            }
 
569
            FT_FREE( full );
 
570
          }
 
571
        }
 
572
        else
 
573
        {
 
574
          char  *cid_font_name =
 
575
                   cff_index_get_sid_string( &cff->string_index,
 
576
                                             dict->cid_font_name,
 
577
                                             psnames );
 
578
 
 
579
 
 
580
          /* do we have a `/FontName' for a CID-keyed font? */
 
581
          if ( cid_font_name )
 
582
            cffface->family_name = cid_font_name;
 
583
        }
 
584
 
 
585
        if ( style_name )
 
586
          cffface->style_name = style_name;
 
587
        else
 
588
          /* assume "Regular" style if we don't know better */
 
589
          cffface->style_name = cff_strcpy( memory, (char *)"Regular" );
 
590
 
 
591
        /*******************************************************************/
 
592
        /*                                                                 */
 
593
        /* Compute face flags.                                             */
 
594
        /*                                                                 */
 
595
        flags = FT_FACE_FLAG_SCALABLE  |    /* scalable outlines */
 
596
                FT_FACE_FLAG_HORIZONTAL;    /* horizontal data   */
 
597
 
 
598
        if ( sfnt_format )
 
599
          flags |= FT_FACE_FLAG_SFNT;
 
600
 
 
601
        /* fixed width font? */
 
602
        if ( dict->is_fixed_pitch )
 
603
          flags |= FT_FACE_FLAG_FIXED_WIDTH;
 
604
 
 
605
  /* XXX: WE DO NOT SUPPORT KERNING METRICS IN THE GPOS TABLE FOR NOW */
 
606
#if 0
 
607
        /* kerning available? */
 
608
        if ( face->kern_pairs )
 
609
          flags |= FT_FACE_FLAG_KERNING;
 
610
#endif
 
611
 
 
612
        cffface->face_flags = flags;
 
613
 
 
614
        /*******************************************************************/
 
615
        /*                                                                 */
 
616
        /* Compute style flags.                                            */
 
617
        /*                                                                 */
 
618
        flags = 0;
 
619
 
 
620
        if ( dict->italic_angle )
 
621
          flags |= FT_STYLE_FLAG_ITALIC;
 
622
 
 
623
        {
 
624
          char  *weight = cff_index_get_sid_string( &cff->string_index,
 
625
                                                    dict->weight,
 
626
                                                    psnames );
 
627
 
 
628
 
 
629
          if ( weight )
 
630
            if ( !ft_strcmp( weight, "Bold"  ) ||
 
631
                 !ft_strcmp( weight, "Black" ) )
 
632
              flags |= FT_STYLE_FLAG_BOLD;
 
633
          FT_FREE( weight );
 
634
        }
 
635
 
 
636
        cffface->style_flags = flags;
 
637
      }
 
638
 
 
639
#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
 
640
      /* CID-keyed CFF fonts don't have glyph names -- the SFNT loader */
 
641
      /* has unset this flag because of the 3.0 `post' table           */
 
642
      if ( dict->cid_registry == 0xFFFFU )
 
643
        cffface->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
 
644
#endif
 
645
 
 
646
      /*******************************************************************/
 
647
      /*                                                                 */
 
648
      /* Compute char maps.                                              */
 
649
      /*                                                                 */
 
650
 
 
651
      /* Try to synthetize a Unicode charmap if there is none available */
 
652
      /* already.  If an OpenType font contains a Unicode "cmap", we    */
 
653
      /* will use it, whatever be in the CFF part of the file.          */
 
654
      {
 
655
        FT_CharMapRec  cmaprec;
 
656
        FT_CharMap     cmap;
 
657
        FT_UInt        nn;
 
658
        CFF_Encoding   encoding = &cff->encoding;
 
659
 
 
660
 
 
661
        for ( nn = 0; nn < (FT_UInt)cffface->num_charmaps; nn++ )
 
662
        {
 
663
          cmap = cffface->charmaps[nn];
 
664
 
 
665
          /* Windows Unicode (3,1)? */
 
666
          if ( cmap->platform_id == 3 && cmap->encoding_id == 1 )
 
667
            goto Skip_Unicode;
 
668
 
 
669
          /* Deprecated Unicode platform id? */
 
670
          if ( cmap->platform_id == 0 )
 
671
            goto Skip_Unicode; /* Standard Unicode (deprecated) */
 
672
        }
 
673
 
 
674
        /* since CID-keyed fonts don't contain glyph names, we can't */
 
675
        /* construct a cmap                                          */
 
676
        if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU )
 
677
          goto Exit;
 
678
 
 
679
        /* we didn't find a Unicode charmap -- synthetize one */
 
680
        cmaprec.face        = cffface;
 
681
        cmaprec.platform_id = 3;
 
682
        cmaprec.encoding_id = 1;
 
683
        cmaprec.encoding    = FT_ENCODING_UNICODE;
 
684
 
 
685
        nn = (FT_UInt)cffface->num_charmaps;
 
686
 
 
687
        FT_CMap_New( &cff_cmap_unicode_class_rec, NULL, &cmaprec, NULL );
 
688
 
 
689
        /* if no Unicode charmap was previously selected, select this one */
 
690
        if ( cffface->charmap == NULL && nn != (FT_UInt)cffface->num_charmaps )
 
691
          cffface->charmap = cffface->charmaps[nn];
 
692
 
 
693
      Skip_Unicode:
 
694
        if ( encoding->count > 0 )
 
695
        {
 
696
          FT_CMap_Class  clazz;
 
697
 
 
698
 
 
699
          cmaprec.face        = cffface;
 
700
          cmaprec.platform_id = 7;  /* Adobe platform id */
 
701
 
 
702
          if ( encoding->offset == 0 )
 
703
          {
 
704
            cmaprec.encoding_id = TT_ADOBE_ID_STANDARD;
 
705
            cmaprec.encoding    = FT_ENCODING_ADOBE_STANDARD;
 
706
            clazz               = &cff_cmap_encoding_class_rec;
 
707
          }
 
708
          else if ( encoding->offset == 1 )
 
709
          {
 
710
            cmaprec.encoding_id = TT_ADOBE_ID_EXPERT;
 
711
            cmaprec.encoding    = FT_ENCODING_ADOBE_EXPERT;
 
712
            clazz               = &cff_cmap_encoding_class_rec;
 
713
          }
 
714
          else
 
715
          {
 
716
            cmaprec.encoding_id = TT_ADOBE_ID_CUSTOM;
 
717
            cmaprec.encoding    = FT_ENCODING_ADOBE_CUSTOM;
 
718
            clazz               = &cff_cmap_encoding_class_rec;
 
719
          }
 
720
 
 
721
          FT_CMap_New( clazz, NULL, &cmaprec, NULL );
 
722
        }
 
723
      }
 
724
    }
 
725
 
 
726
  Exit:
 
727
    return error;
 
728
 
 
729
  Bad_Format:
 
730
    error = CFF_Err_Unknown_File_Format;
 
731
    goto Exit;
 
732
  }
 
733
 
 
734
 
 
735
  FT_LOCAL_DEF( void )
 
736
  cff_face_done( FT_Face  cffface )         /* CFF_Face */
 
737
  {
 
738
    CFF_Face      face   = (CFF_Face)cffface;
 
739
    FT_Memory     memory = cffface->memory;
 
740
    SFNT_Service  sfnt   = (SFNT_Service)face->sfnt;
 
741
 
 
742
 
 
743
    if ( sfnt )
 
744
      sfnt->done_face( face );
 
745
 
 
746
    {
 
747
      CFF_Font  cff = (CFF_Font)face->extra.data;
 
748
 
 
749
 
 
750
      if ( cff )
 
751
      {
 
752
        cff_font_done( cff );
 
753
        FT_FREE( face->extra.data );
 
754
      }
 
755
    }
 
756
  }
 
757
 
 
758
 
 
759
  FT_LOCAL_DEF( FT_Error )
 
760
  cff_driver_init( FT_Module  module )
 
761
  {
 
762
    FT_UNUSED( module );
 
763
 
 
764
    return CFF_Err_Ok;
 
765
  }
 
766
 
 
767
 
 
768
  FT_LOCAL_DEF( void )
 
769
  cff_driver_done( FT_Module  module )
 
770
  {
 
771
    FT_UNUSED( module );
 
772
  }
 
773
 
 
774
 
 
775
/* END */