misc/libfreetype/src/psaux/psobjs.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
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
/*  psobjs.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
/*    Auxiliary functions for PostScript fonts (body).                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2011 by                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_POSTSCRIPT_AUX_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_CALC_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "psobjs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "psconv.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "psauxerr.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#define FT_COMPONENT  trace_psobjs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*************************************************************************/
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
  /*****                             PS_TABLE                          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /*    ps_table_new                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /*    Initializes a PS_Table.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  /*    table  :: The address of the target table.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  /*    count  :: The table size = the maximum number of elements.         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /*    memory :: The memory object to use for all subsequent              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /*              reallocations.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  ps_table_new( PS_Table   table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
                FT_Int     count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                FT_Memory  memory )
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
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    table->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    if ( FT_NEW_ARRAY( table->elements, count ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
         FT_NEW_ARRAY( table->lengths,  count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    table->max_elems = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    table->init      = 0xDEADBEEFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    table->num_elems = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    table->block     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    table->capacity  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    table->cursor    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    *(PS_Table_FuncsRec*)&table->funcs = ps_table_funcs;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
      FT_FREE( table->elements );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  shift_elements( PS_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
                  FT_Byte*  old_base )
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
    FT_PtrDist  delta  = table->block - old_base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_Byte**   offset = table->elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    FT_Byte**   limit  = offset + table->max_elems;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    for ( ; offset < limit; offset++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
      if ( offset[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        offset[0] += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  reallocate_t1_table( PS_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
                       FT_Long   new_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    FT_Memory  memory   = table->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    FT_Byte*   old_base = table->block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    FT_Error   error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    /* allocate new base block */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    if ( FT_ALLOC( table->block, new_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      table->block = old_base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    /* copy elements and shift offsets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    if ( old_base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      FT_MEM_COPY( table->block, old_base, table->capacity );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      shift_elements( table, old_base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      FT_FREE( old_base );
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
    table->capacity = new_size;
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
    return PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  /*    ps_table_add                                                       */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  /*    Adds an object to a PS_Table, possibly growing its memory block.   */
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
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  /*    table  :: The target table.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  /*    idx    :: The index of the object in the table.                    */
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
  /*    object :: The address of the object to copy in memory.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
  /*    length :: The length in bytes of the source object.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
  /*    FreeType error code.  0 means success.  An error is returned if a  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  /*    reallocation fails.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
  ps_table_add( PS_Table    table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
                FT_Int      idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
                void*       object,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
                FT_PtrDist  length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    if ( idx < 0 || idx >= table->max_elems )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      FT_ERROR(( "ps_table_add: invalid index\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      return PSaux_Err_Invalid_Argument;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    if ( length < 0 )
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
      FT_ERROR(( "ps_table_add: invalid length\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
      return PSaux_Err_Invalid_Argument;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    /* grow the base block if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    if ( table->cursor + length > table->capacity )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
      FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
      FT_Offset   new_size = table->capacity;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
      FT_PtrDist  in_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      in_offset = (FT_Byte*)object - table->block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      if ( in_offset < 0 || (FT_Offset)in_offset >= table->capacity )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        in_offset = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      while ( new_size < table->cursor + length )
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
        /* increase size by 25% and round up to the nearest multiple
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
           of 1024 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
        new_size += ( new_size >> 2 ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        new_size  = FT_PAD_CEIL( new_size, 1024 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      }
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
      error = reallocate_t1_table( table, new_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      if ( in_offset >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
        object = table->block + in_offset;
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
    /* add the object to the base block and adjust offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    table->elements[idx] = table->block + table->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    table->lengths [idx] = length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    FT_MEM_COPY( table->block + table->cursor, object, length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    table->cursor += length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    return PSaux_Err_Ok;
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
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  /*    ps_table_done                                                      */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  /*    Finalizes a PS_TableRec (i.e., reallocate it to its current        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  /*    cursor).                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  /*    table :: The target table.                                         */
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
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
  /*    This function does NOT release the heap's memory block.  It is up  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
  /*    to the caller to clean it, or reference it in its own structures.  */
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  ps_table_done( PS_Table  table )
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
    FT_Memory  memory = table->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    FT_Byte*   old_base = table->block;
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
    /* should never fail, because rec.cursor <= rec.size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    if ( !old_base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    if ( FT_ALLOC( table->block, table->cursor ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    FT_MEM_COPY( table->block, old_base, table->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    shift_elements( table, old_base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    table->capacity = table->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
    FT_FREE( old_base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    FT_UNUSED( error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
  ps_table_release( PS_Table  table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    FT_Memory  memory = table->memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    if ( (FT_ULong)table->init == 0xDEADBEEFUL )
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
      FT_FREE( table->block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      FT_FREE( table->elements );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      FT_FREE( table->lengths );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      table->init = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
  /*************************************************************************/
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
  /*****                            T1 PARSER                          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
  /* first character must be already part of the comment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
  skip_comment( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
                FT_Byte*   limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    FT_Byte*  cur = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    while ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      if ( IS_PS_NEWLINE( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      cur++;
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
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
  skip_spaces( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
               FT_Byte*   limit )
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
    FT_Byte*  cur = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    while ( cur < limit )
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
      if ( !IS_PS_SPACE( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
        if ( *cur == '%' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
          /* According to the PLRM, a comment is equal to a space. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
          skip_comment( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
          break;
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
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
#define IS_OCTAL_DIGIT( c ) ( '0' <= (c) && (c) <= '7' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
  /* first character must be `(';                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
  /* *acur is positioned at the character after the closing `)' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  skip_literal_string( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
                       FT_Byte*   limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    FT_Byte*      cur   = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    FT_Int        embed = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
    FT_Error      error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    unsigned int  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    while ( cur < limit )
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
      FT_Byte  c = *cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
      ++cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      if ( c == '\\' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
        /* Red Book 3rd ed., section `Literal Text Strings', p. 29:     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
        /* A backslash can introduce three different types              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
        /* of escape sequences:                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
        /*   - a special escaped char like \r, \n, etc.                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
        /*   - a one-, two-, or three-digit octal number                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
        /*   - none of the above in which case the backslash is ignored */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
        if ( cur == limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
          /* error (or to be ignored?) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
        switch ( *cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
          /* skip `special' escape */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
        case 'n':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
        case 'r':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
        case 't':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
        case 'b':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
        case 'f':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
        case '\\':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
        case '(':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
        case ')':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
          ++cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
          break;
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
        default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
          /* skip octal escape or ignore backslash */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
          for ( i = 0; i < 3 && cur < limit; ++i )
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
            if ( !IS_OCTAL_DIGIT( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
              break;
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
            ++cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      else if ( c == '(' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
        embed++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      else if ( c == ')' )
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
        embed--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
        if ( embed == 0 )
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
          error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    *acur = cur;
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
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
  /* first character must be `<' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  skip_string( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
               FT_Byte*   limit )
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
    FT_Byte*  cur = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
    FT_Error  err =  PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    while ( ++cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      /* All whitespace characters are ignored. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      skip_spaces( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      if ( !IS_PS_XDIGIT( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
    if ( cur < limit && *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
      FT_ERROR(( "skip_string: missing closing delimiter `>'\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      err = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      cur++;
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
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
    return err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
  /* first character must be the opening brace that */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
  /* starts the procedure                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
  /* NB: [ and ] need not match:                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  /* `/foo {[} def' is a valid PostScript fragment, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
  /* even within a Type1 font                       */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
  skip_procedure( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
                  FT_Byte*   limit )
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
    FT_Byte*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    FT_Int    embed = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    FT_Error  error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
    FT_ASSERT( **acur == '{' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    for ( cur = *acur; cur < limit && error == PSaux_Err_Ok; ++cur )
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
      switch ( *cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
      case '{':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
        ++embed;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      case '}':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
        --embed;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
        if ( embed == 0 )
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
          ++cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
          goto end;
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
        break;
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
      case '(':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
        error = skip_literal_string( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
        break;
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
      case '<':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
        error = skip_string( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
        break;
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
      case '%':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
        skip_comment( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
  end:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    if ( embed != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
      error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
  /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  /* All exported parsing routines handle leading whitespace and stop at */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  /* the first character which isn't part of the just handled token.     */
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
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
  ps_parser_skip_PS_token( PS_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
    /* Note: PostScript allows any non-delimiting, non-whitespace        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
    /*       character in a name (PS Ref Manual, 3rd ed, p31).           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    /*       PostScript delimiters are (, ), <, >, [, ], {, }, /, and %. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
    FT_Byte*  cur   = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    FT_Byte*  limit = parser->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    FT_Error  error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    skip_spaces( &cur, limit );             /* this also skips comments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    /* self-delimiting, single-character tokens */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    if ( *cur == '[' || *cur == ']' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    /* skip balanced expressions (procedures and strings) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    if ( *cur == '{' )                              /* {...} */
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
      error = skip_procedure( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
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
      error = skip_literal_string( &cur, limit );
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
    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
      if ( cur + 1 < limit && *(cur + 1) == '<' )   /* << */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
        error = skip_string( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
    if ( *cur == '>' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
      if ( cur >= limit || *cur != '>' )             /* >> */
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
        FT_ERROR(( "ps_parser_skip_PS_token:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
                   " unexpected closing delimiter `>'\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
        goto Exit;
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
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    if ( *cur == '/' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
    /* anything else */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
    while ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
      /* *cur might be invalid (e.g., ')' or '}'), but this   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
      /* is handled by the test `cur == parser->cursor' below */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
      if ( IS_PS_DELIM( *cur ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    if ( cur == parser->cursor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
      FT_ERROR(( "ps_parser_skip_PS_token:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
                 " current token is `%c' which is self-delimiting\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
                 "                        "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
                 " but invalid at this point\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
                 *cur ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
      error = PSaux_Err_Invalid_File_Format;
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
    parser->error  = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
    parser->cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
  ps_parser_skip_spaces( PS_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
    skip_spaces( &parser->cursor, parser->limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
  /* `token' here means either something between balanced delimiters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
  /* or the next token; the delimiters are not removed.              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
  ps_parser_to_token( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
                      T1_Token   token )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    FT_Byte*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
    FT_Byte*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
    FT_Int    embed;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
    token->type  = T1_TOKEN_TYPE_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
    token->start = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    token->limit = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    /* first of all, skip leading whitespace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    ps_parser_skip_spaces( parser );
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
    cur   = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    limit = parser->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    switch ( *cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
      /************* check for literal string *****************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    case '(':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      token->type  = T1_TOKEN_TYPE_STRING;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
      token->start = cur;
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
      if ( skip_literal_string( &cur, limit ) == PSaux_Err_Ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
        token->limit = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
      /************* check for programs/array *****************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    case '{':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
      token->type  = T1_TOKEN_TYPE_ARRAY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
      token->start = cur;
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
      if ( skip_procedure( &cur, limit ) == PSaux_Err_Ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
        token->limit = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      break;
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
      /************* check for table/array ********************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
      /* XXX: in theory we should also look for "<<"          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
      /*      since this is semantically equivalent to "[";   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      /*      in practice it doesn't matter (?)               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
    case '[':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
      token->type  = T1_TOKEN_TYPE_ARRAY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
      embed        = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
      token->start = cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
      /* we need this to catch `[ ]' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
      parser->cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
      ps_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
      cur = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
      while ( cur < limit && !parser->error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
        /* XXX: this is wrong because it does not      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
        /*      skip comments, procedures, and strings */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
        if ( *cur == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
          embed++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
        else if ( *cur == ']' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
          embed--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
          if ( embed <= 0 )
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
            token->limit = ++cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
            break;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
        parser->cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
        ps_parser_skip_PS_token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
        /* we need this to catch `[XXX ]' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
        ps_parser_skip_spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
        cur = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
      break;
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
      /* ************ otherwise, it is any token **************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
      token->start = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
      token->type  = ( *cur == '/' ? T1_TOKEN_TYPE_KEY : T1_TOKEN_TYPE_ANY );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
      ps_parser_skip_PS_token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
      cur = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      if ( !parser->error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
        token->limit = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    if ( !token->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
      token->start = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      token->type  = T1_TOKEN_TYPE_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    parser->cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
  /* NB: `tokens' can be NULL if we only want to count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
  /* the number of array elements                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
  ps_parser_to_token_array( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
                            T1_Token   tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
                            FT_UInt    max_tokens,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
                            FT_Int*    pnum_tokens )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
    T1_TokenRec  master;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    *pnum_tokens = -1;
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
    /* this also handles leading whitespace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    ps_parser_to_token( parser, &master );
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
    if ( master.type == T1_TOKEN_TYPE_ARRAY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
      FT_Byte*  old_cursor = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      FT_Byte*  old_limit  = parser->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
      T1_Token  cur        = tokens;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
      T1_Token  limit      = cur + max_tokens;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
      /* don't include outermost delimiters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
      parser->cursor = master.start + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
      parser->limit  = master.limit - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      while ( parser->cursor < parser->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
        T1_TokenRec  token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
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
        ps_parser_to_token( parser, &token );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
        if ( !token.type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
        if ( tokens != NULL && cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
          *cur = token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
      *pnum_tokens = (FT_Int)( cur - tokens );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
      parser->cursor = old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
      parser->limit  = old_limit;
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
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
  /* first character must be a delimiter or a part of a number */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
  /* NB: `coords' can be NULL if we just want to skip the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
  /*     array; in this case we ignore `max_coords'            */
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
  static FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
  ps_tocoordarray( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
                   FT_Byte*   limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
                   FT_Int     max_coords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
                   FT_Short*  coords )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    FT_Byte*  cur   = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
    FT_Int    count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    FT_Byte   c, ender;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
    if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    /* check for the beginning of an array; otherwise, only one number */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
    /* will be read                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
    c     = *cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    ender = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    if ( c == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
      ender = ']';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
    else if ( c == '{' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
      ender = '}';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    if ( ender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
    /* now, read the coordinates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    while ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
      FT_Short  dummy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
      FT_Byte*  old_cur;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      /* skip whitespace in front of data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
      skip_spaces( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
      if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
      if ( *cur == ender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
      old_cur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
      if ( coords != NULL && count >= max_coords )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
      /* call PS_Conv_ToFixed() even if coords == NULL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
      /* to properly parse number at `cur'             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
      *( coords != NULL ? &coords[count] : &dummy ) =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
        (FT_Short)( PS_Conv_ToFixed( &cur, limit, 0 ) >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
      if ( old_cur == cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
        count = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        goto Exit;
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
        count++;
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
      if ( !ender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
    return count;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
  /* first character must be a delimiter or a part of a number */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
  /* NB: `values' can be NULL if we just want to skip the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
  /*     array; in this case we ignore `max_values'            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
  static FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
  ps_tofixedarray( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
                   FT_Byte*   limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
                   FT_Int     max_values,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
                   FT_Fixed*  values,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
                   FT_Int     power_ten )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    FT_Byte*  cur   = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    FT_Int    count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    FT_Byte   c, ender;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
    /* Check for the beginning of an array.  Otherwise, only one number */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
    /* will be read.                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
    c     = *cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
    ender = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    if ( c == '[' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      ender = ']';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
    else if ( c == '{' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
      ender = '}';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
    if ( ender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
      cur++;
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
    /* now, read the values */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
    while ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
      FT_Fixed  dummy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
      FT_Byte*  old_cur;
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
      /* skip whitespace in front of data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
      skip_spaces( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
      if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
        goto Exit;
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
      if ( *cur == ender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
      old_cur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
      if ( values != NULL && count >= max_values )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
      /* call PS_Conv_ToFixed() even if coords == NULL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
      /* to properly parse number at `cur'             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      *( values != NULL ? &values[count] : &dummy ) =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
        PS_Conv_ToFixed( &cur, limit, power_ten );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
      if ( old_cur == cur )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
        count = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
        count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
      if ( !ender )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
    return count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
#if 0
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
  static FT_String*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
  ps_tostring( FT_Byte**  cursor,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
               FT_Byte*   limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
               FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
    FT_Byte*    cur = *cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    FT_PtrDist  len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
    FT_Int      count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
    FT_String*  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
    /* XXX: some stupid fonts have a `Notice' or `Copyright' string     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
    /*      that simply doesn't begin with an opening parenthesis, even */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
    /*      though they have a closing one!  E.g. "amuncial.pfb"        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
    /*                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
    /*      We must deal with these ill-fated cases there.  Note that   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
    /*      these fonts didn't work with the old Type 1 driver as the   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
    /*      notice/copyright was not recognized as a valid string token */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
    /*      and made the old token parser commit errors.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
    while ( cur < limit && ( *cur == ' ' || *cur == '\t' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
    if ( cur + 1 >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
    if ( *cur == '(' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
      cur++;  /* skip the opening parenthesis, if there is one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    *cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
    count   = 0;
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
    /* then, count its length */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    for ( ; cur < limit; cur++ )
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
      if ( *cur == '(' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
        count++;
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
      else if ( *cur == ')' )
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
        count--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
        if ( count < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
    len = cur - *cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
    if ( cur >= limit || FT_ALLOC( result, len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
      return 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
    /* now copy the string */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
    FT_MEM_COPY( result, *cursor, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
    result[len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    *cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
#endif /* 0 */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
  ps_tobool( FT_Byte*  *acur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
             FT_Byte*   limit )
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
    FT_Byte*  cur    = *acur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
    FT_Bool   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
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
    /* return 1 if we find `true', 0 otherwise */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
    if ( cur + 3 < limit &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
         cur[0] == 't'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
         cur[1] == 'r'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
         cur[2] == 'u'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
         cur[3] == 'e'   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
      result = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
      cur   += 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    else if ( cur + 4 < limit &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
              cur[0] == 'f'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
              cur[1] == 'a'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
              cur[2] == 'l'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
              cur[3] == 's'   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
              cur[4] == 'e'   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
      result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
      cur   += 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
    *acur = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
  }
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
  /* load a simple field (i.e. non-table) into the current list of objects */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
  ps_parser_load_field( PS_Parser       parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
                        const T1_Field  field,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
                        void**          objects,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
                        FT_UInt         max_objects,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
                        FT_ULong*       pflags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
    T1_TokenRec  token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
    FT_Byte*     cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
    FT_Byte*     limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
    FT_UInt      count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
    FT_UInt      idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
    /* this also skips leading whitespace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
    ps_parser_to_token( parser, &token );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    if ( !token.type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
    count = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
    idx   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    cur   = token.start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
    limit = token.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    /* we must detect arrays in /FontBBox */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
    if ( field->type == T1_FIELD_TYPE_BBOX )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
      T1_TokenRec  token2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
      FT_Byte*     old_cur   = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
      FT_Byte*     old_limit = parser->limit;
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
      /* don't include delimiters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
      parser->cursor = token.start + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
      parser->limit  = token.limit - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
      ps_parser_to_token( parser, &token2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
      parser->cursor = old_cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
      parser->limit  = old_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 ( token2.type == T1_TOKEN_TYPE_ARRAY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
        goto FieldArray;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
    else if ( token.type == T1_TOKEN_TYPE_ARRAY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
    FieldArray:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
      /* if this is an array and we have no blend, an error occurs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
      if ( max_objects == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
        goto Fail;
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
      count = max_objects;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
      idx   = 1;
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
      /* don't include delimiters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
      limit--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
    for ( ; count > 0; count--, idx++ )
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
      FT_Byte*    q = (FT_Byte*)objects[idx] + field->offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
      FT_Long     val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
      FT_String*  string;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
      skip_spaces( &cur, limit );
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
      switch ( field->type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
      case T1_FIELD_TYPE_BOOL:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
        val = ps_tobool( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
        goto Store_Integer;
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
      case T1_FIELD_TYPE_FIXED:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
        val = PS_Conv_ToFixed( &cur, limit, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
        goto Store_Integer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
      case T1_FIELD_TYPE_FIXED_1000:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
        val = PS_Conv_ToFixed( &cur, limit, 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
        goto Store_Integer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
      case T1_FIELD_TYPE_INTEGER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
        val = PS_Conv_ToInt( &cur, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
        /* fall through */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
      Store_Integer:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
        switch ( field->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
        case (8 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
          *(FT_Byte*)q = (FT_Byte)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
          break;
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
        case (16 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
          *(FT_UShort*)q = (FT_UShort)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
          break;
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
        case (32 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
          *(FT_UInt32*)q = (FT_UInt32)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
        default:                /* for 64-bit systems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
          *(FT_Long*)q = val;
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
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
      case T1_FIELD_TYPE_STRING:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
      case T1_FIELD_TYPE_KEY:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
          FT_Memory  memory = parser->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
          FT_UInt    len    = (FT_UInt)( limit - cur );
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
          if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
          /* we allow both a string or a name   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
          /* for cases like /FontName (foo) def */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
          if ( token.type == T1_TOKEN_TYPE_KEY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
            /* don't include leading `/' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
            len--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
            cur++;
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
          else if ( token.type == T1_TOKEN_TYPE_STRING )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
            /* don't include delimiting parentheses    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
            /* XXX we don't handle <<...>> here        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
            /* XXX should we convert octal escapes?    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
            /*     if so, what encoding should we use? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
            cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
            len -= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
            FT_ERROR(( "ps_parser_load_field:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
                       " expected a name or string\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
                       "                     "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
                       " but found token of type %d instead\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
                       token.type ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
            error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
          /* for this to work (FT_String**)q must have been */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
          /* initialized to NULL                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
          if ( *(FT_String**)q != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
            FT_TRACE0(( "ps_parser_load_field: overwriting field %s\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
                        field->ident ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
            FT_FREE( *(FT_String**)q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
            *(FT_String**)q = NULL;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
          if ( FT_ALLOC( string, len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
          FT_MEM_COPY( string, cur, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
          string[len] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
          *(FT_String**)q = string;
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
        break;
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
      case T1_FIELD_TYPE_BBOX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
          FT_Fixed  temp[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
          FT_BBox*  bbox = (FT_BBox*)q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
          FT_Int    result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
          result = ps_tofixedarray( &cur, limit, 4, temp, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
          if ( result < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
            FT_ERROR(( "ps_parser_load_field:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
                       " expected four integers in bounding box\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
            error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
          bbox->xMin = FT_RoundFix( temp[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
          bbox->yMin = FT_RoundFix( temp[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
          bbox->xMax = FT_RoundFix( temp[2] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
          bbox->yMax = FT_RoundFix( temp[3] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
        /* an error occurred */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
#if 0  /* obsolete -- keep for reference */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
    if ( pflags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
      *pflags |= 1L << field->flag_bit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
    FT_UNUSED( pflags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
    error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
    error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
#define T1_MAX_TABLE_ELEMENTS  32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
  ps_parser_load_field_table( PS_Parser       parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
                              const T1_Field  field,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
                              void**          objects,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
                              FT_UInt         max_objects,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
                              FT_ULong*       pflags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
    T1_TokenRec  elements[T1_MAX_TABLE_ELEMENTS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
    T1_Token     token;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
    FT_Int       num_elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
    FT_Error     error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
    FT_Byte*     old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
    FT_Byte*     old_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
    T1_FieldRec  fieldrec = *(T1_Field)field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
    fieldrec.type = T1_FIELD_TYPE_INTEGER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
    if ( field->type == T1_FIELD_TYPE_FIXED_ARRAY ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
         field->type == T1_FIELD_TYPE_BBOX        )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
      fieldrec.type = T1_FIELD_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
    ps_parser_to_token_array( parser, elements,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
                              T1_MAX_TABLE_ELEMENTS, &num_elements );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
    if ( num_elements < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
      error = PSaux_Err_Ignore;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
    if ( (FT_UInt)num_elements > field->array_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
      num_elements = field->array_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
    old_cursor = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
    old_limit  = parser->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
    /* we store the elements count if necessary;           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
    /* we further assume that `count_offset' can't be zero */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
    if ( field->type != T1_FIELD_TYPE_BBOX && field->count_offset != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
      *(FT_Byte*)( (FT_Byte*)objects[0] + field->count_offset ) =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
        (FT_Byte)num_elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
    /* we now load each element, adjusting the field.offset on each one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
    token = elements;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
    for ( ; num_elements > 0; num_elements--, token++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
      parser->cursor = token->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
      parser->limit  = token->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
      ps_parser_load_field( parser, &fieldrec, objects, max_objects, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
      fieldrec.offset += fieldrec.size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
#if 0  /* obsolete -- keep for reference */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
    if ( pflags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
      *pflags |= 1L << field->flag_bit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
    FT_UNUSED( pflags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
    parser->cursor = old_cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
    parser->limit  = old_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
  FT_LOCAL_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
  ps_parser_to_int( PS_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
    ps_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
    return PS_Conv_ToInt( &parser->cursor, parser->limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
  /* first character must be `<' if `delimiters' is non-zero */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
  ps_parser_to_bytes( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
                      FT_Byte*   bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
                      FT_Offset  max_bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
                      FT_Long*   pnum_bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
                      FT_Bool    delimiters )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
    FT_Error  error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
    FT_Byte*  cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
    ps_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
    cur = parser->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
    if ( cur >= parser->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
    if ( delimiters )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
      if ( *cur != '<' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
        FT_ERROR(( "ps_parser_to_bytes: Missing starting delimiter `<'\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
        error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
    *pnum_bytes = PS_Conv_ASCIIHexDecode( &cur,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
                                          parser->limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
                                          bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
                                          max_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    if ( delimiters )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
      if ( cur < parser->limit && *cur != '>' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
        FT_ERROR(( "ps_parser_to_bytes: Missing closing delimiter `>'\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
        error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
      cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
    parser->cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
  FT_LOCAL_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
  ps_parser_to_fixed( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
                      FT_Int     power_ten )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
    ps_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
    return PS_Conv_ToFixed( &parser->cursor, parser->limit, power_ten );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
  ps_parser_to_coord_array( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
                            FT_Int     max_coords,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
                            FT_Short*  coords )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
    ps_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
    return ps_tocoordarray( &parser->cursor, parser->limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
                            max_coords, coords );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
  ps_parser_to_fixed_array( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
                            FT_Int     max_values,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
                            FT_Fixed*  values,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
                            FT_Int     power_ten )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
    ps_parser_skip_spaces( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
    return ps_tofixedarray( &parser->cursor, parser->limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
                            max_values, values, power_ten );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
  FT_LOCAL_DEF( FT_String* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
  T1_ToString( PS_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
    return ps_tostring( &parser->cursor, parser->limit, parser->memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
  FT_LOCAL_DEF( FT_Bool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
  T1_ToBool( PS_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
    return ps_tobool( &parser->cursor, parser->limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
  ps_parser_init( PS_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
                  FT_Byte*   base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
                  FT_Byte*   limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
                  FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
    parser->error  = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
    parser->base   = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
    parser->limit  = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
    parser->cursor = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
    parser->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
    parser->funcs  = ps_parser_funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
  ps_parser_done( PS_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
    FT_UNUSED( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
  /*****                            T1 BUILDER                         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
  /*    t1_builder_init                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
  /*    Initializes a given glyph builder.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
  /*    builder :: A pointer to the glyph builder to initialize.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
  /*    face    :: The current face object.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
  /*    size    :: The current size object.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
  /*    glyph   :: The current glyph object.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
  /*    hinting :: Whether hinting should be applied.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
  t1_builder_init( T1_Builder    builder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
                   FT_Face       face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
                   FT_Size       size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
                   FT_GlyphSlot  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
                   FT_Bool       hinting )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
    builder->parse_state = T1_Parse_Start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
    builder->load_points = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
    builder->face   = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
    builder->glyph  = glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
    builder->memory = face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    if ( glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
      FT_GlyphLoader  loader = glyph->internal->loader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
      builder->loader  = loader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
      builder->base    = &loader->base.outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
      builder->current = &loader->current.outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
      FT_GlyphLoader_Rewind( loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
      builder->hints_globals = size->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
      builder->hints_funcs   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
      if ( hinting )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
        builder->hints_funcs = glyph->internal->glyph_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
    builder->pos_x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
    builder->pos_y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
    builder->left_bearing.x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
    builder->left_bearing.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
    builder->advance.x      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
    builder->advance.y      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
    builder->funcs = t1_builder_funcs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
  /*    t1_builder_done                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
  /*    Finalizes a given glyph builder.  Its contents can still be used   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
  /*    after the call, but the function saves important information       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
  /*    within the corresponding glyph slot.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
  /*    builder :: A pointer to the glyph builder to finalize.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
  t1_builder_done( T1_Builder  builder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
    FT_GlyphSlot  glyph = builder->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
    if ( glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
      glyph->outline = *builder->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
  /* check that there is enough space for `count' more points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
  t1_builder_check_points( T1_Builder  builder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
                           FT_Int      count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
    return FT_GLYPHLOADER_CHECK_POINTS( builder->loader, count, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
  /* add a new point, do not check space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
  t1_builder_add_point( T1_Builder  builder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
                        FT_Pos      x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
                        FT_Pos      y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
                        FT_Byte     flag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
    FT_Outline*  outline = builder->current;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
    if ( builder->load_points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
      FT_Vector*  point   = outline->points + outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
      FT_Byte*    control = (FT_Byte*)outline->tags + outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
      point->x = FIXED_TO_INT( x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
      point->y = FIXED_TO_INT( y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
      *control = (FT_Byte)( flag ? FT_CURVE_TAG_ON : FT_CURVE_TAG_CUBIC );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
    outline->n_points++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
  /* check space for a new on-curve point, then add it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
  t1_builder_add_point1( T1_Builder  builder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
                         FT_Pos      x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
                         FT_Pos      y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
    error = t1_builder_check_points( builder, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
      t1_builder_add_point( builder, x, y, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
  /* check space for a new contour, then add it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
  t1_builder_add_contour( T1_Builder  builder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
    FT_Outline*  outline = builder->current;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
    /* this might happen in invalid fonts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
      FT_ERROR(( "t1_builder_add_contour: no outline to add points to\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
      return PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
    if ( !builder->load_points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
      outline->n_contours++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
      return PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
    error = FT_GLYPHLOADER_CHECK_POINTS( builder->loader, 0, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
      if ( outline->n_contours > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
        outline->contours[outline->n_contours - 1] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
          (short)( outline->n_points - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
      outline->n_contours++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
  /* if a path was begun, add its first on-curve point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
  t1_builder_start_point( T1_Builder  builder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
                          FT_Pos      x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
                          FT_Pos      y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
    FT_Error  error = PSaux_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
    /* test whether we are building a new contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
    if ( builder->parse_state == T1_Parse_Have_Path )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
      error = PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
      builder->parse_state = T1_Parse_Have_Path;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
      error = t1_builder_add_contour( builder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
        error = t1_builder_add_point1( builder, x, y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
  /* close the current contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
  t1_builder_close_contour( T1_Builder  builder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
    FT_Outline*  outline = builder->current;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
    FT_Int       first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
    if ( !outline )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
    first = outline->n_contours <= 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
            ? 0 : outline->contours[outline->n_contours - 2] + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
    /* We must not include the last point in the path if it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
    /* is located on the first point.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
    if ( outline->n_points > 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
      FT_Vector*  p1      = outline->points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
      FT_Vector*  p2      = outline->points + outline->n_points - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
      FT_Byte*    control = (FT_Byte*)outline->tags + outline->n_points - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
      /* `delete' last point only if it coincides with the first */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
      /* point and it is not a control point (which can happen). */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
      if ( p1->x == p2->x && p1->y == p2->y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
        if ( *control == FT_CURVE_TAG_ON )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
          outline->n_points--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
    if ( outline->n_contours > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
      /* Don't add contours only consisting of one point, i.e.,  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
      /* check whether the first and the last point is the same. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
      if ( first == outline->n_points - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
        outline->n_contours--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
        outline->n_points--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
        outline->contours[outline->n_contours - 1] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
          (short)( outline->n_points - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
  /*****                            OTHER                              *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
  t1_decrypt( FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
              FT_Offset  length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
              FT_UShort  seed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
    PS_Conv_EexecDecode( &buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
                         buffer + length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
                         buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
                         length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
                         &seed );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
/* END */