misc/libfreetype/src/type42/t42parse.c
author nemo
Wed, 14 Sep 2011 14:14:23 -0400
changeset 5903 71466bccdf97
parent 5172 88f2e05288ba
permissions -rw-r--r--
merge
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
/*  t42parse.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 42 font parser (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 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  Roberto Alameda.                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include "t42parse.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "t42error.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_POSTSCRIPT_AUX_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /* 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
    29
  /* 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
    30
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#define FT_COMPONENT  trace_t42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  t42_parse_font_matrix( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
                         T42_Loader  loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  t42_parse_encoding( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
                      T42_Loader  loader );
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  t42_parse_charstrings( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
                         T42_Loader  loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  t42_parse_sfnts( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
                   T42_Loader  loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /* as Type42 fonts have no Private dict,         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /* we set the last argument of T1_FIELD_XXX to 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  static const
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  T1_FieldRec  t42_keywords[] =
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
#define FT_STRUCTURE  T1_FontInfo
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
#undef  T1CODE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
#define T1CODE        T1_FIELD_LOCATION_FONT_INFO
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
    T1_FIELD_STRING( "version",            version,             0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    T1_FIELD_STRING( "Notice",             notice,              0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    T1_FIELD_STRING( "FullName",           full_name,           0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    T1_FIELD_STRING( "FamilyName",         family_name,         0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    T1_FIELD_STRING( "Weight",             weight,              0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    T1_FIELD_NUM   ( "ItalicAngle",        italic_angle,        0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    T1_FIELD_BOOL  ( "isFixedPitch",       is_fixed_pitch,      0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    T1_FIELD_NUM   ( "UnderlinePosition",  underline_position,  0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    T1_FIELD_NUM   ( "UnderlineThickness", underline_thickness, 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
#define FT_STRUCTURE  PS_FontExtraRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
#undef  T1CODE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
#define T1CODE        T1_FIELD_LOCATION_FONT_EXTRA
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    T1_FIELD_NUM   ( "FSType",             fs_type,             0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
#define FT_STRUCTURE  T1_FontRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
#undef  T1CODE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
#define T1CODE        T1_FIELD_LOCATION_FONT_DICT
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
    T1_FIELD_KEY  ( "FontName",    font_name,    0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    T1_FIELD_NUM  ( "PaintType",   paint_type,   0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    T1_FIELD_NUM  ( "FontType",    font_type,    0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    T1_FIELD_FIXED( "StrokeWidth", stroke_width, 0 )
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
#define FT_STRUCTURE  FT_BBox
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
#undef  T1CODE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
#define T1CODE        T1_FIELD_LOCATION_BBOX
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
    T1_FIELD_BBOX("FontBBox", xMin, 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    T1_FIELD_CALLBACK( "FontMatrix",  t42_parse_font_matrix, 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    T1_FIELD_CALLBACK( "Encoding",    t42_parse_encoding,    0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    T1_FIELD_CALLBACK( "CharStrings", t42_parse_charstrings, 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    T1_FIELD_CALLBACK( "sfnts",       t42_parse_sfnts,       0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    { 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
   103
  };
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
#define T1_Add_Table( p, i, o, l )  (p)->funcs.add( (p), i, o, l )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
#define T1_Done_Table( p )          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
          do                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
          {                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
            if ( (p)->funcs.done )  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
              (p)->funcs.done( p ); \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
          } while ( 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
#define T1_Release_Table( p )          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
          do                           \
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
            if ( (p)->funcs.release )  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
              (p)->funcs.release( p ); \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
          } while ( 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
#define T1_Skip_Spaces( p )    (p)->root.funcs.skip_spaces( &(p)->root )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
#define T1_Skip_PS_Token( p )  (p)->root.funcs.skip_PS_token( &(p)->root )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
#define T1_ToInt( p )                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
          (p)->root.funcs.to_int( &(p)->root )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
#define T1_ToBytes( p, b, m, n, d )                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
          (p)->root.funcs.to_bytes( &(p)->root, b, m, n, d )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
#define T1_ToFixedArray( p, m, f, t )                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
          (p)->root.funcs.to_fixed_array( &(p)->root, m, f, t )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
#define T1_ToToken( p, t )                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
          (p)->root.funcs.to_token( &(p)->root, t )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
#define T1_Load_Field( p, f, o, m, pf )                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
          (p)->root.funcs.load_field( &(p)->root, f, o, m, pf )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
#define T1_Load_Field_Table( p, f, o, m, pf )                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
          (p)->root.funcs.load_field_table( &(p)->root, f, o, m, pf )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
  /********************* Parsing Functions ******************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  t42_parser_init( T42_Parser     parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
                   FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
                   FT_Memory      memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
                   PSAux_Service  psaux )
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
    FT_Error  error = T42_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    FT_Long   size;
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
    psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    parser->stream    = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    parser->base_len  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    parser->base_dict = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    parser->in_memory = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
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
    /* Here a short summary of what is going on:                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    /*   When creating a new Type 42 parser, we try to locate and load */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    /*   the base dictionary, loading the whole font into memory.      */
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
    /*   When `loading' the base dictionary, we only set up pointers   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    /*   in the case of a memory-based stream.  Otherwise, we allocate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    /*   and load the base dictionary in it.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
    /*   parser->in_memory is set if we have a memory stream.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    /*                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    if ( FT_STREAM_SEEK( 0L ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
         FT_FRAME_ENTER( 17 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    if ( ft_memcmp( stream->cursor, "%!PS-TrueTypeFont", 17 ) != 0 )
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
      FT_TRACE2(( "not a Type42 font\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      error = T42_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    FT_FRAME_EXIT();
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
    if ( error || FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    size = stream->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    /* now, try to load `size' bytes of the `base' dictionary we */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    /* found previously                                          */
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
    /* if it is a memory-based resource, set up pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    if ( !stream->read )
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
      parser->base_dict = (FT_Byte*)stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
      parser->base_len  = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      parser->in_memory = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      /* check that the `size' field is valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      if ( FT_STREAM_SKIP( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    else
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
      /* read segment in memory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      if ( FT_ALLOC( parser->base_dict, size )       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
           FT_STREAM_READ( parser->base_dict, size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
        goto Exit;
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
      parser->base_len = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    parser->root.base   = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    parser->root.cursor = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    parser->root.limit  = parser->root.cursor + parser->base_len;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    if ( error && !parser->in_memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      FT_FREE( parser->base_dict );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  t42_parser_done( T42_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    FT_Memory  memory = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    /* free the base dictionary only when we have a disk stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    if ( !parser->in_memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      FT_FREE( parser->base_dict );
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
    parser->root.funcs.done( &parser->root );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  t42_is_space( FT_Byte  c )
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 ( c == ' '  || c == '\t'              ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
             c == '\r' || c == '\n' || c == '\f' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
             c == '\0'                           );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  t42_parse_font_matrix( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
                         T42_Loader  loader )
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
    T42_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    FT_Matrix*  matrix = &face->type1.font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    FT_Vector*  offset = &face->type1.font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    FT_Face     root   = (FT_Face)&face->root;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    FT_Fixed    temp[6];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
    FT_Fixed    temp_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    (void)T1_ToFixedArray( parser, 6, temp, 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    temp_scale = FT_ABS( temp[3] );
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
    /* 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
   265
    /* 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
   266
    /* 1000 (in t1_tofixed, from psobjs.c).                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    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
   269
                                                 temp_scale ) >> 16 );
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
    /* 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
   272
    if ( temp_scale != 0x10000L )
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
      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
   275
      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
   276
      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
   277
      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
   278
      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
   279
      temp[3] = 0x10000L;
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
    matrix->xx = temp[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    matrix->yx = temp[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    matrix->xy = temp[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    matrix->yy = temp[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    /* 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
   288
    offset->x = temp[4] >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    offset->y = temp[5] >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
  t42_parse_encoding( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                      T42_Loader  loader )
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
    T42_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    FT_Byte*    cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    FT_Byte*    limit  = parser->root.limit;
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
    PSAux_Service  psaux  = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
    cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
    if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      FT_ERROR(( "t42_parse_encoding: out of bounds\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
      parser->root.error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    /* 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
   314
    /* and we must load it now                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    if ( ft_isdigit( *cur ) || *cur == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      T1_Encoding  encode          = &face->type1.encoding;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
      FT_UInt      count, n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
      PS_Table     char_table      = &loader->encoding_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      FT_Memory    memory          = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
      FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
      FT_Bool      only_immediates = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      /* 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
   326
      if ( *cur == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
        count           = 256;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
        only_immediates = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
        parser->root.cursor++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
        count = (FT_UInt)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
      if ( parser->root.cursor >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
      /* 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
   340
      loader->num_chars = encode->num_chars = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      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
   342
           FT_NEW_ARRAY( encode->char_name,  count )     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
           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
   344
                           char_table, count, memory ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        parser->root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
      }
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
      /* 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
   351
      for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
        char*  notdef = (char *)".notdef";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
        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
   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
      /* 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
   360
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      /*   ... charcode /charname ...                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
      /* for each entry in our table.                           */
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
      /* 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
   366
      /* 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
   367
      /* that is often seen in type42 fonts:                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      /*   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
   370
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
      /* 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
   372
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      /* 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
   374
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      /*   /Encoding [ ... ]                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
      /* we only read immediates.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      n = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
      while ( parser->root.cursor < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
        cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        /* we stop when we encounter `def' or `]' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
        if ( *cur == 'd' && cur + 3 < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
          if ( cur[1] == 'e'          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
               cur[2] == 'f'          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
               t42_is_space( cur[3] ) )
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
            FT_TRACE6(( "encoding end\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
            cur += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
          }
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 ( *cur == ']' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
          FT_TRACE6(( "encoding end\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
          cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
        }
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
        /* check whether we have found an entry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
        if ( ft_isdigit( *cur ) || only_immediates )
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
          FT_Int  charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
          if ( only_immediates )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
            charcode = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
            charcode = (FT_Int)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
            T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
          cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
          if ( *cur == '/' && cur + 2 < limit && n < count )
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
            FT_PtrDist  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
            cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
            parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
            T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
            if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
              return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
            len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
            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
   436
                                               cur, len + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
            if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
              return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
            char_table->elements[charcode][len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
            n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
          T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
          if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
            return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
        }
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
        T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
      }
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
      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
   455
      parser->root.cursor        = cur;
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
    /* Otherwise, we should have either `StandardEncoding', */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    /* `ExpertEncoding', or `ISOLatin1Encoding'             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      if ( cur + 17 < limit                                            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
           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
   464
        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
   465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
      else if ( cur + 15 < limit                                          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
                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
   468
        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
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
      else if ( cur + 18 < limit                                             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
                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
   472
        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
   473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
      else
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
        FT_ERROR(( "t42_parse_encoding: invalid token\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
        parser->root.error = T42_Err_Invalid_File_Format;
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
  }
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
  typedef enum  T42_Load_Status_
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
    BEFORE_START,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    BEFORE_TABLE_DIR,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    OTHER_TABLES
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
  } T42_Load_Status;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
  t42_parse_sfnts( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
                   T42_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    T42_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    FT_Memory   memory = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
    FT_Byte*    cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    FT_Byte*    limit  = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    FT_Int      num_tables = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    FT_ULong    count, ttf_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    FT_Long     n, string_size, old_string_size, real_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    FT_Byte*    string_buf = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    FT_Bool     allocated  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    T42_Load_Status  status;
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
    /* The format is                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    /*                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    /*   /sfnts [ <hexstring> <hexstring> ... ] def */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    /*                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    /* or                                           */
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
    /*   /sfnts [                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    /*      <num_bin_bytes> RD <binary data>        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    /*      <num_bin_bytes> RD <binary data>        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
    /*      ...                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    /*   ] def                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    /*                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    /* with exactly one space after the `RD' token. */
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
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
    if ( parser->root.cursor >= limit || *parser->root.cursor++ != '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
      FT_ERROR(( "t42_parse_sfnts: can't find begin of sfnts vector\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
      error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    status          = BEFORE_START;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    string_size     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    old_string_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    count           = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    while ( parser->root.cursor < limit )
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
      cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
      if ( *cur == ']' )
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
        parser->root.cursor++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      }
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
      else if ( *cur == '<' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
          goto Exit;
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
        /* don't include delimiters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
        string_size = (FT_Long)( ( parser->root.cursor - cur - 2 + 1 ) / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
        if ( FT_REALLOC( string_buf, old_string_size, string_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
        allocated = 1;
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
        parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
        (void)T1_ToBytes( parser, string_buf, string_size, &real_size, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
        old_string_size = string_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
        string_size = real_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      else if ( ft_isdigit( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
        if ( allocated )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
          FT_ERROR(( "t42_parse_sfnts: "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
                     "can't handle mixed binary and hex strings\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
          error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
        string_size = T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
        if ( string_size < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
          FT_ERROR(( "t42_parse_sfnts: invalid string size\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
          error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
          goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
        T1_Skip_PS_Token( parser );             /* `RD' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
          return;
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
        string_buf = parser->root.cursor + 1;   /* one space after `RD' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
        if ( limit - parser->root.cursor < string_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
          FT_ERROR(( "t42_parse_sfnts: too many binary data\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
          error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
          parser->root.cursor += string_size + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      if ( !string_buf )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
        FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
        error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
      /* A string can have a trailing zero byte for padding.  Ignore it. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      if ( string_buf[string_size - 1] == 0 && ( string_size % 2 == 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
        string_size--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
      if ( !string_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
        FT_ERROR(( "t42_parse_sfnts: invalid string\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
        error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
      for ( n = 0; n < string_size; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
        switch ( status )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        case BEFORE_START:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
          /* load offset table, 12 bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
          if ( count < 12 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
            face->ttf_data[count++] = string_buf[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
            continue;
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
            num_tables = 16 * face->ttf_data[4] + face->ttf_data[5];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
            status     = BEFORE_TABLE_DIR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
            ttf_size   = 12 + 16 * num_tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
            if ( FT_REALLOC( face->ttf_data, 12, ttf_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
              goto Fail;
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
          /* fall through */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
        case BEFORE_TABLE_DIR:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
          /* the offset table is read; read the table directory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
          if ( count < ttf_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
            face->ttf_data[count++] = string_buf[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
            continue;
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
            int       i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
            FT_ULong  len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
            for ( i = 0; i < num_tables; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
              FT_Byte*  p = face->ttf_data + 12 + 16 * i + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
              len = FT_PEEK_ULONG( p );
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
              /* Pad to a 4-byte boundary length */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
              ttf_size += ( len + 3 ) & ~3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
            status         = OTHER_TABLES;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
            face->ttf_size = ttf_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
            /* there are no more than 256 tables, so no size check here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
            if ( FT_REALLOC( face->ttf_data, 12 + 16 * num_tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
                             ttf_size + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
              goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
          /* fall through */
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
        case OTHER_TABLES:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
          /* all other tables are just copied */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
          if ( count >= ttf_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
            FT_ERROR(( "t42_parse_sfnts: too many binary data\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
            error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
            goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
          face->ttf_data[count++] = string_buf[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
        }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
    /* if control reaches this point, the format was not valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
    error = T42_Err_Invalid_File_Format;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
    parser->root.error = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    if ( allocated )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
      FT_FREE( string_buf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
  t42_parse_charstrings( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
                         T42_Loader  loader )
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
    T42_Parser     parser       = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    PS_Table       code_table   = &loader->charstrings;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    PS_Table       name_table   = &loader->glyph_names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
    PS_Table       swap_table   = &loader->swap_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    FT_Memory      memory       = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
    PSAux_Service  psaux        = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    FT_Byte*       cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
    FT_Byte*       limit        = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    FT_UInt        n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    FT_UInt        notdef_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    FT_Byte        notdef_found = 0;
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
    T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    if ( parser->root.cursor >= limit )
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
      FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
      error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    }
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
    if ( ft_isdigit( *parser->root.cursor ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
      loader->num_glyphs = (FT_UInt)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
      if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    else if ( *parser->root.cursor == '<' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
      /* We have `<< ... >>'.  Count the number of `/' in the dictionary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
      /* to get its size.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
      FT_UInt  count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
      cur = parser->root.cursor;
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
      while ( parser->root.cursor < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
        if ( *parser->root.cursor == '/' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
          count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
        else if ( *parser->root.cursor == '>' )
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
          loader->num_glyphs  = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
          parser->root.cursor = cur;        /* rewind */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
          return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
        T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
      FT_ERROR(( "t42_parse_charstrings: invalid token\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
      error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
      goto Fail;
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
    if ( parser->root.cursor >= limit )
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
      FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
      error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    }
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
    /* initialize tables */
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
    error = psaux->ps_table_funcs->init( code_table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
                                         loader->num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
                                         memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
    error = psaux->ps_table_funcs->init( name_table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
                                         loader->num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
                                         memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
    /* 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
   797
    /* index 0 names and codes (if necessary).              */
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
    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
   800
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    n = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
      /* The format is simple:                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      /*   `/glyphname' + index [+ def]          */
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
      T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
      cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
      if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
      /* We stop when we find an `end' keyword or '>' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
      if ( *cur   == 'e'          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
           cur + 3 < limit        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
           cur[1] == 'n'          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
           cur[2] == 'd'          &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
           t42_is_space( cur[3] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
      if ( *cur == '>' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
      T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
      if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
      if ( *cur == '/' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        FT_PtrDist  len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
        if ( cur + 1 >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
          FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
          error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
          goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
        cur++;                              /* skip `/' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
        len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
        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
   846
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
          goto Fail;
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
        /* 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
   850
        name_table->elements[n][len] = '\0';
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
        /* record index of /.notdef */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
        if ( *cur == '.'                                              &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
             ft_strcmp( ".notdef",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
                        (const char*)(name_table->elements[n]) ) == 0 )
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
          notdef_index = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
          notdef_found = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
        T1_Skip_Spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
        cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
        (void)T1_ToInt( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
        if ( parser->root.cursor >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
          FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
          error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
          goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
        len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
        error = T1_Add_Table( code_table, n, cur, len + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
          goto Fail;
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
        code_table->elements[n][len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
        n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
        if ( n >= loader->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
    loader->num_glyphs = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    if ( !notdef_found )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      FT_ERROR(( "t42_parse_charstrings: no /.notdef glyph\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
      error = T42_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
    }
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
    /* if /.notdef 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
   897
    if ( ft_strcmp( (const char*)".notdef",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
                    (const char*)name_table->elements[0] ) )
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
      /* 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
   901
      /* 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
   902
      /* 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
   903
      /* 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
   904
      /* swap_table.                                                     */
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
      /* Index 0 name */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
      error = T1_Add_Table( swap_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
                            name_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
                            name_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
        goto Fail;
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
      /* Index 0 code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
      error = T1_Add_Table( swap_table, 1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
                            code_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
                            code_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
      /* Index notdef_index name */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
      error = T1_Add_Table( swap_table, 2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
                            name_table->elements[notdef_index],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
                            name_table->lengths [notdef_index] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
      /* Index notdef_index code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
      error = T1_Add_Table( swap_table, 3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
                            code_table->elements[notdef_index],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
                            code_table->lengths [notdef_index] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
      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
   935
                            swap_table->elements[0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
                            swap_table->lengths [0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
      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
   941
                            swap_table->elements[1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
                            swap_table->lengths [1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
      error = T1_Add_Table( name_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
                            swap_table->elements[2],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
                            swap_table->lengths [2] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
      error = T1_Add_Table( code_table, 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
                            swap_table->elements[3],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
                            swap_table->lengths [3] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    return;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    parser->root.error = error;
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
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
  t42_load_keyword( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
                    T42_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
                    T1_Field    field )
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
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
    void*     dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
    void**    objects;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
    FT_UInt   max_objects = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
    /* 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
   979
    if ( field->type == T1_FIELD_TYPE_CALLBACK )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
      field->reader( (FT_Face)face, loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
      error = loader->parser.root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
    /* 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
   987
    /* 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
   988
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    switch ( field->location )
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
    case T1_FIELD_LOCATION_FONT_INFO:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
      dummy_object = &face->type1.font_info;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
    case T1_FIELD_LOCATION_FONT_EXTRA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
      dummy_object = &face->type1.font_extra;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
      break;
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
    case T1_FIELD_LOCATION_BBOX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
      dummy_object = &face->type1.font_bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
      dummy_object = &face->type1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
    objects = &dummy_object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
    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
  1010
         field->type == T1_FIELD_TYPE_FIXED_ARRAY   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
      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
  1012
                                   objects, max_objects, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
      error = T1_Load_Field( &loader->parser, field,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
                             objects, max_objects, 0 );
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
   Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
  t42_parse_dict( T42_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
                  T42_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
                  FT_Byte*    base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
                  FT_Long     size )
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
    T42_Parser  parser     = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
    FT_Byte*    limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
    FT_Int      n_keywords = (FT_Int)( sizeof ( t42_keywords ) /
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
                                         sizeof ( t42_keywords[0] ) );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
    parser->root.cursor = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
    parser->root.limit  = base + size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    parser->root.error  = T42_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
    limit = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    T1_Skip_Spaces( parser );
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
    while ( parser->root.cursor < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
      FT_Byte*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
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
      cur = parser->root.cursor;
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
      /* look for `FontDirectory' which causes problems for some fonts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
      if ( *cur == 'F' && cur + 25 < limit                    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
           ft_strncmp( (char*)cur, "FontDirectory", 13 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
        FT_Byte*  cur2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
        /* skip the `FontDirectory' keyword */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
        T1_Skip_Spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
        cur = cur2 = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
        /* look up the `known' keyword */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
        while ( cur < limit )
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
          if ( *cur == 'k' && cur + 5 < limit             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
                ft_strncmp( (char*)cur, "known", 5 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
          T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
          if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
          T1_Skip_Spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
          cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
        }
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
        if ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
          T1_TokenRec  token;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
          /* skip the `known' keyword and the token following it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
          T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
          T1_ToToken( parser, &token );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
          /* if the last token was an array, skip it! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
          if ( token.type == T1_TOKEN_TYPE_ARRAY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
            cur2 = parser->root.cursor;
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
        parser->root.cursor = cur2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
      /* look for immediates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
      else if ( *cur == '/' && cur + 2 < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
        FT_PtrDist  len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
        parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
          goto Exit;
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
        len = parser->root.cursor - cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
        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
  1107
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
          int  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
          /* 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
  1112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
          /* loop through all known keywords */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
          for ( i = 0; i < n_keywords; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
            T1_Field  keyword = (T1_Field)&t42_keywords[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
            FT_Byte   *name   = (FT_Byte*)keyword->ident;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
            if ( !name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
              continue;
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
            if ( cur[0] == name[0]                                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
                 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
  1125
                 ft_memcmp( cur, name, len ) == 0                   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
              /* we found it -- run the parsing callback! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
              parser->root.error = t42_load_keyword( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
                                                     loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
                                                     keyword );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
              if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
                return parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
        }
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
          goto Exit;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
    return parser->root.error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
  t42_loader_init( T42_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
                   T42_Face    face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
    FT_UNUSED( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
    FT_MEM_ZERO( loader, sizeof ( *loader ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
    loader->num_glyphs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
    loader->num_chars  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
    /* 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
  1164
    loader->encoding_table.init = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
    loader->charstrings.init    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
    loader->glyph_names.init    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
  t42_loader_done( T42_Loader  loader )
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
    T42_Parser  parser = &loader->parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
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
    /* finalize tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
    T1_Release_Table( &loader->encoding_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
    T1_Release_Table( &loader->charstrings );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
    T1_Release_Table( &loader->glyph_names );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
    T1_Release_Table( &loader->swap_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
    /* finalize parser */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
    t42_parser_done( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
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
/* END */