misc/libfreetype/src/sfnt/ttsbit0.c
author nemo
Sun, 02 Sep 2012 09:23:36 -0400
changeset 7649 df90970ae81a
parent 5172 88f2e05288ba
permissions -rw-r--r--
Correct snow fall/rotation (matching visual gear)
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
/*  ttsbit0.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
/*    TrueType and OpenType embedded bitmap support (body).                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*    This is a heap-optimized version.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  Copyright 2005, 2006, 2007, 2008, 2009 by                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  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
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
/* This file is included by ttsbit.c */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "ttsbit.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include "sferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#define FT_COMPONENT  trace_ttsbit
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  tt_face_load_eblc( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
                     FT_Stream  stream )
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_Error  error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    FT_Fixed  version;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    FT_ULong  num_strikes, table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    FT_Byte*  p_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_UInt   count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    face->sbit_num_strikes = 0;
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
    /* this table is optional */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    error = face->goto_table( face, TTAG_EBLC, stream, &table_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
      error = face->goto_table( face, TTAG_bloc, stream, &table_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    if ( table_size < 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
      FT_ERROR(( "tt_face_load_sbit_strikes: table too short\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
      goto Exit;
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
    face->sbit_table_size = table_size;
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
    p       = face->sbit_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    p_limit = p + table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    version     = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    num_strikes = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    if ( version != 0x00020000UL || num_strikes >= 0x10000UL )
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
      FT_ERROR(( "tt_face_load_sbit_strikes: invalid table version\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      goto Fail;
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
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
     *  Count the number of strikes available in the table.  We are a bit
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
     *  paranoid there and don't trust the data.
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
    count = (FT_UInt)num_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    if ( 8 + 48UL * count > table_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      count = (FT_UInt)( ( p_limit - p ) / 48 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    face->sbit_num_strikes = count;
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
    FT_TRACE3(( "sbit_num_strikes: %u\n", count ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    return error;
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_FRAME_RELEASE( face->sbit_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    face->sbit_table_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    goto Exit;
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
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  tt_face_free_eblc( TT_Face  face )
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_Stream  stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    FT_FRAME_RELEASE( face->sbit_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    face->sbit_table_size  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    face->sbit_num_strikes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  tt_face_set_sbit_strike( TT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
                           FT_Size_Request  req,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
                           FT_ULong*        astrike_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    return FT_Match_Size( (FT_Face)face, req, 0, astrike_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
  tt_face_load_strike_metrics( TT_Face           face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
                               FT_ULong          strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
                               FT_Size_Metrics*  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    FT_Byte*  strike;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    if ( strike_index >= (FT_ULong)face->sbit_num_strikes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      return SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    strike = face->sbit_table + 8 + strike_index * 48;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    metrics->x_ppem = (FT_UShort)strike[44];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    metrics->y_ppem = (FT_UShort)strike[45];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    metrics->ascender  = (FT_Char)strike[16] << 6;  /* hori.ascender  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    metrics->descender = (FT_Char)strike[17] << 6;  /* hori.descender */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    metrics->height    = metrics->ascender - metrics->descender;
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
    /* XXX: Is this correct? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
                                      strike[18] + /* max_width      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
                             (FT_Char)strike[23]   /* min_advance_SB */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
                                                 ) << 6;
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
    return SFNT_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  typedef struct  TT_SBitDecoderRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    TT_Face          face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    FT_Stream        stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    FT_Bitmap*       bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    TT_SBit_Metrics  metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    FT_Bool          metrics_loaded;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    FT_Bool          bitmap_allocated;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    FT_Byte          bit_depth;
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
    FT_ULong         ebdt_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    FT_ULong         ebdt_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    FT_ULong         strike_index_array;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    FT_ULong         strike_index_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    FT_Byte*         eblc_base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    FT_Byte*         eblc_limit;
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
  } TT_SBitDecoderRec, *TT_SBitDecoder;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
  tt_sbit_decoder_init( TT_SBitDecoder       decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
                        TT_Face              face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
                        FT_ULong             strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
                        TT_SBit_MetricsRec*  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    FT_Stream  stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    FT_ULong   ebdt_size;
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
    error = face->goto_table( face, TTAG_EBDT, stream, &ebdt_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      error = face->goto_table( face, TTAG_bdat, stream, &ebdt_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
      goto Exit;
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
    decoder->face    = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    decoder->stream  = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    decoder->bitmap  = &face->root.glyph->bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    decoder->metrics = metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    decoder->metrics_loaded   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    decoder->bitmap_allocated = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    decoder->ebdt_start = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    decoder->ebdt_size  = ebdt_size;
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
    decoder->eblc_base  = face->sbit_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    decoder->eblc_limit = face->sbit_table + face->sbit_table_size;
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
    /* now find the strike corresponding to the index */
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
      FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      if ( 8 + 48 * strike_index + 3 * 4 + 34 + 1 > face->sbit_table_size )
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
        error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      p = decoder->eblc_base + 8 + 48 * strike_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      decoder->strike_index_array = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      p                          += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      decoder->strike_index_count = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
      p                          += 34;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      decoder->bit_depth          = *p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      if ( decoder->strike_index_array > face->sbit_table_size             ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
           decoder->strike_index_array + 8 * decoder->strike_index_count >
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
             face->sbit_table_size                                         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
        error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  tt_sbit_decoder_done( TT_SBitDecoder  decoder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    FT_UNUSED( decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
  tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder  decoder )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    FT_Error    error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    FT_UInt     width, height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    FT_Bitmap*  map = decoder->bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    FT_Long     size;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    if ( !decoder->metrics_loaded )
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
      error = SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    width  = decoder->metrics->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    height = decoder->metrics->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    map->width = (int)width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    map->rows  = (int)height;
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
    switch ( decoder->bit_depth )
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
    case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      map->pixel_mode = FT_PIXEL_MODE_MONO;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      map->pitch      = ( map->width + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      map->pixel_mode = FT_PIXEL_MODE_GRAY2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      map->pitch      = ( map->width + 3 ) >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
      break;
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
    case 4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
      map->pixel_mode = FT_PIXEL_MODE_GRAY4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
      map->pitch      = ( map->width + 1 ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      map->pixel_mode = FT_PIXEL_MODE_GRAY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
      map->pitch      = map->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    size = map->rows * map->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    /* check that there is no empty image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    if ( size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      goto Exit;     /* exit successfully! */
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
    error = ft_glyphslot_alloc_bitmap( decoder->face->root.glyph, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      goto Exit;
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
    decoder->bitmap_allocated = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  }
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
  tt_sbit_decoder_load_metrics( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
                                FT_Byte*       *pp,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
                                FT_Byte*        limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
                                FT_Bool         big )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    FT_Byte*         p       = *pp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    TT_SBit_Metrics  metrics = decoder->metrics;
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
    if ( p + 5 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      goto Fail;
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
    metrics->height       = p[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    metrics->width        = p[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
    metrics->horiBearingX = (FT_Char)p[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    metrics->horiBearingY = (FT_Char)p[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    metrics->horiAdvance  = p[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    p += 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    if ( big )
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
      if ( p + 3 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
        goto Fail;
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
      metrics->vertBearingX = (FT_Char)p[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      metrics->vertBearingY = (FT_Char)p[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      metrics->vertAdvance  = p[2];
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
      p += 3;
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
    decoder->metrics_loaded = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    *pp = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    return SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  /* forward declaration */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  tt_sbit_decoder_load_image( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
                              FT_UInt         glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
                              FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
                              FT_Int          y_pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
  typedef FT_Error  (*TT_SBitDecoder_LoadFunc)( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
                                                FT_Byte*        p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
                                                FT_Byte*        plimit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
                                                FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
                                                FT_Int          y_pos );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
  tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
                                     FT_Byte*        p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
                                     FT_Byte*        limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
                                     FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
                                     FT_Int          y_pos )
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
    FT_Error    error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    FT_Byte*    line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    FT_Int      bit_height, bit_width, pitch, width, height, h;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    FT_Bitmap*  bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
    if ( !decoder->bitmap_allocated )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      error = tt_sbit_decoder_alloc_bitmap( decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    }
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
    /* check that we can write the glyph into the bitmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
    bitmap     = decoder->bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    bit_width  = bitmap->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    bit_height = bitmap->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
    pitch      = bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    line       = bitmap->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    width  = decoder->metrics->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    height = decoder->metrics->height;
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
    if ( x_pos < 0 || x_pos + width > bit_width   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
         y_pos < 0 || y_pos + height > bit_height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    if ( p + ( ( width + 7 ) >> 3 ) * height > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
    /* now do the blit */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
    line  += y_pos * pitch + ( x_pos >> 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
    x_pos &= 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    if ( x_pos == 0 )  /* the easy one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      for ( h = height; h > 0; h--, line += pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
        FT_Byte*  write = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
        FT_Int    w;
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
        for ( w = width; w >= 8; w -= 8 )
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
          write[0] = (FT_Byte)( write[0] | *p++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
          write   += 1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
        if ( w > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
          write[0] = (FT_Byte)( write[0] | ( *p++ & ( 0xFF00U >> w ) ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    else  /* x_pos > 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      for ( h = height; h > 0; h--, line += pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
        FT_Byte*  write = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
        FT_Int    w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        FT_UInt   wval = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        for ( w = width; w >= 8; w -= 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
          wval      = (FT_UInt)( wval | *p++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
          write[0]  = (FT_Byte)( write[0] | ( wval >> x_pos ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
          write    += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
          wval    <<= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
        if ( w > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
          wval = (FT_UInt)( wval | ( *p++ & ( 0xFF00U >> w ) ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
        /* all bits read and there are `x_pos + w' bits to be written */
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
        write[0] = (FT_Byte)( write[0] | ( wval >> x_pos ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        if ( x_pos + w > 8 )
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
          write++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
          wval   <<= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
          write[0] = (FT_Byte)( write[0] | ( wval >> x_pos ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
  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
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
   * Load a bit-aligned bitmap (with pointer `p') into a line-aligned bitmap
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
   * (with pointer `write').  In the example below, the width is 3 pixel,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
   * and `x_pos' is 1 pixel.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
   *       p                               p+1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
   *     |                               |                               |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
   *     | 7   6   5   4   3   2   1   0 | 7   6   5   4   3   2   1   0 |...
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
   *     |                               |                               |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
   *       +-------+   +-------+   +-------+ ...
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
   *           .           .           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
   *           .           .           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
   *           v           .           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
   *       +-------+       .           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
   * |                               | .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
   * | 7   6   5   4   3   2   1   0 | .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
   * |                               | .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
   *   write               .           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
   *                       .           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
   *                       v           .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
   *                   +-------+       .
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
   *             | 7   6   5   4   3   2   1   0 |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
   *             |                               |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
   *               write+1             .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
   *                                   .
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
   *                                   v
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
   *                               +-------+
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
   *                         |                               |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
   *                         | 7   6   5   4   3   2   1   0 |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
   *                         |                               |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
   *                           write+2
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
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
  tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
                                    FT_Byte*        p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
                                    FT_Byte*        limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
                                    FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
                                    FT_Int          y_pos )
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
    FT_Error    error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    FT_Byte*    line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
    FT_Int      bit_height, bit_width, pitch, width, height, h, nbits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
    FT_Bitmap*  bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    FT_UShort   rval;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    if ( !decoder->bitmap_allocated )
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
      error = tt_sbit_decoder_alloc_bitmap( decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
        goto Exit;
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
    /* check that we can write the glyph into the bitmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    bitmap     = decoder->bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    bit_width  = bitmap->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
    bit_height = bitmap->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    pitch      = bitmap->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
    line       = bitmap->buffer;
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
    width  = decoder->metrics->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    height = decoder->metrics->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    if ( x_pos < 0 || x_pos + width  > bit_width  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
         y_pos < 0 || y_pos + height > bit_height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    if ( p + ( ( width * height + 7 ) >> 3 ) > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
    /* now do the blit */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    /* adjust `line' to point to the first byte of the bitmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
    line  += y_pos * pitch + ( x_pos >> 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    x_pos &= 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
    /* the higher byte of `rval' is used as a buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    rval  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    nbits = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    for ( h = height; h > 0; h--, line += pitch )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      FT_Byte*  write = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      FT_Int    w     = width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
      /* handle initial byte (in target bitmap) specially if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
      if ( x_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        w = ( width < 8 - x_pos ) ? width : 8 - x_pos;
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
        if ( h == height )
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
          rval  = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
          nbits = x_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
        else if ( nbits < w )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
          if ( p < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
            rval |= *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
          nbits += 8 - w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
          rval  >>= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
          nbits  -= w;
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
        *write++ |= ( ( rval >> nbits ) & 0xFF ) &
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
                    ( ~( 0xFF << w ) << ( 8 - w - x_pos ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
        rval    <<= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
        w = width - w;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
      /* handle medial bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
      for ( ; w >= 8; w -= 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
        rval     |= *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
        *write++ |= ( rval >> nbits ) & 0xFF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
        rval <<= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
      /* handle final byte if necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
      if ( w > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
        if ( nbits < w )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
          if ( p < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
            rval |= *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
          *write |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
          nbits  += 8 - w;
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
          rval <<= 8;
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
          *write |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
          nbits  -= w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
        }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
  tt_sbit_decoder_load_compound( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
                                 FT_Byte*        p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
                                 FT_Byte*        limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
                                 FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
                                 FT_Int          y_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    FT_Error  error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    FT_UInt   num_components, nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    FT_Char  horiBearingX = decoder->metrics->horiBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    FT_Char  horiBearingY = decoder->metrics->horiBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    FT_Byte  horiAdvance  = decoder->metrics->horiAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    FT_Char  vertBearingX = decoder->metrics->vertBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
    FT_Char  vertBearingY = decoder->metrics->vertBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    FT_Byte  vertAdvance  = decoder->metrics->vertAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
    if ( p + 2 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
    num_components = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    if ( p + 4 * num_components > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
      goto Fail;
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 ( !decoder->bitmap_allocated )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
      error = tt_sbit_decoder_alloc_bitmap( decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    for ( nn = 0; nn < num_components; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
      FT_UInt  gindex = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
      FT_Byte  dx     = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
      FT_Byte  dy     = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
      /* NB: a recursive call */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
      error = tt_sbit_decoder_load_image( decoder, gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
                                          x_pos + dx, y_pos + dy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
        break;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    decoder->metrics->horiBearingX = horiBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
    decoder->metrics->horiBearingY = horiBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    decoder->metrics->horiAdvance  = horiAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    decoder->metrics->vertBearingX = vertBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    decoder->metrics->vertBearingY = vertBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    decoder->metrics->vertAdvance  = vertAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    decoder->metrics->width        = (FT_UInt)decoder->bitmap->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    decoder->metrics->height       = (FT_UInt)decoder->bitmap->rows;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
    error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
    goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
  tt_sbit_decoder_load_bitmap( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
                               FT_UInt         glyph_format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
                               FT_ULong        glyph_start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
                               FT_ULong        glyph_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
                               FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
                               FT_Int          y_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    FT_Stream  stream = decoder->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    FT_Byte*   p_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    FT_Byte*   data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    /* seek into the EBDT table now */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    if ( glyph_start + glyph_size > decoder->ebdt_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
      error = SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
    if ( FT_STREAM_SEEK( decoder->ebdt_start + glyph_start ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
         FT_FRAME_EXTRACT( glyph_size, data )                )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    p       = data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    p_limit = p + glyph_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
    /* read the data, depending on the glyph format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
    switch ( glyph_format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
      error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
    case 6:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    case 7:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    case 9:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
      error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
      error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      TT_SBitDecoder_LoadFunc  loader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
      switch ( glyph_format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
      case 6:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
        loader = tt_sbit_decoder_load_byte_aligned;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
        break;
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
      case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
      case 5:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
      case 7:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
        loader = tt_sbit_decoder_load_bit_aligned;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
        break;
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
      case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
        if ( p + 1 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
          goto Fail;
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
        p += 1;  /* skip padding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
        /* fall-through */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
      case 9:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
        loader = tt_sbit_decoder_load_compound;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
      error = loader( decoder, p, p_limit, x_pos, y_pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
    FT_FRAME_RELEASE( data );
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
  tt_sbit_decoder_load_image( TT_SBitDecoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
                              FT_UInt         glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
                              FT_Int          x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
                              FT_Int          y_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
     *  First, we find the correct strike range that applies to this
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
     *  glyph index.
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
    FT_Byte*  p          = decoder->eblc_base + decoder->strike_index_array;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
    FT_Byte*  p_limit    = decoder->eblc_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
    FT_ULong  num_ranges = decoder->strike_index_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    FT_UInt   start, end, index_format, image_format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    FT_ULong  image_start = 0, image_end = 0, image_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
    for ( ; num_ranges > 0; num_ranges-- )
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
      start = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
      end   = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
      if ( glyph_index >= start && glyph_index <= end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
        goto FoundRange;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
      p += 4;  /* ignore index offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
    goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
  FoundRange:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
    image_offset = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
    /* overflow check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
    if ( decoder->eblc_base + decoder->strike_index_array + image_offset <
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
           decoder->eblc_base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
      goto Failure;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    p = decoder->eblc_base + decoder->strike_index_array + image_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
    if ( p + 8 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
      goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
    /* now find the glyph's location and extend within the ebdt table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
    index_format = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
    image_format = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
    image_offset = FT_NEXT_ULONG ( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
    switch ( index_format )
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
    case 1: /* 4-byte offsets relative to `image_offset' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
        p += 4 * ( glyph_index - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
        if ( p + 8 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
          goto NoBitmap;
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
        image_start = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
        image_end   = FT_NEXT_ULONG( 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
        if ( image_start == image_end )  /* missing glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
      break;
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
    case 2: /* big metrics, constant image size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
        FT_ULong  image_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
        if ( p + 12 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
          goto NoBitmap;
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
        image_size = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
        if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
          goto NoBitmap;
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
        image_start = image_size * ( glyph_index - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
        image_end   = image_start + image_size;
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
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
    case 3: /* 2-byte offsets relative to 'image_offset' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
        p += 2 * ( glyph_index - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
        if ( p + 4 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
        image_start = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
        image_end   = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
        if ( image_start == image_end )  /* missing glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
      break;
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
    case 4: /* sparse glyph array with (glyph,offset) pairs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
        FT_ULong  mm, num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
        if ( p + 4 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
          goto NoBitmap;
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
        num_glyphs = FT_NEXT_ULONG( p );
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
        /* overflow check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
        if ( p + ( num_glyphs + 1 ) * 4 < p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
          goto Failure;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
        if ( p + ( num_glyphs + 1 ) * 4 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
          goto NoBitmap;
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
        for ( mm = 0; mm < num_glyphs; mm++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
          FT_UInt  gindex = FT_NEXT_USHORT( p );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
          if ( gindex == glyph_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
            image_start = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
            p          += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
            image_end   = FT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
          p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
        if ( mm >= num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
      break;
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
    case 5: /* constant metrics with sparse glyph codes */
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
        FT_ULong  image_size, mm, num_glyphs;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
        if ( p + 16 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
        image_size = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
        if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
        num_glyphs = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
        /* overflow check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
        if ( p + 2 * num_glyphs < p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
          goto Failure;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
        if ( p + 2 * num_glyphs > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
        for ( mm = 0; mm < num_glyphs; mm++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
          FT_UInt  gindex = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
          if ( gindex == glyph_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
        if ( mm >= num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
          goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
        image_start = image_size * mm;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
        image_end   = image_start + image_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
      goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    if ( image_start > image_end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
      goto NoBitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
    image_end  -= image_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
    image_start = image_offset + image_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
    return tt_sbit_decoder_load_bitmap( decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
                                        image_format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
                                        image_start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
                                        image_end,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
                                        x_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
                                        y_pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
  Failure:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
    return SFNT_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
  NoBitmap:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    return SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
  tt_face_load_sbit_image( TT_Face              face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
                           FT_ULong             strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
                           FT_UInt              glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
                           FT_UInt              load_flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
                           FT_Stream            stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
                           FT_Bitmap           *map,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
                           TT_SBit_MetricsRec  *metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
    TT_SBitDecoderRec  decoder[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
    FT_Error           error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
    FT_UNUSED( load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    FT_UNUSED( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
    FT_UNUSED( map );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    error = tt_sbit_decoder_init( decoder, face, strike_index, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
      error = tt_sbit_decoder_load_image( decoder, glyph_index, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
      tt_sbit_decoder_done( decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
/* EOF */