misc/libfreetype/src/sfnt/ttload.c
author nemo
Thu, 08 Sep 2011 13:03:58 -0400
changeset 5813 d5e9c22c59a2
parent 5172 88f2e05288ba
permissions -rw-r--r--
oops
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
/*  ttload.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
/*    Load the basic TrueType tables, i.e., tables that can be either in   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*    TTF or OTF fonts (body).                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*            2010 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  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
    16
/*  understand and accept it fully.                                        */
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "ttload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "sferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#define FT_COMPONENT  trace_ttload
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*    tt_face_lookup_table                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*    Looks for a TrueType table by name.                                */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*    face :: A face object handle.                                      */
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
  /*    tag  :: The searched tag.                                          */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /*    A pointer to the table directory entry.  0 if not found.           */
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
  FT_LOCAL_DEF( TT_Table  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  tt_face_lookup_table( TT_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
                        FT_ULong  tag  )
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
    TT_Table  entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    TT_Table  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    FT_Bool   zero_length = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
#endif
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
    FT_TRACE4(( "tt_face_lookup_table: %08p, `%c%c%c%c' -- ",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
                face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
                (FT_Char)( tag >> 24 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
                (FT_Char)( tag >> 16 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                (FT_Char)( tag >> 8  ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
                (FT_Char)( tag       ) ));
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
    entry = face->dir_tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    limit = entry + face->num_tables;
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
    for ( ; entry < limit; entry++ )
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
      /* For compatibility with Windows, we consider    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
      /* zero-length tables the same as missing tables. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      if ( entry->Tag == tag )
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
        if ( entry->Length != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
          FT_TRACE4(( "found table.\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
          return entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
        zero_length = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    if ( zero_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      FT_TRACE4(( "ignoring empty table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      FT_TRACE4(( "could not find table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
#endif
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
    return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  /*    tt_face_goto_table                                                 */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  /*    Looks for a TrueType table by name, then seek a stream to it.      */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  /*    face   :: A face object handle.                                    */
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
  /*    tag    :: The searched tag.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  /*    stream :: The stream to seek when the table is found.              */
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
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  /*    length :: The length of the table if found, undefined otherwise.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  tt_face_goto_table( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
                      FT_ULong   tag,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
                      FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
                      FT_ULong*  length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    TT_Table  table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    FT_Error  error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    table = tt_face_lookup_table( face, tag );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    if ( table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      if ( length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
        *length = table->Length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      if ( FT_STREAM_SEEK( table->Offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
        goto Exit;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      error = SFNT_Err_Table_Missing;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    return error;
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
  /* Here, we                                                         */
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
  /* - check that `num_tables' is valid (and adjust it if necessary)  */
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
  /* - look for a `head' table, check its size, and parse it to check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  /*   whether its `magic' field is correctly set                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  /*                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  /* - errors (except errors returned by stream handling)             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
  /*                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  /*     SFNT_Err_Unknown_File_Format:                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  /*       no table is defined in directory, it is not sfnt-wrapped   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
  /*       data                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  /*     SFNT_Err_Table_Missing:                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  /*       table directory is valid, but essential tables             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  /*       (head/bhed/SING) are missing                               */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
  check_table_dir( SFNT_Header  sfnt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
                   FT_Stream    stream )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    FT_UShort  nn, valid_entries = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    FT_UInt    has_head = 0, has_sing = 0, has_meta = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    FT_ULong   offset = sfnt->offset + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    static const FT_Frame_Field  table_dir_entry_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
#define FT_STRUCTURE  TT_TableRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
      FT_FRAME_START( 16 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        FT_FRAME_ULONG( Tag ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
        FT_FRAME_ULONG( CheckSum ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
        FT_FRAME_ULONG( Offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
        FT_FRAME_ULONG( Length ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
      FT_FRAME_END
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
    if ( FT_STREAM_SEEK( offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      goto Exit;
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
    for ( nn = 0; nn < sfnt->num_tables; nn++ )
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
      TT_TableRec  table;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields, &table ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        nn--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
        FT_TRACE2(( "check_table_dir:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
                    " can read only %d table%s in font (instead of %d)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
                    nn, nn == 1 ? "" : "s", sfnt->num_tables ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
        sfnt->num_tables = nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      /* we ignore invalid tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      if ( table.Offset + table.Length > stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
        FT_TRACE2(( "check_table_dir: table entry %d invalid\n", nn ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
        valid_entries++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      if ( table.Tag == TTAG_head || table.Tag == TTAG_bhed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        FT_UInt32  magic;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
#ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
        if ( table.Tag == TTAG_head )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
          has_head = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
        /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
         * The table length should be 0x36, but certain font tools make it
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
         * 0x38, so we will just check that it is greater.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
         *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
         * Note that according to the specification, the table must be
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
         * padded to 32-bit lengths, but this doesn't apply to the value of
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
         * its `Length' field!
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
         *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        if ( table.Length < 0x36 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
          FT_TRACE2(( "check_table_dir: `head' table too small\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
          error = SFNT_Err_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
        if ( FT_STREAM_SEEK( table.Offset + 12 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
             FT_READ_ULONG( magic )              )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
          goto Exit;
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
        if ( magic != 0x5F0F3CF5UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
          FT_TRACE2(( "check_table_dir:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
                      " no magic number found in `head' table\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
          error = SFNT_Err_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
          goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        if ( FT_STREAM_SEEK( offset + ( nn + 1 ) * 16 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
          goto Exit;
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
      else if ( table.Tag == TTAG_SING )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
        has_sing = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      else if ( table.Tag == TTAG_META )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
        has_meta = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    sfnt->num_tables = valid_entries;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    if ( sfnt->num_tables == 0 )
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
      FT_TRACE2(( "check_table_dir: no tables found\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      error = SFNT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    /* if `sing' and `meta' tables are present, there is no `head' table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    if ( has_head || ( has_sing && has_meta ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    else
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
      FT_TRACE2(( "check_table_dir:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      FT_TRACE2(( " neither `head', `bhed', nor `sing' table found\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
      FT_TRACE2(( " neither `head' nor `sing' table found\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
      error = SFNT_Err_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
  /*    tt_face_load_font_dir                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
  /*    Loads the header of a SFNT font file.                              */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
  /*    face       :: A handle to the target face object.                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
  /*    stream     :: The input stream.                                    */
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
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  /*    sfnt       :: The SFNT header.                                     */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
  /*    FreeType error code.  0 means success.                             */
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
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
  /*    The stream cursor must be at the beginning of the font directory.  */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  tt_face_load_font_dir( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
                         FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    SFNT_HeaderRec  sfnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    FT_Memory       memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    TT_TableRec*    entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    FT_Int          nn;
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
    static const FT_Frame_Field  offset_table_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
#define FT_STRUCTURE  SFNT_HeaderRec
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
      FT_FRAME_START( 8 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
        FT_FRAME_USHORT( num_tables ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
        FT_FRAME_USHORT( search_range ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
        FT_FRAME_USHORT( entry_selector ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
        FT_FRAME_USHORT( range_shift ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    /* read the offset table */
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
    sfnt.offset = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    if ( FT_READ_ULONG( sfnt.format_tag )                    ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
         FT_STREAM_READ_FIELDS( offset_table_fields, &sfnt ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
      goto Exit;
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
    /* many fonts don't have these fields set correctly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
    if ( sfnt.search_range != 1 << ( sfnt.entry_selector + 4 )        ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
         sfnt.search_range + sfnt.range_shift != sfnt.num_tables << 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
      return SFNT_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
#endif
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
    /* load the table directory */
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
    FT_TRACE2(( "-- Number of tables: %10u\n",    sfnt.num_tables ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    FT_TRACE2(( "-- Format version:   0x%08lx\n", sfnt.format_tag ));
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
    /* check first */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    error = check_table_dir( &sfnt, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    if ( error )
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
      FT_TRACE2(( "tt_face_load_font_dir:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
                  " invalid table directory for TrueType\n" ));
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
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
    face->num_tables = sfnt.num_tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
    face->format_tag = sfnt.format_tag;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      goto Exit;
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
    if ( FT_STREAM_SEEK( sfnt.offset + 12 )       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
         FT_FRAME_ENTER( face->num_tables * 16L ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      goto Exit;
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
    entry = face->dir_tables;
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
    FT_TRACE2(( "\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
                "  tag    offset    length   checksum\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
                "  ----------------------------------\n" ));
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
    for ( nn = 0; nn < sfnt.num_tables; nn++ )
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
      entry->Tag      = FT_GET_TAG4();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      entry->CheckSum = FT_GET_ULONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      entry->Offset   = FT_GET_LONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      entry->Length   = FT_GET_LONG();
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
      /* ignore invalid tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      if ( entry->Offset + entry->Length > stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      else
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
        FT_TRACE2(( "  %c%c%c%c  %08lx  %08lx  %08lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
                    (FT_Char)( entry->Tag >> 24 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
                    (FT_Char)( entry->Tag >> 16 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
                    (FT_Char)( entry->Tag >> 8  ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
                    (FT_Char)( entry->Tag       ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
                    entry->Offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
                    entry->Length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
                    entry->CheckSum ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
        entry++;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
    FT_FRAME_EXIT();
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
    FT_TRACE2(( "table directory loaded\n\n" ));
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
  /*    tt_face_load_any                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
  /*    Loads any font table into client memory.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
  /*    face   :: The face object to look for.                             */
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
  /*    tag    :: The tag of table to load.  Use the value 0 if you want   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
  /*              to access the whole font file, else set this parameter   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  /*              to a valid TrueType table tag that you can forge with    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
  /*              the MAKE_TT_TAG macro.                                   */
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
  /*    offset :: The starting offset in the table (or the file if         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
  /*              tag == 0).                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
  /*    length :: The address of the decision variable:                    */
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
  /*                If length == NULL:                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
  /*                  Loads the whole table.  Returns an error if          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
  /*                  `offset' == 0!                                       */
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 *length == 0:                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  /*                  Exits immediately; returning the length of the given */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
  /*                  table or of the font file, depending on the value of */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
  /*                  `tag'.                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
  /*                If *length != 0:                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
  /*                  Loads the next `length' bytes of table or font,      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
  /*                  starting at offset `offset' (in table or font too).  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
  /*    buffer :: The address of target buffer.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
  tt_face_load_any( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
                    FT_ULong   tag,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
                    FT_Long    offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
                    FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
                    FT_ULong*  length )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
    FT_Stream  stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    TT_Table   table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    FT_ULong   size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    if ( tag != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
      /* look for tag in font directory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      table = tt_face_lookup_table( face, tag );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
      if ( !table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
        error = SFNT_Err_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      offset += table->Offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      size    = table->Length;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      /* tag == 0 -- the user wants to access the font file directly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
      size = face->root.stream->size;
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
    if ( length && *length == 0 )
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
      *length = size;
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
      return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    if ( length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
      size = *length;
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
    stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    /* the `if' is syntactic sugar for picky compilers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    if ( FT_STREAM_READ_AT( offset, buffer, size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      goto Exit;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
  /*    tt_face_load_generic_header                                        */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
  /*    Loads the TrueType table `head' or `bhed'.                         */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  /*    face   :: A handle to the target face object.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
  /*    stream :: The input stream.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
  /*    FreeType error code.  0 means success.                             */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
  tt_face_load_generic_header( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
                               FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
                               FT_ULong   tag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    TT_Header*  header;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    static const FT_Frame_Field  header_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
#define FT_STRUCTURE  TT_Header
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
      FT_FRAME_START( 54 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
        FT_FRAME_ULONG ( Table_Version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
        FT_FRAME_ULONG ( Font_Revision ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
        FT_FRAME_LONG  ( CheckSum_Adjust ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
        FT_FRAME_LONG  ( Magic_Number ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
        FT_FRAME_USHORT( Flags ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
        FT_FRAME_USHORT( Units_Per_EM ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
        FT_FRAME_LONG  ( Created[0] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
        FT_FRAME_LONG  ( Created[1] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
        FT_FRAME_LONG  ( Modified[0] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
        FT_FRAME_LONG  ( Modified[1] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
        FT_FRAME_SHORT ( xMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        FT_FRAME_SHORT ( yMin ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
        FT_FRAME_SHORT ( xMax ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
        FT_FRAME_SHORT ( yMax ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
        FT_FRAME_USHORT( Mac_Style ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
        FT_FRAME_USHORT( Lowest_Rec_PPEM ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
        FT_FRAME_SHORT ( Font_Direction ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
        FT_FRAME_SHORT ( Index_To_Loc_Format ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
        FT_FRAME_SHORT ( Glyph_Data_Format ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
    error = face->goto_table( face, tag, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      goto Exit;
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
    header = &face->header;
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
    if ( FT_STREAM_READ_FIELDS( header_fields, header ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    FT_TRACE3(( "Units per EM: %4u\n", header->Units_Per_EM ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    FT_TRACE3(( "IndexToLoc:   %4d\n", header->Index_To_Loc_Format ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
  tt_face_load_head( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
    return tt_face_load_generic_header( face, stream, TTAG_head );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
  tt_face_load_bhed( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    return tt_face_load_generic_header( face, stream, TTAG_bhed );
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
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
  /*    tt_face_load_max_profile                                           */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
  /*    Loads the maximum profile into a face object.                      */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
  /*    face   :: A handle to the target face object.                      */
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
  /*    stream :: The input stream.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
  /*    FreeType error code.  0 means success.                             */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
  tt_face_load_maxp( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
    TT_MaxProfile*  maxProfile = &face->max_profile;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
    const FT_Frame_Field  maxp_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
#define FT_STRUCTURE  TT_MaxProfile
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
      FT_FRAME_START( 6 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
        FT_FRAME_LONG  ( version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
        FT_FRAME_USHORT( numGlyphs ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    const FT_Frame_Field  maxp_fields_extra[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      FT_FRAME_START( 26 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
        FT_FRAME_USHORT( maxPoints ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
        FT_FRAME_USHORT( maxContours ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
        FT_FRAME_USHORT( maxCompositePoints ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
        FT_FRAME_USHORT( maxCompositeContours ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
        FT_FRAME_USHORT( maxZones ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
        FT_FRAME_USHORT( maxTwilightPoints ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
        FT_FRAME_USHORT( maxStorage ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
        FT_FRAME_USHORT( maxFunctionDefs ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        FT_FRAME_USHORT( maxInstructionDefs ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
        FT_FRAME_USHORT( maxStackElements ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        FT_FRAME_USHORT( maxSizeOfInstructions ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
        FT_FRAME_USHORT( maxComponentElements ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
        FT_FRAME_USHORT( maxComponentDepth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
      FT_FRAME_END
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
    error = face->goto_table( face, TTAG_maxp, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
      goto Exit;
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
    if ( FT_STREAM_READ_FIELDS( maxp_fields, maxProfile ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
    maxProfile->maxPoints             = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
    maxProfile->maxContours           = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
    maxProfile->maxCompositePoints    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
    maxProfile->maxCompositeContours  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
    maxProfile->maxZones              = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    maxProfile->maxTwilightPoints     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    maxProfile->maxStorage            = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    maxProfile->maxFunctionDefs       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
    maxProfile->maxInstructionDefs    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    maxProfile->maxStackElements      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    maxProfile->maxSizeOfInstructions = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    maxProfile->maxComponentElements  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
    maxProfile->maxComponentDepth     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    if ( maxProfile->version >= 0x10000L )
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
      if ( FT_STREAM_READ_FIELDS( maxp_fields_extra, maxProfile ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
      /* XXX: an adjustment that is necessary to load certain */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
      /*      broken fonts like `Keystrokes MT' :-(           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
      /*                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
      /*   We allocate 64 function entries by default when    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
      /*   the maxFunctionDefs value is smaller.              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
      if ( maxProfile->maxFunctionDefs < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
        maxProfile->maxFunctionDefs = 64;
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
      /* we add 4 phantom points later */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
      if ( maxProfile->maxTwilightPoints > ( 0xFFFFU - 4 ) )
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
        FT_TRACE0(( "tt_face_load_maxp:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
                    " too much twilight points in `maxp' table;\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
                    "                  "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
                    " some glyphs might be rendered incorrectly\n" ));
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
        maxProfile->maxTwilightPoints = 0xFFFFU - 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      /* we arbitrarily limit recursion to avoid stack exhaustion */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
      if ( maxProfile->maxComponentDepth > 100 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
        FT_TRACE0(( "tt_face_load_maxp:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
                    " abnormally large component depth (%d) set to 100\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
                    maxProfile->maxComponentDepth ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
        maxProfile->maxComponentDepth = 100;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    FT_TRACE3(( "numGlyphs: %u\n", maxProfile->numGlyphs ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
  /*    tt_face_load_names                                                 */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
  /*    Loads the name records.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
  /*    face   :: A handle to the target face object.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
  /*    stream :: The input stream.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
  tt_face_load_name( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    FT_Memory     memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    FT_ULong      table_pos, table_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
    FT_ULong      storage_start, storage_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    FT_UInt       count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
    TT_NameTable  table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
    static const FT_Frame_Field  name_table_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
#define FT_STRUCTURE  TT_NameTableRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      FT_FRAME_START( 6 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
        FT_FRAME_USHORT( format ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
        FT_FRAME_USHORT( numNameRecords ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
        FT_FRAME_USHORT( storageOffset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
    static const FT_Frame_Field  name_record_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
#define FT_STRUCTURE  TT_NameEntryRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
      /* no FT_FRAME_START */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
        FT_FRAME_USHORT( platformID ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
        FT_FRAME_USHORT( encodingID ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
        FT_FRAME_USHORT( languageID ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
        FT_FRAME_USHORT( nameID ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
        FT_FRAME_USHORT( stringLength ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
        FT_FRAME_USHORT( stringOffset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
    table         = &face->name_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
    table->stream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
    error = face->goto_table( face, TTAG_name, stream, &table_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
    table_pos = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
    if ( FT_STREAM_READ_FIELDS( name_table_fields, table ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
    /* Some popular Asian fonts have an invalid `storageOffset' value   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
    /* (it should be at least "6 + 12*num_names").  However, the string */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    /* offsets, computed as "storageOffset + entry->stringOffset", are  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
    /* valid pointers within the name table...                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    /*                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    /* We thus can't check `storageOffset' right now.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
    /*                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
    storage_start = table_pos + 6 + 12*table->numNameRecords;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
    storage_limit = table_pos + table_len;
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
    if ( storage_start > storage_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
      FT_ERROR(( "tt_face_load_name: invalid `name' table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
      error = SFNT_Err_Name_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
    /* Allocate the array of name records. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
    count                 = table->numNameRecords;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    table->numNameRecords = 0;
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
    if ( FT_NEW_ARRAY( table->names, count ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
         FT_FRAME_ENTER( count * 12 )        )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
      goto Exit;
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
    /* Load the name records and determine how much storage is needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
    /* to hold the strings themselves.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
      TT_NameEntryRec*  entry = table->names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
      for ( ; count > 0; count-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
        if ( FT_STREAM_READ_FIELDS( name_record_fields, entry ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
          continue;
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
        /* check that the name is not empty */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
        if ( entry->stringLength == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
        /* check that the name string is within the table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
        entry->stringOffset += table_pos + table->storageOffset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
        if ( entry->stringOffset                       < storage_start ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
             entry->stringOffset + entry->stringLength > storage_limit )
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
          /* invalid entry - ignore it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
          entry->stringOffset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
          entry->stringLength = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
        }
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
        entry++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
      table->numNameRecords = (FT_UInt)( entry - table->names );
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_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    /* everything went well, update face->num_names */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    face->num_names = (FT_UShort) table->numNameRecords;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
  /*    tt_face_free_names                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
  /*    Frees the name records.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
  /*    face :: A handle to the target face object.                        */
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
  tt_face_free_name( TT_Face  face )
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
    FT_Memory     memory = face->root.driver->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    TT_NameTable  table  = &face->name_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
    TT_NameEntry  entry  = table->names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
    FT_UInt       count  = table->numNameRecords;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
    if ( table->names )
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
      for ( ; count > 0; count--, entry++ )
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
        FT_FREE( entry->string );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
        entry->stringLength = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      /* free strings table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
      FT_FREE( table->names );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
    table->numNameRecords = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    table->format         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
    table->storageOffset  = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
  /*    tt_face_load_cmap                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
  /*    Loads the cmap directory in a face object.  The cmaps themselves   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
  /*    are loaded on demand in the `ttcmap.c' module.                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
  /*    face   :: A handle to the target face object.                      */
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
  /*    stream :: A handle to the input stream.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
  tt_face_load_cmap( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
    if ( FT_FRAME_EXTRACT( face->cmap_size, face->cmap_table ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
      face->cmap_size = 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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
  /*    tt_face_load_os2                                                   */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
  /*    Loads the OS2 table.                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
  /*    face   :: A handle to the target face object.                      */
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
  /*    stream :: A handle to the input stream.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
  tt_face_load_os2( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
                    FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
    TT_OS2*   os2;
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
    const FT_Frame_Field  os2_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
#define FT_STRUCTURE  TT_OS2
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
      FT_FRAME_START( 78 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
        FT_FRAME_USHORT( version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
        FT_FRAME_SHORT ( xAvgCharWidth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
        FT_FRAME_USHORT( usWeightClass ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
        FT_FRAME_USHORT( usWidthClass ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
        FT_FRAME_SHORT ( fsType ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
        FT_FRAME_SHORT ( ySubscriptXSize ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
        FT_FRAME_SHORT ( ySubscriptYSize ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
        FT_FRAME_SHORT ( ySubscriptXOffset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
        FT_FRAME_SHORT ( ySubscriptYOffset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
        FT_FRAME_SHORT ( ySuperscriptXSize ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
        FT_FRAME_SHORT ( ySuperscriptYSize ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
        FT_FRAME_SHORT ( ySuperscriptXOffset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
        FT_FRAME_SHORT ( ySuperscriptYOffset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
        FT_FRAME_SHORT ( yStrikeoutSize ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
        FT_FRAME_SHORT ( yStrikeoutPosition ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
        FT_FRAME_SHORT ( sFamilyClass ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
        FT_FRAME_BYTE  ( panose[0] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
        FT_FRAME_BYTE  ( panose[1] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
        FT_FRAME_BYTE  ( panose[2] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
        FT_FRAME_BYTE  ( panose[3] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
        FT_FRAME_BYTE  ( panose[4] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
        FT_FRAME_BYTE  ( panose[5] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
        FT_FRAME_BYTE  ( panose[6] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
        FT_FRAME_BYTE  ( panose[7] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
        FT_FRAME_BYTE  ( panose[8] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
        FT_FRAME_BYTE  ( panose[9] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
        FT_FRAME_ULONG ( ulUnicodeRange1 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
        FT_FRAME_ULONG ( ulUnicodeRange2 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
        FT_FRAME_ULONG ( ulUnicodeRange3 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
        FT_FRAME_ULONG ( ulUnicodeRange4 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
        FT_FRAME_BYTE  ( achVendID[0] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
        FT_FRAME_BYTE  ( achVendID[1] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
        FT_FRAME_BYTE  ( achVendID[2] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
        FT_FRAME_BYTE  ( achVendID[3] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
        FT_FRAME_USHORT( fsSelection ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
        FT_FRAME_USHORT( usFirstCharIndex ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
        FT_FRAME_USHORT( usLastCharIndex ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
        FT_FRAME_SHORT ( sTypoAscender ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
        FT_FRAME_SHORT ( sTypoDescender ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
        FT_FRAME_SHORT ( sTypoLineGap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
        FT_FRAME_USHORT( usWinAscent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
        FT_FRAME_USHORT( usWinDescent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
    const FT_Frame_Field  os2_fields_extra[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
      FT_FRAME_START( 8 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
        FT_FRAME_ULONG( ulCodePageRange1 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
        FT_FRAME_ULONG( ulCodePageRange2 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    const FT_Frame_Field  os2_fields_extra2[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
      FT_FRAME_START( 10 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
        FT_FRAME_SHORT ( sxHeight ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
        FT_FRAME_SHORT ( sCapHeight ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
        FT_FRAME_USHORT( usDefaultChar ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
        FT_FRAME_USHORT( usBreakChar ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
        FT_FRAME_USHORT( usMaxContext ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
    /* We now support old Mac fonts where the OS/2 table doesn't  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
    /* exist.  Simply put, we set the `version' field to 0xFFFF   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
    /* and test this value each time we need to access the table. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
    error = face->goto_table( face, TTAG_OS2, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
    os2 = &face->os2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
    os2->ulCodePageRange1 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    os2->ulCodePageRange2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    os2->sxHeight         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
    os2->sCapHeight       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
    os2->usDefaultChar    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
    os2->usBreakChar      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    os2->usMaxContext     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
    if ( os2->version >= 0x0001 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
      /* only version 1 tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
      if ( FT_STREAM_READ_FIELDS( os2_fields_extra, os2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
      if ( os2->version >= 0x0002 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
        /* only version 2 tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
        if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
    FT_TRACE3(( "sTypoAscender:  %4d\n",   os2->sTypoAscender ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
    FT_TRACE3(( "sTypoDescender: %4d\n",   os2->sTypoDescender ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
    FT_TRACE3(( "usWinAscent:    %4u\n",   os2->usWinAscent ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
    FT_TRACE3(( "usWinDescent:   %4u\n",   os2->usWinDescent ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
    FT_TRACE3(( "fsSelection:    0x%2x\n", os2->fsSelection ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
  /*    tt_face_load_postscript                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
  /*    Loads the Postscript table.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
  /*    face   :: A handle to the target face object.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
  /*    stream :: A handle to the input stream.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
  tt_face_load_post( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
    TT_Postscript*  post = &face->postscript;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
    static const FT_Frame_Field  post_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
#define FT_STRUCTURE  TT_Postscript
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
      FT_FRAME_START( 32 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
        FT_FRAME_ULONG( FormatType ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
        FT_FRAME_ULONG( italicAngle ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
        FT_FRAME_SHORT( underlinePosition ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
        FT_FRAME_SHORT( underlineThickness ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
        FT_FRAME_ULONG( isFixedPitch ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
        FT_FRAME_ULONG( minMemType42 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
        FT_FRAME_ULONG( maxMemType42 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
        FT_FRAME_ULONG( minMemType1 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
        FT_FRAME_ULONG( maxMemType1 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    error = face->goto_table( face, TTAG_post, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
    if ( FT_STREAM_READ_FIELDS( post_fields, post ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
    /* we don't load the glyph names, we do that in another */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
    /* module (ttpost).                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
    FT_TRACE3(( "FormatType:   0x%x\n", post->FormatType ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
    FT_TRACE3(( "isFixedPitch:   %s\n", post->isFixedPitch
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
                                        ? "  yes" : "   no" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
  /*    tt_face_load_pclt                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
  /*    Loads the PCL 5 Table.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
  /*    face   :: A handle to the target face object.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
  /*    stream :: A handle to the input stream.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
  tt_face_load_pclt( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
    static const FT_Frame_Field  pclt_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
#define FT_STRUCTURE  TT_PCLT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
      FT_FRAME_START( 54 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
        FT_FRAME_ULONG ( Version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
        FT_FRAME_ULONG ( FontNumber ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
        FT_FRAME_USHORT( Pitch ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
        FT_FRAME_USHORT( xHeight ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
        FT_FRAME_USHORT( Style ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
        FT_FRAME_USHORT( TypeFamily ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
        FT_FRAME_USHORT( CapHeight ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
        FT_FRAME_BYTES ( TypeFace, 16 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
        FT_FRAME_BYTES ( CharacterComplement, 8 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
        FT_FRAME_BYTES ( FileName, 6 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
        FT_FRAME_CHAR  ( StrokeWeight ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
        FT_FRAME_CHAR  ( WidthType ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
        FT_FRAME_BYTE  ( SerifStyle ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
        FT_FRAME_BYTE  ( Reserved ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
    TT_PCLT*  pclt = &face->pclt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
    /* optional table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
    error = face->goto_table( face, TTAG_PCLT, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
    if ( FT_STREAM_READ_FIELDS( pclt_fields, pclt ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
  /*    tt_face_load_gasp                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
  /*    Loads the `gasp' table into a face object.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
  /*    face   :: A handle to the target face object.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
  /*    stream :: The input stream.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
  tt_face_load_gasp( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
    FT_UInt        j,num_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
    TT_GaspRange   gaspranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
    /* the gasp table is optional */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
    error = face->goto_table( face, TTAG_gasp, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
    if ( FT_FRAME_ENTER( 4L ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
    face->gasp.version   = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
    face->gasp.numRanges = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
    FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
    /* only support versions 0 and 1 of the table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
    if ( face->gasp.version >= 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
      face->gasp.numRanges = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
      error = SFNT_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
    num_ranges = face->gasp.numRanges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
    FT_TRACE3(( "numRanges: %u\n", num_ranges ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
    if ( FT_QNEW_ARRAY( gaspranges, num_ranges ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
         FT_FRAME_ENTER( num_ranges * 4L )      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
    face->gasp.gaspRanges = gaspranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
    for ( j = 0; j < num_ranges; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
      gaspranges[j].maxPPEM  = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
      gaspranges[j].gaspFlag = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
      FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
                  j,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
                  gaspranges[j].maxPPEM,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
                  gaspranges[j].gaspFlag ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
    FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
/* END */