misc/libfreetype/src/cid/cidload.c
author nemo
Sat, 22 Oct 2011 11:50:55 -0400
changeset 6184 335ece2bce9c
parent 5172 88f2e05288ba
permissions -rw-r--r--
Tweak ratios to deemphasise foreground flakes further
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
/*  cidload.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
/*    CID-keyed Type1 font loader (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-2001, 2002, 2003, 2004, 2005, 2006, 2009 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_CONFIG_CONFIG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_MULTIPLE_MASTERS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_TYPE1_TYPES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "cidload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "ciderrs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* 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
    33
  /* 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
    34
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#define FT_COMPONENT  trace_cidload
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
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
  /* read a single offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  FT_LOCAL_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  cid_get_offset( FT_Byte*  *start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                  FT_Byte    offsize )
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
    FT_Long   result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_Byte*  p = *start;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    for ( result = 0; offsize > 0; offsize-- )
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
      result <<= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
      result  |= *p++;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    *start = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  /*************************************************************************/
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
  /*****                    TYPE 1 SYMBOL PARSING                      *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  cid_load_keyword( CID_Face        face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                    CID_Loader*     loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
                    const T1_Field  keyword )
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
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    CID_Parser*   parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    FT_Byte*      object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    void*         dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    CID_FaceInfo  cid = &face->cid;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    /* if the keyword has a dedicated callback, call it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    if ( keyword->type == T1_FIELD_TYPE_CALLBACK )
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
      keyword->reader( (FT_Face)face, parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      error = parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    /* we must now compute the address of our target object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    switch ( keyword->location )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    case T1_FIELD_LOCATION_CID_INFO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
      object = (FT_Byte*)cid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      break;
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
    case T1_FIELD_LOCATION_FONT_INFO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
      object = (FT_Byte*)&cid->font_info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      break;
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
    case T1_FIELD_LOCATION_FONT_EXTRA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      object = (FT_Byte*)&face->font_extra;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    case T1_FIELD_LOCATION_BBOX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
      object = (FT_Byte*)&cid->font_bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        CID_FaceDict  dict;
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
        if ( parser->num_dict < 0 )
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
          FT_ERROR(( "cid_load_keyword: invalid use of `%s'\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
                     keyword->ident ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
          error = CID_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        dict = cid->font_dicts + parser->num_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        switch ( keyword->location )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
        case T1_FIELD_LOCATION_PRIVATE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
          object = (FT_Byte*)&dict->private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
        default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
          object = (FT_Byte*)dict;
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    dummy_object = object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    /* now, load the keyword data in the object's field(s) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    if ( keyword->type == T1_FIELD_TYPE_INTEGER_ARRAY ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
         keyword->type == T1_FIELD_TYPE_FIXED_ARRAY   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      error = cid_parser_load_field_table( &loader->parser, keyword,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
                                           &dummy_object );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      error = cid_parser_load_field( &loader->parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
                                     keyword, &dummy_object );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
  parse_font_matrix( CID_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
                     CID_Parser*  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    FT_Matrix*    matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    FT_Vector*    offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    CID_FaceDict  dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    FT_Face       root = (FT_Face)&face->root;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    FT_Fixed      temp[6];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    FT_Fixed      temp_scale;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    if ( parser->num_dict >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      dict   = face->cid.font_dicts + parser->num_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      matrix = &dict->font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      offset = &dict->font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      (void)cid_parser_to_fixed_array( parser, 6, temp, 3 );
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
      temp_scale = FT_ABS( temp[3] );
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
      /* Set units per EM based on FontMatrix values.  We set the value to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      /* `1000/temp_scale', because temp_scale was already multiplied by   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
      /* 1000 (in `t1_tofixed', from psobjs.c).                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      root->units_per_EM = (FT_UShort)( FT_DivFix( 0x10000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
                                        FT_DivFix( temp_scale, 1000 ) ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      /* we need to scale the values by 1.0/temp[3] */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      if ( temp_scale != 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
        temp[0] = FT_DivFix( temp[0], temp_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
        temp[1] = FT_DivFix( temp[1], temp_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
        temp[2] = FT_DivFix( temp[2], temp_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        temp[4] = FT_DivFix( temp[4], temp_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        temp[5] = FT_DivFix( temp[5], temp_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
        temp[3] = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
      matrix->xx = temp[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
      matrix->yx = temp[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
      matrix->xy = temp[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
      matrix->yy = temp[3];
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
      /* note that the font offsets are expressed in integer font units */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      offset->x  = temp[4] >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      offset->y  = temp[5] >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    }
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
    return CID_Err_Ok;      /* this is a callback function; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
                            /* we must return an error code */
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
  parse_fd_array( CID_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
                  CID_Parser*  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    CID_FaceInfo  cid    = &face->cid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    FT_Memory     memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    FT_Error      error  = CID_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    FT_Long       num_dicts;
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
    num_dicts = cid_parser_to_int( parser );
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
    if ( !cid->font_dicts )
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
      FT_Int  n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      cid->num_dicts = (FT_UInt)num_dicts;
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
      /* don't forget to set a few defaults */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      for ( n = 0; n < cid->num_dicts; n++ )
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
        CID_FaceDict  dict = cid->font_dicts + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
        /* default value for lenIV */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
        dict->private_dict.lenIV = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  /* by mistake, `expansion_factor' appears both in PS_PrivateRec */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
  /* and CID_FaceDictRec (both are public header files and can't  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  /* changed); we simply copy the value                           */
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  parse_expansion_factor( CID_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
                          CID_Parser*  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    CID_FaceDict  dict;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    if ( parser->num_dict >= 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
      dict = face->cid.font_dicts + parser->num_dict;
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
      dict->expansion_factor              = cid_parser_to_fixed( parser, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
      dict->private_dict.expansion_factor = dict->expansion_factor;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    return CID_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  const T1_FieldRec  cid_field_records[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
#include "cidtoken.h"
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
    T1_FIELD_CALLBACK( "FDArray",         parse_fd_array, 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
    T1_FIELD_CALLBACK( "FontMatrix",      parse_font_matrix, 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    T1_FIELD_CALLBACK( "ExpansionFactor", parse_expansion_factor, 0 )
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
    { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0, 0 }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
  cid_parse_dict( CID_Face     face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
                  CID_Loader*  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
                  FT_Byte*     base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
                  FT_Long      size )
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
    CID_Parser*  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
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
    parser->root.cursor = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    parser->root.limit  = base + size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    parser->root.error  = CID_Err_Ok;
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
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      FT_Byte*  cur   = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      FT_Byte*  limit = cur + size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
      for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
        FT_Byte*  newlimit;
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
        parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
        cid_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
        if ( parser->root.cursor >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
          newlimit = limit - 1 - 17;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
          newlimit = parser->root.cursor - 17;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
        /* look for `%ADOBeginFontDict' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
        for ( ; cur < newlimit; cur++ )
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 ( *cur == '%'                                            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
               ft_strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
            /* if /FDArray was found, then cid->num_dicts is > 0, and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
            /* we can start increasing parser->num_dict               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
            if ( face->cid.num_dicts > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
              parser->num_dict++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
        }
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
        cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
        /* no error can occur in cid_parser_skip_spaces */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
        if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
          break;
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
        cid_parser_skip_PS_token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
        if ( parser->root.cursor >= limit || parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
          break;
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
        /* look for immediates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
        if ( *cur == '/' && cur + 2 < limit )
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
          FT_PtrDist  len;
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
          cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
          len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
          if ( len > 0 && len < 22 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
            /* now compare the immediate name to the keyword table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
            T1_Field  keyword = (T1_Field)cid_field_records;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
            for (;;)
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
              FT_Byte*  name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
              name = (FT_Byte*)keyword->ident;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
              if ( !name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
                break;
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
              if ( cur[0] == name[0]                                 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
                   len == (FT_PtrDist)ft_strlen( (const char*)name ) )
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
                FT_PtrDist  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
                for ( n = 1; n < len; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
                  if ( cur[n] != name[n] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
                    break;
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
                if ( n >= len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
                  /* we found it - run the parsing callback */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
                  parser->root.error = cid_load_keyword( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
                                                         loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
                                                         keyword );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
                  if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
                    return parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
                  break;
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
              keyword++;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
        cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
      }
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
    return parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
  }
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
  /* read the subrmap and the subrs of each font dict */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  cid_read_subrs( CID_Face  face )
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
    CID_FaceInfo   cid    = &face->cid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
    FT_Memory      memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    FT_Stream      stream = face->cid_stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    FT_Int         n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    CID_Subrs      subr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
    FT_UInt        max_offsets = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    FT_ULong*      offsets = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
    PSAux_Service  psaux = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
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
    if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    subr = face->subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    for ( n = 0; n < cid->num_dicts; n++, subr++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
      CID_FaceDict  dict  = cid->font_dicts + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
      FT_Int        lenIV = dict->private_dict.lenIV;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      FT_UInt       count, num_subrs = dict->num_subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
      FT_ULong      data_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
      FT_Byte*      p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      /* reallocate offsets array if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      if ( num_subrs + 1 > max_offsets )
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
        FT_UInt  new_max = FT_PAD_CEIL( num_subrs + 1, 4 );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
        if ( FT_RENEW_ARRAY( offsets, max_offsets, new_max ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
          goto Fail;
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
        max_offsets = new_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      /* read the subrmap's offsets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
           FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes )      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      p = (FT_Byte*)stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      for ( count = 0; count <= num_subrs; count++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        offsets[count] = cid_get_offset( &p, (FT_Byte)dict->sd_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      /* now, compute the size of subrs charstrings, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      /* allocate, and read them                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      data_len = offsets[num_subrs] - offsets[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
      if ( FT_NEW_ARRAY( subr->code, num_subrs + 1 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
               FT_ALLOC( subr->code[0], data_len )   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      if ( FT_STREAM_SEEK( cid->data_offset + offsets[0] ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
           FT_STREAM_READ( subr->code[0], data_len )  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
        goto Fail;
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
      /* set up pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
      for ( count = 1; count <= num_subrs; count++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
        FT_ULong  len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
        len               = offsets[count] - offsets[count - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        subr->code[count] = subr->code[count - 1] + len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
      }
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
      /* decrypt subroutines, but only if lenIV >= 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      if ( lenIV >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
        for ( count = 0; count < num_subrs; count++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
          FT_ULong  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
          len = offsets[count + 1] - offsets[count];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
          psaux->t1_decrypt( subr->code[count], len, 4330 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
        }
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
      subr->num_subrs = num_subrs;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    FT_FREE( offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    if ( face->subrs )
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
      for ( n = 0; n < cid->num_dicts; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
        if ( face->subrs[n].code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
          FT_FREE( face->subrs[n].code[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
        FT_FREE( face->subrs[n].code );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      FT_FREE( face->subrs );
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
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
  t1_init_loader( CID_Loader*  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
                  CID_Face     face )
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
    FT_UNUSED( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
    FT_MEM_ZERO( loader, sizeof ( *loader ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  t1_done_loader( CID_Loader*  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    CID_Parser*  parser = &loader->parser;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    /* finalize parser */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    cid_parser_done( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  }
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
  cid_hex_to_binary( FT_Byte*  data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
                     FT_Long   data_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
                     FT_ULong  offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
                     CID_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    FT_Stream  stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
    FT_Byte    buffer[256];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
    FT_Byte   *p, *plimit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    FT_Byte   *d, *dlimit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    FT_Byte    val;
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
    FT_Bool    upper_nibble, done;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    if ( FT_STREAM_SEEK( offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    d      = data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    dlimit = d + data_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    p      = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    plimit = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    upper_nibble = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    done         = 0;
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
    while ( d < dlimit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      if ( p >= plimit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
        FT_ULong  oldpos = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
        FT_ULong  size   = stream->size - oldpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
        if ( size == 0 )
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
          error = CID_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
        if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
        p      = buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
        plimit = p + FT_STREAM_POS() - oldpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
      if ( ft_isdigit( *p ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
        val = (FT_Byte)( *p - '0' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
      else if ( *p >= 'a' && *p <= 'f' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
        val = (FT_Byte)( *p - 'a' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
      else if ( *p >= 'A' && *p <= 'F' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
        val = (FT_Byte)( *p - 'A' + 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
      else if ( *p == ' '  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
                *p == '\t' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
                *p == '\r' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
                *p == '\n' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
                *p == '\f' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
                *p == '\0' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
        p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
      else if ( *p == '>' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
        val  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
        done = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
      else
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
        error = CID_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      if ( upper_nibble )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
        *d = (FT_Byte)( val << 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      else
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
        *d = (FT_Byte)( *d + val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
        d++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      upper_nibble = (FT_Byte)( 1 - upper_nibble );
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
      if ( done )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
        break;
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
      p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
    }
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
    error = CID_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
  cid_face_open( CID_Face  face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
                 FT_Int    face_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    CID_Loader   loader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    CID_Parser*  parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    FT_Memory    memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    t1_init_loader( &loader, face );
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
    parser = &loader.parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    error = cid_parser_new( parser, face->root.stream, face->root.memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
                            (PSAux_Service)face->psaux );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    error = cid_parse_dict( face, &loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
                            parser->postscript,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
                            parser->postscript_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
      goto Exit;
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
    if ( face_index < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      goto Exit;
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
    if ( FT_NEW( face->cid_stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      goto Exit;
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
    if ( parser->binary_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      /* we must convert the data section from hexadecimal to binary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      if ( FT_ALLOC( face->binary_data, parser->binary_length )         ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
           cid_hex_to_binary( face->binary_data, parser->binary_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
                              parser->data_offset, face )               )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
        goto Exit;
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
      FT_Stream_OpenMemory( face->cid_stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
                            face->binary_data, parser->binary_length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
      face->cid.data_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
    else
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
      *face->cid_stream     = *face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
      face->cid.data_offset = loader.parser.data_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
    error = cid_read_subrs( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
    t1_done_loader( &loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
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
/* END */