misc/libfreetype/src/type1/t1parse.c
author belphegorr <szabibibi@gmail.com>
Mon, 23 Jul 2012 19:15:59 +0300
changeset 7263 644eabbc9218
parent 5172 88f2e05288ba
permissions -rw-r--r--
Added a new function: AddNewEvent, which only adds an event to the list if it doesn't already exist. Kept the old one as it might me useful to be able to add an event more than once.
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
/*  t1parse.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    Type 1 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 1996-2001, 2002, 2003, 2004, 2005, 2008, 2009 by             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* The Type 1 parser is in charge of the following:                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
  /*  - provide an implementation of a growing sequence of objects called  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /*    a `T1_Table' (used to build various tables needed by the loader).  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  /*  - opening .pfb and .pfa files to extract their top-level and private */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /*    dictionaries.                                                      */
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
  /*  - read numbers, arrays & strings from any dictionary.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* See `t1load.c' to see how data is loaded from the font file.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*                                                                       */
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#include FT_INTERNAL_POSTSCRIPT_AUX_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#include "t1parse.h"
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
#include "t1errors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
#define FT_COMPONENT  trace_t1parse
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  /*****                   INPUT STREAM PARSER                         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /* see Adobe Technical Note 5040.Download_Fonts.pdf */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  read_pfb_tag( FT_Stream   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                FT_UShort  *atag,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
                FT_ULong   *asize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    FT_UShort  tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    FT_ULong   size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    *atag  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    *asize = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    if ( !FT_READ_USHORT( tag ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      if ( tag == 0x8001U || tag == 0x8002U )
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
        if ( !FT_READ_ULONG_LE( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
          *asize = size;
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
      *atag = tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  check_type1_format( FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
                      const char*  header_string,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
                      size_t       header_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_UShort  tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    FT_ULong   dummy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    if ( FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    error = read_pfb_tag( stream, &tag, &dummy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    /* We assume that the first segment in a PFB is always encoded as   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    /* text.  This might be wrong (and the specification doesn't insist */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    /* on that), but we have never seen a counterexample.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    if ( tag != 0x8001U && FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    if ( !FT_FRAME_ENTER( header_length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      error = T1_Err_Ok;
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
      if ( ft_memcmp( stream->cursor, header_string, header_length ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
        error = T1_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      FT_FRAME_EXIT();
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
  T1_New_Parser( T1_Parser      parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
                 FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
                 FT_Memory      memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
                 PSAux_Service  psaux )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    FT_UShort  tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    FT_ULong   size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    parser->stream       = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    parser->base_len     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    parser->base_dict    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    parser->private_len  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    parser->private_dict = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    parser->in_pfb       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    parser->in_memory    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    parser->single_block = 0;
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
    /* check the header format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    error = check_type1_format( stream, "%!PS-AdobeFont", 14 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      if ( error != T1_Err_Unknown_File_Format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
        goto Exit;
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
      error = check_type1_format( stream, "%!FontType", 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
        FT_TRACE2(( "[not a Type1 font]\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    /******************************************************************/
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
    /* Here a short summary of what is going on:                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    /*   When creating a new Type 1 parser, we try to locate and load */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    /*   the base dictionary if this is possible (i.e., for PFB       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    /*   files).  Otherwise, we load the whole font into memory.      */
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
    /*   When `loading' the base dictionary, we only setup pointers   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    /*   in the case of a memory-based stream.  Otherwise, we         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    /*   allocate and load the base dictionary in it.                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    /*   parser->in_pfb is set if we are in a binary (`.pfb') font.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    /*   parser->in_memory is set if we have a memory stream.         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    /*                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    /* try to compute the size of the base dictionary;     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    /* look for a Postscript binary file tag, i.e., 0x8001 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    if ( FT_STREAM_SEEK( 0L ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    error = read_pfb_tag( stream, &tag, &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      goto Exit;
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
    if ( tag != 0x8001U )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      /* assume that this is a PFA file for now; an error will */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      /* be produced later when more things are checked        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      if ( FT_STREAM_SEEK( 0L ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      size = stream->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      parser->in_pfb = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    /* now, try to load `size' bytes of the `base' dictionary we */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    /* found previously                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    /* if it is a memory-based resource, set up pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
    if ( !stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      parser->base_dict = (FT_Byte*)stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      parser->base_len  = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      parser->in_memory = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      /* check that the `size' field is valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      if ( FT_STREAM_SKIP( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      /* read segment in memory -- this is clumsy, but so does the format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      if ( FT_ALLOC( parser->base_dict, size )       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
           FT_STREAM_READ( parser->base_dict, size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
      parser->base_len = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    parser->root.base   = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    parser->root.cursor = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    parser->root.limit  = parser->root.cursor + parser->base_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
    if ( error && !parser->in_memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      FT_FREE( parser->base_dict );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  T1_Finalize_Parser( T1_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
    FT_Memory  memory = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    /* always free the private dictionary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    FT_FREE( parser->private_dict );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    /* free the base dictionary only when we have a disk stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    if ( !parser->in_memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      FT_FREE( parser->base_dict );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    parser->root.funcs.done( &parser->root );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
  T1_Get_Private_Dict( T1_Parser      parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
                       PSAux_Service  psaux )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    FT_Stream  stream = parser->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    FT_Memory  memory = parser->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    FT_Error   error  = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    FT_ULong   size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    if ( parser->in_pfb )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      /* in the case of the PFB format, the private dictionary can be  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      /* made of several segments.  We thus first read the number of   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      /* segments to compute the total size of the private dictionary  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      /* then re-read them into memory.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
      FT_Long    start_pos = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
      FT_UShort  tag;
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
      parser->private_len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
      for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
        error = read_pfb_tag( stream, &tag, &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
        if ( tag != 0x8002U )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
        parser->private_len += size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
        if ( FT_STREAM_SKIP( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
      /* Check that we have a private dictionary there */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
      /* and allocate private dictionary buffer        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      if ( parser->private_len == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
        FT_ERROR(( "T1_Get_Private_Dict:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
                   " invalid private dictionary section\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
        error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      if ( FT_STREAM_SEEK( start_pos )                           ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
           FT_ALLOC( parser->private_dict, parser->private_len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      parser->private_len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
        error = read_pfb_tag( stream, &tag, &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
        if ( error || tag != 0x8002U )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
          error = T1_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
        if ( FT_STREAM_READ( parser->private_dict + parser->private_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
                             size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
        parser->private_len += size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
      /* We have already `loaded' the whole PFA font file into memory; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
      /* if this is a memory resource, allocate a new block to hold    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      /* the private dict.  Otherwise, simply overwrite into the base  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
      /* dictionary block in the heap.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      /* first of all, look at the `eexec' keyword */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      FT_Byte*  cur   = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
      FT_Byte*  limit = cur + parser->base_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
      FT_Byte   c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
    Again:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
        c = cur[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
        if ( c == 'e' && cur + 9 < limit )  /* 9 = 5 letters for `eexec' + */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
                                            /* newline + 4 chars           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
          if ( cur[1] == 'e' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
               cur[2] == 'x' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
               cur[3] == 'e' &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
               cur[4] == 'c' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
        cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
        if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
          FT_ERROR(( "T1_Get_Private_Dict:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
                     " could not find `eexec' keyword\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
          error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
      /* check whether `eexec' was real -- it could be in a comment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      /* or string (as e.g. in u003043t.gsf from ghostscript)       */
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
      parser->root.cursor = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      parser->root.limit  = cur + 9;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      cur   = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
      limit = parser->root.limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      while ( cur < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
        if ( *cur == 'e' && ft_strncmp( (char*)cur, "eexec", 5 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
          goto Found;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
        T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
        if ( parser->root.error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
        T1_Skip_Spaces  ( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
        cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      /* we haven't found the correct `eexec'; go back and continue */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      /* searching                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      cur   = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
      limit = parser->base_dict + parser->base_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      goto Again;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
      /* now determine where to write the _encrypted_ binary private  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
      /* dictionary.  We overwrite the base dictionary for disk-based */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      /* resources and allocate a new block otherwise                 */
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
    Found:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      parser->root.limit = parser->base_dict + parser->base_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      T1_Skip_PS_Token( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      cur = parser->root.cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      /* according to the Type1 spec, the first cipher byte must not be  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
      /* an ASCII whitespace character code (blank, tab, carriage return */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      /* or line feed).  We have seen Type 1 fonts with two line feed    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      /* characters...  So skip now all whitespace character codes.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      while ( cur < limit       &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
              ( *cur == ' '  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
                *cur == '\t' || 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
                *cur == '\r' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
                *cur == '\n' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
        ++cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      if ( cur >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
        FT_ERROR(( "T1_Get_Private_Dict:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
                   " `eexec' not properly terminated\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
        error = T1_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      size = parser->base_len - ( cur - parser->base_dict );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      if ( parser->in_memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
        /* note that we allocate one more byte to put a terminating `0' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
        if ( FT_ALLOC( parser->private_dict, size + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
        parser->private_len = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
        parser->single_block = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        parser->private_dict = parser->base_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        parser->private_len  = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        parser->base_dict    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
        parser->base_len     = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      /* now determine whether the private dictionary is encoded in binary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      /* or hexadecimal ASCII format -- decode it accordingly              */
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
      /* we need to access the next 4 bytes (after the final \r following */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      /* the `eexec' keyword); if they all are hexadecimal digits, then   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      /* we have a case of ASCII storage                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
      if ( ft_isxdigit( cur[0] ) && ft_isxdigit( cur[1] ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
           ft_isxdigit( cur[2] ) && ft_isxdigit( cur[3] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
        /* ASCII hexadecimal encoding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
        FT_Long  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
        parser->root.cursor = cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
        (void)psaux->ps_parser_funcs->to_bytes( &parser->root,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
                                                parser->private_dict,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
                                                parser->private_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
                                                &len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
                                                0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
        parser->private_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
        /* put a safeguard */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
        parser->private_dict[len] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
        /* binary encoding -- copy the private dict */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
        FT_MEM_MOVE( parser->private_dict, cur, size );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    /* we now decrypt the encoded binary private dictionary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    psaux->t1_decrypt( parser->private_dict, parser->private_len, 55665U );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    /* replace the four random bytes at the beginning with whitespace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    parser->private_dict[0] = ' ';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
    parser->private_dict[1] = ' ';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    parser->private_dict[2] = ' ';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    parser->private_dict[3] = ' ';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
    parser->root.base   = parser->private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    parser->root.cursor = parser->private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    parser->root.limit  = parser->root.cursor + parser->private_len;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
/* END */