misc/libfreetype/src/psaux/afmparse.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
/*  afmparse.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
/*    AFM parser (body).                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2006, 2007, 2008, 2009, 2010 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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include FT_FREETYPE_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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include "afmparse.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include "psconv.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "psauxerr.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
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
/*    AFM_Stream                                                           */
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 use of AFM_Stream is largely inspired by parseAFM.[ch] from t1lib.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  enum
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    AFM_STREAM_STATUS_NORMAL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
    AFM_STREAM_STATUS_EOC,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
    AFM_STREAM_STATUS_EOL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    AFM_STREAM_STATUS_EOF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  typedef struct  AFM_StreamRec_
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
    FT_Byte*  cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    FT_Byte*  base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_Byte*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_Int    status;
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
  } AFM_StreamRec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
#ifndef EOF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
#define EOF -1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /* this works because empty lines are ignored */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
#define AFM_IS_NEWLINE( ch )  ( (ch) == '\r' || (ch) == '\n' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
#define AFM_IS_EOF( ch )      ( (ch) == EOF  || (ch) == '\x1a' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
#define AFM_IS_SPACE( ch )    ( (ch) == ' '  || (ch) == '\t' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /* column separator; there is no `column' in the spec actually */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
#define AFM_IS_SEP( ch )      ( (ch) == ';' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
#define AFM_GETC()                                                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
          ( ( (stream)->cursor < (stream)->limit ) ? *(stream)->cursor++ \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
                                                   : EOF )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
