misc/libfreetype/src/type1/t1load.c
author unc0rr
Wed, 10 Oct 2012 00:40:00 +0400
changeset 7738 abcc7012de0b
parent 5172 88f2e05288ba
permissions -rw-r--r--
Please pas2c
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
/*  t1load.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
/*    Type 1 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, 2007, 2008, 2009,   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*            2010 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  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
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  understand and accept it fully.                                        */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /* This is the new and improved Type 1 data loader for FreeType 2.  The  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
  /* old loader has several problems: it is slow, complex, difficult to    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /* maintain, and contains incredible hacks to make it accept some        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  /* ill-formed Type 1 fonts without hiccup-ing.  Moreover, about 5% of    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  /* the Type 1 fonts on my machine still aren't loaded correctly by it.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /* This version is much simpler, much faster and also easier to read and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /* maintain by a great order of magnitude.  The idea behind it is to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* _not_ try to read the Type 1 token stream with a state machine (i.e.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* a Postscript-like interpreter) but rather to perform simple pattern   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* matching.                                                             */
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
  /* Indeed, nearly all data definitions follow a simple pattern like      */
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
  /*  ... /Field <data> ...                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* where <data> can be a number, a boolean, a string, or an array of     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /* numbers.  There are a few exceptions, namely the encoding, font name, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /* charstrings, and subrs; they are handled with a special pattern       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /* matching routine.                                                     */
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
  /* All other common cases are handled very simply.  The matching rules   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /* are defined in the file `t1tokens.h' through the use of several       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /* macros calls PARSE_XXX.  This file is included twice here; the first  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /* time to generate parsing callback functions, the second time to       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /* generate a table of keywords (with pointers to the associated         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* callback functions).                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /* The function `parse_dict' simply scans *linearly* a given dictionary  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /* (either the top-level or private one) and calls the appropriate       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /* callback when it encounters an immediate keyword.                     */
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
  /* This is by far the fastest way one can find to parse and read all     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /* data.                                                                 */
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
  /* This led to tremendous code size reduction.  Note that later, the     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /* glyph loader will also be _greatly_ simplified, and the automatic     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /* hinter will replace the clumsy `t1hinter'.                            */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
