misc/libfreetype/src/sfnt/ttkern.c
author koda
Wed, 19 Dec 2012 18:17:23 +0100
changeset 8312 9e8781faabab
parent 5172 88f2e05288ba
permissions -rw-r--r--
can compile engine as library on linux but not run the executable (automatically), most likely breaking other platforms (wrt engine-as-library)
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
/*  ttkern.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
/*    Load the basic TrueType kerning table.  This doesn't handle          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*    kerning data within the GPOS table at the moment.                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include <ft2build.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
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "ttkern.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
#include "sferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* 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
    32
  /* 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
    33
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#define FT_COMPONENT  trace_ttkern
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#undef  TT_KERN_INDEX
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#define TT_KERN_INDEX( g1, g2 )  ( ( (FT_ULong)(g1) << 16 ) | (g2) )
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  tt_face_load_kern( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
                     FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    FT_ULong   table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    FT_Byte*   p_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_UInt    nn, num_tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    FT_UInt32  avail = 0, ordered = 0;
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
    /* the kern table is optional; exit silently if it is missing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    error = face->goto_table( face, TTAG_kern, stream, &table_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      goto Exit;
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 ( table_size < 4 )  /* the case of a malformed table */
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
      FT_ERROR(( "tt_face_load_kern:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
                 " kerning table is too small - ignored\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
      error = SFNT_Err_Table_Missing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
      goto Exit;
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
    if ( FT_FRAME_EXTRACT( table_size, face->kern_table ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
      FT_ERROR(( "tt_face_load_kern:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                 " could not extract kerning table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    }
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
    face->kern_table_size = table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    p       = face->kern_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    p_limit = p + table_size;
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
    p         += 2; /* skip version */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    num_tables = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    if ( num_tables > 32 ) /* we only support up to 32 sub-tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      num_tables = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    for ( nn = 0; nn < num_tables; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
      FT_UInt    num_pairs, length, coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      FT_Byte*   p_next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      FT_UInt32  mask = (FT_UInt32)1UL << nn;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
      if ( p + 6 > p_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      p_next = p;
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
      p += 2; /* skip version */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
      length   = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
      coverage = FT_NEXT_USHORT( p );
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 ( length <= 6 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
        break;
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
      p_next += length;
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
      if ( p_next > p_limit )  /* handle broken table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
        p_next = p_limit;
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
      /* only use horizontal kerning tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
      if ( ( coverage & ~8 ) != 0x0001 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
           p + 8 > p_limit             )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
        goto NextTable;
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
      num_pairs = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
      p        += 6;
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
      if ( ( p_next - p ) < 6 * (int)num_pairs ) /* handle broken count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
        num_pairs = (FT_UInt)( ( p_next - p ) / 6 );
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
      avail |= mask;
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
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
       *  Now check whether the pairs in this table are ordered.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
       *  We then can use binary search.
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
      if ( num_pairs > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
        FT_ULong  count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
        FT_ULong  old_pair;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
        old_pair = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
        p       += 2;
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
        for ( count = num_pairs - 1; count > 0; count-- )
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
          FT_UInt32  cur_pair;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
          cur_pair = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
          if ( cur_pair <= old_pair )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
            break;
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
          p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
          old_pair = cur_pair;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
        if ( count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
          ordered |= mask;
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
    NextTable:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      p = p_next;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    face->num_kern_tables = nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    face->kern_avail_bits = avail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    face->kern_order_bits = ordered;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  tt_face_done_kern( TT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
    FT_Stream  stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    FT_FRAME_RELEASE( face->kern_table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    face->kern_table_size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    face->num_kern_tables = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    face->kern_avail_bits = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    face->kern_order_bits = 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
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
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  tt_face_get_kerning( TT_Face  face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
                       FT_UInt  left_glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
                       FT_UInt  right_glyph )
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
    FT_Int    result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    FT_UInt   count, mask = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    FT_Byte*  p       = face->kern_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    FT_Byte*  p_limit = p + face->kern_table_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    p   += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    mask = 0x0001;
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
    for ( count = face->num_kern_tables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
          count > 0 && p + 6 <= p_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
          count--, mask <<= 1 )
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
      FT_Byte* base     = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      FT_Byte* next     = base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      FT_UInt  version  = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      FT_UInt  length   = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      FT_UInt  coverage = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      FT_UInt  num_pairs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
      FT_Int   value    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      FT_UNUSED( version );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      next = base + length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      if ( next > p_limit )  /* handle broken table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
        next = p_limit;
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
      if ( ( face->kern_avail_bits & mask ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
        goto NextTable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      if ( p + 8 > next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
        goto NextTable;
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
      num_pairs = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
      p        += 6;
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
      if ( ( next - p ) < 6 * (int)num_pairs )  /* handle broken count  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
        num_pairs = (FT_UInt)( ( next - p ) / 6 );
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
      switch ( coverage >> 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
      case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
          FT_ULong  key0 = TT_KERN_INDEX( left_glyph, right_glyph );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
          if ( face->kern_order_bits & mask )   /* binary search */
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
            FT_UInt   min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
            FT_UInt   max = num_pairs;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
            while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
              FT_UInt   mid = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
              FT_Byte*  q   = p + 6 * mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
              FT_ULong  key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
              key = FT_NEXT_ULONG( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
              if ( key == key0 )
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
                value = FT_PEEK_SHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
                goto Found;
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
              if ( key < key0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
                min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
              else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
                max = mid;
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
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
          else /* linear search */
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
            FT_UInt  count2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
            for ( count2 = num_pairs; count2 > 0; count2-- )
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
              FT_ULong  key = FT_NEXT_ULONG( p );
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
              if ( key == key0 )
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
                value = FT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
                goto Found;
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
              p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
            }
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
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
        *  We don't support format 2 because we haven't seen a single font
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
        *  using it in real life...
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      default:
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
      goto NextTable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    Found:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      if ( coverage & 8 ) /* override or add */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
        result = value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
        result += value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    NextTable:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      p = next;
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
    return result;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
#undef TT_KERN_INDEX
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
/* END */