misc/libfreetype/src/pcf/pcfread.c
author Medo <smaxein@googlemail.com>
Wed, 23 May 2012 22:46:37 +0200
changeset 7123 9fe1c4091dd1
parent 5172 88f2e05288ba
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/*  pcfread.c
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
    FreeType font driver for pcf fonts
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
  Copyright 2000, 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
     6
            2010 by
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
  Francesco Zappa Nardelli
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
Permission is hereby granted, free of charge, to any person obtaining a copy
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
of this software and associated documentation files (the "Software"), to deal
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
in the Software without restriction, including without limitation the rights
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
copies of the Software, and to permit persons to whom the Software is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
furnished to do so, subject to the following conditions:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
The above copyright notice and this permission notice shall be included in
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
all copies or substantial portions of the Software.
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
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
THE SOFTWARE.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
*/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include <ft2build.h>
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
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#include "pcf.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#include "pcfread.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#include "pcferror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /* 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
    44
  /* 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
    45
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
#define FT_COMPONENT  trace_pcfread
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
#ifdef FT_DEBUG_LEVEL_TRACE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  static const char* const  tableNames[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    "prop", "accl", "mtrcs", "bmps", "imtrcs",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    "enc", "swidth", "names", "accel"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  const FT_Frame_Field  pcf_toc_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
#define FT_STRUCTURE  PCF_TocRec
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
    FT_FRAME_START( 8 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
      FT_FRAME_ULONG_LE( version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
      FT_FRAME_ULONG_LE( count ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  const FT_Frame_Field  pcf_table_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
#define FT_STRUCTURE  PCF_TableRec
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
    FT_FRAME_START( 16  ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
      FT_FRAME_ULONG_LE( type ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      FT_FRAME_ULONG_LE( format ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      FT_FRAME_ULONG_LE( size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
      FT_FRAME_ULONG_LE( offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  pcf_read_TOC( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
                PCF_Face   face )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    PCF_Toc    toc = &face->toc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    PCF_Table  tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    FT_Memory  memory = FT_FACE(face)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    FT_UInt    n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    if ( FT_STREAM_SEEK ( 0 )                          ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
         FT_STREAM_READ_FIELDS ( pcf_toc_header, toc ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      return PCF_Err_Cannot_Open_Resource;
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
    if ( toc->version != PCF_FILE_VERSION                 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
         toc->count   >  FT_ARRAY_MAX( face->toc.tables ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
         toc->count   == 0                                )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
      return PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    if ( FT_NEW_ARRAY( face->toc.tables, toc->count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
      return PCF_Err_Out_Of_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    tables = face->toc.tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    for ( n = 0; n < toc->count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
      if ( FT_STREAM_READ_FIELDS( pcf_table_header, tables ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      tables++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    /* Sort tables and check for overlaps.  Because they are almost      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    /* always ordered already, an in-place bubble sort with simultaneous */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    /* boundary checking seems appropriate.                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    tables = face->toc.tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    for ( n = 0; n < toc->count - 1; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      FT_UInt  i, have_change;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      have_change = 0;
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
      for ( i = 0; i < toc->count - 1 - n; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
        PCF_TableRec  tmp;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
        if ( tables[i].offset > tables[i + 1].offset )
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
          tmp           = tables[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
          tables[i]     = tables[i + 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
          tables[i + 1] = tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
          have_change = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
        if ( ( tables[i].size   > tables[i + 1].offset )                  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
             ( tables[i].offset > tables[i + 1].offset - tables[i].size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
          return PCF_Err_Invalid_Offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
      if ( !have_change )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    }
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
#ifdef FT_DEBUG_LEVEL_TRACE
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
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
      FT_UInt      i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
      const char*  name = "?";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      FT_TRACE4(( "pcf_read_TOC:\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      FT_TRACE4(( "  number of tables: %ld\n", face->toc.count ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      tables = face->toc.tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      for ( i = 0; i < toc->count; i++ )
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
        for ( j = 0; j < sizeof ( tableNames ) / sizeof ( tableNames[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
              j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
          if ( tables[i].type == (FT_UInt)( 1 << j ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
            name = tableNames[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
        FT_TRACE4(( "  %d: type=%s, format=0x%X, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
                    "size=%ld (0x%lX), offset=%ld (0x%lX)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
                    i, name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
                    tables[i].format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
                    tables[i].size, tables[i].size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
                    tables[i].offset, tables[i].offset ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    return PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    FT_FREE( face->toc.tables );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
#define PCF_METRIC_SIZE  12
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
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
  const FT_Frame_Field  pcf_metric_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
#define FT_STRUCTURE  PCF_MetricRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    FT_FRAME_START( PCF_METRIC_SIZE ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      FT_FRAME_SHORT_LE( leftSideBearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      FT_FRAME_SHORT_LE( rightSideBearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
      FT_FRAME_SHORT_LE( characterWidth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
      FT_FRAME_SHORT_LE( ascent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      FT_FRAME_SHORT_LE( descent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      FT_FRAME_SHORT_LE( attributes ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    FT_FRAME_END
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
  const FT_Frame_Field  pcf_metric_msb_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
#define FT_STRUCTURE  PCF_MetricRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    FT_FRAME_START( PCF_METRIC_SIZE ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      FT_FRAME_SHORT( leftSideBearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      FT_FRAME_SHORT( rightSideBearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
      FT_FRAME_SHORT( characterWidth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
      FT_FRAME_SHORT( ascent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      FT_FRAME_SHORT( descent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      FT_FRAME_SHORT( attributes ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
#define PCF_COMPRESSED_METRIC_SIZE  5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  const FT_Frame_Field  pcf_compressed_metric_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
#define FT_STRUCTURE  PCF_Compressed_MetricRec
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
    FT_FRAME_START( PCF_COMPRESSED_METRIC_SIZE ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      FT_FRAME_BYTE( leftSideBearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      FT_FRAME_BYTE( rightSideBearing ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      FT_FRAME_BYTE( characterWidth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
      FT_FRAME_BYTE( ascent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
      FT_FRAME_BYTE( descent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
    FT_FRAME_END
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  pcf_get_metric( FT_Stream   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
                  FT_ULong    format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
                  PCF_Metric  metric )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    FT_Error  error = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
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
      const FT_Frame_Field*  fields;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      /* parsing normal metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      fields = PCF_BYTE_ORDER( format ) == MSBFirst
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
               ? pcf_metric_msb_header
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
               : pcf_metric_header;
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
      /* the following sets `error' but doesn't return in case of failure */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
      (void)FT_STREAM_READ_FIELDS( fields, metric );
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
    else
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
      PCF_Compressed_MetricRec  compr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      /* parsing compressed metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      if ( FT_STREAM_READ_FIELDS( pcf_compressed_metric_header, &compr ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
      metric->leftSideBearing  = (FT_Short)( compr.leftSideBearing  - 0x80 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      metric->rightSideBearing = (FT_Short)( compr.rightSideBearing - 0x80 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      metric->characterWidth   = (FT_Short)( compr.characterWidth   - 0x80 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
      metric->ascent           = (FT_Short)( compr.ascent           - 0x80 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
      metric->descent          = (FT_Short)( compr.descent          - 0x80 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
      metric->attributes       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
  pcf_seek_to_table_type( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
                          PCF_Table  tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
                          FT_ULong   ntables, /* same as PCF_Toc->count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
                          FT_ULong   type,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                          FT_ULong  *aformat,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
                          FT_ULong  *asize )
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
    FT_Error  error = PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    FT_ULong  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    for ( i = 0; i < ntables; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
      if ( tables[i].type == type )
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
        if ( stream->pos > tables[i].offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
          error = PCF_Err_Invalid_Stream_Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        if ( FT_STREAM_SKIP( tables[i].offset - stream->pos ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
          error = PCF_Err_Invalid_Stream_Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
          goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
        *asize   = tables[i].size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
        *aformat = tables[i].format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
        return PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
      }
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    *asize = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  static FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
  pcf_has_table_type( PCF_Table  tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
                      FT_ULong   ntables, /* same as PCF_Toc->count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
                      FT_ULong   type )
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_ULong  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    for ( i = 0; i < ntables; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      if ( tables[i].type == type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
        return TRUE;
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
    return FALSE;
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
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
#define PCF_PROPERTY_SIZE  9
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
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
  const FT_Frame_Field  pcf_property_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
#define FT_STRUCTURE  PCF_ParsePropertyRec
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
    FT_FRAME_START( PCF_PROPERTY_SIZE ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
      FT_FRAME_LONG_LE( name ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      FT_FRAME_BYTE   ( isString ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
      FT_FRAME_LONG_LE( value ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
    FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
  const FT_Frame_Field  pcf_property_msb_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
#define FT_STRUCTURE  PCF_ParsePropertyRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    FT_FRAME_START( PCF_PROPERTY_SIZE ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      FT_FRAME_LONG( name ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      FT_FRAME_BYTE( isString ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
      FT_FRAME_LONG( value ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
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
  FT_LOCAL_DEF( PCF_Property )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
  pcf_find_property( PCF_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
                     const FT_String*  prop )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    PCF_Property  properties = face->properties;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    FT_Bool       found      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
    int           i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    for ( i = 0 ; i < face->nprops && !found; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
      if ( !ft_strcmp( properties[i].name, prop ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
        found = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
    if ( found )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
      return properties + i - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
  pcf_get_properties( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
                      PCF_Face   face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    PCF_ParseProperty  props      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    PCF_Property       properties;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
    FT_ULong           nprops, i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    FT_ULong           format, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    FT_Error           error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    FT_Memory          memory     = FT_FACE(face)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    FT_ULong           string_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    FT_String*         strings    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
    error = pcf_seek_to_table_type( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
                                    face->toc.tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
                                    face->toc.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
                                    PCF_PROPERTIES,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
                                    &format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
                                    &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    if ( FT_READ_ULONG_LE( format ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    FT_TRACE4(( "pcf_get_properties:\n" ));
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
    FT_TRACE4(( "  format = %ld\n", format ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      (void)FT_READ_ULONG( nprops );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      (void)FT_READ_ULONG_LE( nprops );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
    FT_TRACE4(( "  nprop = %d (truncate %d props)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
                (int)nprops, nprops - (int)nprops ));
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
    nprops = (int)nprops;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
    /* rough estimate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    if ( nprops > size / PCF_PROPERTY_SIZE )
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
      error = PCF_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
    face->nprops = (int)nprops;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
    if ( FT_NEW_ARRAY( props, nprops ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
      goto Bail;
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
    for ( i = 0; i < nprops; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
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
        if ( FT_STREAM_READ_FIELDS( pcf_property_msb_header, props + i ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
          goto Bail;
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
        if ( FT_STREAM_READ_FIELDS( pcf_property_header, props + i ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
          goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    /* pad the property array                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    /* clever here - nprops is the same as the number of odd-units read, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    /* as only isStringProp are odd length   (Keith Packard)             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    if ( nprops & 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      i = 4 - ( nprops & 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      if ( FT_STREAM_SKIP( i ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
        error = PCF_Err_Invalid_Stream_Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
      (void)FT_READ_ULONG( string_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
      (void)FT_READ_ULONG_LE( string_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      goto Bail;
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
    FT_TRACE4(( "  string_size = %ld\n", string_size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    /* rough estimate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    if ( string_size > size - nprops * PCF_PROPERTY_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
      error = PCF_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      goto Bail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    if ( FT_NEW_ARRAY( strings, string_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    error = FT_Stream_Read( stream, (FT_Byte*)strings, string_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    if ( FT_NEW_ARRAY( properties, nprops ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      goto Bail;
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
    face->properties = properties;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    for ( i = 0; i < nprops; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      FT_Long  name_offset = props[i].name;
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
      if ( ( name_offset < 0 )                     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
           ( (FT_ULong)name_offset > string_size ) )
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
        error = PCF_Err_Invalid_Offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
      if ( FT_STRDUP( properties[i].name, strings + name_offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      FT_TRACE4(( "  %s:", properties[i].name ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
      properties[i].isString = props[i].isString;
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
      if ( props[i].isString )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
        FT_Long  value_offset = props[i].value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
        if ( ( value_offset < 0 )                     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
             ( (FT_ULong)value_offset > string_size ) )
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
          error = PCF_Err_Invalid_Offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
          goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
        if ( FT_STRDUP( properties[i].value.atom, strings + value_offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
          goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
        FT_TRACE4(( " `%s'\n", properties[i].value.atom ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
        properties[i].value.l = props[i].value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
        FT_TRACE4(( " %d\n", properties[i].value.l ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    error = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
  Bail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    FT_FREE( props );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    FT_FREE( strings );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
  pcf_get_metrics( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
                   PCF_Face   face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    FT_Error    error    = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    FT_Memory   memory   = FT_FACE(face)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    FT_ULong    format, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    PCF_Metric  metrics  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
    FT_ULong    nmetrics, i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    error = pcf_seek_to_table_type( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
                                    face->toc.tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
                                    face->toc.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
                                    PCF_METRICS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
                                    &format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
                                    &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    if ( FT_READ_ULONG_LE( format ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
      goto Bail;
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
    if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT )     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
         !PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
      return PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
    if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
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
      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
        (void)FT_READ_ULONG( nmetrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
        (void)FT_READ_ULONG_LE( nmetrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
        (void)FT_READ_USHORT( nmetrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
        (void)FT_READ_USHORT_LE( nmetrics );
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
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      return PCF_Err_Invalid_File_Format;
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
    face->nmetrics = nmetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
    if ( !nmetrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
      return PCF_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
    FT_TRACE4(( "pcf_get_metrics:\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
    FT_TRACE4(( "  number of metrics: %d\n", nmetrics ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
    /* rough estimate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
    if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
      if ( nmetrics > size / PCF_METRIC_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        return PCF_Err_Invalid_Table;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
      if ( nmetrics > size / PCF_COMPRESSED_METRIC_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
        return PCF_Err_Invalid_Table;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
    if ( FT_NEW_ARRAY( face->metrics, nmetrics ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
      return PCF_Err_Out_Of_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    metrics = face->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    for ( i = 0; i < nmetrics; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
      error = pcf_get_metric( stream, format, metrics + i );
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
      metrics[i].bits = 0;
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_TRACE5(( "  idx %d: width=%d, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
                  "lsb=%d, rsb=%d, ascent=%d, descent=%d, swidth=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
                  i,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
                  ( metrics + i )->characterWidth,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
                  ( metrics + i )->leftSideBearing,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
                  ( metrics + i )->rightSideBearing,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
                  ( metrics + i )->ascent,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
                  ( metrics + i )->descent,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
                  ( metrics + i )->attributes ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
      FT_FREE( face->metrics );
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
  Bail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
  pcf_get_bitmaps( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
                   PCF_Face   face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
    FT_Error   error  = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
    FT_Memory  memory = FT_FACE(face)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
    FT_Long*   offsets;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
    FT_Long    bitmapSizes[GLYPHPADOPTIONS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    FT_ULong   format, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    FT_ULong   nbitmaps, i, sizebitmaps = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    error = pcf_seek_to_table_type( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
                                    face->toc.tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
                                    face->toc.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
                                    PCF_BITMAPS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
                                    &format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
                                    &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    error = FT_Stream_EnterFrame( stream, 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
      return error;
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
    format = FT_GET_ULONG_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      nbitmaps  = FT_GET_ULONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
      nbitmaps  = FT_GET_ULONG_LE();
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
    FT_Stream_ExitFrame( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
    if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
      return PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    FT_TRACE4(( "pcf_get_bitmaps:\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    FT_TRACE4(( "  number of bitmaps: %d\n", nbitmaps ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    /* XXX: PCF_Face->nmetrics is singed FT_Long, see pcf.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    if ( face->nmetrics < 0 || nbitmaps != ( FT_ULong )face->nmetrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      return PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    if ( FT_NEW_ARRAY( offsets, nbitmaps ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    for ( i = 0; i < nbitmaps; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
        (void)FT_READ_LONG( offsets[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
        (void)FT_READ_LONG_LE( offsets[i] );
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
      FT_TRACE5(( "  bitmap %d: offset %ld (0x%lX)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
                  i, offsets[i], offsets[i] ));
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
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      goto Bail;
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
    for ( i = 0; i < GLYPHPADOPTIONS; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
        (void)FT_READ_LONG( bitmapSizes[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
        (void)FT_READ_LONG_LE( bitmapSizes[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX( format )];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
      FT_TRACE4(( "  padding %d implies a size of %ld\n", i, bitmapSizes[i] ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    FT_TRACE4(( "  %d bitmaps, padding index %ld\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
                nbitmaps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
                PCF_GLYPH_PAD_INDEX( format ) ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    FT_TRACE4(( "  bitmap size = %d\n", sizebitmaps ));
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_UNUSED( sizebitmaps );       /* only used for debugging */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    for ( i = 0; i < nbitmaps; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
      /* rough estimate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      if ( ( offsets[i] < 0 )              ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
           ( (FT_ULong)offsets[i] > size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
        FT_TRACE0(( "pcf_get_bitmaps:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
                    " invalid offset to bitmap data of glyph %d\n", i ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
        face->metrics[i].bits = stream->pos + offsets[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
    face->bitmapsFormat = format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
  Bail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
    FT_FREE( offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
  pcf_get_encodings( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
                     PCF_Face   face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    FT_Error      error  = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
    FT_Memory     memory = FT_FACE(face)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
    FT_ULong      format, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
    int           firstCol, lastCol;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
    int           firstRow, lastRow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
    int           nencoding, encodingOffset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
    int           i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
    PCF_Encoding  tmpEncoding, encoding = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
    error = pcf_seek_to_table_type( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
                                    face->toc.tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
                                    face->toc.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
                                    PCF_BDF_ENCODINGS,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
                                    &format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
                                    &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    error = FT_Stream_EnterFrame( stream, 14 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    format = FT_GET_ULONG_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
      firstCol          = FT_GET_SHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
      lastCol           = FT_GET_SHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
      firstRow          = FT_GET_SHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
      lastRow           = FT_GET_SHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
      face->defaultChar = FT_GET_SHORT();
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
      firstCol          = FT_GET_SHORT_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
      lastCol           = FT_GET_SHORT_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
      firstRow          = FT_GET_SHORT_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
      lastRow           = FT_GET_SHORT_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
      face->defaultChar = FT_GET_SHORT_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
    FT_Stream_ExitFrame( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
      return PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
    FT_TRACE4(( "pdf_get_encodings:\n" ));
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
    FT_TRACE4(( "  firstCol %d, lastCol %d, firstRow %d, lastRow %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
                firstCol, lastCol, firstRow, lastRow ));
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
    nencoding = ( lastCol - firstCol + 1 ) * ( lastRow - firstRow + 1 );
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_NEW_ARRAY( tmpEncoding, nencoding ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
      return PCF_Err_Out_Of_Memory;
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
    error = FT_Stream_EnterFrame( stream, 2 * nencoding );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
      goto Bail;
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
    for ( i = 0, j = 0 ; i < nencoding; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        encodingOffset = FT_GET_SHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
        encodingOffset = FT_GET_SHORT_LE();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
      if ( encodingOffset != -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
        tmpEncoding[j].enc = ( ( ( i / ( lastCol - firstCol + 1 ) ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
                                 firstRow ) * 256 ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
                               ( ( i % ( lastCol - firstCol + 1 ) ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
                                 firstCol );
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
        tmpEncoding[j].glyph = (FT_Short)encodingOffset;
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
        FT_TRACE5(( "  code %d (0x%04X): idx %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
                    tmpEncoding[j].enc, tmpEncoding[j].enc,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
                    tmpEncoding[j].glyph ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
        j++;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
    FT_Stream_ExitFrame( stream );
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
    if ( FT_NEW_ARRAY( encoding, j ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
      goto Bail;
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
    for ( i = 0; i < j; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
      encoding[i].enc   = tmpEncoding[i].enc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
      encoding[i].glyph = tmpEncoding[i].glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    face->nencodings = j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
    face->encodings  = encoding;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
    FT_FREE( tmpEncoding );
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
  Bail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
    FT_FREE( encoding );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    FT_FREE( tmpEncoding );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
  }
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
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
  const FT_Frame_Field  pcf_accel_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
#define FT_STRUCTURE  PCF_AccelRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
    FT_FRAME_START( 20 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
      FT_FRAME_BYTE      ( noOverlap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      FT_FRAME_BYTE      ( constantMetrics ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
      FT_FRAME_BYTE      ( terminalFont ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      FT_FRAME_BYTE      ( constantWidth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
      FT_FRAME_BYTE      ( inkInside ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
      FT_FRAME_BYTE      ( inkMetrics ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
      FT_FRAME_BYTE      ( drawDirection ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
      FT_FRAME_SKIP_BYTES( 1 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      FT_FRAME_LONG_LE   ( fontAscent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
      FT_FRAME_LONG_LE   ( fontDescent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
      FT_FRAME_LONG_LE   ( maxOverlap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
    FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
  static
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
  const FT_Frame_Field  pcf_accel_msb_header[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
#define FT_STRUCTURE  PCF_AccelRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
    FT_FRAME_START( 20 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
      FT_FRAME_BYTE      ( noOverlap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
      FT_FRAME_BYTE      ( constantMetrics ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
      FT_FRAME_BYTE      ( terminalFont ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
      FT_FRAME_BYTE      ( constantWidth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
      FT_FRAME_BYTE      ( inkInside ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
      FT_FRAME_BYTE      ( inkMetrics ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
      FT_FRAME_BYTE      ( drawDirection ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
      FT_FRAME_SKIP_BYTES( 1 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
      FT_FRAME_LONG      ( fontAscent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
      FT_FRAME_LONG      ( fontDescent ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
      FT_FRAME_LONG      ( maxOverlap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    FT_FRAME_END
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
  pcf_get_accel( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
                 PCF_Face   face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
                 FT_ULong   type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
    FT_ULong   format, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
    FT_Error   error = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    PCF_Accel  accel = &face->accel;
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
    error = pcf_seek_to_table_type( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
                                    face->toc.tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
                                    face->toc.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
                                    type,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
                                    &format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
                                    &size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
    if ( FT_READ_ULONG_LE( format ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
    if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT )    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
         !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
    if ( PCF_BYTE_ORDER( format ) == MSBFirst )
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
      if ( FT_STREAM_READ_FIELDS( pcf_accel_msb_header, accel ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
      if ( FT_STREAM_READ_FIELDS( pcf_accel_header, accel ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
    error = pcf_get_metric( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
                            format & ( ~PCF_FORMAT_MASK ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
                            &(accel->minbounds) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    error = pcf_get_metric( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
                            format & ( ~PCF_FORMAT_MASK ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
                            &(accel->maxbounds) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
      goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
    if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
      error = pcf_get_metric( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
                              format & ( ~PCF_FORMAT_MASK ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
                              &(accel->ink_minbounds) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
      error = pcf_get_metric( stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
                              format & ( ~PCF_FORMAT_MASK ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
                              &(accel->ink_maxbounds) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
        goto Bail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
      accel->ink_minbounds = accel->minbounds; /* I'm not sure about this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
      accel->ink_maxbounds = accel->maxbounds;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
  Bail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
  pcf_interpret_style( PCF_Face  pcf )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    FT_Error   error  = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
    FT_Face    face   = FT_FACE( pcf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
    FT_Memory  memory = face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    PCF_Property  prop;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
    size_t  nn, len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
    char*   strings[4] = { NULL, NULL, NULL, NULL };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    size_t  lengths[4];
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
    face->style_flags = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
    prop = pcf_find_property( pcf, "SLANT" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
    if ( prop && prop->isString                                       &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
         ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
           *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) )
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
      face->style_flags |= FT_STYLE_FLAG_ITALIC;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
      strings[2] = ( *(prop->value.atom) == 'O' ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
                     *(prop->value.atom) == 'o' ) ? (char *)"Oblique"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
                                                  : (char *)"Italic";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
    prop = pcf_find_property( pcf, "WEIGHT_NAME" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
    if ( prop && prop->isString                                       &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
         ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
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
      face->style_flags |= FT_STYLE_FLAG_BOLD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
      strings[1] = (char *)"Bold";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
    prop = pcf_find_property( pcf, "SETWIDTH_NAME" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
    if ( prop && prop->isString                                        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
         *(prop->value.atom)                                           &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
         !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
      strings[3] = (char *)(prop->value.atom);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
    prop = pcf_find_property( pcf, "ADD_STYLE_NAME" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    if ( prop && prop->isString                                        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
         *(prop->value.atom)                                           &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
         !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
      strings[0] = (char *)(prop->value.atom);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    for ( len = 0, nn = 0; nn < 4; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
      lengths[nn] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
      if ( strings[nn] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
        lengths[nn] = ft_strlen( strings[nn] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
        len        += lengths[nn] + 1;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
    if ( len == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
      strings[0] = (char *)"Regular";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
      lengths[0] = ft_strlen( strings[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
      len        = lengths[0] + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
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
      char*  s;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
      if ( FT_ALLOC( face->style_name, len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
        return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
      s = face->style_name;
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
      for ( nn = 0; nn < 4; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
        char*  src = strings[nn];
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
        len = lengths[nn];
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
        if ( src == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
          continue;
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
        /* separate elements with a space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
        if ( s != face->style_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
          *s++ = ' ';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
        ft_memcpy( s, src, len );
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
        /* need to convert spaces to dashes for */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
        /* add_style_name and setwidth_name     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
        if ( nn == 0 || nn == 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
          size_t  mm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
          for ( mm = 0; mm < len; mm++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
            if (s[mm] == ' ')
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
              s[mm] = '-';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
        s += len;
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
      *s = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
  pcf_load_font( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
                 PCF_Face   face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
    FT_Error   error  = PCF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
    FT_Memory  memory = FT_FACE(face)->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
    FT_Bool    hasBDFAccelerators;
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
    error = pcf_read_TOC( stream, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
    error = pcf_get_properties( stream, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
      goto Exit;
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
    /* Use the old accelerators if no BDF accelerators are in the file. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
    hasBDFAccelerators = pcf_has_table_type( face->toc.tables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
                                             face->toc.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
                                             PCF_BDF_ACCELERATORS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
    if ( !hasBDFAccelerators )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
      error = pcf_get_accel( stream, face, PCF_ACCELERATORS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
        goto Exit;
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
    /* metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
    error = pcf_get_metrics( stream, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
      goto Exit;
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
    /* bitmaps */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
    error = pcf_get_bitmaps( stream, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
    /* encodings */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
    error = pcf_get_encodings( stream, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    /* BDF style accelerators (i.e. bounds based on encoded glyphs) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
    if ( hasBDFAccelerators )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
      error = pcf_get_accel( stream, face, PCF_BDF_ACCELERATORS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
    /* XXX: TO DO: inkmetrics and glyph_names are missing */
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
    /* now construct the face object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
      FT_Face       root = FT_FACE( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
      PCF_Property  prop;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
      root->num_faces  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
      root->face_index = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
      root->face_flags = FT_FACE_FLAG_FIXED_SIZES |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
                         FT_FACE_FLAG_HORIZONTAL  |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
                         FT_FACE_FLAG_FAST_GLYPHS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
      if ( face->accel.constantWidth )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
        root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
      if ( ( error = pcf_interpret_style( face ) ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
         goto Exit;
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
      prop = pcf_find_property( face, "FAMILY_NAME" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      if ( prop && prop->isString )
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
        if ( FT_STRDUP( root->family_name, prop->value.atom ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
        root->family_name = NULL;
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
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
       * Note: We shift all glyph indices by +1 since we must
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
       * respect the convention that glyph 0 always corresponds
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
       * to the `missing glyph'.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
       *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
       * This implies bumping the number of `available' glyphs by 1.
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
      root->num_glyphs = face->nmetrics + 1;
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
      root->num_fixed_sizes = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
      if ( FT_NEW_ARRAY( root->available_sizes, 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
        goto Exit;
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
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
        FT_Bitmap_Size*  bsize = root->available_sizes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
        FT_Short         resolution_x = 0, resolution_y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
        FT_MEM_ZERO( bsize, sizeof ( FT_Bitmap_Size ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
        bsize->height = face->accel.maxbounds.ascent << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
        bsize->height = (FT_Short)( face->accel.fontAscent +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
                                    face->accel.fontDescent );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
        prop = pcf_find_property( face, "AVERAGE_WIDTH" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
        if ( prop )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
          bsize->width = (FT_Short)( ( prop->value.l + 5 ) / 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
          bsize->width = (FT_Short)( bsize->height * 2/3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
        prop = pcf_find_property( face, "POINT_SIZE" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
        if ( prop )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
          /* convert from 722.7 decipoints to 72 points per inch */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
          bsize->size =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
            (FT_Pos)( ( prop->value.l * 64 * 7200 + 36135L ) / 72270L );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
        prop = pcf_find_property( face, "PIXEL_SIZE" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
        if ( prop )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
          bsize->y_ppem = (FT_Short)prop->value.l << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
        prop = pcf_find_property( face, "RESOLUTION_X" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
        if ( prop )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
          resolution_x = (FT_Short)prop->value.l;
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
        prop = pcf_find_property( face, "RESOLUTION_Y" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
        if ( prop )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
          resolution_y = (FT_Short)prop->value.l;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
        if ( bsize->y_ppem == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
          bsize->y_ppem = bsize->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
          if ( resolution_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
            bsize->y_ppem = bsize->y_ppem * resolution_y / 72;
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
        if ( resolution_x && resolution_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
          bsize->x_ppem = bsize->y_ppem * resolution_x / resolution_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
          bsize->x_ppem = bsize->y_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
      /* set up charset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
        PCF_Property  charset_registry = 0, charset_encoding = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
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
        charset_registry = pcf_find_property( face, "CHARSET_REGISTRY" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
        charset_encoding = pcf_find_property( face, "CHARSET_ENCODING" );
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
        if ( charset_registry && charset_registry->isString &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
             charset_encoding && charset_encoding->isString )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
          if ( FT_STRDUP( face->charset_encoding,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
                          charset_encoding->value.atom ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
               FT_STRDUP( face->charset_registry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
                          charset_registry->value.atom ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
      }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
      /* This is done to respect the behaviour of the original */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
      /* PCF font driver.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
      error = PCF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
/* END */