#define AFM_STREAM_KEY_BEGIN( stream )    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
          (char*)( (stream)->cursor - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
#define AFM_STREAM_KEY_LEN( stream, key )       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
          ( (char*)(stream)->cursor - key - 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
#define AFM_STATUS_EOC( stream ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
          ( (stream)->status >= AFM_STREAM_STATUS_EOC )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
#define AFM_STATUS_EOL( stream ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
          ( (stream)->status >= AFM_STREAM_STATUS_EOL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
#define AFM_STATUS_EOF( stream ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
          ( (stream)->status >= AFM_STREAM_STATUS_EOF )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  afm_stream_skip_spaces( AFM_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    int  ch = 0;  /* make stupid compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    if ( AFM_STATUS_EOC( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
      return ';';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    while ( 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      ch = AFM_GETC();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      if ( !AFM_IS_SPACE( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    if ( AFM_IS_NEWLINE( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
      stream->status = AFM_STREAM_STATUS_EOL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    else if ( AFM_IS_SEP( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
      stream->status = AFM_STREAM_STATUS_EOC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    else if ( AFM_IS_EOF( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
      stream->status = AFM_STREAM_STATUS_EOF;
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
    return ch;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  /* read a key or value in current column */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  static char*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  afm_stream_read_one( AFM_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    char*  str;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    int    ch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    afm_stream_skip_spaces( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    if ( AFM_STATUS_EOC( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    str = AFM_STREAM_KEY_BEGIN( stream );
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
    while ( 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
      ch = AFM_GETC();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      if ( AFM_IS_SPACE( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      else if ( AFM_IS_NEWLINE( ch ) )
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
        stream->status = AFM_STREAM_STATUS_EOL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
        break;
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
      else if ( AFM_IS_SEP( ch ) )
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
        stream->status = AFM_STREAM_STATUS_EOC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
        break;
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
      else if ( AFM_IS_EOF( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
        stream->status = AFM_STREAM_STATUS_EOF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    return str;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  /* read a string (i.e., read to EOL) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  static char*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  afm_stream_read_string( AFM_Stream  stream )
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
    char*  str;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    int    ch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    afm_stream_skip_spaces( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    if ( AFM_STATUS_EOL( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
    str = AFM_STREAM_KEY_BEGIN( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    /* scan to eol */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    while ( 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      ch = AFM_GETC();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      if ( AFM_IS_NEWLINE( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
        stream->status = AFM_STREAM_STATUS_EOL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
      else if ( AFM_IS_EOF( ch ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
        stream->status = AFM_STREAM_STATUS_EOF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    return str;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
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
  /*    AFM_Parser                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
  /* all keys defined in Ch. 7-10 of 5004.AFM_Spec.pdf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
  typedef enum  AFM_Token_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    AFM_TOKEN_ASCENDER,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    AFM_TOKEN_AXISLABEL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    AFM_TOKEN_AXISTYPE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    AFM_TOKEN_B,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    AFM_TOKEN_BLENDAXISTYPES,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    AFM_TOKEN_BLENDDESIGNMAP,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    AFM_TOKEN_BLENDDESIGNPOSITIONS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    AFM_TOKEN_C,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    AFM_TOKEN_CC,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    AFM_TOKEN_CH,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    AFM_TOKEN_CAPHEIGHT,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    AFM_TOKEN_CHARWIDTH,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
    AFM_TOKEN_CHARACTERSET,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    AFM_TOKEN_CHARACTERS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    AFM_TOKEN_DESCENDER,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    AFM_TOKEN_ENCODINGSCHEME,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    AFM_TOKEN_ENDAXIS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    AFM_TOKEN_ENDCHARMETRICS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    AFM_TOKEN_ENDCOMPOSITES,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    AFM_TOKEN_ENDDIRECTION,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    AFM_TOKEN_ENDFONTMETRICS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    AFM_TOKEN_ENDKERNDATA,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    AFM_TOKEN_ENDKERNPAIRS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    AFM_TOKEN_ENDTRACKKERN,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
    AFM_TOKEN_ESCCHAR,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    AFM_TOKEN_FAMILYNAME,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
    AFM_TOKEN_FONTBBOX,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
    AFM_TOKEN_FONTNAME,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    AFM_TOKEN_FULLNAME,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    AFM_TOKEN_ISBASEFONT,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    AFM_TOKEN_ISCIDFONT,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    AFM_TOKEN_ISFIXEDPITCH,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    AFM_TOKEN_ISFIXEDV,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    AFM_TOKEN_ITALICANGLE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    AFM_TOKEN_KP,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    AFM_TOKEN_KPH,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    AFM_TOKEN_KPX,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    AFM_TOKEN_KPY,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    AFM_TOKEN_L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    AFM_TOKEN_MAPPINGSCHEME,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    AFM_TOKEN_METRICSSETS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    AFM_TOKEN_N,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    AFM_TOKEN_NOTICE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
    AFM_TOKEN_PCC,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    AFM_TOKEN_STARTAXIS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    AFM_TOKEN_STARTCHARMETRICS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
    AFM_TOKEN_STARTCOMPOSITES,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    AFM_TOKEN_STARTDIRECTION,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    AFM_TOKEN_STARTFONTMETRICS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    AFM_TOKEN_STARTKERNDATA,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    AFM_TOKEN_STARTKERNPAIRS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    AFM_TOKEN_STARTKERNPAIRS0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    AFM_TOKEN_STARTKERNPAIRS1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    AFM_TOKEN_STARTTRACKKERN,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    AFM_TOKEN_STDHW,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    AFM_TOKEN_STDVW,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    AFM_TOKEN_TRACKKERN,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
    AFM_TOKEN_UNDERLINEPOSITION,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    AFM_TOKEN_UNDERLINETHICKNESS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    AFM_TOKEN_VV,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    AFM_TOKEN_VVECTOR,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    AFM_TOKEN_VERSION,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    AFM_TOKEN_W,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    AFM_TOKEN_W0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    AFM_TOKEN_W0X,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    AFM_TOKEN_W0Y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    AFM_TOKEN_W1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    AFM_TOKEN_W1X,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    AFM_TOKEN_W1Y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    AFM_TOKEN_WX,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    AFM_TOKEN_WY,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
    AFM_TOKEN_WEIGHT,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    AFM_TOKEN_WEIGHTVECTOR,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    AFM_TOKEN_XHEIGHT,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    N_AFM_TOKENS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    AFM_TOKEN_UNKNOWN
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
  } AFM_Token;
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
  static const char*  const afm_key_table[N_AFM_TOKENS] =
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
    "Ascender",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    "AxisLabel",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    "AxisType",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    "B",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    "BlendAxisTypes",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    "BlendDesignMap",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    "BlendDesignPositions",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    "C",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    "CC",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    "CH",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    "CapHeight",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    "CharWidth",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    "CharacterSet",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
    "Characters",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    "Descender",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    "EncodingScheme",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    "EndAxis",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    "EndCharMetrics",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    "EndComposites",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
    "EndDirection",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    "EndFontMetrics",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
    "EndKernData",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    "EndKernPairs",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
    "EndTrackKern",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
    "EscChar",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    "FamilyName",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
    "FontBBox",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
    "FontName",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    "FullName",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    "IsBaseFont",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    "IsCIDFont",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    "IsFixedPitch",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    "IsFixedV",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    "ItalicAngle",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    "KP",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    "KPH",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    "KPX",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    "KPY",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    "L",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    "MappingScheme",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    "MetricsSets",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    "N",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    "Notice",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    "PCC",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    "StartAxis",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    "StartCharMetrics",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    "StartComposites",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
    "StartDirection",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    "StartFontMetrics",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    "StartKernData",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    "StartKernPairs",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    "StartKernPairs0",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    "StartKernPairs1",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    "StartTrackKern",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    "StdHW",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    "StdVW",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
    "TrackKern",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
    "UnderlinePosition",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
    "UnderlineThickness",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    "VV",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    "VVector",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    "Version",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
    "W",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    "W0",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    "W0X",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    "W0Y",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    "W1",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    "W1X",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    "W1Y",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    "WX",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    "WY",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    "Weight",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
    "WeightVector",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
    "XHeight"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
   * `afm_parser_read_vals' and `afm_parser_next_key' provide
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
   * high-level operations to an AFM_Stream.  The rest of the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
   * parser functions should use them without accessing the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
   * AFM_Stream directly.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
  afm_parser_read_vals( AFM_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
                        AFM_Value   vals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
                        FT_UInt     n )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    AFM_Stream  stream = parser->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    char*       str;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    FT_UInt     i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
    if ( n > AFM_MAX_ARGUMENTS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    for ( i = 0; i < n; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      FT_Offset  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
      AFM_Value  val = vals + i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      if ( val->type == AFM_VALUE_TYPE_STRING )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        str = afm_stream_read_string( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
        str = afm_stream_read_one( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      if ( !str )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
        break;
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
      len = AFM_STREAM_KEY_LEN( stream, str );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      switch ( val->type )
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
      case AFM_VALUE_TYPE_STRING:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      case AFM_VALUE_TYPE_NAME:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
          FT_Memory  memory = parser->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
          FT_Error   error;
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
          if ( !FT_QALLOC( val->u.s, len + 1 ) )
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
            ft_memcpy( val->u.s, str, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
            val->u.s[len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
        break;
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
      case AFM_VALUE_TYPE_FIXED:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
        val->u.f = PS_Conv_ToFixed( (FT_Byte**)(void*)&str,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
                                    (FT_Byte*)str + len, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      case AFM_VALUE_TYPE_INTEGER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
        val->u.i = PS_Conv_ToInt( (FT_Byte**)(void*)&str,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
                                  (FT_Byte*)str + len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
        break;
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
      case AFM_VALUE_TYPE_BOOL:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
        val->u.b = FT_BOOL( len == 4                      &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
                            !ft_strncmp( str, "true", 4 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      case AFM_VALUE_TYPE_INDEX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
        if ( parser->get_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
          val->u.i = parser->get_index( str, len, parser->user_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
          val->u.i = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    return i;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
  FT_LOCAL_DEF( char* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
  afm_parser_next_key( AFM_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
                       FT_Bool     line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
                       FT_Offset*  len )
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
    AFM_Stream  stream = parser->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    char*       key    = 0;  /* make stupid compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
    if ( line )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      while ( 1 )
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
        /* skip current line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
        if ( !AFM_STATUS_EOL( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
          afm_stream_read_string( stream );
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
        stream->status = AFM_STREAM_STATUS_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        key = afm_stream_read_one( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
        /* skip empty line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
        if ( !key                      &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
             !AFM_STATUS_EOF( stream ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
             AFM_STATUS_EOL( stream )  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
          continue;
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
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
      while ( 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
        /* skip current column */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
        while ( !AFM_STATUS_EOC( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
          afm_stream_read_one( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
        stream->status = AFM_STREAM_STATUS_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
        key = afm_stream_read_one( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
        /* skip empty column */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        if ( !key                      &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
             !AFM_STATUS_EOF( stream ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
             AFM_STATUS_EOC( stream )  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    if ( len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      *len = ( key ) ? (FT_Offset)AFM_STREAM_KEY_LEN( stream, key )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
                     : 0;
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
    return key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
  static AFM_Token
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
  afm_tokenize( const char*  key,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
                FT_Offset    len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    int  n;
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
    for ( n = 0; n < N_AFM_TOKENS; n++ )
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
      if ( *( afm_key_table[n] ) == *key )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
        for ( ; n < N_AFM_TOKENS; n++ )
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
          if ( *( afm_key_table[n] ) != *key )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
            return AFM_TOKEN_UNKNOWN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
          if ( ft_strncmp( afm_key_table[n], key, len ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
            return (AFM_Token) n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    }
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
    return AFM_TOKEN_UNKNOWN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
  afm_parser_init( AFM_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
                   FT_Memory   memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
                   FT_Byte*    base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
                   FT_Byte*    limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    AFM_Stream  stream = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    if ( FT_NEW( stream ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    stream->cursor = stream->base = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    stream->limit  = limit;
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
    /* don't skip the first line during the first call */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    stream->status = AFM_STREAM_STATUS_EOL;
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
    parser->memory    = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    parser->stream    = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    parser->FontInfo  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    parser->get_index = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
    return PSaux_Err_Ok;
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
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
  FT_LOCAL( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
  afm_parser_done( AFM_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    FT_Memory  memory = parser->memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    FT_FREE( parser->stream );
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
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
  afm_parser_read_int( AFM_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
                       FT_Int*     aint )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
    AFM_ValueRec  val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    val.type = AFM_VALUE_TYPE_INTEGER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    if ( afm_parser_read_vals( parser, &val, 1 ) == 1 )
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
      *aint = val.u.i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
      return PSaux_Err_Ok;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      return PSaux_Err_Syntax_Error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
  afm_parse_track_kern( AFM_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    AFM_FontInfo   fi = parser->FontInfo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    AFM_TrackKern  tk;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    char*          key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
    FT_Offset      len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    int            n = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    if ( afm_parser_read_int( parser, &fi->NumTrackKern ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    if ( fi->NumTrackKern )
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
      FT_Memory  memory = parser->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
      FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      if ( FT_QNEW_ARRAY( fi->TrackKerns, fi->NumTrackKern ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
    while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
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
      AFM_ValueRec  shared_vals[5];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
      switch ( afm_tokenize( key, len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
      case AFM_TOKEN_TRACKKERN:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
        n++;
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
        if ( n >= fi->NumTrackKern )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
          goto Fail;
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
        tk = fi->TrackKerns + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
        shared_vals[0].type = AFM_VALUE_TYPE_INTEGER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
        shared_vals[1].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        shared_vals[2].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
        shared_vals[3].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        shared_vals[4].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        if ( afm_parser_read_vals( parser, shared_vals, 5 ) != 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
        tk->degree     = shared_vals[0].u.i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
        tk->min_ptsize = shared_vals[1].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
        tk->min_kern   = shared_vals[2].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
        tk->max_ptsize = shared_vals[3].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
        tk->max_kern   = shared_vals[4].u.f;
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
        /* is this correct? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
        if ( tk->degree < 0 && tk->min_kern > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
          tk->min_kern = -tk->min_kern;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
      case AFM_TOKEN_ENDTRACKKERN:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      case AFM_TOKEN_ENDKERNDATA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      case AFM_TOKEN_ENDFONTMETRICS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
        fi->NumTrackKern = n + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
        return PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
      case AFM_TOKEN_UNKNOWN:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        goto Fail;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
    return PSaux_Err_Syntax_Error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
#undef  KERN_INDEX
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
#define KERN_INDEX( g1, g2 )  ( ( (FT_ULong)g1 << 16 ) | g2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
  /* compare two kerning pairs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
  FT_CALLBACK_DEF( int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  afm_compare_kern_pairs( const void*  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
                          const void*  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
    AFM_KernPair  kp1 = (AFM_KernPair)a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
    AFM_KernPair  kp2 = (AFM_KernPair)b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    FT_ULong  index1 = KERN_INDEX( kp1->index1, kp1->index2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    FT_ULong  index2 = KERN_INDEX( kp2->index1, kp2->index2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    if ( index1 > index2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
      return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    else if ( index1 < index2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
  afm_parse_kern_pairs( AFM_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
    AFM_FontInfo  fi = parser->FontInfo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    AFM_KernPair  kp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    char*         key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
    FT_Offset     len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
    int           n = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
    if ( afm_parser_read_int( parser, &fi->NumKernPair ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
      goto Fail;
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
    if ( fi->NumKernPair )
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
      FT_Memory  memory = parser->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
      FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
      if ( FT_QNEW_ARRAY( fi->KernPairs, fi->NumKernPair ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
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
      AFM_Token  token = afm_tokenize( key, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      switch ( token )
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
      case AFM_TOKEN_KP:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
      case AFM_TOKEN_KPX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
      case AFM_TOKEN_KPY:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
          FT_Int        r;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
          AFM_ValueRec  shared_vals[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
          n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
          if ( n >= fi->NumKernPair )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
            goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
          kp = fi->KernPairs + n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
          shared_vals[0].type = AFM_VALUE_TYPE_INDEX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
          shared_vals[1].type = AFM_VALUE_TYPE_INDEX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
          shared_vals[2].type = AFM_VALUE_TYPE_INTEGER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
          shared_vals[3].type = AFM_VALUE_TYPE_INTEGER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
          r = afm_parser_read_vals( parser, shared_vals, 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
          if ( r < 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
            goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
          kp->index1 = shared_vals[0].u.i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
          kp->index2 = shared_vals[1].u.i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
          if ( token == AFM_TOKEN_KPY )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
            kp->x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
            kp->y = shared_vals[2].u.i;
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
            kp->x = shared_vals[2].u.i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
            kp->y = ( token == AFM_TOKEN_KP && r == 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
                      ? shared_vals[3].u.i : 0;
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
        break;
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
      case AFM_TOKEN_ENDKERNPAIRS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      case AFM_TOKEN_ENDKERNDATA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
      case AFM_TOKEN_ENDFONTMETRICS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
        fi->NumKernPair = n + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
        ft_qsort( fi->KernPairs, fi->NumKernPair,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
                  sizeof( AFM_KernPairRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
                  afm_compare_kern_pairs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
        return PSaux_Err_Ok;
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
      case AFM_TOKEN_UNKNOWN:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
        break;
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
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
        goto Fail;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
    return PSaux_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
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_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
  afm_parse_kern_data( AFM_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
    char*      key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
    FT_Offset  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
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
      switch ( afm_tokenize( key, len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
      case AFM_TOKEN_STARTTRACKKERN:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
        error = afm_parse_track_kern( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
          return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
      case AFM_TOKEN_STARTKERNPAIRS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
      case AFM_TOKEN_STARTKERNPAIRS0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
        error = afm_parse_kern_pairs( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
          return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
      case AFM_TOKEN_ENDKERNDATA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
      case AFM_TOKEN_ENDFONTMETRICS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
        return PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
      case AFM_TOKEN_UNKNOWN:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    return PSaux_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
  afm_parser_skip_section( AFM_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
                           FT_UInt     n,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
                           AFM_Token   end_section )
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
    char*      key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
    FT_Offset  len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
    while ( n-- > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
      key = afm_parser_next_key( parser, 1, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
      if ( !key )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
        goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
    while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
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
      AFM_Token  token = afm_tokenize( key, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
      if ( token == end_section || token == AFM_TOKEN_ENDFONTMETRICS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
        return PSaux_Err_Ok;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
    return PSaux_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
  }
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
  afm_parser_parse( AFM_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    FT_Memory     memory = parser->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    AFM_FontInfo  fi     = parser->FontInfo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
    FT_Error      error  = PSaux_Err_Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
    char*         key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
    FT_Offset     len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
    FT_Int        metrics_sets = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    if ( !fi )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
      return PSaux_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    key = afm_parser_next_key( parser, 1, &len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
    if ( !key || len != 16                              ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
         ft_strncmp( key, "StartFontMetrics", 16 ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
      return PSaux_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
    while ( ( key = afm_parser_next_key( parser, 1, &len ) ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
      AFM_ValueRec  shared_vals[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
      switch ( afm_tokenize( key, len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      case AFM_TOKEN_METRICSSETS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
        if ( afm_parser_read_int( parser, &metrics_sets ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
          goto Fail;
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 ( metrics_sets != 0 && metrics_sets != 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
          error = PSaux_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
          goto Fail;
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
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      case AFM_TOKEN_ISCIDFONT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
        shared_vals[0].type = AFM_VALUE_TYPE_BOOL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
        if ( afm_parser_read_vals( parser, shared_vals, 1 ) != 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
        fi->IsCIDFont = shared_vals[0].u.b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
      case AFM_TOKEN_FONTBBOX:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
        shared_vals[0].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
        shared_vals[1].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
        shared_vals[2].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
        shared_vals[3].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
        if ( afm_parser_read_vals( parser, shared_vals, 4 ) != 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
        fi->FontBBox.xMin = shared_vals[0].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
        fi->FontBBox.yMin = shared_vals[1].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
        fi->FontBBox.xMax = shared_vals[2].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
        fi->FontBBox.yMax = shared_vals[3].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
      case AFM_TOKEN_ASCENDER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
        shared_vals[0].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
        if ( afm_parser_read_vals( parser, shared_vals, 1 ) != 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
        fi->Ascender = shared_vals[0].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
      case AFM_TOKEN_DESCENDER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
        shared_vals[0].type = AFM_VALUE_TYPE_FIXED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
        if ( afm_parser_read_vals( parser, shared_vals, 1 ) != 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
          goto Fail;
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
        fi->Descender = shared_vals[0].u.f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
      case AFM_TOKEN_STARTCHARMETRICS:
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
          FT_Int  n = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
          if ( afm_parser_read_int( parser, &n ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
            goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
          error = afm_parser_skip_section( parser, n,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
                                           AFM_TOKEN_ENDCHARMETRICS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
            return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
      case AFM_TOKEN_STARTKERNDATA:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
        error = afm_parse_kern_data( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
        /* fall through since we only support kern data */
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
      case AFM_TOKEN_ENDFONTMETRICS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
        return PSaux_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    FT_FREE( fi->TrackKerns );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
    fi->NumTrackKern = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
    FT_FREE( fi->KernPairs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    fi->NumKernPair = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
    fi->IsCIDFont = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
/* END */