misc/libfreetype/src/cff/cffobjs.c
author c_korn
Mon, 03 Jun 2013 23:25:15 +0200
branch0.9.19
changeset 9112 cefab5ac8f0f
parent 5172 88f2e05288ba
permissions -rw-r--r--
http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#deprecated-items - The Encoding key is deprecated.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  cffobjs.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    OpenType objects manager (body).                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2011 by                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_CALC_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_ERRORS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_TRUETYPE_IDS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include FT_INTERNAL_SFNT_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "cffobjs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include "cffload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include "cffcmap.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include "cfferrs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#include "cffpic.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#define FT_COMPONENT  trace_cffobjs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*                            SIZE FUNCTIONS                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /*  Note that we store the global hints in the size's `internal' root    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*  field.                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  static PSH_Globals_Funcs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  cff_size_get_globals_funcs( CFF_Size  size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    CFF_Face          face     = (CFF_Face)size->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    CFF_Font          font     = (CFF_Font)face->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    PSHinter_Service  pshinter = font->pshinter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    FT_Module         module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    module = FT_Get_Module( size->root.face->driver->root.library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
                            "pshinter" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    return ( module && pshinter && pshinter->get_globals_funcs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
           ? pshinter->get_globals_funcs( module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
           : 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  cff_size_done( FT_Size  cffsize )        /* CFF_Size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    CFF_Size      size     = (CFF_Size)cffsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    CFF_Face      face     = (CFF_Face)size->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    CFF_Font      font     = (CFF_Font)face->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    CFF_Internal  internal = (CFF_Internal)cffsize->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    if ( internal )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      PSH_Globals_Funcs  funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      funcs = cff_size_get_globals_funcs( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      if ( funcs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
        FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
        funcs->destroy( internal->topfont );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
        for ( i = font->num_subfonts; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
          funcs->destroy( internal->subfonts[i - 1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
      /* `internal' is freed by destroy_size (in ftobjs.c) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  /* CFF and Type 1 private dictionaries have slightly different      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  /* structures; we need to synthesize a Type 1 dictionary on the fly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  cff_make_private_dict( CFF_SubFont  subfont,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
                         PS_Private   priv )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    CFF_Private  cpriv = &subfont->private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    FT_UInt      n, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    FT_MEM_ZERO( priv, sizeof ( *priv ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    count = priv->num_blue_values = cpriv->num_blue_values;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      priv->blue_values[n] = (FT_Short)cpriv->blue_values[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    count = priv->num_other_blues = cpriv->num_other_blues;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      priv->other_blues[n] = (FT_Short)cpriv->other_blues[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    count = priv->num_family_blues = cpriv->num_family_blues;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      priv->family_blues[n] = (FT_Short)cpriv->family_blues[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    count = priv->num_family_other_blues = cpriv->num_family_other_blues;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
      priv->family_other_blues[n] = (FT_Short)cpriv->family_other_blues[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    priv->blue_scale = cpriv->blue_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    priv->blue_shift = (FT_Int)cpriv->blue_shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    priv->blue_fuzz  = (FT_Int)cpriv->blue_fuzz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    priv->standard_width[0]  = (FT_UShort)cpriv->standard_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    priv->standard_height[0] = (FT_UShort)cpriv->standard_height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    count = priv->num_snap_widths = cpriv->num_snap_widths;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
      priv->snap_widths[n] = (FT_Short)cpriv->snap_widths[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    count = priv->num_snap_heights = cpriv->num_snap_heights;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
      priv->snap_heights[n] = (FT_Short)cpriv->snap_heights[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    priv->force_bold     = cpriv->force_bold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    priv->language_group = cpriv->language_group;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    priv->lenIV          = cpriv->lenIV;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
  cff_size_init( FT_Size  cffsize )         /* CFF_Size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    CFF_Size           size  = (CFF_Size)cffsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    FT_Error           error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    PSH_Globals_Funcs  funcs = cff_size_get_globals_funcs( size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    if ( funcs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      CFF_Face      face     = (CFF_Face)cffsize->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      CFF_Font      font     = (CFF_Font)face->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      CFF_Internal  internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      PS_PrivateRec  priv;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      FT_Memory      memory = cffsize->face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      if ( FT_NEW( internal ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      cff_make_private_dict( &font->top_font, &priv );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      error = funcs->create( cffsize->face->memory, &priv,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
                             &internal->topfont );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
      for ( i = font->num_subfonts; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        CFF_SubFont  sub = font->subfonts[i - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
        cff_make_private_dict( sub, &priv );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
        error = funcs->create( cffsize->face->memory, &priv,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
                               &internal->subfonts[i - 1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      cffsize->internal = (FT_Size_Internal)(void*)internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    size->strike_index = 0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  cff_size_select( FT_Size   size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
                   FT_ULong  strike_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    CFF_Size           cffsize = (CFF_Size)size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    PSH_Globals_Funcs  funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    cffsize->strike_index = strike_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    FT_Select_Metrics( size->face, strike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    funcs = cff_size_get_globals_funcs( cffsize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    if ( funcs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
      CFF_Face      face     = (CFF_Face)size->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
      CFF_Font      font     = (CFF_Font)face->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      CFF_Internal  internal = (CFF_Internal)size->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      FT_ULong  top_upm  = font->top_font.font_dict.units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      FT_UInt   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      funcs->set_scale( internal->topfont,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
                        size->metrics.x_scale, size->metrics.y_scale,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
                        0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      for ( i = font->num_subfonts; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
        CFF_SubFont  sub     = font->subfonts[i - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
        FT_ULong     sub_upm = sub->font_dict.units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
        FT_Pos       x_scale, y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
        if ( top_upm != sub_upm )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
          x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
          y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
          x_scale = size->metrics.x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
          y_scale = size->metrics.y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
        funcs->set_scale( internal->subfonts[i - 1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
                          x_scale, y_scale, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    return CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
  cff_size_request( FT_Size          size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
                    FT_Size_Request  req )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    CFF_Size           cffsize = (CFF_Size)size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    PSH_Globals_Funcs  funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    if ( FT_HAS_FIXED_SIZES( size->face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      CFF_Face      cffface = (CFF_Face)size->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      SFNT_Service  sfnt    = (SFNT_Service)cffface->sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
      FT_ULong      strike_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      if ( sfnt->set_sbit_strike( cffface, req, &strike_index ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
        cffsize->strike_index = 0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
        return cff_size_select( size, strike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    FT_Request_Metrics( size->face, req );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    funcs = cff_size_get_globals_funcs( cffsize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    if ( funcs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      CFF_Face      cffface  = (CFF_Face)size->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      CFF_Font      font     = (CFF_Font)cffface->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      CFF_Internal  internal = (CFF_Internal)size->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
      FT_ULong  top_upm  = font->top_font.font_dict.units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      FT_UInt   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      funcs->set_scale( internal->topfont,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
                        size->metrics.x_scale, size->metrics.y_scale,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
                        0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      for ( i = font->num_subfonts; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
        CFF_SubFont  sub     = font->subfonts[i - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
        FT_ULong     sub_upm = sub->font_dict.units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
        FT_Pos       x_scale, y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
        if ( top_upm != sub_upm )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
          x_scale = FT_MulDiv( size->metrics.x_scale, top_upm, sub_upm );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
          y_scale = FT_MulDiv( size->metrics.y_scale, top_upm, sub_upm );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
          x_scale = size->metrics.x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
          y_scale = size->metrics.y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
        funcs->set_scale( internal->subfonts[i - 1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
                          x_scale, y_scale, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    return CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  /*                            SLOT  FUNCTIONS                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  cff_slot_done( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    slot->internal->glyph_hints = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  cff_slot_init( FT_GlyphSlot  slot )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    CFF_Face          face     = (CFF_Face)slot->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    CFF_Font          font     = (CFF_Font)face->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    PSHinter_Service  pshinter = font->pshinter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    if ( pshinter )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      FT_Module  module;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
      module = FT_Get_Module( slot->face->driver->root.library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
                              "pshinter" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
      if ( module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
        T2_Hints_Funcs  funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
        funcs = pshinter->get_t2_funcs( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
        slot->internal->glyph_hints = (void*)funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    return CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
  /*                           FACE  FUNCTIONS                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
  static FT_String*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
  cff_strcpy( FT_Memory         memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
              const FT_String*  source )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    FT_String*  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    (void)FT_STRDUP( result, source );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
    FT_UNUSED( error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
  /* Strip all subset prefixes of the form `ABCDEF+'.  Usually, there */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
  /* is only one, but font names like `APCOOG+JFABTD+FuturaBQ-Bold'   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
  /* have been seen in the wild.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
  remove_subset_prefix( FT_String*  name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
    FT_Int32  idx             = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    FT_Int32  length          = strlen( name ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    FT_Bool   continue_search = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    while ( continue_search )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
      if ( length >= 7 && name[6] == '+' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
        for ( idx = 0; idx < 6; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
          /* ASCII uppercase letters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
          if ( !( 'A' <= name[idx] && name[idx] <= 'Z' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
            continue_search = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
        if ( continue_search )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
          for ( idx = 7; idx < length; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
            name[idx - 7] = name[idx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
          length -= 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
        continue_search = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
  /* Remove the style part from the family name (if present). */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
  remove_style( FT_String*        family_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
                const FT_String*  style_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    FT_Int32  family_name_length, style_name_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
    family_name_length = strlen( family_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
    style_name_length  = strlen( style_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
    if ( family_name_length > style_name_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      FT_Int  idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
      for ( idx = 1; idx <= style_name_length; ++idx )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
        if ( family_name[family_name_length - idx] !=
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
             style_name[style_name_length - idx] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      if ( idx > style_name_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        /* family_name ends with style_name; remove it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
        idx = family_name_length - style_name_length - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
        /* also remove special characters     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
        /* between real family name and style */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
        while ( idx > 0                     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
                ( family_name[idx] == '-' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
                  family_name[idx] == ' ' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
                  family_name[idx] == '_' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
                  family_name[idx] == '+' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
          --idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
        if ( idx > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
          family_name[idx + 1] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
  cff_face_init( FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
                 FT_Face        cffface,        /* CFF_Face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
                 FT_Int         face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
                 FT_Int         num_params,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
                 FT_Parameter*  params )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    CFF_Face            face        = (CFF_Face)cffface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    FT_Error            error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    SFNT_Service        sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    FT_Service_PsCMaps  psnames;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    PSHinter_Service    pshinter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
    FT_Bool             pure_cff    = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    FT_Bool             sfnt_format = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    FT_Library          library     = cffface->driver->root.library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    sfnt = (SFNT_Service)FT_Get_Module_Interface(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
             library, "sfnt" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    if ( !sfnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
      goto Bad_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    pshinter = (PSHinter_Service)FT_Get_Module_Interface(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
                 library, "pshinter" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    /* create input stream from resource */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    if ( FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    /* check whether we have a valid OpenType file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
    error = sfnt->init_face( stream, face, face_index, num_params, params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      if ( face->format_tag != TTAG_OTTO )  /* `OTTO'; OpenType/CFF font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
        FT_TRACE2(( "[not a valid OpenType/CFF font]\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
        goto Bad_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
      /* if we are performing a simple font format check, exit immediately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      if ( face_index < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
        return CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
      /* UNDOCUMENTED!  A CFF in an SFNT can have only a single font. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
      if ( face_index > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
        FT_ERROR(( "cff_face_init: invalid face index\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
        error = CFF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
      sfnt_format = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
      /* now, the font can be either an OpenType/CFF font, or an SVG CEF */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
      /* font; in the latter case it doesn't have a `head' table         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
      error = face->goto_table( face, TTAG_head, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
        pure_cff = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
        /* load font directory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
        error = sfnt->load_face( stream, face, 0, num_params, params );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
        /* load the `cmap' table explicitly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
        error = sfnt->load_cmap( face, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
        /* XXX: we don't load the GPOS table, as OpenType Layout     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
        /* support will be added later to a layout library on top of */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
        /* FreeType 2                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
      /* now load the CFF part of the file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
      error = face->goto_table( face, TTAG_CFF, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      /* rewind to start of file; we are going to load a pure-CFF font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      if ( FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
      error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    /* now load and parse the CFF table in the file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
      CFF_Font         cff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
      CFF_FontRecDict  dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
      FT_Memory        memory = cffface->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
      FT_Int32         flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
      FT_UInt          i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      if ( FT_NEW( cff ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
      face->extra.data = cff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
      error = cff_font_load( library, stream, face_index, cff, pure_cff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
      cff->pshinter = pshinter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
      cff->psnames  = psnames;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
      cffface->face_index = face_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
      /* Complement the root flags with some interesting information. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      /* Note that this is only necessary for pure CFF and CEF fonts; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      /* SFNT based fonts use the `name' table instead.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      cffface->num_glyphs = cff->num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
      dict = &cff->top_font.font_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
      /* we need the `PSNames' module for CFF and CEF formats */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
      /* which aren't CID-keyed                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      if ( dict->cid_registry == 0xFFFFU && !psnames )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
        FT_ERROR(( "cff_face_init:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
                   " cannot open CFF & CEF fonts\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
                   "              "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
                   " without the `PSNames' module\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
        goto Bad_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
      if ( !dict->units_per_em )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
        dict->units_per_em = pure_cff ? 1000 : face->root.units_per_EM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      /* Normalize the font matrix so that `matrix->xx' is 1; the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
      /* scaling is done with `units_per_em' then (at this point, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      /* it already contains the scaling factor, but without      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
      /* normalization of the matrix).                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      /*                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      /* Note that the offsets must be expressed in integer font  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      /* units.                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        FT_Matrix*  matrix = &dict->font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
        FT_Vector*  offset = &dict->font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        FT_ULong*   upm    = &dict->units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        FT_Fixed    temp   = FT_ABS( matrix->yy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
        if ( temp != 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
          *upm = FT_DivFix( *upm, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
          matrix->xx = FT_DivFix( matrix->xx, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
          matrix->yx = FT_DivFix( matrix->yx, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
          matrix->xy = FT_DivFix( matrix->xy, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
          matrix->yy = FT_DivFix( matrix->yy, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
          offset->x  = FT_DivFix( offset->x,  temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
          offset->y  = FT_DivFix( offset->y,  temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
        offset->x >>= 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
        offset->y >>= 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      for ( i = cff->num_subfonts; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
        CFF_FontRecDict  sub = &cff->subfonts[i - 1]->font_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
        CFF_FontRecDict  top = &cff->top_font.font_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        FT_Matrix*  matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
        FT_Vector*  offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        FT_ULong*   upm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
        FT_Fixed    temp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
        if ( sub->units_per_em )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
          FT_Long  scaling;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
          if ( top->units_per_em > 1 && sub->units_per_em > 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
            scaling = FT_MIN( top->units_per_em, sub->units_per_em );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
            scaling = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
          FT_Matrix_Multiply_Scaled( &top->font_matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
                                     &sub->font_matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
                                     scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
          FT_Vector_Transform_Scaled( &sub->font_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
                                      &top->font_matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
                                      scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
          sub->units_per_em = FT_MulDiv( sub->units_per_em,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
                                         top->units_per_em,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
                                         scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
          sub->font_matrix = top->font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
          sub->font_offset = top->font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
          sub->units_per_em = top->units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
        matrix = &sub->font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
        offset = &sub->font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
        upm    = &sub->units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
        temp   = FT_ABS( matrix->yy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
        if ( temp != 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
          *upm = FT_DivFix( *upm, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
          /* if *upm is larger than 100*1000 we divide by 1000 --     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
          /* this can happen if e.g. there is no top-font FontMatrix  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
          /* and the subfont FontMatrix already contains the complete */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
          /* scaling for the subfont (see section 5.11 of the PLRM)   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
          /* 100 is a heuristic value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
          if ( *upm > 100L * 1000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
            *upm = ( *upm + 500 ) / 1000;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
          matrix->xx = FT_DivFix( matrix->xx, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
          matrix->yx = FT_DivFix( matrix->yx, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
          matrix->xy = FT_DivFix( matrix->xy, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
          matrix->yy = FT_DivFix( matrix->yy, temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
          offset->x  = FT_DivFix( offset->x,  temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
          offset->y  = FT_DivFix( offset->y,  temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
        offset->x >>= 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
        offset->y >>= 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
      if ( pure_cff )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
        char*  style_name = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
        /* set up num_faces */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
        cffface->num_faces = cff->num_faces;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
        /* compute number of glyphs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
        if ( dict->cid_registry != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
          cffface->num_glyphs = cff->charset.max_cid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
          cffface->num_glyphs = cff->charstrings_index.count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
        /* set global bbox, as well as EM size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
        cffface->bbox.xMin =   dict->font_bbox.xMin            >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
        cffface->bbox.yMin =   dict->font_bbox.yMin            >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
        /* no `U' suffix here to 0xFFFF! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
        cffface->bbox.xMax = ( dict->font_bbox.xMax + 0xFFFF ) >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
        cffface->bbox.yMax = ( dict->font_bbox.yMax + 0xFFFF ) >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
        cffface->units_per_EM = (FT_UShort)( dict->units_per_em );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
        cffface->ascender  = (FT_Short)( cffface->bbox.yMax );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
        cffface->descender = (FT_Short)( cffface->bbox.yMin );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
        cffface->height = (FT_Short)( ( cffface->units_per_EM * 12 ) / 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
        if ( cffface->height < cffface->ascender - cffface->descender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
          cffface->height = (FT_Short)( cffface->ascender - cffface->descender );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
        cffface->underline_position  =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
          (FT_Short)( dict->underline_position >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
        cffface->underline_thickness =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
          (FT_Short)( dict->underline_thickness >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
        /* retrieve font family & style name */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
        cffface->family_name = cff_index_get_name( cff, face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
        if ( cffface->family_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
          char*  full   = cff_index_get_sid_string( cff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
                                                    dict->full_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
          char*  fullp  = full;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
          char*  family = cffface->family_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
          char*  family_name = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
          remove_subset_prefix( cffface->family_name ); 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
          if ( dict->family_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
            family_name = cff_index_get_sid_string( cff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
                                                    dict->family_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
            if ( family_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
              family = family_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
          /* We try to extract the style name from the full name.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
          /* We need to ignore spaces and dashes during the search. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
          if ( full && family )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
            while ( *fullp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
              /* skip common characters at the start of both strings */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
              if ( *fullp == *family )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
                family++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
                fullp++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
                continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
              /* ignore spaces and dashes in full name during comparison */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
              if ( *fullp == ' ' || *fullp == '-' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
                fullp++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
                continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
              /* ignore spaces and dashes in family name during comparison */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
              if ( *family == ' ' || *family == '-' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
                family++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
                continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
              if ( !*family && *fullp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
                /* The full name begins with the same characters as the  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
                /* family name, with spaces and dashes removed.  In this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
                /* case, the remaining string in `fullp' will be used as */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
                /* the style name.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
                style_name = cff_strcpy( memory, fullp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
                /* remove the style part from the family name (if present) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
                remove_style( cffface->family_name, style_name ); 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
          char  *cid_font_name =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
                   cff_index_get_sid_string( cff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
                                             dict->cid_font_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
          /* do we have a `/FontName' for a CID-keyed font? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
          if ( cid_font_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
            cffface->family_name = cff_strcpy( memory, cid_font_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
        if ( style_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
          cffface->style_name = style_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
          /* assume "Regular" style if we don't know better */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
          cffface->style_name = cff_strcpy( memory, (char *)"Regular" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        /*******************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
        /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
        /* Compute face flags.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
        /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
        flags = (FT_UInt32)( FT_FACE_FLAG_SCALABLE   | /* scalable outlines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
                             FT_FACE_FLAG_HORIZONTAL | /* horizontal data   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
                             FT_FACE_FLAG_HINTER );    /* has native hinter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
        if ( sfnt_format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
          flags |= (FT_UInt32)FT_FACE_FLAG_SFNT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
        /* fixed width font? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
        if ( dict->is_fixed_pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
          flags |= (FT_UInt32)FT_FACE_FLAG_FIXED_WIDTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
  /* XXX: WE DO NOT SUPPORT KERNING METRICS IN THE GPOS TABLE FOR NOW */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
        /* kerning available? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
        if ( face->kern_pairs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
          flags |= (FT_UInt32)FT_FACE_FLAG_KERNING;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
        cffface->face_flags = flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
        /*******************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
        /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
        /* Compute style flags.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
        /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
        flags = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
        if ( dict->italic_angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
          flags |= FT_STYLE_FLAG_ITALIC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
          char  *weight = cff_index_get_sid_string( cff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
                                                    dict->weight );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
          if ( weight )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
            if ( !ft_strcmp( weight, "Bold"  ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
                 !ft_strcmp( weight, "Black" ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
              flags |= FT_STYLE_FLAG_BOLD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
        /* double check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
        if ( !(flags & FT_STYLE_FLAG_BOLD) && cffface->style_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
          if ( !ft_strncmp( cffface->style_name, "Bold", 4 )  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
               !ft_strncmp( cffface->style_name, "Black", 5 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
            flags |= FT_STYLE_FLAG_BOLD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
        cffface->style_flags = flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
      /* CID-keyed CFF fonts don't have glyph names -- the SFNT loader */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
      /* has unset this flag because of the 3.0 `post' table.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
      if ( dict->cid_registry == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
        cffface->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
      if ( dict->cid_registry != 0xFFFFU && pure_cff )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
        cffface->face_flags |= FT_FACE_FLAG_CID_KEYED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
      /*******************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
      /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
      /* Compute char maps.                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
      /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
      /* Try to synthesize a Unicode charmap if there is none available */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
      /* already.  If an OpenType font contains a Unicode "cmap", we    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      /* will use it, whatever be in the CFF part of the file.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
        FT_CharMapRec  cmaprec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
        FT_CharMap     cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
        FT_UInt        nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
        CFF_Encoding   encoding = &cff->encoding;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
        for ( nn = 0; nn < (FT_UInt)cffface->num_charmaps; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
          cmap = cffface->charmaps[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
          /* Windows Unicode? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
          if ( cmap->platform_id == TT_PLATFORM_MICROSOFT &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
               cmap->encoding_id == TT_MS_ID_UNICODE_CS   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
            goto Skip_Unicode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
          /* Apple Unicode platform id? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
          if ( cmap->platform_id == TT_PLATFORM_APPLE_UNICODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
            goto Skip_Unicode; /* Apple Unicode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
        /* since CID-keyed fonts don't contain glyph names, we can't */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
        /* construct a cmap                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
        if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
        if ( nn + 1 > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
          FT_ERROR(( "cff_face_init: no Unicode cmap is found, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
                     "and too many subtables (%d) to add synthesized cmap\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
                     nn ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
        /* we didn't find a Unicode charmap -- synthesize one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
        cmaprec.face        = cffface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
        cmaprec.platform_id = TT_PLATFORM_MICROSOFT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
        cmaprec.encoding_id = TT_MS_ID_UNICODE_CS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
        cmaprec.encoding    = FT_ENCODING_UNICODE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
        nn = (FT_UInt)cffface->num_charmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
        error = FT_CMap_New( &FT_CFF_CMAP_UNICODE_CLASS_REC_GET, NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
                             &cmaprec, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
        if ( error && FT_Err_No_Unicode_Glyph_Name != error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
        error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
        /* if no Unicode charmap was previously selected, select this one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
        if ( cffface->charmap == NULL && nn != (FT_UInt)cffface->num_charmaps )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
          cffface->charmap = cffface->charmaps[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
      Skip_Unicode:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
        if ( nn > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
          FT_ERROR(( "cff_face_init: Unicode cmap is found, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
                     "but too many preceding subtables (%d) to access\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
                     nn - 1 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
        if ( encoding->count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
          FT_CMap_Class  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
          cmaprec.face        = cffface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
          cmaprec.platform_id = TT_PLATFORM_ADOBE;  /* Adobe platform id */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
          if ( encoding->offset == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
            cmaprec.encoding_id = TT_ADOBE_ID_STANDARD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
            cmaprec.encoding    = FT_ENCODING_ADOBE_STANDARD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
            clazz               = &FT_CFF_CMAP_ENCODING_CLASS_REC_GET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
          else if ( encoding->offset == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
            cmaprec.encoding_id = TT_ADOBE_ID_EXPERT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
            cmaprec.encoding    = FT_ENCODING_ADOBE_EXPERT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
            clazz               = &FT_CFF_CMAP_ENCODING_CLASS_REC_GET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
            cmaprec.encoding_id = TT_ADOBE_ID_CUSTOM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
            cmaprec.encoding    = FT_ENCODING_ADOBE_CUSTOM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
            clazz               = &FT_CFF_CMAP_ENCODING_CLASS_REC_GET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
          error = FT_CMap_New( clazz, NULL, &cmaprec, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
  Bad_Format:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    error = CFF_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
  cff_face_done( FT_Face  cffface )         /* CFF_Face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
    CFF_Face      face = (CFF_Face)cffface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
    FT_Memory     memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    SFNT_Service  sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
    memory = cffface->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
    sfnt   = (SFNT_Service)face->sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
    if ( sfnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
      sfnt->done_face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
      CFF_Font  cff = (CFF_Font)face->extra.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
      if ( cff )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
        cff_font_done( cff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
        FT_FREE( face->extra.data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
  cff_driver_init( FT_Module  module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
    FT_UNUSED( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    return CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
  cff_driver_done( FT_Module  module )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
    FT_UNUSED( module );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
/* END */