#include FT_CONFIG_CONFIG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
#include FT_MULTIPLE_MASTERS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
#include FT_INTERNAL_TYPE1_TYPES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
#include FT_INTERNAL_CALC_H
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
#include "t1load.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
#include "t1errors.h"
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /* 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
    78
  /* 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
    79
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
#define FT_COMPONENT  trace_t1load
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
#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
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
  /*************************************************************************/
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
  /*****                    MULTIPLE MASTERS SUPPORT                   *****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  /*************************************************************************/
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  t1_allocate_blend( T1_Face  face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
                     FT_UInt  num_designs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
                     FT_UInt  num_axis )
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
    PS_Blend   blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    FT_Memory  memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_Error   error  = T1_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    if ( !blend )
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
      if ( FT_NEW( blend ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        goto Exit;
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
      blend->num_default_design_vector = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      face->blend = blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    /* allocate design data if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    if ( num_designs > 0 )
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
      if ( blend->num_designs == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        FT_UInt  nn;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
        /* allocate the blend `private' and `font_info' dictionaries */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
        if ( FT_NEW_ARRAY( blend->font_infos[1], num_designs     ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
             FT_NEW_ARRAY( blend->privates[1], num_designs       ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
             FT_NEW_ARRAY( blend->bboxes[1], num_designs         ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
             FT_NEW_ARRAY( blend->weight_vector, num_designs * 2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
          goto Exit;
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
        blend->default_weight_vector = blend->weight_vector + num_designs;
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
        blend->font_infos[0] = &face->type1.font_info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
        blend->privates  [0] = &face->type1.private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
        blend->bboxes    [0] = &face->type1.font_bbox;
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
        for ( nn = 2; nn <= num_designs; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
          blend->privates[nn]   = blend->privates  [nn - 1] + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
          blend->font_infos[nn] = blend->font_infos[nn - 1] + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
          blend->bboxes[nn]     = blend->bboxes    [nn - 1] + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        blend->num_designs   = num_designs;
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
      else if ( blend->num_designs != num_designs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
        goto Fail;
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
    /* allocate axis data if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    if ( num_axis > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      if ( blend->num_axis != 0 && blend->num_axis != num_axis )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
      blend->num_axis = num_axis;
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
    /* allocate the blend design pos table if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    num_designs = blend->num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    num_axis    = blend->num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    if ( num_designs && num_axis && blend->design_pos[0] == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      FT_UInt  n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      if ( FT_NEW_ARRAY( blend->design_pos[0], num_designs * num_axis ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
        goto Exit;
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
      for ( n = 1; n < num_designs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
        blend->design_pos[n] = blend->design_pos[0] + num_axis * n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
  T1_Get_Multi_Master( T1_Face           face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
                       FT_Multi_Master*  master )
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
    PS_Blend  blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    FT_UInt   n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    FT_Error  error;
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
    error = T1_Err_Invalid_Argument;
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
    if ( blend )
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
      master->num_axis    = blend->num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      master->num_designs = blend->num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      for ( n = 0; n < blend->num_axis; n++ )
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
        FT_MM_Axis*   axis = master->axis + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
        PS_DesignMap  map = blend->design_map + n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
        axis->name    = blend->axis_names[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        axis->minimum = map->design_points[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
        axis->maximum = map->design_points[map->num_points - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      error = T1_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  }
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
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
  /* Given a normalized (blend) coordinate, figure out the design          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
  /* coordinate appropriate for that value.                                */
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
  FT_LOCAL_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
  mm_axis_unmap( PS_DesignMap  axismap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
                 FT_Fixed      ncv )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
    int  j;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    if ( ncv <= axismap->blend_points[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      return INT_TO_FIXED( axismap->design_points[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 ( j = 1; j < axismap->num_points; ++j )
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
      if ( ncv <= axismap->blend_points[j] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
        FT_Fixed  t = FT_MulDiv( ncv - axismap->blend_points[j - 1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
                                 0x10000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
                                 axismap->blend_points[j] -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
                                   axismap->blend_points[j - 1] );
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
        return INT_TO_FIXED( axismap->design_points[j - 1] ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
                 FT_MulDiv( t,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
                            axismap->design_points[j] -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
                              axismap->design_points[j - 1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
                            1L );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    return INT_TO_FIXED( axismap->design_points[axismap->num_points - 1] );
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
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
  /* Given a vector of weights, one for each design, figure out the        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  /* normalized axis coordinates which gave rise to those weights.         */
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  mm_weights_unmap( FT_Fixed*  weights,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
                    FT_Fixed*  axiscoords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
                    FT_UInt    axis_count )
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
    FT_ASSERT( axis_count <= T1_MAX_MM_AXIS );
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
    if ( axis_count == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      axiscoords[0] = weights[1];
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
    else if ( axis_count == 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      axiscoords[0] = weights[3] + weights[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      axiscoords[1] = weights[3] + weights[2];
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    else if ( axis_count == 3 )
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
      axiscoords[0] = weights[7] + weights[5] + weights[3] + weights[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      axiscoords[1] = weights[7] + weights[6] + weights[3] + weights[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      axiscoords[2] = weights[7] + weights[6] + weights[5] + weights[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    else
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
      axiscoords[0] = weights[15] + weights[13] + weights[11] + weights[9] +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
                        weights[7] + weights[5] + weights[3] + weights[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
      axiscoords[1] = weights[15] + weights[14] + weights[11] + weights[10] +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
                        weights[7] + weights[6] + weights[3] + weights[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      axiscoords[2] = weights[15] + weights[14] + weights[13] + weights[12] +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
                        weights[7] + weights[6] + weights[5] + weights[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
      axiscoords[3] = weights[15] + weights[14] + weights[13] + weights[12] +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
                        weights[11] + weights[10] + weights[9] + weights[8];
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
  }
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
  /*************************************************************************/
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
  /* Just a wrapper around T1_Get_Multi_Master to support the different    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
  /*  arguments needed by the GX var distortable fonts.                    */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
  T1_Get_MM_Var( T1_Face      face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
                 FT_MM_Var*  *master )
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
    FT_Memory        memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
    FT_MM_Var       *mmvar;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    FT_Multi_Master  mmaster;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
    FT_UInt          i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    FT_Fixed         axiscoords[T1_MAX_MM_AXIS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    PS_Blend         blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
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
    error = T1_Get_Multi_Master( face, &mmaster );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    if ( FT_ALLOC( mmvar,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
                   sizeof ( FT_MM_Var ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
                     mmaster.num_axis * sizeof ( FT_Var_Axis ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      goto Exit;
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
    mmvar->num_axis        = mmaster.num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    mmvar->num_designs     = mmaster.num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    mmvar->num_namedstyles = (FT_UInt)-1;                /* Does not apply */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    mmvar->axis            = (FT_Var_Axis*)&mmvar[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
                                      /* Point to axes after MM_Var struct */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    mmvar->namedstyle      = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
    for ( i = 0 ; i < mmaster.num_axis; ++i )
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
      mmvar->axis[i].name    = mmaster.axis[i].name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
      mmvar->axis[i].minimum = INT_TO_FIXED( mmaster.axis[i].minimum);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      mmvar->axis[i].maximum = INT_TO_FIXED( mmaster.axis[i].maximum);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      mmvar->axis[i].def     = ( mmvar->axis[i].minimum +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
                                   mmvar->axis[i].maximum ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
                            /* Does not apply.  But this value is in range */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
      mmvar->axis[i].strid   = (FT_UInt)-1;    /* Does not apply */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      mmvar->axis[i].tag     = (FT_ULong)-1;   /* Does not apply */
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 ( ft_strcmp( mmvar->axis[i].name, "Weight" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
        mmvar->axis[i].tag = FT_MAKE_TAG( 'w', 'g', 'h', 't' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
      else if ( ft_strcmp( mmvar->axis[i].name, "Width" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
        mmvar->axis[i].tag = FT_MAKE_TAG( 'w', 'd', 't', 'h' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
      else if ( ft_strcmp( mmvar->axis[i].name, "OpticalSize" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
        mmvar->axis[i].tag = FT_MAKE_TAG( 'o', 'p', 's', 'z' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    }
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
    if ( blend->num_designs == ( 1U << blend->num_axis ) )
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
      mm_weights_unmap( blend->default_weight_vector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
                        axiscoords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
                        blend->num_axis );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
      for ( i = 0; i < mmaster.num_axis; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
        mmvar->axis[i].def = mm_axis_unmap( &blend->design_map[i],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
                                            axiscoords[i] );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    *master = mmvar;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
  T1_Set_MM_Blend( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
                   FT_UInt    num_coords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
                   FT_Fixed*  coords )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    PS_Blend  blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    FT_UInt   n, m;
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
    error = T1_Err_Invalid_Argument;
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
    if ( blend && blend->num_axis == num_coords )
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
      /* recompute the weight vector from the blend coordinates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      error = T1_Err_Ok;
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
      for ( n = 0; n < blend->num_designs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
        FT_Fixed  result = 0x10000L;  /* 1.0 fixed */
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
        for ( m = 0; m < blend->num_axis; m++ )
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_Fixed  factor;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
          /* get current blend axis position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
          factor = coords[m];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
          if ( factor < 0 )        factor = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
          if ( factor > 0x10000L ) factor = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
          if ( ( n & ( 1 << m ) ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
            factor = 0x10000L - factor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
          result = FT_MulFix( result, factor );
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
        blend->weight_vector[n] = result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      }
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
      error = T1_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  T1_Set_MM_Design( T1_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
                    FT_UInt   num_coords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
                    FT_Long*  coords )
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
    PS_Blend  blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    FT_UInt   n, p;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    error = T1_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    if ( blend && blend->num_axis == num_coords )
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
      /* compute the blend coordinates through the blend design map */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      FT_Fixed  final_blends[T1_MAX_MM_DESIGNS];
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
      for ( n = 0; n < blend->num_axis; n++ )
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
        FT_Long       design  = coords[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        FT_Fixed      the_blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
        PS_DesignMap  map     = blend->design_map + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        FT_Long*      designs = map->design_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        FT_Fixed*     blends  = map->blend_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
        FT_Int        before  = -1, after = -1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        for ( p = 0; p < (FT_UInt)map->num_points; p++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
          FT_Long  p_design = designs[p];
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
          /* exact match? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
          if ( design == p_design )
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
            the_blend = blends[p];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
            goto Found;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
          if ( design < p_design )
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
            after = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
            break;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
          before = p;
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
        /* now interpolate if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
        if ( before < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
          the_blend = blends[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
        else if ( after < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
          the_blend = blends[map->num_points - 1];
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
          the_blend = FT_MulDiv( design         - designs[before],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
                                 blends [after] - blends [before],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
                                 designs[after] - designs[before] );
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
      Found:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
        final_blends[n] = the_blend;
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
      error = T1_Set_MM_Blend( face, num_coords, final_blends );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
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
  /*************************************************************************/
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
  /* Just a wrapper around T1_Set_MM_Design to support the different       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
  /* arguments needed by the GX var distortable fonts.                     */
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_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
  T1_Set_Var_Design( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
                     FT_UInt    num_coords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
                     FT_Fixed*  coords )
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
     FT_Long   lcoords[4];          /* maximum axis count is 4 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
     FT_UInt   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
     FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
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
     error = T1_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
     if ( num_coords <= 4 && num_coords > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
     {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
       for ( i = 0; i < num_coords; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
         lcoords[i] = FIXED_TO_INT( coords[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
       error = T1_Set_MM_Design( face, num_coords, lcoords );
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
     return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
  T1_Done_Blend( T1_Face  face )
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_Memory  memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    PS_Blend   blend  = face->blend;
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 ( blend )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      FT_UInt  num_designs = blend->num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
      FT_UInt  num_axis    = blend->num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
      FT_UInt  n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
      /* release design pos table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      FT_FREE( blend->design_pos[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      for ( n = 1; n < num_designs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
        blend->design_pos[n] = 0;
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
      /* release blend `private' and `font info' dictionaries */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      FT_FREE( blend->privates[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
      FT_FREE( blend->font_infos[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
      FT_FREE( blend->bboxes[1] );
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
      for ( n = 0; n < num_designs; n++ )
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
        blend->privates  [n] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
        blend->font_infos[n] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
        blend->bboxes    [n] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      /* release weight vectors */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
      FT_FREE( blend->weight_vector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
      blend->default_weight_vector = 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
      /* release axis names */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      for ( n = 0; n < num_axis; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
        FT_FREE( blend->axis_names[n] );
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
      /* release design map */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      for ( n = 0; n < num_axis; n++ )
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
        PS_DesignMap  dmap = blend->design_map + n;
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
        FT_FREE( dmap->design_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
        dmap->num_points = 0;
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
      FT_FREE( face->blend );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    }
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
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
  parse_blend_axis_types( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
                          T1_Loader  loader )
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
    T1_TokenRec  axis_tokens[T1_MAX_MM_AXIS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    FT_Int       n, num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    FT_Error     error = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    PS_Blend     blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    /* take an array of objects */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    T1_ToTokenArray( &loader->parser, axis_tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
                     T1_MAX_MM_AXIS, &num_axis );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    if ( num_axis < 0 )
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
      error = T1_Err_Ignore;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
      goto Exit;
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
    if ( num_axis == 0 || num_axis > T1_MAX_MM_AXIS )
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
      FT_ERROR(( "parse_blend_axis_types: incorrect number of axes: %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
                 num_axis ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
      error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    /* allocate blend if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
    error = t1_allocate_blend( face, 0, (FT_UInt)num_axis );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      goto Exit;
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
    blend  = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    memory = face->root.memory;
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
    /* each token is an immediate containing the name of the axis */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
    for ( n = 0; n < num_axis; n++ )
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
      T1_Token    token = axis_tokens + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
      FT_Byte*    name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
      FT_PtrDist  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
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
      /* skip first slash, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
      if ( token->start[0] == '/' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
        token->start++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
      len = token->limit - token->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      if ( len == 0 )
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
        error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      if ( FT_ALLOC( blend->axis_names[n], len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
        goto Exit;
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
      name = (FT_Byte*)blend->axis_names[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      FT_MEM_COPY( name, token->start, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
      name[len] = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
    loader->parser.root.error = error;
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
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
  parse_blend_design_positions( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
                                T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    T1_TokenRec  design_tokens[T1_MAX_MM_DESIGNS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    FT_Int       num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    FT_Int       num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    T1_Parser    parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    FT_Error     error = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    PS_Blend     blend;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    /* get the array of design tokens -- compute number of designs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    T1_ToTokenArray( parser, design_tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
                     T1_MAX_MM_DESIGNS, &num_designs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
    if ( num_designs < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      error = T1_Err_Ignore;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
    if ( num_designs == 0 || num_designs > T1_MAX_MM_DESIGNS )
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
      FT_ERROR(( "parse_blend_design_positions:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
                 " incorrect number of designs: %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
                 num_designs ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
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
      FT_Byte*  old_cursor = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
      FT_Byte*  old_limit  = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
      FT_Int    n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
      blend    = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
      num_axis = 0;  /* make compiler happy */
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
      for ( n = 0; n < num_designs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
        T1_TokenRec  axis_tokens[T1_MAX_MM_AXIS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
        T1_Token     token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
        FT_Int       axis, n_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
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
        /* read axis/coordinates tokens */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
        token = design_tokens + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
        parser->root.cursor = token->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
        parser->root.limit  = token->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
        T1_ToTokenArray( parser, axis_tokens, T1_MAX_MM_AXIS, &n_axis );
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
        if ( n == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
          if ( n_axis <= 0 || n_axis > T1_MAX_MM_AXIS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
            FT_ERROR(( "parse_blend_design_positions:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
                       " invalid number of axes: %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
                       n_axis ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
            error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
          num_axis = n_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
          error = t1_allocate_blend( face, num_designs, num_axis );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
          blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
        else if ( n_axis != num_axis )
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
          FT_ERROR(( "parse_blend_design_positions: incorrect table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
          error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
        /* now read each axis token into the design position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
        for ( axis = 0; axis < n_axis; axis++ )
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
          T1_Token  token2 = axis_tokens + axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
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
          parser->root.cursor = token2->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
          parser->root.limit  = token2->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
          blend->design_pos[n][axis] = T1_ToFixed( parser, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
        }
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
      loader->parser.root.cursor = old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
      loader->parser.root.limit  = old_limit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
    loader->parser.root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
  parse_blend_design_map( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
                          T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    FT_Error     error  = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    T1_Parser    parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    PS_Blend     blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    T1_TokenRec  axis_tokens[T1_MAX_MM_AXIS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    FT_Int       n, num_axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    FT_Byte*     old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    FT_Byte*     old_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
    FT_Memory    memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    T1_ToTokenArray( parser, axis_tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
                     T1_MAX_MM_AXIS, &num_axis );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    if ( num_axis < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      error = T1_Err_Ignore;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
      goto Exit;
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
    if ( num_axis == 0 || num_axis > T1_MAX_MM_AXIS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
      FT_ERROR(( "parse_blend_design_map: incorrect number of axes: %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
                 num_axis ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
      error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
    old_cursor = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
    old_limit  = parser->root.limit;
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
    error = t1_allocate_blend( face, 0, num_axis );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
    blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
    /* now read each axis design map */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    for ( n = 0; n < num_axis; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
      PS_DesignMap  map = blend->design_map + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
      T1_Token      axis_token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
      T1_TokenRec   point_tokens[T1_MAX_MM_MAP_POINTS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
      FT_Int        p, num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
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
      axis_token = axis_tokens + n;
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
      parser->root.cursor = axis_token->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
      parser->root.limit  = axis_token->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
      T1_ToTokenArray( parser, point_tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
                       T1_MAX_MM_MAP_POINTS, &num_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
      if ( num_points <= 0 || num_points > T1_MAX_MM_MAP_POINTS )
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
        FT_ERROR(( "parse_blend_design_map: incorrect table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
        error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
      /* allocate design map data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
      if ( FT_NEW_ARRAY( map->design_points, num_points * 2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
      map->blend_points = map->design_points + num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
      map->num_points   = (FT_Byte)num_points;
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
      for ( p = 0; p < num_points; p++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
        T1_Token  point_token;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
        point_token = point_tokens + p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
        /* don't include delimiting brackets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
        parser->root.cursor = point_token->start + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
        parser->root.limit  = point_token->limit - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
        map->design_points[p] = T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
        map->blend_points [p] = T1_ToFixed( parser, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
    parser->root.cursor = old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    parser->root.limit  = old_limit;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
    parser->root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
  parse_weight_vector( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
                       T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
    T1_TokenRec  design_tokens[T1_MAX_MM_DESIGNS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
    FT_Int       num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
    FT_Error     error  = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    T1_Parser    parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
    PS_Blend     blend  = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
    T1_Token     token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
    FT_Int       n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
    FT_Byte*     old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
    FT_Byte*     old_limit;
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
    T1_ToTokenArray( parser, design_tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
                     T1_MAX_MM_DESIGNS, &num_designs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
    if ( num_designs < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      error = T1_Err_Ignore;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
    if ( num_designs == 0 || num_designs > T1_MAX_MM_DESIGNS )
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
      FT_ERROR(( "parse_weight_vector:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
                 " incorrect number of designs: %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
                 num_designs ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
      error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    if ( !blend || !blend->num_designs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
      error = t1_allocate_blend( face, num_designs, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
      blend = face->blend;
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
    else if ( blend->num_designs != (FT_UInt)num_designs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
      FT_ERROR(( "parse_weight_vector:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
                 " /BlendDesignPosition and /WeightVector have\n"
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
                 " different number of elements\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
      error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
    old_cursor = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
    old_limit  = parser->root.limit;
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
    for ( n = 0; n < num_designs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      token = design_tokens + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
      parser->root.cursor = token->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
      parser->root.limit  = token->limit;
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
      blend->default_weight_vector[n] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
      blend->weight_vector[n]         = T1_ToFixed( parser, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
    parser->root.cursor = old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
    parser->root.limit  = old_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
    parser->root.error = error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
  /* e.g., /BuildCharArray [0 0 0 0 0 0 0 0] def           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
  /* we're only interested in the number of array elements */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
  parse_buildchar( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
                   T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
    face->len_buildchar = T1_ToFixedArray( &loader->parser, 0, NULL, 0 );
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
    return;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
#endif /* T1_CONFIG_OPTION_NO_MM_SUPPORT */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
  /*****                      TYPE 1 SYMBOL PARSING                    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
  /*****                                                               *****/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
  t1_load_keyword( T1_Face         face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
                   T1_Loader       loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
                   const T1_Field  field )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    void*     dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    void**    objects;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
    FT_UInt   max_objects;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
    PS_Blend  blend = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
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
    /* 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
   926
    if ( field->type == T1_FIELD_TYPE_CALLBACK )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
      field->reader( (FT_Face)face, loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
      error = loader->parser.root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    /* now, the keyword is either a simple field, or a table of fields; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
    /* we are now going to take care of it                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
    switch ( field->location )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
    case T1_FIELD_LOCATION_FONT_INFO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
      dummy_object = &face->type1.font_info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
      if ( blend )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
        objects     = (void**)blend->font_infos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
        max_objects = blend->num_designs;
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
      break;
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
    case T1_FIELD_LOCATION_FONT_EXTRA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
      dummy_object = &face->type1.font_extra;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
      break;
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
    case T1_FIELD_LOCATION_PRIVATE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
      dummy_object = &face->type1.private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
      if ( blend )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
        objects     = (void**)blend->privates;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
        max_objects = blend->num_designs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
    case T1_FIELD_LOCATION_BBOX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
      dummy_object = &face->type1.font_bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
      if ( blend )
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
        objects     = (void**)blend->bboxes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
        max_objects = blend->num_designs;
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
      break;
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
    case T1_FIELD_LOCATION_LOADER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
      dummy_object = loader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
      break;
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
    case T1_FIELD_LOCATION_FACE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
      dummy_object = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
      break;
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
#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
    case T1_FIELD_LOCATION_BLEND:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
      dummy_object = face->blend;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
      max_objects  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
#endif
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
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
      dummy_object = &face->type1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
      objects      = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
      max_objects  = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    if ( field->type == T1_FIELD_TYPE_INTEGER_ARRAY ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
         field->type == T1_FIELD_TYPE_FIXED_ARRAY   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
      error = T1_Load_Field_Table( &loader->parser, field,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
                                   objects, max_objects, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
      error = T1_Load_Field( &loader->parser, field,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
                             objects, max_objects, 0 );
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
  }
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
  parse_private( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
                 T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
    FT_UNUSED( face );
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
    loader->keywords_encountered |= T1_PRIVATE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
  }
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
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
  read_binary_data( T1_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
                    FT_Long*   size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
                    FT_Byte**  base )
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
    FT_Byte*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
    FT_Byte*  limit = parser->root.limit;
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
    /* the binary data has one of the following formats */
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
    /*   `size' [white*] RD white ....... ND            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    /*   `size' [white*] -| white ....... |-            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    /*                                                  */
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
    T1_Skip_Spaces( parser );
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
    cur = parser->root.cursor;
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
    if ( cur < limit && ft_isdigit( *cur ) )
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_Long  s = T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
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
      T1_Skip_PS_Token( parser );   /* `RD' or `-|' or something else */
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
      /* there is only one whitespace char after the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
      /* `RD' or `-|' token                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
      *base = parser->root.cursor + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
      if ( s >= 0 && s < limit - *base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
        parser->root.cursor += s + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
        *size = s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
        return !parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
    FT_ERROR(( "read_binary_data: invalid size field\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
    parser->root.error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
  /* We now define the routines to handle the `/Encoding', `/Subrs', */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
  /* and `/CharStrings' dictionaries.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
  parse_font_matrix( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
                     T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
    T1_Parser   parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
    FT_Matrix*  matrix = &face->type1.font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
    FT_Vector*  offset = &face->type1.font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
    FT_Face     root   = (FT_Face)&face->root;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
    FT_Fixed    temp[6];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
    FT_Fixed    temp_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
    FT_Int      result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
    result = T1_ToFixedArray( parser, 6, temp, 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
    if ( result < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
      parser->root.error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
    temp_scale = FT_ABS( temp[3] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
    if ( temp_scale == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
      FT_ERROR(( "parse_font_matrix: invalid font matrix\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
      parser->root.error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
    /* 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
  1106
    /* 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
  1107
    /* 1000 (in t1_tofixed, from psobjs.c).                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
    root->units_per_EM = (FT_UShort)( FT_DivFix( 1000 * 0x10000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
                                                 temp_scale ) >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
    /* we need to scale the values by 1.0/temp_scale */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
    if ( temp_scale != 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
      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
  1116
      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
  1117
      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
  1118
      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
  1119
      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
  1120
      temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
    matrix->xx = temp[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
    matrix->yx = temp[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
    matrix->xy = temp[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
    matrix->yy = temp[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
    /* note that the offsets must be expressed in integer font units */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
    offset->x = temp[4] >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
    offset->y = temp[5] >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
  parse_encoding( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
                  T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
    T1_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
    FT_Byte*   cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
    FT_Byte*   limit  = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
    PSAux_Service  psaux = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
    cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
      FT_ERROR(( "parse_encoding: out of bounds\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
      parser->root.error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
    /* if we have a number or `[', the encoding is an array, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
    /* and we must load it now                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
    if ( ft_isdigit( *cur ) || *cur == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
      T1_Encoding  encode          = &face->type1.encoding;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
      FT_Int       count, n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
      PS_Table     char_table      = &loader->encoding_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
      FT_Memory    memory          = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
      FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
      FT_Bool      only_immediates = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
      /* read the number of entries in the encoding; should be 256 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
      if ( *cur == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
        count           = 256;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
        only_immediates = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
        parser->root.cursor++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
        count = (FT_Int)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
      if ( parser->root.cursor >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
      /* we use a T1_Table to store our charnames */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
      loader->num_chars = encode->num_chars = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
      if ( FT_NEW_ARRAY( encode->char_index, count )     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
           FT_NEW_ARRAY( encode->char_name,  count )     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
           FT_SET_ERROR( psaux->ps_table_funcs->init(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
                           char_table, count, memory ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
        parser->root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
      /* We need to `zero' out encoding_table.elements */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
      for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
        char*  notdef = (char *)".notdef";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
        T1_Add_Table( char_table, n, notdef, 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
      /* Now we need to read records of the form                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
      /*   ... charcode /charname ...                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
      /* for each entry in our table.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
      /* We simply look for a number followed by an immediate   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
      /* name.  Note that this ignores correctly the sequence   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
      /* that is often seen in type1 fonts:                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
      /*   0 1 255 { 1 index exch /.notdef put } for dup        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
      /* used to clean the encoding array before anything else. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
      /* Alternatively, if the array is directly given as       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
      /*   /Encoding [ ... ]                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
      /* we only read immediates.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
      n = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
      while ( parser->root.cursor < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
        cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
        /* we stop when we encounter a `def' or `]' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
        if ( *cur == 'd' && cur + 3 < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
          if ( cur[1] == 'e'         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
               cur[2] == 'f'         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
               IS_PS_DELIM( cur[3] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
            FT_TRACE6(( "encoding end\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
            cur += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
        if ( *cur == ']' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
          FT_TRACE6(( "encoding end\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
          cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
        /* check whether we've found an entry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
        if ( ft_isdigit( *cur ) || only_immediates )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
          FT_Int  charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
          if ( only_immediates )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
            charcode = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
            charcode = (FT_Int)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
            T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
          cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
          if ( *cur == '/' && cur + 2 < limit && n < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
            FT_PtrDist  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
            cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
            parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
            T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
            if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
              return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
            len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
            parser->root.error = T1_Add_Table( char_table, charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
                                               cur, len + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
            if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
              return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
            char_table->elements[charcode][len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
            n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
          else if ( only_immediates )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
            /* Since the current position is not updated for           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
            /* immediates-only mode we would get an infinite loop if   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
            /* we don't do anything here.                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
            /*                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
            /* This encoding array is not valid according to the type1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
            /* specification (it might be an encoding for a CID type1  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
            /* font, however), so we conclude that this font is NOT a  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
            /* type1 font.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
            parser->root.error = FT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
            return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
          T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
          if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
            return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
        T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
      face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
      parser->root.cursor       = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
    /* Otherwise, we should have either `StandardEncoding', */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
    /* `ExpertEncoding', or `ISOLatin1Encoding'             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
      if ( cur + 17 < limit                                            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
           ft_strncmp( (const char*)cur, "StandardEncoding", 16 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
        face->type1.encoding_type = T1_ENCODING_TYPE_STANDARD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
      else if ( cur + 15 < limit                                          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
                ft_strncmp( (const char*)cur, "ExpertEncoding", 14 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
        face->type1.encoding_type = T1_ENCODING_TYPE_EXPERT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
      else if ( cur + 18 < limit                                             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
                ft_strncmp( (const char*)cur, "ISOLatin1Encoding", 17 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
        face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
        parser->root.error = T1_Err_Ignore;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
  parse_subrs( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
               T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
    T1_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
    PS_Table   table  = &loader->subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
    FT_Memory  memory = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
    FT_Int     num_subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
    PSAux_Service  psaux = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
    /* test for empty array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
    if ( parser->root.cursor < parser->root.limit &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
         *parser->root.cursor == '['              )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
      T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
      T1_Skip_Spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
      if ( parser->root.cursor >= parser->root.limit ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
           *parser->root.cursor != ']'               )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
        parser->root.error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
    num_subrs = (FT_Int)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
    /* position the parser right before the `dup' of the first subr */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
    T1_Skip_PS_Token( parser );         /* `array' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
    if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
    /* initialize subrs array -- with synthetic fonts it is possible */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
    /* we get here twice                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
    if ( !loader->num_subrs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
      error = psaux->ps_table_funcs->init( table, num_subrs, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
    /* the format is simple:   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
    /*                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
    /*   `index' + binary data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
    /*                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
      FT_Long   idx, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
      FT_Byte*  base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
      /* If the next token isn't `dup' we are done. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
      if ( ft_strncmp( (char*)parser->root.cursor, "dup", 3 ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
      T1_Skip_PS_Token( parser );       /* `dup' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
      idx = T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
      if ( !read_binary_data( parser, &size, &base ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
      /* The binary string is followed by one token, e.g. `NP' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
      /* (bound to `noaccess put') or by two separate tokens:  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
      /* `noaccess' & `put'.  We position the parser right     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
      /* before the next `dup', if any.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
      T1_Skip_PS_Token( parser );   /* `NP' or `|' or `noaccess' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
      if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
      T1_Skip_Spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
      if ( ft_strncmp( (char*)parser->root.cursor, "put", 3 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
        T1_Skip_PS_Token( parser ); /* skip `put' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
        T1_Skip_Spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
      /* with synthetic fonts it is possible we get here twice */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
      if ( loader->num_subrs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
      /* some fonts use a value of -1 for lenIV to indicate that */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
      /* the charstrings are unencoded                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
      /*                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
      /* thanks to Tom Kacvinsky for pointing this out           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
      /*                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
      if ( face->type1.private_dict.lenIV >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
        FT_Byte*  temp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
        /* some fonts define empty subr records -- this is not totally */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
        /* compliant to the specification (which says they should at   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
        /* least contain a `return'), but we support them anyway       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
        if ( size < face->type1.private_dict.lenIV )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
          error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
        /* t1_decrypt() shouldn't write to base -- make temporary copy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
        if ( FT_ALLOC( temp, size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
        FT_MEM_COPY( temp, base, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
        psaux->t1_decrypt( temp, size, 4330 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
        size -= face->type1.private_dict.lenIV;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
        error = T1_Add_Table( table, (FT_Int)idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
                              temp + face->type1.private_dict.lenIV, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
        FT_FREE( temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
        error = T1_Add_Table( table, (FT_Int)idx, base, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
    if ( !loader->num_subrs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
      loader->num_subrs = num_subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
    return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
    parser->root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
#define TABLE_EXTEND  5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
  parse_charstrings( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
                     T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
    T1_Parser      parser       = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
    PS_Table       code_table   = &loader->charstrings;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
    PS_Table       name_table   = &loader->glyph_names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
    PS_Table       swap_table   = &loader->swap_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
    FT_Memory      memory       = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
    PSAux_Service  psaux        = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
    FT_Byte*       cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    FT_Byte*       limit        = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
    FT_Int         n, num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
    FT_UInt        notdef_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
    FT_Byte        notdef_found = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
    num_glyphs = (FT_Int)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
    /* some fonts like Optima-Oblique not only define the /CharStrings */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
    /* array but access it also                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
    if ( num_glyphs == 0 || parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
    /* initialize tables, leaving space for addition of .notdef, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
    /* if necessary, and a few other glyphs to handle buggy      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
    /* fonts which have more glyphs than specified.              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
    /* for some non-standard fonts like `Optima' which provides  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
    /* different outlines depending on the resolution it is      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
    /* possible to get here twice                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
    if ( !loader->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
      error = psaux->ps_table_funcs->init(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
                code_table, num_glyphs + 1 + TABLE_EXTEND, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
      error = psaux->ps_table_funcs->init(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
                name_table, num_glyphs + 1 + TABLE_EXTEND, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
      /* Initialize table for swapping index notdef_index and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
      /* index 0 names and codes (if necessary).              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
      error = psaux->ps_table_funcs->init( swap_table, 4, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
    n = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
      FT_Long   size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
      FT_Byte*  base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
      /* the format is simple:        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
      /*   `/glyphname' + binary data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
      cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
      if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
      /* we stop when we find a `def' or `end' keyword */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
      if ( cur + 3 < limit && IS_PS_DELIM( cur[3] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
        if ( cur[0] == 'd' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
             cur[1] == 'e' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
             cur[2] == 'f' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
          /* There are fonts which have this: */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
          /*                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
          /*   /CharStrings 118 dict def      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
          /*   Private begin                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
          /*   CharStrings begin              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
          /*   ...                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
          /*                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
          /* To catch this we ignore `def' if */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
          /* no charstring has actually been  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
          /* seen.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
          if ( n )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
        if ( cur[0] == 'e' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
             cur[1] == 'n' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
             cur[2] == 'd' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
      T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
      if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
      if ( *cur == '/' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
        FT_PtrDist  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
        if ( cur + 1 >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
          error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
        cur++;                              /* skip `/' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
        len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
        if ( !read_binary_data( parser, &size, &base ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
          return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
        /* for some non-standard fonts like `Optima' which provides */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
        /* different outlines depending on the resolution it is     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
        /* possible to get here twice                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
        if ( loader->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
        error = T1_Add_Table( name_table, n, cur, len + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
        /* add a trailing zero to the name table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
        name_table->elements[n][len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
        /* record index of /.notdef */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
        if ( *cur == '.'                                              &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
             ft_strcmp( ".notdef",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
                        (const char*)(name_table->elements[n]) ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
          notdef_index = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
          notdef_found = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
        if ( face->type1.private_dict.lenIV >= 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
             n < num_glyphs + TABLE_EXTEND       )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
          FT_Byte*  temp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
          if ( size <= face->type1.private_dict.lenIV )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
            error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
            goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
          /* t1_decrypt() shouldn't write to base -- make temporary copy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
          if ( FT_ALLOC( temp, size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
            goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
          FT_MEM_COPY( temp, base, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
          psaux->t1_decrypt( temp, size, 4330 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
          size -= face->type1.private_dict.lenIV;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
          error = T1_Add_Table( code_table, n,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
                                temp + face->type1.private_dict.lenIV, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
          FT_FREE( temp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
          error = T1_Add_Table( code_table, n, base, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
        n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
    loader->num_glyphs = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
    /* if /.notdef is found but does not occupy index 0, do our magic. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
    if ( notdef_found                                                 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
         ft_strcmp( ".notdef", (const char*)name_table->elements[0] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
      /* Swap glyph in index 0 with /.notdef glyph.  First, add index 0  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
      /* name and code entries to swap_table.  Then place notdef_index   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
      /* name and code entries into swap_table.  Then swap name and code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
      /* entries at indices notdef_index and 0 using values stored in    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
      /* swap_table.                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
      /* Index 0 name */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
      error = T1_Add_Table( swap_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
                            name_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
                            name_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
      /* Index 0 code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
      error = T1_Add_Table( swap_table, 1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
                            code_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
                            code_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
      /* Index notdef_index name */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
      error = T1_Add_Table( swap_table, 2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
                            name_table->elements[notdef_index],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
                            name_table->lengths [notdef_index] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
      /* Index notdef_index code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
      error = T1_Add_Table( swap_table, 3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
                            code_table->elements[notdef_index],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
                            code_table->lengths [notdef_index] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
      error = T1_Add_Table( name_table, notdef_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
                            swap_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
                            swap_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
      error = T1_Add_Table( code_table, notdef_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
                            swap_table->elements[1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
                            swap_table->lengths [1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
      error = T1_Add_Table( name_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
                            swap_table->elements[2],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
                            swap_table->lengths [2] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
      error = T1_Add_Table( code_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
                            swap_table->elements[3],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
                            swap_table->lengths [3] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
    else if ( !notdef_found )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
      /* notdef_index is already 0, or /.notdef is undefined in   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
      /* charstrings dictionary.  Worry about /.notdef undefined. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
      /* We take index 0 and add it to the end of the table(s)    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
      /* and add our own /.notdef glyph to index 0.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
      /* 0 333 hsbw endchar */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
      FT_Byte  notdef_glyph[] = { 0x8B, 0xF7, 0xE1, 0x0D, 0x0E };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
      char*    notdef_name    = (char *)".notdef";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
      error = T1_Add_Table( swap_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
                            name_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
                            name_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
      error = T1_Add_Table( swap_table, 1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
                            code_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
                            code_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
      error = T1_Add_Table( name_table, 0, notdef_name, 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
      error = T1_Add_Table( code_table, 0, notdef_glyph, 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
      error = T1_Add_Table( name_table, n,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
                            swap_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
                            swap_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
      error = T1_Add_Table( code_table, n,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
                            swap_table->elements[1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
                            swap_table->lengths [1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
      /* we added a glyph. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
      loader->num_glyphs += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
    return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
    parser->root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
  /* Define the token field static variables.  This is a set of            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1761
  /* T1_FieldRec variables.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
  const T1_FieldRec  t1_keywords[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
#include "t1tokens.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
    /* now add the special functions... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
    T1_FIELD_CALLBACK( "FontMatrix",           parse_font_matrix,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
    T1_FIELD_CALLBACK( "Encoding",             parse_encoding,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
    T1_FIELD_CALLBACK( "Subrs",                parse_subrs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
                       T1_FIELD_DICT_PRIVATE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
    T1_FIELD_CALLBACK( "CharStrings",          parse_charstrings,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
                       T1_FIELD_DICT_PRIVATE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
    T1_FIELD_CALLBACK( "Private",              parse_private,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
    T1_FIELD_CALLBACK( "BlendDesignPositions", parse_blend_design_positions,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
    T1_FIELD_CALLBACK( "BlendDesignMap",       parse_blend_design_map,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
    T1_FIELD_CALLBACK( "BlendAxisTypes",       parse_blend_axis_types,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
    T1_FIELD_CALLBACK( "WeightVector",         parse_weight_vector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
                       T1_FIELD_DICT_FONTDICT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
    T1_FIELD_CALLBACK( "BuildCharArray",       parse_buildchar,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1794
                       T1_FIELD_DICT_PRIVATE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1795
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
    { 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
  1798
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
#define T1_FIELD_COUNT                                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
          ( sizeof ( t1_keywords ) / sizeof ( t1_keywords[0] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
  parse_dict( T1_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
              T1_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
              FT_Byte*   base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
              FT_Long    size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
    T1_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
    FT_Byte   *limit, *start_binary = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
    FT_Bool    have_integer = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
    parser->root.cursor = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
    parser->root.limit  = base + size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
    parser->root.error  = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
    limit = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
    while ( parser->root.cursor < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
      FT_Byte*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
      cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
      /* look for `eexec' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
      if ( IS_PS_TOKEN( cur, limit, "eexec" ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
      /* look for `closefile' which ends the eexec section */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
      else if ( IS_PS_TOKEN( cur, limit, "closefile" ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
      /* in a synthetic font the base font starts after a           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
      /* `FontDictionary' token that is placed after a Private dict */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
      else if ( IS_PS_TOKEN( cur, limit, "FontDirectory" ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
        if ( loader->keywords_encountered & T1_PRIVATE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
          loader->keywords_encountered |=
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
            T1_FONTDIR_AFTER_PRIVATE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
        parser->root.cursor += 13;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
      /* check whether we have an integer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
      else if ( ft_isdigit( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
        start_binary = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1855
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1856
        have_integer = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
      /* in valid Type 1 fonts we don't see `RD' or `-|' directly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
      /* since those tokens are handled by parse_subrs and        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
      /* parse_charstrings                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
      else if ( *cur == 'R' && cur + 6 < limit && *(cur + 1) == 'D' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
                have_integer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
        FT_Long   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
        FT_Byte*  b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
        parser->root.cursor = start_binary;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
        if ( !read_binary_data( parser, &s, &b ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
          return T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
        have_integer = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
      else if ( *cur == '-' && cur + 6 < limit && *(cur + 1) == '|' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
                have_integer )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
        FT_Long   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
        FT_Byte*  b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
        parser->root.cursor = start_binary;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
        if ( !read_binary_data( parser, &s, &b ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
          return T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
        have_integer = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
      /* look for immediates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
      else if ( *cur == '/' && cur + 2 < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
        FT_PtrDist  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
        parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1898
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1899
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
        len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
        if ( len > 0 && len < 22 && parser->root.cursor < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
          /* 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
  1906
          T1_Field  keyword = (T1_Field)t1_keywords;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
          for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
            FT_Byte*  name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
            name = (FT_Byte*)keyword->ident;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
            if ( !name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
            if ( cur[0] == name[0]                                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
                 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
  1920
                 ft_memcmp( cur, name, len ) == 0                   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
              /* We found it -- run the parsing callback!     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
              /* We record every instance of every field      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
              /* (until we reach the base font of a           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
              /* synthetic font) to deal adequately with      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
              /* multiple master fonts; this is also          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
              /* necessary because later PostScript           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
              /* definitions override earlier ones.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
              /* Once we encounter `FontDirectory' after      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
              /* `/Private', we know that this is a synthetic */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
              /* font; except for `/CharStrings' we are not   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
              /* interested in anything that follows this     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
              /* `FontDirectory'.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
              /* MM fonts have more than one /Private token at */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
              /* the top level; let's hope that all the junk   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
              /* that follows the first /Private token is not  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
              /* interesting to us.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
              /* According to Adobe Tech Note #5175 (CID-Keyed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
              /* Font Installation for ATM Software) a `begin' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
              /* must be followed by exactly one `end', and    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
              /* `begin' -- `end' pairs must be accurately     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
              /* paired.  We could use this to distinguish     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
              /* between the global Private and the Private    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
              /* dict that is a member of the Blend dict.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
              const FT_UInt dict =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
                ( loader->keywords_encountered & T1_PRIVATE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
                    ? T1_FIELD_DICT_PRIVATE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
                    : T1_FIELD_DICT_FONTDICT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
              if ( !( dict & keyword->dict ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
                FT_TRACE1(( "parse_dict: found %s but ignoring it "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
                            "since it is in the wrong dictionary\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
                            keyword->ident ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
                break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
              if ( !( loader->keywords_encountered &
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
                      T1_FONTDIR_AFTER_PRIVATE     )                  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
                   ft_strcmp( (const char*)name, "CharStrings" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
                parser->root.error = t1_load_keyword( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
                                                      loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
                                                      keyword );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
                if ( parser->root.error != T1_Err_Ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
                  if ( FT_ERROR_BASE( parser->root.error ) == FT_Err_Ignore )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
                    parser->root.error = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
                  else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
                    return parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
                }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
            keyword++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
        have_integer = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
        have_integer = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
    return parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
  t1_init_loader( T1_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
                  T1_Face    face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
    FT_UNUSED( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
    FT_MEM_ZERO( loader, sizeof ( *loader ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
    loader->num_glyphs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
    loader->num_chars  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
    /* initialize the tables -- simply set their `init' field to 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
    loader->encoding_table.init  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
    loader->charstrings.init     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
    loader->glyph_names.init     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
    loader->subrs.init           = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
    loader->swap_table.init      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
    loader->fontdata             = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
    loader->keywords_encountered = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
  t1_done_loader( T1_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
    T1_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
    /* finalize tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
    T1_Release_Table( &loader->encoding_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
    T1_Release_Table( &loader->charstrings );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
    T1_Release_Table( &loader->glyph_names );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
    T1_Release_Table( &loader->swap_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
    T1_Release_Table( &loader->subrs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
    /* finalize parser */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
    T1_Finalize_Parser( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
  T1_Open_Face( T1_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
    T1_LoaderRec   loader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
    T1_Parser      parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
    T1_Font        type1 = &face->type1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
    PS_Private     priv  = &type1->private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
    PSAux_Service  psaux = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
    t1_init_loader( &loader, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
    /* default values */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
    face->ndv_idx          = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
    face->cdv_idx          = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
    face->len_buildchar    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2060
    priv->blue_shift       = 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2061
    priv->blue_fuzz        = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
    priv->lenIV            = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
    priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
    priv->blue_scale       = (FT_Fixed)( 0.039625 * 0x10000L * 1000 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2066
    parser = &loader.parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
    error  = T1_New_Parser( parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2068
                            face->root.stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2069
                            face->root.memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2070
                            psaux );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2071
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2072
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2073
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2074
    error = parse_dict( face, &loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2075
                        parser->base_dict, parser->base_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2076
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2077
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2078
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2079
    error = T1_Get_Private_Dict( parser, psaux );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2080
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2081
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2082
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2083
    error = parse_dict( face, &loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2084
                        parser->private_dict, parser->private_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2085
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2086
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2087
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2088
    /* ensure even-ness of `num_blue_values' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2089
    priv->num_blue_values &= ~1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
#ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2092
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2093
    if ( face->blend                                                     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
         face->blend->num_default_design_vector != 0                     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
         face->blend->num_default_design_vector != face->blend->num_axis )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
      /* we don't use it currently so just warn, reset, and ignore */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
      FT_ERROR(( "T1_Open_Face(): /DesignVector contains %u entries "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2099
                 "while there are %u axes.\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2100
                 face->blend->num_default_design_vector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2101
                 face->blend->num_axis ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2103
      face->blend->num_default_design_vector = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2104
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
    /* the following can happen for MM instances; we then treat the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2107
    /* font as a normal PS font                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2108
    if ( face->blend                                             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
         ( !face->blend->num_designs || !face->blend->num_axis ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2110
      T1_Done_Blend( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2112
    /* another safety check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2113
    if ( face->blend )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2114
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2115
      FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2118
      for ( i = 0; i < face->blend->num_axis; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2119
        if ( !face->blend->design_map[i].num_points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2120
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2121
          T1_Done_Blend( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2122
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2123
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2124
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2125
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2126
    if ( face->blend )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2127
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2128
      if ( face->len_buildchar > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
        FT_Memory  memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
        if ( FT_NEW_ARRAY( face->buildchar, face->len_buildchar ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2134
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2135
          FT_ERROR(( "T1_Open_Face: cannot allocate BuildCharArray\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
          face->len_buildchar = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2137
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2138
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
#endif /* T1_CONFIG_OPTION_NO_MM_SUPPORT */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2144
    /* now, propagate the subrs, charstrings, and glyphnames tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2145
    /* to the Type1 data                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
    type1->num_glyphs = loader.num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
    if ( loader.subrs.init )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2150
      loader.subrs.init  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2151
      type1->num_subrs   = loader.num_subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
      type1->subrs_block = loader.subrs.block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2153
      type1->subrs       = loader.subrs.elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2154
      type1->subrs_len   = loader.subrs.lengths;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
#ifdef FT_CONFIG_OPTION_INCREMENTAL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2158
    if ( !face->root.internal->incremental_interface )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2159
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2160
      if ( !loader.charstrings.init )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2162
        FT_ERROR(( "T1_Open_Face: no `/CharStrings' array in face\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
        error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2164
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2166
    loader.charstrings.init  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
    type1->charstrings_block = loader.charstrings.block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2168
    type1->charstrings       = loader.charstrings.elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2169
    type1->charstrings_len   = loader.charstrings.lengths;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2171
    /* we copy the glyph names `block' and `elements' fields; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2172
    /* the `lengths' field must be released later             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2173
    type1->glyph_names_block    = loader.glyph_names.block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
    type1->glyph_names          = (FT_String**)loader.glyph_names.elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2175
    loader.glyph_names.block    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2176
    loader.glyph_names.elements = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2178
    /* we must now build type1.encoding when we have a custom array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2179
    if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2180
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2181
      FT_Int    charcode, idx, min_char, max_char;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
      FT_Byte*  char_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
      FT_Byte*  glyph_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
      /* OK, we do the following: for each element in the encoding  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
      /* table, look up the index of the glyph having the same name */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2188
      /* the index is then stored in type1.encoding.char_index, and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2189
      /* the name to type1.encoding.char_name                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
      min_char = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
      max_char = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
      charcode = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
      for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2196
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2197
        type1->encoding.char_index[charcode] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2198
        type1->encoding.char_name [charcode] = (char *)".notdef";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2200
        char_name = loader.encoding_table.elements[charcode];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2201
        if ( char_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2202
          for ( idx = 0; idx < type1->num_glyphs; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2203
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2204
            glyph_name = (FT_Byte*)type1->glyph_names[idx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
            if ( ft_strcmp( (const char*)char_name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
                            (const char*)glyph_name ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2208
              type1->encoding.char_index[charcode] = (FT_UShort)idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
              type1->encoding.char_name [charcode] = (char*)glyph_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2211
              /* Change min/max encoded char only if glyph name is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
              /* not /.notdef                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
              if ( ft_strcmp( (const char*)".notdef",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
                              (const char*)glyph_name ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2216
                if ( charcode < min_char )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
                  min_char = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2218
                if ( charcode >= max_char )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
                  max_char = charcode + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2222
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2223
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
      type1->encoding.code_first = min_char;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
      type1->encoding.code_last  = max_char;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
      type1->encoding.num_chars  = loader.num_chars;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2229
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2231
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
    t1_done_loader( &loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2233
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2234
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
/* END */