misc/libfreetype/src/pfr/pfrload.c
author unc0rr
Sat, 06 Oct 2012 01:09:41 +0400
changeset 7723 ca05b576ec74
parent 5172 88f2e05288ba
permissions -rw-r--r--
Start moving to players list model.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  pfrload.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType PFR loader (body).                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2002, 2003, 2004, 2005, 2007, 2009, 2010 by                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include "pfrload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include "pfrerror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#define FT_COMPONENT  trace_pfr
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*****                          EXTRA ITEMS                          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  pfr_extra_items_skip( FT_Byte*  *pp,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
                        FT_Byte*   limit )
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
    return pfr_extra_items_parse( pp, limit, NULL, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  pfr_extra_items_parse( FT_Byte*       *pp,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
                         FT_Byte*        limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
                         PFR_ExtraItem   item_list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
                         FT_Pointer      item_data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    FT_Error  error = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    FT_Byte*  p     = *pp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    FT_UInt   num_items, item_type, item_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    num_items = PFR_NEXT_BYTE( p );
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
    for ( ; num_items > 0; num_items-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
      PFR_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
      item_size = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
      item_type = PFR_NEXT_BYTE( p );
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
      PFR_CHECK( item_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
      if ( item_list )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
        PFR_ExtraItem  extra = item_list;
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
        for ( extra = item_list; extra->parser != NULL; extra++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
          if ( extra->type == item_type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
            error = extra->parser( p, p + item_size, item_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
            if ( error ) goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      p += item_size;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    *pp = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    return error;
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
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    FT_ERROR(( "pfr_extra_items_parse: invalid extra items table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  /*****                          PFR HEADER                           *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
   static const FT_Frame_Field  pfr_header_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
#define FT_STRUCTURE  PFR_HeaderRec
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
     FT_FRAME_START( 58 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
       FT_FRAME_ULONG ( signature ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
       FT_FRAME_USHORT( version ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
       FT_FRAME_USHORT( signature2 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
       FT_FRAME_USHORT( header_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
       FT_FRAME_USHORT( log_dir_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
       FT_FRAME_USHORT( log_dir_offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
       FT_FRAME_USHORT( log_font_max_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
       FT_FRAME_UOFF3 ( log_font_section_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
       FT_FRAME_UOFF3 ( log_font_section_offset ),
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
       FT_FRAME_USHORT( phy_font_max_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
       FT_FRAME_UOFF3 ( phy_font_section_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
       FT_FRAME_UOFF3 ( phy_font_section_offset ),
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
       FT_FRAME_USHORT( gps_max_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
       FT_FRAME_UOFF3 ( gps_section_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
       FT_FRAME_UOFF3 ( gps_section_offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
       FT_FRAME_BYTE  ( max_blue_values ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
       FT_FRAME_BYTE  ( max_x_orus ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
       FT_FRAME_BYTE  ( max_y_orus ),
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
       FT_FRAME_BYTE  ( phy_font_max_size_high ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
       FT_FRAME_BYTE  ( color_flags ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
       FT_FRAME_UOFF3 ( bct_max_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
       FT_FRAME_UOFF3 ( bct_set_max_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
       FT_FRAME_UOFF3 ( phy_bct_set_max_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
       FT_FRAME_USHORT( num_phy_fonts ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
       FT_FRAME_BYTE  ( max_vert_stem_snap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
       FT_FRAME_BYTE  ( max_horz_stem_snap ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
       FT_FRAME_USHORT( max_chars ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
     FT_FRAME_END
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
  pfr_header_load( PFR_Header  header,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
                   FT_Stream   stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    FT_Error  error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    /* read header directly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    if ( !FT_STREAM_SEEK( 0 )                                &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
         !FT_STREAM_READ_FIELDS( pfr_header_fields, header ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      /* make a few adjustments to the header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      header->phy_font_max_size +=
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
        (FT_UInt32)header->phy_font_max_size_high << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  FT_LOCAL_DEF( FT_Bool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
  pfr_header_check( PFR_Header  header )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    FT_Bool  result = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    /* check signature and header size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    if ( header->signature  != 0x50465230L ||   /* "PFR0" */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
         header->version     > 4           ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
         header->header_size < 58          ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
         header->signature2 != 0x0d0a      )    /* CR/LF  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
      result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    return  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
  /*****                                                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  /*****                    PFR LOGICAL FONTS                        *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
  /*****                                                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
  pfr_log_font_count( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
                      FT_UInt32  section_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
                      FT_UInt   *acount )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    FT_UInt   count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    FT_UInt   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    if ( FT_STREAM_SEEK( section_offset ) || FT_READ_USHORT( count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      goto Exit;
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
    result = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    *acount = result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
  pfr_log_font_load( PFR_LogFont  log_font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
                     FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
                     FT_UInt      idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
                     FT_UInt32    section_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
                     FT_Bool      size_increment )
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
    FT_UInt    num_log_fonts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    FT_UInt    flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    FT_UInt32  offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    FT_UInt32  size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    if ( FT_STREAM_SEEK( section_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
         FT_READ_USHORT( num_log_fonts )  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    if ( idx >= num_log_fonts )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      return PFR_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    if ( FT_STREAM_SKIP( idx * 5 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
         FT_READ_USHORT( size )    ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
         FT_READ_UOFF3 ( offset )  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
      goto Exit;
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
    /* save logical font size and offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    log_font->size   = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    log_font->offset = offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    /* now, check the rest of the table before loading it */
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_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      FT_Byte*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      FT_UInt   local;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
      if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      p     = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      limit = p + size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
      PFR_CHECK(13);
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
      log_font->matrix[0] = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
      log_font->matrix[1] = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      log_font->matrix[2] = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
      log_font->matrix[3] = PFR_NEXT_LONG( p );
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
      flags = PFR_NEXT_BYTE( p );
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
      local = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      if ( flags & PFR_LOG_STROKE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        local++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        if ( flags & PFR_LOG_2BYTE_STROKE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
          local++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
        if ( (flags & PFR_LINE_JOIN_MASK) == PFR_LINE_JOIN_MITER )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
          local += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
      if ( flags & PFR_LOG_BOLD )
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
        local++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
        if ( flags & PFR_LOG_2BYTE_BOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
          local++;
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
      PFR_CHECK( local );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
      if ( flags & PFR_LOG_STROKE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
        log_font->stroke_thickness = ( flags & PFR_LOG_2BYTE_STROKE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
                                     ? PFR_NEXT_SHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                                     : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
        if ( ( flags & PFR_LINE_JOIN_MASK ) == PFR_LINE_JOIN_MITER )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
          log_font->miter_limit = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      if ( flags & PFR_LOG_BOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
        log_font->bold_thickness = ( flags & PFR_LOG_2BYTE_BOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
                                   ? PFR_NEXT_SHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
                                   : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      if ( flags & PFR_LOG_EXTRA_ITEMS )
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
        error = pfr_extra_items_skip( &p, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        if (error) goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
      PFR_CHECK(5);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
      log_font->phys_size   = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
      log_font->phys_offset = PFR_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      if ( size_increment )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
        PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
        log_font->phys_size += (FT_UInt32)PFR_NEXT_BYTE( p ) << 16;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    FT_FRAME_EXIT();
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    FT_ERROR(( "pfr_log_font_load: invalid logical font table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
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
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  /*****                                                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
  /*****                    PFR PHYSICAL FONTS                       *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
  /*****                                                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  /***********************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  /* load bitmap strikes lists */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
  pfr_extra_item_load_bitmap_info( FT_Byte*     p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
                                   FT_Byte*     limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
                                   PFR_PhyFont  phy_font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    FT_Memory   memory = phy_font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    PFR_Strike  strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
    FT_UInt     flags0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
    FT_UInt     n, count, size1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
    FT_Error    error = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    PFR_CHECK( 5 );
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
    p += 3;  /* skip bctSize */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    flags0 = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    count  = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    /* re-allocate when needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    if ( phy_font->num_strikes + count > phy_font->max_strikes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      FT_UInt  new_max = FT_PAD_CEIL( phy_font->num_strikes + count, 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
      if ( FT_RENEW_ARRAY( phy_font->strikes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
                           phy_font->num_strikes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
                           new_max ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      phy_font->max_strikes = new_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    size1 = 1 + 1 + 1 + 2 + 2 + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    if ( flags0 & PFR_STRIKE_2BYTE_XPPM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      size1++;
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
    if ( flags0 & PFR_STRIKE_2BYTE_YPPM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      size1++;
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 ( flags0 & PFR_STRIKE_3BYTE_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      size1++;
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
    if ( flags0 & PFR_STRIKE_3BYTE_OFFSET )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      size1++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    if ( flags0 & PFR_STRIKE_2BYTE_COUNT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      size1++;
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
    strike = phy_font->strikes + phy_font->num_strikes;
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
    PFR_CHECK( count * size1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    for ( n = 0; n < count; n++, strike++ )
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
      strike->x_ppm       = ( flags0 & PFR_STRIKE_2BYTE_XPPM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
                            ? PFR_NEXT_USHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
                            : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      strike->y_ppm       = ( flags0 & PFR_STRIKE_2BYTE_YPPM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
                            ? PFR_NEXT_USHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
                            : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
      strike->flags       = PFR_NEXT_BYTE( p );
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
      strike->bct_size    = ( flags0 & PFR_STRIKE_3BYTE_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
                            ? PFR_NEXT_ULONG( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
                            : PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
      strike->bct_offset  = ( flags0 & PFR_STRIKE_3BYTE_OFFSET )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
                            ? PFR_NEXT_ULONG( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
                            : PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      strike->num_bitmaps = ( flags0 & PFR_STRIKE_2BYTE_COUNT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
                            ? PFR_NEXT_USHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
                            : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    phy_font->num_strikes += count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    FT_ERROR(( "pfr_extra_item_load_bitmap_info:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
               " invalid bitmap info table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  /* Load font ID.  This is a so-called "unique" name that is rather
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
   * long and descriptive (like "Tiresias ScreenFont v7.51").
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
   * Note that a PFR font's family name is contained in an *undocumented*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
   * string of the "auxiliary data" portion of a physical font record.  This
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
   * may also contain the "real" style name!
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
   * If no family name is present, the font ID is used instead for the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
   * family.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
  pfr_extra_item_load_font_id( FT_Byte*     p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
                               FT_Byte*     limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
                               PFR_PhyFont  phy_font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
    FT_Error    error  = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
    FT_Memory   memory = phy_font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
    FT_PtrDist  len    = limit - p;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
    if ( phy_font->font_id != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    if ( FT_ALLOC( phy_font->font_id, len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
      goto Exit;
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
    /* copy font ID name, and terminate it for safety */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    FT_MEM_COPY( phy_font->font_id, p, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    phy_font->font_id[len] = 0;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
  /* load stem snap tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
  pfr_extra_item_load_stem_snaps( FT_Byte*     p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
                                  FT_Byte*     limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
                                  PFR_PhyFont  phy_font )
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
    FT_UInt    count, num_vert, num_horz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    FT_Int*    snaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    FT_Error   error  = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    FT_Memory  memory = phy_font->memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    if ( phy_font->vertical.stem_snaps != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    count = PFR_NEXT_BYTE( p );
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
    num_vert = count & 15;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    num_horz = count >> 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    count    = num_vert + num_horz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    PFR_CHECK( count * 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    if ( FT_NEW_ARRAY( snaps, count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
      goto Exit;
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
    phy_font->vertical.stem_snaps = snaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    phy_font->horizontal.stem_snaps = snaps + num_vert;
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
    for ( ; count > 0; count--, snaps++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
      *snaps = FT_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    FT_ERROR(( "pfr_exta_item_load_stem_snaps:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
               " invalid stem snaps table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
  /* load kerning pair data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
  pfr_extra_item_load_kerning_pairs( FT_Byte*     p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
                                     FT_Byte*     limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
                                     PFR_PhyFont  phy_font )
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
    PFR_KernItem  item   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    FT_Error      error  = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    FT_Memory     memory = phy_font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
    FT_TRACE2(( "pfr_extra_item_load_kerning_pairs()\n" ));
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 ( FT_NEW( item ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
    PFR_CHECK( 4 );
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
    item->pair_count = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    item->base_adj   = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    item->flags      = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    item->offset     = phy_font->offset + ( p - phy_font->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
#ifndef PFR_CONFIG_NO_CHECKS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    item->pair_size = 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    if ( item->flags & PFR_KERN_2BYTE_CHAR )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
      item->pair_size += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    if ( item->flags & PFR_KERN_2BYTE_ADJ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      item->pair_size += 1;
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
    PFR_CHECK( item->pair_count * item->pair_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
    /* load first and last pairs into the item to speed up */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    /* lookup later...                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
    if ( item->pair_count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
      FT_UInt   char1, char2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
      FT_Byte*  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      if ( item->flags & PFR_KERN_2BYTE_CHAR )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
        q     = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
        char1 = PFR_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
        char2 = PFR_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
        item->pair1 = PFR_KERN_INDEX( char1, char2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
        q = p + item->pair_size * ( item->pair_count - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
        char1 = PFR_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        char2 = PFR_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
        item->pair2 = PFR_KERN_INDEX( char1, char2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
      else
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
        q     = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
        char1 = PFR_NEXT_BYTE( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
        char2 = PFR_NEXT_BYTE( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
        item->pair1 = PFR_KERN_INDEX( char1, char2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
        q = p + item->pair_size * ( item->pair_count - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
        char1 = PFR_NEXT_BYTE( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
        char2 = PFR_NEXT_BYTE( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
        item->pair2 = PFR_KERN_INDEX( char1, char2 );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
      /* add new item to the current list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
      item->next                 = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
      *phy_font->kern_items_tail = item;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      phy_font->kern_items_tail  = &item->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      phy_font->num_kern_pairs  += item->pair_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
      /* empty item! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
      FT_FREE( item );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
    FT_FREE( item );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
    FT_ERROR(( "pfr_extra_item_load_kerning_pairs:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
               " invalid kerning pairs table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
  static const PFR_ExtraItemRec  pfr_phy_font_extra_items[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
    { 1, (PFR_ExtraItem_ParseFunc)pfr_extra_item_load_bitmap_info },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
    { 2, (PFR_ExtraItem_ParseFunc)pfr_extra_item_load_font_id },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
    { 3, (PFR_ExtraItem_ParseFunc)pfr_extra_item_load_stem_snaps },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    { 4, (PFR_ExtraItem_ParseFunc)pfr_extra_item_load_kerning_pairs },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    { 0, NULL }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
  };
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
  /* Loads a name from the auxiliary data.  Since this extracts undocumented
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
   * strings from the font file, we need to be careful here.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
  pfr_aux_name_load( FT_Byte*     p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
                     FT_UInt      len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
                     FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
                     FT_String*  *astring )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    FT_Error    error = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    FT_String*  result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    FT_UInt     n, ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    if ( len > 0 && p[len - 1] == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      len--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    /* check that each character is ASCII for making sure not to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
       load garbage
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    ok = ( len > 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    for ( n = 0; n < len; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
      if ( p[n] < 32 || p[n] > 127 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        ok = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
    if ( ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
      if ( FT_ALLOC( result, len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      FT_MEM_COPY( result, p, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
      result[len] = 0;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    *astring = result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
  pfr_phy_font_done( PFR_PhyFont  phy_font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
                     FT_Memory    memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    FT_FREE( phy_font->font_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    FT_FREE( phy_font->family_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
    FT_FREE( phy_font->style_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    FT_FREE( phy_font->vertical.stem_snaps );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    phy_font->vertical.num_stem_snaps = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    phy_font->horizontal.stem_snaps     = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    phy_font->horizontal.num_stem_snaps = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    FT_FREE( phy_font->strikes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    phy_font->num_strikes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    phy_font->max_strikes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    FT_FREE( phy_font->chars );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
    phy_font->num_chars    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    phy_font->chars_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
    FT_FREE( phy_font->blue_values );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
    phy_font->num_blue_values = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
      PFR_KernItem  item, next;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
      item = phy_font->kern_items;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
      while ( item )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
        next = item->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
        FT_FREE( item );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
        item = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
      phy_font->kern_items      = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      phy_font->kern_items_tail = NULL;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    phy_font->num_kern_pairs = 0;
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
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
  pfr_phy_font_load( PFR_PhyFont  phy_font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
                     FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
                     FT_UInt32    offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
                     FT_UInt32    size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    FT_UInt    flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    FT_ULong   num_aux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
    FT_Byte*   limit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
    phy_font->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    phy_font->offset = offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    phy_font->kern_items      = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
    phy_font->kern_items_tail = &phy_font->kern_items;
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
    if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    phy_font->cursor = stream->cursor;
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
    p     = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    limit = p + size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
    PFR_CHECK( 15 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
    phy_font->font_ref_number    = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
    phy_font->outline_resolution = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    phy_font->metrics_resolution = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    phy_font->bbox.xMin          = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
    phy_font->bbox.yMin          = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    phy_font->bbox.xMax          = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
    phy_font->bbox.yMax          = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
    phy_font->flags      = flags = PFR_NEXT_BYTE( p );
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
    /* get the standard advance for non-proportional fonts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
    if ( !(flags & PFR_PHY_PROPORTIONAL) )
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
      PFR_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      phy_font->standard_advance = PFR_NEXT_SHORT( p );
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
    /* load the extra items when present */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
    if ( flags & PFR_PHY_EXTRA_ITEMS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
      error =  pfr_extra_items_parse( &p, limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
                                      pfr_phy_font_extra_items, phy_font );
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
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
    /* In certain fonts, the auxiliary bytes contain interesting  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    /* information. These are not in the specification but can be */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
    /* guessed by looking at the content of a few PFR0 fonts.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
    PFR_CHECK( 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
    num_aux = PFR_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
    if ( num_aux > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
      FT_Byte*  q = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
      FT_Byte*  q2;
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
      PFR_CHECK( num_aux );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
      p += num_aux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
      while ( num_aux > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
        FT_UInt  length, type;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
        if ( q + 4 > p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
        length = PFR_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
        if ( length < 4 || length > num_aux )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
          break;
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
        q2   = q + length - 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
        type = PFR_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
        switch ( type )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
        case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
          /* this seems to correspond to the font's family name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
           * padded to 16-bits with one zero when necessary
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
          error = pfr_aux_name_load( q, length - 4U, memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
                                     &phy_font->family_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
        case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
          if ( q + 32 > q2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
            break;
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
          q += 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
          phy_font->ascent  = PFR_NEXT_SHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
          phy_font->descent = PFR_NEXT_SHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
          phy_font->leading = PFR_NEXT_SHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
          q += 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
        case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
          /* this seems to correspond to the font's style name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
           * padded to 16-bits with one zero when necessary
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
          error = pfr_aux_name_load( q, length - 4U, memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
                                     &phy_font->style_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
          break;
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
        default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
          ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
        q        = q2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
        num_aux -= length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
    /* read the blue values */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
      FT_UInt  n, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
      PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
      phy_font->num_blue_values = count = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
      PFR_CHECK( count * 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
      if ( FT_NEW_ARRAY( phy_font->blue_values, count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
        goto Fail;
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
      for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
        phy_font->blue_values[n] = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
    PFR_CHECK( 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
    phy_font->blue_fuzz  = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    phy_font->blue_scale = PFR_NEXT_BYTE( p );
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
    phy_font->vertical.standard   = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    phy_font->horizontal.standard = PFR_NEXT_USHORT( p );
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
    /* read the character descriptors */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      FT_UInt  n, count, Size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
      phy_font->num_chars    = count = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
      phy_font->chars_offset = offset + ( p - stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
      if ( FT_NEW_ARRAY( phy_font->chars, count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
      Size = 1 + 1 + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
      if ( flags & PFR_PHY_2BYTE_CHARCODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
        Size += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
      if ( flags & PFR_PHY_PROPORTIONAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
        Size += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
      if ( flags & PFR_PHY_ASCII_CODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
        Size += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
      if ( flags & PFR_PHY_2BYTE_GPS_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
        Size += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      if ( flags & PFR_PHY_3BYTE_GPS_OFFSET )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
        Size += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
      PFR_CHECK( count * Size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
        PFR_Char  cur = &phy_font->chars[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
        cur->char_code = ( flags & PFR_PHY_2BYTE_CHARCODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
                         ? PFR_NEXT_USHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
                         : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
        cur->advance   = ( flags & PFR_PHY_PROPORTIONAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
                         ? PFR_NEXT_SHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
                         : (FT_Int) phy_font->standard_advance;
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
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
        cur->ascii     = ( flags & PFR_PHY_ASCII_CODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
                         ? PFR_NEXT_BYTE( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
                         : 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
        if ( flags & PFR_PHY_ASCII_CODE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
          p += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
        cur->gps_size  = ( flags & PFR_PHY_2BYTE_GPS_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
                         ? PFR_NEXT_USHORT( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
                         : PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
        cur->gps_offset = ( flags & PFR_PHY_3BYTE_GPS_OFFSET )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
                          ? PFR_NEXT_ULONG( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
                          : PFR_NEXT_USHORT( p );
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
    /* that's it! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
    FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    /* save position of bitmap info */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
    phy_font->bct_offset = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
    phy_font->cursor     = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    FT_ERROR(( "pfr_phy_font_load: invalid physical font table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
    goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
/* END */