misc/libfreetype/src/pfr/pfrsbit.c
author koda
Wed, 06 Mar 2013 16:42:56 +0100
changeset 8672 4cccc0520988
parent 5172 88f2e05288ba
permissions -rw-r--r--
our cmake modules have become good enough, prefer them over system ones
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
/*  pfrsbit.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType PFR bitmap loader (body).                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2002, 2003, 2006, 2009, 2010 by                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include "pfrsbit.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "pfrload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_STREAM_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
#include "pfrerror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#define FT_COMPONENT  trace_pfr
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /*****                      PFR BIT WRITER                           *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  typedef struct  PFR_BitWriter_
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
    FT_Byte*  line;      /* current line start                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    FT_Int    pitch;     /* line size in bytes                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    FT_Int    width;     /* width in pixels/bits                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    FT_Int    rows;      /* number of remaining rows to scan      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    FT_Int    total;     /* total number of bits to draw          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  } PFR_BitWriterRec, *PFR_BitWriter;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  pfr_bitwriter_init( PFR_BitWriter  writer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
                      FT_Bitmap*     target,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
                      FT_Bool        decreasing )
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
    writer->line   = target->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    writer->pitch  = target->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    writer->width  = target->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    writer->rows   = target->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    writer->total  = writer->width * writer->rows;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    if ( !decreasing )
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
      writer->line += writer->pitch * ( target->rows-1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
      writer->pitch = -writer->pitch;
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
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  pfr_bitwriter_decode_bytes( PFR_BitWriter  writer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
                              FT_Byte*       p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                              FT_Byte*       limit )
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
    FT_Int    n, reload;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    FT_Int    left = writer->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    FT_Byte*  cur  = writer->line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    FT_UInt   mask = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    FT_UInt   val  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    FT_UInt   c    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    n = (FT_Int)( limit - p ) * 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    if ( n > writer->total )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
      n = writer->total;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    reload = n & 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    for ( ; n > 0; n-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      if ( ( n & 7 ) == reload )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
        val = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
      if ( val & 0x80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
        c |= mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      val  <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      mask >>= 1;
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
      if ( --left <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
        cur[0] = (FT_Byte)c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
        left   = writer->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
        mask   = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
        writer->line += writer->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
        cur           = writer->line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
        c             = 0;
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
      else if ( mask == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        cur[0] = (FT_Byte)c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
        mask   = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
        c      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
        cur ++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    }
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
    if ( mask != 0x80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
      cur[0] = (FT_Byte)c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  pfr_bitwriter_decode_rle1( PFR_BitWriter  writer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
                             FT_Byte*       p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
                             FT_Byte*       limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    FT_Int    n, phase, count, counts[2], reload;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    FT_Int    left = writer->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    FT_Byte*  cur  = writer->line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    FT_UInt   mask = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    FT_UInt   c    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    n = writer->total;
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
    phase     = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    counts[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    counts[1] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    count     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    reload    = 1;
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
    for ( ; n > 0; n-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
      if ( reload )
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
        do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
          if ( phase )
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
            FT_Int  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
            if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
              break;
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
            v         = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
            counts[0] = v >> 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
            counts[1] = v & 15;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
            phase     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
            count     = counts[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
          else
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
            phase = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
            count = counts[1];
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
        } while ( count == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      if ( phase )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
        c |= mask;
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
      mask >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      if ( --left <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
        cur[0] = (FT_Byte) c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
        left   = writer->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
        mask   = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
        writer->line += writer->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        cur           = writer->line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        c             = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
      else if ( mask == 0 )
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
        cur[0] = (FT_Byte)c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
        mask   = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
        c      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
        cur ++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      reload = ( --count <= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    if ( mask != 0x80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      cur[0] = (FT_Byte) c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
  pfr_bitwriter_decode_rle2( PFR_BitWriter  writer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
                             FT_Byte*       p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
                             FT_Byte*       limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    FT_Int    n, phase, count, reload;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    FT_Int    left = writer->width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    FT_Byte*  cur  = writer->line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    FT_UInt   mask = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    FT_UInt   c    = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    n = writer->total;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    phase  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    count  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    reload = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    for ( ; n > 0; n-- )
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
      if ( reload )
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
        do
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
          if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
            break;
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
          count = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
          phase = phase ^ 1;
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
        } while ( count == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      if ( phase )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
        c |= mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      mask >>= 1;
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
      if ( --left <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
        cur[0] = (FT_Byte) c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        c      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
        mask   = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
        left   = writer->width;
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
        writer->line += writer->pitch;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
        cur           = writer->line;
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
      else if ( mask == 0 )
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
        cur[0] = (FT_Byte)c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
        c      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
        mask   = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
        cur ++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
      reload = ( --count <= 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    if ( mask != 0x80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      cur[0] = (FT_Byte) c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  /*****                  BITMAP DATA DECODING                         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
  pfr_lookup_bitmap_data( FT_Byte*   base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
                          FT_Byte*   limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
                          FT_UInt    count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
                          FT_UInt    flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
                          FT_UInt    char_code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
                          FT_ULong*  found_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
                          FT_ULong*  found_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    FT_UInt   left, right, char_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
    FT_Bool   two = FT_BOOL( flags & 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    FT_Byte*  buff;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    char_len = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    if ( two )       char_len += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    if ( flags & 2 ) char_len += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    if ( flags & 4 ) char_len += 1;
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
    left  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    right = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    while ( left < right )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      FT_UInt  middle, code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      middle = ( left + right ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      buff   = base + middle * char_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      /* check that we are not outside of the table -- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      /* this is possible with broken fonts...         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      if ( buff + char_len > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
      if ( two )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
        code = PFR_NEXT_USHORT( buff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
        code = PFR_NEXT_BYTE( buff );
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
      if ( code == char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
        goto Found_It;
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
      if ( code < char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
        left = middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
        right = middle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    /* Not found */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    *found_size   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    *found_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  Found_It:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    if ( flags & 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      *found_size = PFR_NEXT_USHORT( buff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      *found_size = PFR_NEXT_BYTE( buff );
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
    if ( flags & 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
      *found_offset = PFR_NEXT_ULONG( buff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      *found_offset = PFR_NEXT_USHORT( buff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
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
  /* load bitmap metrics.  "*padvance" must be set to the default value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  /* before calling this function...                                    */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  pfr_load_bitmap_metrics( FT_Byte**  pdata,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
                           FT_Byte*   limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
                           FT_Long    scaled_advance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
                           FT_Long   *axpos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
                           FT_Long   *aypos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
                           FT_UInt   *axsize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
                           FT_UInt   *aysize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
                           FT_Long   *aadvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
                           FT_UInt   *aformat )
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
    FT_Error  error = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
    FT_Byte   flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
    FT_Char   b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    FT_Byte*  p = *pdata;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    FT_Long   xpos, ypos, advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    FT_UInt   xsize, ysize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
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
    PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    flags = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    xpos    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    ypos    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
    xsize   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    ysize   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
    advance = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    switch ( flags & 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
    case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
      b    = PFR_NEXT_INT8( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
      xpos = b >> 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      ypos = ( (FT_Char)( b << 4 ) ) >> 4;
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 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      PFR_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      xpos = PFR_NEXT_INT8( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      ypos = PFR_NEXT_INT8( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      PFR_CHECK( 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      xpos = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
      ypos = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      PFR_CHECK( 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      xpos = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      ypos = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      break;
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
    default:
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    flags >>= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    switch ( flags & 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      /* blank image */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
      xsize = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
      ysize = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
    case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
      PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
      b     = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      xsize = ( b >> 4 ) & 0xF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      ysize = b & 0xF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      PFR_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
      xsize = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
      ysize = PFR_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
    case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      PFR_CHECK( 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      xsize = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      ysize = PFR_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      break;
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
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    flags >>= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
    switch ( flags & 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
    case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      advance = scaled_advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
      PFR_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
      advance = PFR_NEXT_INT8( p ) << 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
      PFR_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
      advance = PFR_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
    case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
      PFR_CHECK( 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
      advance = PFR_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
      ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    }
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
    *axpos    = xpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
    *aypos    = ypos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    *axsize   = xsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    *aysize   = ysize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    *aadvance = advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    *aformat  = flags >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    *pdata    = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
  Too_Short:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
    FT_ERROR(( "pfr_load_bitmap_metrics: invalid glyph data\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
    goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
  pfr_load_bitmap_bits( FT_Byte*    p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
                        FT_Byte*    limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
                        FT_UInt     format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
                        FT_Bool     decreasing,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
                        FT_Bitmap*  target )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    FT_Error          error = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    PFR_BitWriterRec  writer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    if ( target->rows > 0 && target->width > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
      pfr_bitwriter_init( &writer, target, decreasing );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
      switch ( format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
      case 0: /* packed bits */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
        pfr_bitwriter_decode_bytes( &writer, p, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
        break;
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
      case 1: /* RLE1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
        pfr_bitwriter_decode_rle1( &writer, p, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
      case 2: /* RLE2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
        pfr_bitwriter_decode_rle2( &writer, p, limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
        FT_ERROR(( "pfr_read_bitmap_data: invalid image type\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
        error = PFR_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
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
  /*************************************************************************/
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
  /*****                     BITMAP LOADING                            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
  /*************************************************************************/
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
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
  pfr_slot_load_bitmap( PFR_Slot  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
                        PFR_Size  size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
                        FT_UInt   glyph_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    FT_Error     error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
    PFR_Face     face   = (PFR_Face) glyph->root.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    FT_Stream    stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    PFR_PhyFont  phys   = &face->phy_font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    FT_ULong     gps_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    FT_ULong     gps_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    PFR_Char     character;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    PFR_Strike   strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    character = &phys->chars[glyph_index];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    /* Look-up a bitmap strike corresponding to the current */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    /* character dimensions                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      FT_UInt  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
      strike = phys->strikes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      for ( n = 0; n < phys->num_strikes; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
        if ( strike->x_ppm == (FT_UInt)size->root.metrics.x_ppem &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
             strike->y_ppm == (FT_UInt)size->root.metrics.y_ppem )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
          goto Found_Strike;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
        strike++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
      /* couldn't find it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
      return PFR_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
  Found_Strike:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    /* Now lookup the glyph's position within the file */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
      FT_UInt  char_len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
      char_len = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
      if ( strike->flags & 1 ) char_len += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
      if ( strike->flags & 2 ) char_len += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
      if ( strike->flags & 4 ) char_len += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      /* Access data directly in the frame to speed lookups */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
      if ( FT_STREAM_SEEK( phys->bct_offset + strike->bct_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
           FT_FRAME_ENTER( char_len * strike->num_bitmaps )        )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
        goto 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
      pfr_lookup_bitmap_data( stream->cursor,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
                              stream->limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
                              strike->num_bitmaps,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
                              strike->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
                              character->char_code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
                              &gps_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
                              &gps_size );
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
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      if ( gps_size == 0 )
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
        /* Could not find a bitmap program string for this glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
        error = PFR_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
        goto Exit;
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
    /* get the bitmap metrics */
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
      FT_Long   xpos = 0, ypos = 0, advance = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
      FT_UInt   xsize = 0, ysize = 0, format = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
      FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
      /* compute linear advance */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
      advance = character->advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
      if ( phys->metrics_resolution != phys->outline_resolution )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
        advance = FT_MulDiv( advance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
                             phys->outline_resolution,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
                             phys->metrics_resolution );
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
      glyph->root.linearHoriAdvance = advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      /* compute default advance, i.e., scaled advance.  This can be */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      /* overridden in the bitmap header of certain glyphs.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
      advance = FT_MulDiv( (FT_Fixed)size->root.metrics.x_ppem << 8,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
                           character->advance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
                           phys->metrics_resolution );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      if ( FT_STREAM_SEEK( face->header.gps_section_offset + gps_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
           FT_FRAME_ENTER( gps_size )                                     )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        goto Exit;
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
      p     = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      error = pfr_load_bitmap_metrics( &p, stream->limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
                                       advance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
                                       &xpos, &ypos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
                                       &xsize, &ysize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
                                       &advance, &format );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
       * XXX: on 16bit system, we return an error for huge bitmap
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
       *      which causes a size truncation, because truncated
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
       *      size properties makes bitmap glyph broken.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
      if ( xpos > FT_INT_MAX || ( ypos + ysize ) > FT_INT_MAX )
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_TRACE1(( "pfr_slot_load_bitmap:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
        FT_TRACE1(( "huge bitmap glyph %dx%d over FT_GlyphSlot\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
                     xpos, ypos ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
        error = PFR_Err_Invalid_Pixel_Size;
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
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        glyph->root.format = FT_GLYPH_FORMAT_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        /* Set up glyph bitmap and metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
        /* XXX: needs casts to fit FT_Bitmap.{width|rows|pitch} */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
        glyph->root.bitmap.width      = (FT_Int)xsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
        glyph->root.bitmap.rows       = (FT_Int)ysize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
        glyph->root.bitmap.pitch      = (FT_Int)( xsize + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
        glyph->root.bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
        /* XXX: needs casts to fit FT_Glyph_Metrics.{width|height} */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
        glyph->root.metrics.width        = (FT_Pos)xsize << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
        glyph->root.metrics.height       = (FT_Pos)ysize << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
        glyph->root.metrics.horiBearingX = xpos << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
        glyph->root.metrics.horiBearingY = ypos << 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
        glyph->root.metrics.horiAdvance  = FT_PIX_ROUND( ( advance >> 2 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
        glyph->root.metrics.vertBearingX = - glyph->root.metrics.width >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
        glyph->root.metrics.vertBearingY = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
        glyph->root.metrics.vertAdvance  = size->root.metrics.height;
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
        /* XXX: needs casts fit FT_GlyphSlotRec.bitmap_{left|top} */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
        glyph->root.bitmap_left = (FT_Int)xpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
        glyph->root.bitmap_top  = (FT_Int)(ypos + ysize);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
        /* Allocate and read bitmap data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
          FT_ULong  len = glyph->root.bitmap.pitch * ysize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
          error = ft_glyphslot_alloc_bitmap( &glyph->root, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
          if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
            error = pfr_load_bitmap_bits(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
                      p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
                      stream->limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
                      format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
                      FT_BOOL(face->header.color_flags & 2),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
                      &glyph->root.bitmap );
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
  }
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
/* END */