misc/libfreetype/src/sfnt/ttsbit.c
author nemo
Wed, 14 Sep 2011 14:14:23 -0400
changeset 5903 71466bccdf97
parent 5172 88f2e05288ba
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
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
/*  ttsbit.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
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*            2010 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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
   *  Alas, the memory-optimized sbit loader can't be used when implementing
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
   *  the `old internals' hack
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include "ttsbit0.c"
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
#else /* FT_CONFIG_OPTION_OLD_INTERNALS */
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#include "ttsbit.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#include "sferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /* 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
    46
  /* 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
    47
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#define FT_COMPONENT  trace_ttsbit
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /*    blit_sbit                                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /*    Blits a bitmap from an input stream into a given target.  Supports */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  /*    x and y offsets as well as byte padded lines.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /*    target      :: The target bitmap/pixmap.                           */
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
  /*    source      :: The input packed bitmap data.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  /*    line_bits   :: The number of bits per line.                        */
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
  /*    byte_padded :: A flag which is true if lines are byte-padded.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  /*    x_offset    :: The horizontal offset.                              */
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
  /*    y_offset    :: The vertical offset.                                */
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
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /*    IMPORTANT: The x and y offsets are relative to the top corner of   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /*               the target bitmap (unlike the normal TrueType           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  /*               convention).  A positive y offset indicates a downwards */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
  /*               direction!                                              */
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  blit_sbit( FT_Bitmap*  target,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
             FT_Byte*    source,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
             FT_Int      line_bits,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
             FT_Bool     byte_padded,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
             FT_Int      x_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
             FT_Int      y_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
             FT_Int      source_height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    FT_Byte*   line_buff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    FT_Int     line_incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    FT_Int     height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    FT_UShort  acc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    FT_UInt    loaded;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    /* first of all, compute starting write position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    line_incr = target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    line_buff = target->buffer;
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
    if ( line_incr < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
      line_buff -= line_incr * ( target->rows - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    line_buff += ( x_offset >> 3 ) + y_offset * line_incr;
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
    /* We use the extra-classic `accumulator' trick to extract the bits    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    /* from the source byte stream.                                        */
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
    /* Namely, the variable `acc' is a 16-bit accumulator containing the   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    /* last `loaded' bits from the input stream.  The bits are shifted to  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    /* the upmost position in `acc'.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    acc    = 0;  /* clear accumulator   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    loaded = 0;  /* no bits were loaded */
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
    for ( height = source_height; height > 0; height-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      FT_Byte*  cur   = line_buff;        /* current write cursor          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
      FT_Int    count = line_bits;        /* # of bits to extract per line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      FT_Byte   shift = (FT_Byte)( x_offset & 7 ); /* current write shift  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      FT_Byte   space = (FT_Byte)( 8 - shift );
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
      /* first of all, read individual source bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      if ( count >= 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
        count -= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
            FT_Byte  val;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
            /* ensure that there are at least 8 bits in the accumulator */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
            if ( loaded < 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
              acc    |= (FT_UShort)((FT_UShort)*source++ << ( 8 - loaded ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
              loaded += 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
            /* now write one byte */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
            val = (FT_Byte)( acc >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
            if ( shift )
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
              cur[0] |= (FT_Byte)( val >> shift );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
              cur[1] |= (FT_Byte)( val << space );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
              cur[0] |= val;
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
            cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
            acc   <<= 8;  /* remove bits from accumulator */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
            loaded -= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
            count  -= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
          } while ( count >= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
        /* restore `count' to correct value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
        count += 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      /* now write remaining bits (count < 8) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      if ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
        FT_Byte  val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
        /* ensure that there are at least `count' bits in the accumulator */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
        if ( (FT_Int)loaded < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
          acc    |= (FT_UShort)((FT_UShort)*source++ << ( 8 - loaded ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
          loaded += 8;
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
        /* now write remaining bits */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
        val     = (FT_Byte)( ( (FT_Byte)( acc >> 8 ) ) & ~( 0xFF >> count ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        cur[0] |= (FT_Byte)( val >> shift );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
        if ( count > space )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
          cur[1] |= (FT_Byte)( val << space );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
        acc   <<= count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
        loaded -= count;
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
      /* now, skip to next line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      if ( byte_padded )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        acc    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
        loaded = 0;   /* clear accumulator on byte-padded lines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      line_buff += line_incr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
  static const FT_Frame_Field  sbit_metrics_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
#define FT_STRUCTURE  TT_SBit_MetricsRec
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
    FT_FRAME_START( 8 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      FT_FRAME_BYTE( height ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      FT_FRAME_BYTE( width ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      FT_FRAME_CHAR( horiBearingX ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      FT_FRAME_CHAR( horiBearingY ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      FT_FRAME_BYTE( horiAdvance ),
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
      FT_FRAME_CHAR( vertBearingX ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      FT_FRAME_CHAR( vertBearingY ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      FT_FRAME_BYTE( vertAdvance ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    FT_FRAME_END
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
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
  /*    Load_SBit_Const_Metrics                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  /*    Loads the metrics for `EBLC' index tables format 2 and 5.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  /*    range  :: The target range.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
  /*    stream :: The input stream.                                        */
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
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
  /*    FreeType error code.  0 means success.                             */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  Load_SBit_Const_Metrics( TT_SBit_Range  range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
                           FT_Stream      stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    if ( FT_READ_ULONG( range->image_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    return FT_STREAM_READ_FIELDS( sbit_metrics_fields, &range->metrics );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  /*    Load_SBit_Range_Codes                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  /*    Loads the range codes for `EBLC' index tables format 4 and 5.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
  /*    range        :: The target range.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  /*    stream       :: The input stream.                                  */
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
  /*    load_offsets :: A flag whether to load the glyph offset table.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
  /*    FreeType error code.  0 means success.                             */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
  Load_SBit_Range_Codes( TT_SBit_Range  range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
                         FT_Stream      stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
                         FT_Bool        load_offsets )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
    FT_ULong   count, n, size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    if ( FT_READ_ULONG( count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    range->num_glyphs = count;
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
    /* Allocate glyph offsets table if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    if ( load_offsets )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
      if ( FT_NEW_ARRAY( range->glyph_offsets, count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      size = count * 4L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
      size = count * 2L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    /* Allocate glyph codes table and access frame */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    if ( FT_NEW_ARRAY ( range->glyph_codes, count ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
         FT_FRAME_ENTER( size )                     )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      goto Exit;
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
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      range->glyph_codes[n] = FT_GET_USHORT();
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
      if ( load_offsets )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
        range->glyph_offsets[n] = (FT_ULong)range->image_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
                                  FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    FT_FRAME_EXIT();
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
  /*    Load_SBit_Range                                                    */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
  /*    Loads a given `EBLC' index/range table.                            */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
  /*    range  :: The target range.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
  /*    stream :: The input stream.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
  Load_SBit_Range( TT_SBit_Range  range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
                   FT_Stream      stream )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    switch( range->index_format )
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
    case 1:   /* variable metrics with 4-byte offsets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    case 3:   /* variable metrics with 2-byte offsets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
        FT_ULong  num_glyphs, n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
        FT_Int    size_elem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
        FT_Bool   large = FT_BOOL( range->index_format == 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
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
        if ( range->last_glyph < range->first_glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
          error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
        num_glyphs        = range->last_glyph - range->first_glyph + 1L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
        range->num_glyphs = num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
        num_glyphs++;                       /* XXX: BEWARE - see spec */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
        size_elem = large ? 4 : 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
        if ( FT_NEW_ARRAY( range->glyph_offsets, num_glyphs ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
             FT_FRAME_ENTER( num_glyphs * size_elem )         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
        for ( n = 0; n < num_glyphs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
          range->glyph_offsets[n] = (FT_ULong)( range->image_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
                                                ( large ? FT_GET_ULONG()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
                                                        : FT_GET_USHORT() ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
        FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    case 2:   /* all glyphs have identical metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      error = Load_SBit_Const_Metrics( range, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
      break;
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
    case 4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      error = Load_SBit_Range_Codes( range, stream, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    case 5:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      error = Load_SBit_Const_Metrics( range, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
        error = Load_SBit_Range_Codes( range, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
  /*    tt_face_load_eblc                                                  */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
  /*    Loads the table of embedded bitmap sizes for this face.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  /*    face   :: The target face object.                                  */
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
  /*    stream :: The input stream.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
  tt_face_load_eblc( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
    FT_Error   error  = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    FT_Fixed   version;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    FT_ULong   num_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    FT_ULong   table_base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    static const FT_Frame_Field  sbit_line_metrics_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
#define FT_STRUCTURE  TT_SBit_LineMetricsRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
      /* no FT_FRAME_START */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        FT_FRAME_CHAR( ascender ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
        FT_FRAME_CHAR( descender ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        FT_FRAME_BYTE( max_width ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
        FT_FRAME_CHAR( caret_slope_numerator ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
        FT_FRAME_CHAR( caret_slope_denominator ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
        FT_FRAME_CHAR( caret_offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
        FT_FRAME_CHAR( min_origin_SB ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
        FT_FRAME_CHAR( min_advance_SB ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        FT_FRAME_CHAR( max_before_BL ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
        FT_FRAME_CHAR( min_after_BL ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        FT_FRAME_CHAR( pads[0] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
        FT_FRAME_CHAR( pads[1] ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
    static const FT_Frame_Field  strike_start_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
#define FT_STRUCTURE  TT_SBit_StrikeRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
      /* no FT_FRAME_START */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
        FT_FRAME_ULONG( ranges_offset ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
        FT_FRAME_SKIP_LONG,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
        FT_FRAME_ULONG( num_ranges ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
        FT_FRAME_ULONG( color_ref ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
    static const FT_Frame_Field  strike_end_fields[] =
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
      /* no FT_FRAME_START */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
        FT_FRAME_USHORT( start_glyph ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
        FT_FRAME_USHORT( end_glyph ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
        FT_FRAME_BYTE  ( x_ppem ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
        FT_FRAME_BYTE  ( y_ppem ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
        FT_FRAME_BYTE  ( bit_depth ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
        FT_FRAME_CHAR  ( flags ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
    face->num_sbit_strikes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    /* this table is optional */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    error = face->goto_table( face, TTAG_EBLC, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
      error = face->goto_table( face, TTAG_bloc, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    table_base = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    if ( FT_FRAME_ENTER( 8L ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      goto Exit;
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
    version     = FT_GET_LONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    num_strikes = FT_GET_ULONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    FT_FRAME_EXIT();
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
    /* check version number and strike count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    if ( version     != 0x00020000L ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
         num_strikes >= 0x10000L    )
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
      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
   499
      error = SFNT_Err_Invalid_File_Format;
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
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    /* allocate the strikes table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    if ( FT_NEW_ARRAY( face->sbit_strikes, num_strikes ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    face->num_sbit_strikes = num_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    /* now read each strike table separately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      TT_SBit_Strike  strike = face->sbit_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      FT_ULong        count  = num_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      if ( FT_FRAME_ENTER( 48L * num_strikes ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      while ( count > 0 )
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 ( FT_STREAM_READ_FIELDS( strike_start_fields, strike )             ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
             FT_STREAM_READ_FIELDS( sbit_line_metrics_fields, &strike->hori ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
             FT_STREAM_READ_FIELDS( sbit_line_metrics_fields, &strike->vert ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
             FT_STREAM_READ_FIELDS( strike_end_fields, strike )               )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
          break;
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
        count--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
        strike++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    /* allocate the index ranges for each strike table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
      TT_SBit_Strike  strike = face->sbit_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
      FT_ULong        count  = num_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
      while ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
        TT_SBit_Range  range;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
        FT_ULong       count2 = strike->num_ranges;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
        /* read each range */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
        if ( FT_STREAM_SEEK( table_base + strike->ranges_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
             FT_FRAME_ENTER( strike->num_ranges * 8L )            )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
          goto Exit;
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
        if ( FT_NEW_ARRAY( strike->sbit_ranges, strike->num_ranges ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
        range = strike->sbit_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        while ( count2 > 0 )
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
          range->first_glyph  = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
          range->last_glyph   = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
          range->table_offset = table_base + strike->ranges_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
                                  FT_GET_ULONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
          count2--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
          range++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
        FT_FRAME_EXIT();
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
        /* Now, read each index table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
        count2 = strike->num_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
        range  = strike->sbit_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        while ( count2 > 0 )
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
          /* Read the header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
          if ( FT_STREAM_SEEK( range->table_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
               FT_FRAME_ENTER( 8L )                  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
            goto Exit;
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
          range->index_format = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
          range->image_format = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
          range->image_offset = FT_GET_ULONG();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
          FT_FRAME_EXIT();
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
          error = Load_SBit_Range( range, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
          count2--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
          range++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
        count--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
        strike++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
  /*    tt_face_free_eblc                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
  /*    Releases the embedded bitmap tables.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
  /*    face :: The target face object.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
  tt_face_free_eblc( TT_Face  face )
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
    FT_Memory       memory       = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
    TT_SBit_Strike  strike       = face->sbit_strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
    TT_SBit_Strike  strike_limit = strike + face->num_sbit_strikes;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    if ( strike )
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
      for ( ; strike < strike_limit; strike++ )
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
        TT_SBit_Range  range       = strike->sbit_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        TT_SBit_Range  range_limit = range + strike->num_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
        if ( range )
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
          for ( ; range < range_limit; range++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
            /* release the glyph offsets and codes tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
            /* where appropriate                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
            FT_FREE( range->glyph_offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
            FT_FREE( range->glyph_codes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
        FT_FREE( strike->sbit_ranges );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
        strike->num_ranges = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      FT_FREE( face->sbit_strikes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    face->num_sbit_strikes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
  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
   649
                           FT_Size_Request  req,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
                           FT_ULong*        astrike_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    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
   653
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
  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
   658
                               FT_ULong          strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
                               FT_Size_Metrics*  metrics )
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
    TT_SBit_Strike  strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
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
    if ( strike_index >= face->num_sbit_strikes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
      return SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
    strike = face->sbit_strikes + strike_index;
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
    metrics->x_ppem = strike->x_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    metrics->y_ppem = strike->y_ppem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    metrics->ascender  = strike->hori.ascender << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
    metrics->descender = strike->hori.descender << 6;
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
    /* XXX: Is this correct? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    metrics->max_advance = ( strike->hori.min_origin_SB  +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
                             strike->hori.max_width      +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
                             strike->hori.min_advance_SB ) << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    metrics->height = metrics->ascender - metrics->descender;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
  /*    find_sbit_range                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
  /*    Scans a given strike's ranges and return, for a given glyph        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
  /*    index, the corresponding sbit range, and `EBDT' offset.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
  /*    glyph_index   :: The glyph index.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
  /*    strike        :: The source/current sbit strike.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
  /*    arange        :: The sbit range containing the glyph index.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
  /*    aglyph_offset :: The offset of the glyph data in `EBDT' table.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
  /*    FreeType error code.  0 means the glyph index was found.           */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
  find_sbit_range( FT_UInt          glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
                   TT_SBit_Strike   strike,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
                   TT_SBit_Range   *arange,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
                   FT_ULong        *aglyph_offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    TT_SBit_RangeRec  *range, *range_limit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    /* check whether the glyph index is within this strike's */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
    /* glyph range                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    if ( glyph_index < (FT_UInt)strike->start_glyph ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
         glyph_index > (FT_UInt)strike->end_glyph   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
      goto Fail;
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
    /* scan all ranges in strike */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
    range       = strike->sbit_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
    range_limit = range + strike->num_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    if ( !range )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
    for ( ; range < range_limit; range++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      if ( glyph_index >= (FT_UInt)range->first_glyph &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
           glyph_index <= (FT_UInt)range->last_glyph  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
        FT_UShort  delta = (FT_UShort)( glyph_index - range->first_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
        switch ( range->index_format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
        case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
        case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
          *aglyph_offset = range->glyph_offsets[delta];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
        case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
          *aglyph_offset = range->image_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
                           range->image_size * delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
          break;
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
        case 4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
        case 5:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
            FT_ULong  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
            for ( n = 0; n < range->num_glyphs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
              if ( (FT_UInt)range->glyph_codes[n] == glyph_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
                if ( range->index_format == 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
                  *aglyph_offset = range->glyph_offsets[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
                else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
                  *aglyph_offset = range->image_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
                                   n * range->image_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
                goto Found;
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
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
        /* fall-through */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
        default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
          goto Fail;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
      Found:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
        /* return successfully! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
        *arange  = range;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
        return SFNT_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    *arange        = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
    *aglyph_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
    return SFNT_Err_Invalid_Argument;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
  /*    tt_find_sbit_image                                                 */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
  /*    Checks whether an embedded bitmap (an `sbit') exists for a given   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
  /*    glyph, at a given strike.                                          */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
  /*    face          :: The target face object.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
  /*    glyph_index   :: The glyph index.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
  /*    strike_index  :: The current strike index.                         */
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
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
  /*    arange        :: The SBit range containing the glyph index.        */
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
  /*    astrike       :: The SBit strike containing the glyph index.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
  /*    aglyph_offset :: The offset of the glyph data in `EBDT' table.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
  /*    FreeType error code.  0 means success.  Returns                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
  /*    SFNT_Err_Invalid_Argument if no sbit exists for the requested      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
  /*    glyph.                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
  tt_find_sbit_image( TT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
                      FT_UInt          glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
                      FT_ULong         strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
                      TT_SBit_Range   *arange,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
                      TT_SBit_Strike  *astrike,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
                      FT_ULong        *aglyph_offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    TT_SBit_Strike  strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
    if ( !face->sbit_strikes                        ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
         ( face->num_sbit_strikes <= strike_index ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
    strike = &face->sbit_strikes[strike_index];
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
    error = find_sbit_range( glyph_index, strike,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
                             arange, aglyph_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
    *astrike = strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
    /* no embedded bitmap for this glyph in face */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
    *arange        = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
    *astrike       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    *aglyph_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    return SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
  /*    tt_load_sbit_metrics                                               */
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
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
  /*    Gets the big metrics for a given SBit.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
  /*    stream      :: The input stream.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
  /*    range       :: The SBit range containing the glyph.                */
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
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
  /*    big_metrics :: A big SBit metrics structure for the glyph.         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
  /* <Note>                                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
  /*    The stream cursor must be positioned at the glyph's offset within  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
  /*    the `EBDT' table before the call.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
  /*    If the image format uses variable metrics, the stream cursor is    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
  /*    positioned just after the metrics header in the `EBDT' table on    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
  /*    function exit.                                                     */
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
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
  tt_load_sbit_metrics( FT_Stream        stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
                        TT_SBit_Range    range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
                        TT_SBit_Metrics  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
    FT_Error  error = SFNT_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    switch ( range->image_format )
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
    case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
    case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
      /* variable small metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
        TT_SBit_SmallMetricsRec  smetrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
        static const FT_Frame_Field  sbit_small_metrics_fields[] =
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
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
#define FT_STRUCTURE  TT_SBit_SmallMetricsRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
          FT_FRAME_START( 5 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
            FT_FRAME_BYTE( height ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
            FT_FRAME_BYTE( width ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
            FT_FRAME_CHAR( bearingX ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
            FT_FRAME_CHAR( bearingY ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
            FT_FRAME_BYTE( advance ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
          FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
        };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
        /* read small metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
        if ( FT_STREAM_READ_FIELDS( sbit_small_metrics_fields, &smetrics ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
        /* convert it to a big metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
        metrics->height       = smetrics.height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
        metrics->width        = smetrics.width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
        metrics->horiBearingX = smetrics.bearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
        metrics->horiBearingY = smetrics.bearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
        metrics->horiAdvance  = smetrics.advance;
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
        /* these metrics are made up at a higher level when */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
        /* needed.                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
        metrics->vertBearingX = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
        metrics->vertBearingY = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
        metrics->vertAdvance  = 0;
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
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
    case 6:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    case 7:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
    case 9:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
      /* variable big metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
      if ( FT_STREAM_READ_FIELDS( sbit_metrics_fields, metrics ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
    case 5:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
    default:  /* constant metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
      if ( range->index_format == 2 || range->index_format == 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
        *metrics = range->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
        return SFNT_Err_Invalid_File_Format;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
  /*    crop_bitmap                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
  /*    Crops a bitmap to its tightest bounding box, and adjusts its       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
  /*    metrics.                                                           */
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
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
  /*    map     :: The bitmap.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
  /*    metrics :: The corresponding metrics structure.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
  crop_bitmap( FT_Bitmap*       map,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
               TT_SBit_Metrics  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
    /* In this situation, some bounding boxes of embedded bitmaps are too  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
    /* large.  We need to crop it to a reasonable size.                    */
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
    /*      ---------                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
    /*      |       |                -----                                 */
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
    /*      |   *   |                | * |                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    /*      |   *   |    ------>     | * |                                 */
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
    /*      ---------                -----                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
    FT_Int    rows, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    FT_Long   line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    FT_Byte*  line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
    /* first of all, check the top-most lines of the bitmap, and remove    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
    /* them if they're empty.                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
      line     = (FT_Byte*)map->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
      rows     = map->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
      line_len = map->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
      for ( count = 0; count < rows; count++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
        FT_Byte*  cur   = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
        FT_Byte*  limit = line + line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
        for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
          if ( cur[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
            goto Found_Top;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
        /* the current line was empty - skip to next one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
        line  = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    Found_Top:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
      /* check that we have at least one filled line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
      if ( count >= rows )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
        goto Empty_Bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
      /* now, crop the empty upper lines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
      if ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
        line = (FT_Byte*)map->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
        FT_MEM_MOVE( line, line + count * line_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
                     ( rows - count ) * line_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
        metrics->height       = (FT_Byte)( metrics->height - count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
        metrics->horiBearingY = (FT_Char)( metrics->horiBearingY - count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
        metrics->vertBearingY = (FT_Char)( metrics->vertBearingY - count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
        map->rows -= count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
        rows      -= count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
    /* second, crop the lower lines                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
      line = (FT_Byte*)map->buffer + ( rows - 1 ) * line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
      for ( count = 0; count < rows; count++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
        FT_Byte*  cur   = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
        FT_Byte*  limit = line + line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
        for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
          if ( cur[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
            goto Found_Bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
        /* the current line was empty - skip to previous one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
        line -= line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
    Found_Bottom:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
      if ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
        metrics->height  = (FT_Byte)( metrics->height - count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
        rows            -= count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
        map->rows       -= count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
    /* third, get rid of the space on the left side of the glyph           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
      FT_Byte*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
      line  = (FT_Byte*)map->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
      limit = line + rows * line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
      for ( ; line < limit; line += line_len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
        if ( line[0] & 0x80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
          goto Found_Left;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
      /* shift the whole glyph one pixel to the left */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
      line  = (FT_Byte*)map->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
      limit = line + rows * line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
      for ( ; line < limit; line += line_len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
        FT_Int    n, width = map->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
        FT_Byte   old;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
        FT_Byte*  cur = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
        old = (FT_Byte)(cur[0] << 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
        for ( n = 8; n < width; n += 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
          FT_Byte  val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
          val    = cur[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
          cur[0] = (FT_Byte)( old | ( val >> 7 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
          old    = (FT_Byte)( val << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
          cur++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
        cur[0] = old;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
      map->width--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
      metrics->horiBearingX++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
      metrics->vertBearingX++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
      metrics->width--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
    } while ( map->width > 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
  Found_Left:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
    /***********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
    /* finally, crop the bitmap width to get rid of the space on the right */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
    /* side of the glyph.                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
    /*                                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
      FT_Int    right = map->width - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
      FT_Byte*  limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
      FT_Byte   mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
      line  = (FT_Byte*)map->buffer + ( right >> 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
      limit = line + rows * line_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
      mask  = (FT_Byte)( 0x80 >> ( right & 7 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
      for ( ; line < limit; line += line_len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
        if ( line[0] & mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
          goto Found_Right;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
      /* crop the whole glyph to the right */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
      map->width--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
      metrics->width--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
    } while ( map->width > 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
  Found_Right:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    /* all right, the bitmap was cropped */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
    return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
  Empty_Bitmap:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
    map->width      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
    map->rows       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
    map->pitch      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
    map->pixel_mode = FT_PIXEL_MODE_MONO;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
  Load_SBit_Single( FT_Bitmap*       map,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
                    FT_Int           x_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
                    FT_Int           y_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
                    FT_Int           pix_bits,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
                    FT_UShort        image_format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
                    TT_SBit_Metrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
                    FT_Stream        stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
    /* check that the source bitmap fits into the target pixmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
    if ( x_offset < 0 || x_offset + metrics->width  > map->width ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
         y_offset < 0 || y_offset + metrics->height > map->rows  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
      error = SFNT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
      FT_Int   glyph_width  = metrics->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
      FT_Int   glyph_height = metrics->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
      FT_Int   glyph_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
      FT_Int   line_bits    = pix_bits * glyph_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
      FT_Bool  pad_bytes    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
      /* compute size of glyph image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
      switch ( image_format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
      case 1:  /* byte-padded formats */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
      case 6:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
          FT_Int  line_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
          switch ( pix_bits )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
          case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
            line_length = ( glyph_width + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
          case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
            line_length = ( glyph_width + 3 ) >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
          case 4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
            line_length = ( glyph_width + 1 ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
          default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
            line_length =   glyph_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
          glyph_size = glyph_height * line_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
          pad_bytes  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
      case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
      case 5:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
      case 7:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
        line_bits  =   glyph_width  * pix_bits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
        glyph_size = ( glyph_height * line_bits + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
      default:  /* invalid format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
        return SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
      /* Now read data and draw glyph into target pixmap       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
      if ( FT_FRAME_ENTER( glyph_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
      /* don't forget to multiply `x_offset' by `map->pix_bits' as */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
      /* the sbit blitter doesn't make a difference between pixmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
      /* depths.                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
      blit_sbit( map, (FT_Byte*)stream->cursor, line_bits, pad_bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
                 x_offset * pix_bits, y_offset, metrics->height );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
  Load_SBit_Image( TT_SBit_Strike   strike,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
                   TT_SBit_Range    range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
                   FT_ULong         ebdt_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
                   FT_ULong         glyph_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
                   FT_GlyphSlot     slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
                   FT_Int           x_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
                   FT_Int           y_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
                   FT_Stream        stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
                   TT_SBit_Metrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
                   FT_Int           depth )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
    FT_Memory   memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
    FT_Bitmap*  map    = &slot->bitmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
    /* place stream at beginning of glyph data and read metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
    if ( FT_STREAM_SEEK( ebdt_pos + glyph_offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
    error = tt_load_sbit_metrics( stream, range, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
    /* This function is recursive.  At the top-level call, we  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
    /* compute the dimensions of the higher-level glyph to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
    /* allocate the final pixmap buffer.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
    if ( depth == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
      FT_Long  size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
      map->width = metrics->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
      map->rows  = metrics->height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
      switch ( strike->bit_depth )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
        map->pixel_mode = FT_PIXEL_MODE_MONO;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
        map->pitch      = ( map->width + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
      case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
        map->pixel_mode = FT_PIXEL_MODE_GRAY2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
        map->pitch      = ( map->width + 3 ) >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
      case 4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
        map->pixel_mode = FT_PIXEL_MODE_GRAY4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
        map->pitch      = ( map->width + 1 ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
      case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
        map->pixel_mode = FT_PIXEL_MODE_GRAY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
        map->pitch      = map->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
        return SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
      size = map->rows * map->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
      /* check that there is no empty image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
      if ( size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
        goto Exit;     /* exit successfully! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
      error = ft_glyphslot_alloc_bitmap( slot, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
      if (error)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
    switch ( range->image_format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
    case 1:  /* single sbit image - load it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
    case 5:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
    case 6:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
    case 7:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
      return Load_SBit_Single( map, x_offset, y_offset, strike->bit_depth,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
                               range->image_format, metrics, stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
    case 8:  /* compound format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
      if ( FT_STREAM_SKIP( 1L ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
        error = SFNT_Err_Invalid_Stream_Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
      /* fallthrough */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
    case 9:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
    default: /* invalid image format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
      return SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
    /* All right, we have a compound format.  First of all, read */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
    /* the array of elements.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
      TT_SBit_Component  components;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
      TT_SBit_Component  comp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
      FT_UShort          num_components, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
      if ( FT_READ_USHORT( num_components )           ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
           FT_NEW_ARRAY( components, num_components ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
      count = num_components;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
      if ( FT_FRAME_ENTER( 4L * num_components ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
        goto Fail_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
      for ( comp = components; count > 0; count--, comp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
        comp->glyph_code = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
        comp->x_offset   = FT_GET_CHAR();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
        comp->y_offset   = FT_GET_CHAR();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
      /* Now recursively load each element glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
      count = num_components;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
      comp  = components;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
      for ( ; count > 0; count--, comp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
        TT_SBit_Range       elem_range;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
        TT_SBit_MetricsRec  elem_metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
        FT_ULong            elem_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
        /* find the range for this element */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
        error = find_sbit_range( comp->glyph_code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
                                 strike,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
                                 &elem_range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
                                 &elem_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
          goto Fail_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
        /* now load the element, recursively */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
        error = Load_SBit_Image( strike,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
                                 elem_range,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
                                 ebdt_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
                                 elem_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
                                 slot,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
                                 x_offset + comp->x_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
                                 y_offset + comp->y_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
                                 stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
                                 &elem_metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
                                 depth + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
          goto Fail_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
    Fail_Memory:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
      FT_FREE( components );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
  /*    tt_face_load_sbit_image                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
  /*    Loads a given glyph sbit image from the font resource.  This also  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
  /*    returns its metrics.                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
  /*    face         :: The target face object.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
  /*    strike_index :: The current strike index.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
  /*    glyph_index  :: The current glyph index.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
  /*    load_flags   :: The glyph load flags (the code checks for the flag */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
  /*                    FT_LOAD_CROP_BITMAP).                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
  /*    stream       :: The input stream.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
  /*    map          :: The target pixmap.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
  /*    metrics      :: A big sbit metrics structure for the glyph image.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
  /*    FreeType error code.  0 means success.  Returns an error if no     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
  /*    glyph sbit exists for the index.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
  /*  <Note>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
  /*    The `map.buffer' field is always freed before the glyph is loaded. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
  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
  1446
                           FT_ULong             strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
                           FT_UInt              glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
                           FT_UInt              load_flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
                           FT_Stream            stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
                           FT_Bitmap           *map,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
                           TT_SBit_MetricsRec  *metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
    FT_ULong        ebdt_pos, glyph_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
    TT_SBit_Strike  strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
    TT_SBit_Range   range;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
    /* Check whether there is a glyph sbit for the current index */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
    error = tt_find_sbit_image( face, glyph_index, strike_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
                                &range, &strike, &glyph_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
    /* now, find the location of the `EBDT' table in */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
    /* the font file                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
    error = face->goto_table( face, TTAG_EBDT, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
      error = face->goto_table( face, TTAG_bdat, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
    ebdt_pos = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
    error = Load_SBit_Image( strike, range, ebdt_pos, glyph_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
                             face->root.glyph, 0, 0, stream, metrics, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
    /* setup vertical metrics if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
    if ( strike->flags & 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
      /* in case of a horizontal strike only */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
      FT_Int  advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
      advance = strike->hori.ascender - strike->hori.descender;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
      /* some heuristic values */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
      metrics->vertBearingX = (FT_Char)(-metrics->width / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
      metrics->vertBearingY = (FT_Char)( ( advance - metrics->height ) / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
      metrics->vertAdvance  = (FT_Char)( advance * 12 / 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
    /* Crop the bitmap now, unless specified otherwise */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
    if ( load_flags & FT_LOAD_CROP_BITMAP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
      crop_bitmap( map, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
/* END */