misc/libfreetype/src/sfnt/ttcmap.c
author mikade
Fri, 09 Sep 2011 03:21:16 +0200
changeset 5821 afb988c1a2fe
parent 5172 88f2e05288ba
permissions -rw-r--r--
Allow limited form of SuddenDeath (WaterRise = 0) in both CTF modes Fix missing case of support for more players in CTF_Blizzard
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
/*  ttcmap.c                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    TrueType character mapping table (cmap) support (body).              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 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 <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include "sferrors.h"           /* must come before FT_INTERNAL_VALIDATE_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 FT_INTERNAL_VALIDATE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include "ttload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "ttcmap.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include "sfntpic.h"
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
  /* 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
    34
  /* 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
    35
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#define FT_COMPONENT  trace_ttcmap
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#define TT_PEEK_SHORT   FT_PEEK_SHORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#define TT_PEEK_USHORT  FT_PEEK_USHORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
#define TT_PEEK_UINT24  FT_PEEK_UOFF3
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
#define TT_PEEK_LONG    FT_PEEK_LONG
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
#define TT_PEEK_ULONG   FT_PEEK_ULONG
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
#define TT_NEXT_SHORT   FT_NEXT_SHORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
#define TT_NEXT_USHORT  FT_NEXT_USHORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
#define TT_NEXT_UINT24  FT_NEXT_UOFF3
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#define TT_NEXT_LONG    FT_NEXT_LONG
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
#define TT_NEXT_ULONG   FT_NEXT_ULONG
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  tt_cmap_init( TT_CMap   cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
                FT_Byte*  table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    cmap->data = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /*************************************************************************/
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
  /*****                           FORMAT 0                            *****/
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
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  /* TABLE OVERVIEW                                                        */
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  /*   NAME        OFFSET         TYPE          DESCRIPTION                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  /*   format      0              USHORT        must be 0                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
  /*   length      2              USHORT        table length in bytes      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  /*   language    4              USHORT        Mac language code          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  /*   glyph_ids   6              BYTE[256]     array of glyph indices     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  /*               262                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
#ifdef TT_CONFIG_CMAP_FORMAT_0
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  tt_cmap0_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
                     FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    FT_Byte*  p      = table + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    FT_UInt   length = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    if ( table + length > valid->limit || length < 262 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      FT_INVALID_TOO_SHORT;
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
    /* check glyph indices whenever necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      FT_UInt  n, idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
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
      p = table + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
      for ( n = 0; n < 256; n++ )
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
        idx = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
        if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    return SFNT_Err_Ok;
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
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  tt_cmap0_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
                       FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    FT_Byte*  table = cmap->data;
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
    return char_code < 256 ? table[6 + char_code] : 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
  tt_cmap0_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
                      FT_UInt32  *pchar_code )
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
    FT_Byte*   table    = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    FT_UInt32  charcode = *pchar_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    FT_UInt32  result   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    FT_UInt    gindex   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    table += 6;  /* go to glyph IDs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    while ( ++charcode < 256 )
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
      gindex = table[charcode];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      if ( gindex != 0 )
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
        result = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      }
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
    *pchar_code = result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    return gindex;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  tt_cmap0_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
                     TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    FT_Byte*  p = cmap->data + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    cmap_info->format   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
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
    return SFNT_Err_Ok;
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
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
  FT_DEFINE_TT_CMAP(tt_cmap0_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      sizeof ( TT_CMapRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      (FT_CMap_InitFunc)     tt_cmap_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
      (FT_CMap_CharIndexFunc)tt_cmap0_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      (FT_CMap_CharNextFunc) tt_cmap0_char_next,
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
      NULL, NULL, NULL, NULL, NULL
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
    0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    (TT_CMap_ValidateFunc)   tt_cmap0_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    (TT_CMap_Info_GetFunc)   tt_cmap0_get_info
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
#endif /* TT_CONFIG_CMAP_FORMAT_0 */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
  /*****                          FORMAT 2                             *****/
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
  /***** This is used for certain CJK encodings that encode text in a  *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
  /***** mixed 8/16 bits encoding along the following lines:           *****/
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
  /***** * Certain byte values correspond to an 8-bit character code   *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  /*****   (typically in the range 0..127 for ASCII compatibility).    *****/
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
  /***** * Certain byte values signal the first byte of a 2-byte       *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
  /*****   character code (but these values are also valid as the      *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
  /*****   second byte of a 2-byte character).                         *****/
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
  /***** The following charmap lookup and iteration functions all      *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
  /***** assume that the value "charcode" correspond to following:     *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
  /*****   - For one byte characters, "charcode" is simply the         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
  /*****     character code.                                           *****/
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
  /*****   - For two byte characters, "charcode" is the 2-byte         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  /*****     character code in big endian format.  More exactly:       *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /*****       (charcode >> 8)    is the first byte value              *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  /*****       (charcode & 0xFF)  is the second byte value             *****/
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
  /***** Note that not all values of "charcode" are valid according    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  /***** to these rules, and the function moderately check the         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  /***** arguments.                                                    *****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  /*************************************************************************/
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
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
  /*   NAME        OFFSET         TYPE            DESCRIPTION              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
  /*   format      0              USHORT          must be 2                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
  /*   length      2              USHORT          table length in bytes    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
  /*   language    4              USHORT          Mac language code        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  /*   keys        6              USHORT[256]     sub-header keys          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  /*   subs        518            SUBHEAD[NSUBS]  sub-headers array        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
  /*   glyph_ids   518+NSUB*8     USHORT[]        glyph ID array           */
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
  /* The `keys' table is used to map charcode high-bytes to sub-headers.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
  /* The value of `NSUBS' is the number of sub-headers defined in the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
  /* table and is computed by finding the maximum of the `keys' table.     */
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
  /* Note that for any n, `keys[n]' is a byte offset within the `subs'     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
  /* table, i.e., it is the corresponding sub-header index multiplied      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  /* by 8.                                                                 */
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
  /* Each sub-header has the following format:                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  /*   NAME        OFFSET      TYPE            DESCRIPTION                 */
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
  /*   first       0           USHORT          first valid low-byte        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  /*   count       2           USHORT          number of valid low-bytes   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  /*   delta       4           SHORT           see below                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  /*   offset      6           USHORT          see below                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
  /* A sub-header defines, for each high-byte, the range of valid          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
  /* low-bytes within the charmap.  Note that the range defined by `first' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
  /* and `count' must be completely included in the interval [0..255]      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
  /* according to the specification.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  /* If a character code is contained within a given sub-header, then      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  /* mapping it to a glyph index is done as follows:                       */
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
  /* * The value of `offset' is read.  This is a _byte_ distance from the  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
  /*   location of the `offset' field itself into a slice of the           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
  /*   `glyph_ids' table.  Let's call it `slice' (it is a USHORT[] too).   */
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
  /* * The value `slice[char.lo - first]' is read.  If it is 0, there is   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
  /*   no glyph for the charcode.  Otherwise, the value of `delta' is      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  /*   added to it (modulo 65536) to form a new glyph index.               */
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
  /* It is up to the validation routine to check that all offsets fall     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  /* within the glyph IDs table (and not within the `subs' table itself or */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  /* outside of the CMap).                                                 */
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
#ifdef TT_CONFIG_CMAP_FORMAT_2
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
  tt_cmap2_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
                     FT_Validator  valid )
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
    FT_Byte*  p      = table + 2;           /* skip format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
    FT_UInt   length = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
    FT_UInt   n, max_subs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    FT_Byte*  keys;                         /* keys table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    FT_Byte*  subs;                         /* sub-headers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    FT_Byte*  glyph_ids;                    /* glyph ID array */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    if ( table + length > valid->limit || length < 6 + 512 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
      FT_INVALID_TOO_SHORT;
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
    keys = table + 6;
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
    /* parse keys to compute sub-headers count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
    p        = keys;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    max_subs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    for ( n = 0; n < 256; n++ )
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
      FT_UInt  idx = TT_NEXT_USHORT( p );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      /* value must be multiple of 8 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
      if ( valid->level >= FT_VALIDATE_PARANOID && ( idx & 7 ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
        FT_INVALID_DATA;
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
      idx >>= 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      if ( idx > max_subs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        max_subs = idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
    FT_ASSERT( p == table + 518 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    subs      = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    glyph_ids = subs + (max_subs + 1) * 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    if ( glyph_ids > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    /* parse sub-headers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    for ( n = 0; n <= max_subs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
      FT_UInt   first_code, code_count, offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      FT_Int    delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
      FT_Byte*  ids;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
      first_code = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      code_count = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
      delta      = TT_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      offset     = TT_NEXT_USHORT( p );
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
      /* many Dynalab fonts have empty sub-headers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
      if ( code_count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      /* check range within 0..255 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      if ( valid->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
        if ( first_code >= 256 || first_code + code_count > 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      /* check offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      if ( offset != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
        ids = p - 2 + offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
        if ( ids < glyph_ids || ids + code_count*2 > table + length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
          FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
        /* check glyph IDs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
        if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
          FT_Byte*  limit = p + code_count * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
          FT_UInt   idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
          for ( ; p < limit; )
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
            idx = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
            if ( idx != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
              idx = ( idx + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
              if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
                FT_INVALID_GLYPH_ID;
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
  /* return sub header corresponding to a given character code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  /* NULL on invalid charcode                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  static FT_Byte*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  tt_cmap2_get_subheader( FT_Byte*   table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
                          FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    FT_Byte*  result = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
    if ( char_code < 0x10000UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      FT_UInt   char_lo = (FT_UInt)( char_code & 0xFF );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      FT_UInt   char_hi = (FT_UInt)( char_code >> 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      FT_Byte*  p       = table + 6;    /* keys table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
      FT_Byte*  subs    = table + 518;  /* subheaders table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      FT_Byte*  sub;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      if ( char_hi == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
        /* an 8-bit character code -- we use subHeader 0 in this case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
        /* to test whether the character code is in the charmap       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
        /*                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
        sub = subs;  /* jump to first sub-header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
        /* check that the sub-header for this byte is 0, which */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
        /* indicates that it is really a valid one-byte value  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
        /* Otherwise, return 0                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
        /*                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
        p += char_lo * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        if ( TT_PEEK_USHORT( p ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      else
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
        /* a 16-bit character code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        /* jump to key entry  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
        p  += char_hi * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
        /* jump to sub-header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
        sub = subs + ( FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 8 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
        /* check that the high byte isn't a valid one-byte value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
        if ( sub == subs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      result = sub;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
  tt_cmap2_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
                       FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    FT_Byte*  table   = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    FT_UInt   result  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    FT_Byte*  subheader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    subheader = tt_cmap2_get_subheader( table, char_code );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
    if ( subheader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      FT_Byte*  p   = subheader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      FT_UInt   idx = (FT_UInt)(char_code & 0xFF);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      FT_UInt   start, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      FT_Int    delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      FT_UInt   offset;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
      start  = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
      count  = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      delta  = TT_NEXT_SHORT ( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      offset = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
      idx -= start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
      if ( idx < count && offset != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
        p  += offset + 2 * idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
        idx = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
        if ( idx != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
          result = (FT_UInt)( idx + delta ) & 0xFFFFU;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    return result;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  tt_cmap2_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
                      FT_UInt32  *pcharcode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    FT_Byte*   table    = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    FT_UInt    gindex   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    FT_UInt32  result   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    FT_UInt32  charcode = *pcharcode + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    FT_Byte*   subheader;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    while ( charcode < 0x10000UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      subheader = tt_cmap2_get_subheader( table, charcode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
      if ( subheader )
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
        FT_Byte*  p       = subheader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
        FT_UInt   start   = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        FT_UInt   count   = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
        FT_Int    delta   = TT_NEXT_SHORT ( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
        FT_UInt   offset  = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
        FT_UInt   char_lo = (FT_UInt)( charcode & 0xFF );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
        FT_UInt   pos, idx;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
        if ( offset == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
          goto Next_SubHeader;
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 ( char_lo < start )
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
          char_lo = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
          pos     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
          pos = (FT_UInt)( char_lo - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
        p       += offset + pos * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
        charcode = FT_PAD_FLOOR( charcode, 256 ) + char_lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
        for ( ; pos < count; pos++, charcode++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
          idx = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
          if ( idx != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
            gindex = ( idx + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
            if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
              result = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
      /* jump to next sub-header, i.e. higher byte value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    Next_SubHeader:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      charcode = FT_PAD_FLOOR( charcode, 256 ) + 256;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    *pcharcode = result;
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
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
  tt_cmap2_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
                     TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    FT_Byte*  p = cmap->data + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    cmap_info->format   = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    return SFNT_Err_Ok;
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
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
  FT_DEFINE_TT_CMAP(tt_cmap2_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
      sizeof ( TT_CMapRec ),
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_CMap_InitFunc)     tt_cmap_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
      (FT_CMap_CharIndexFunc)tt_cmap2_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
      (FT_CMap_CharNextFunc) tt_cmap2_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
    2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
    (TT_CMap_ValidateFunc)   tt_cmap2_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
    (TT_CMap_Info_GetFunc)   tt_cmap2_get_info
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
#endif /* TT_CONFIG_CMAP_FORMAT_2 */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
  /*****                           FORMAT 4                            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  /*************************************************************************/
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
  /*************************************************************************/
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
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
  /*   NAME          OFFSET         TYPE              DESCRIPTION          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
  /*   format        0              USHORT            must be 4            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
  /*   length        2              USHORT            table length         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
  /*                                                  in bytes             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
  /*   language      4              USHORT            Mac language code    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
  /*   segCountX2    6              USHORT            2*NUM_SEGS           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
  /*   searchRange   8              USHORT            2*(1 << LOG_SEGS)    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
  /*   entrySelector 10             USHORT            LOG_SEGS             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
  /*   rangeShift    12             USHORT            segCountX2 -         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
  /*                                                    searchRange        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
  /*   endCount      14             USHORT[NUM_SEGS]  end charcode for     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
  /*                                                  each segment; last   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
  /*                                                  is 0xFFFF            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
  /*   pad           14+NUM_SEGS*2  USHORT            padding              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
  /*   startCount    16+NUM_SEGS*2  USHORT[NUM_SEGS]  first charcode for   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
  /*                                                  each segment         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
  /*   idDelta       16+NUM_SEGS*4  SHORT[NUM_SEGS]   delta for each       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
  /*                                                  segment              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
  /*   idOffset      16+NUM_SEGS*6  SHORT[NUM_SEGS]   range offset for     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
  /*                                                  each segment; can be */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
  /*                                                  zero                 */
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
  /*   glyphIds      16+NUM_SEGS*8  USHORT[]          array of glyph ID    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
  /*                                                  ranges               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
  /* Character codes are modelled by a series of ordered (increasing)      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
  /* intervals called segments.  Each segment has start and end codes,     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
  /* provided by the `startCount' and `endCount' arrays.  Segments must    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
  /* not overlap, and the last segment should always contain the value     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
  /* 0xFFFF for `endCount'.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
  /* The fields `searchRange', `entrySelector' and `rangeShift' are better */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
  /* ignored (they are traces of over-engineering in the TrueType          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
  /* specification).                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
  /* Each segment also has a signed `delta', as well as an optional offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
  /* within the `glyphIds' table.                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
  /* If a segment's idOffset is 0, the glyph index corresponding to any    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
  /* charcode within the segment is obtained by adding the value of        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
  /* `idDelta' directly to the charcode, modulo 65536.                     */
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
  /* Otherwise, a glyph index is taken from the glyph IDs sub-array for    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
  /* the segment, and the value of `idDelta' is added to it.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
  /*                                                                       */
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
  /* Finally, note that a lot of fonts contain an invalid last segment,    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
  /* where `start' and `end' are correctly set to 0xFFFF but both `delta'  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
  /* and `offset' are incorrect (e.g., `opens___.ttf' which comes with     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
  /* OpenOffice.org).  We need special code to deal with them correctly.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
#ifdef TT_CONFIG_CMAP_FORMAT_4
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
  typedef struct  TT_CMap4Rec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    TT_CMapRec  cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    FT_UInt32   cur_charcode;   /* current charcode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    FT_UInt     cur_gindex;     /* current glyph index */
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_UInt     num_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    FT_UInt     cur_range;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    FT_UInt     cur_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
    FT_UInt     cur_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    FT_Int      cur_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    FT_Byte*    cur_values;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
  } TT_CMap4Rec, *TT_CMap4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
  tt_cmap4_init( TT_CMap4  cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
                 FT_Byte*  table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
    cmap->cmap.data    = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
    p                  = table + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
    cmap->num_ranges   = FT_PEEK_USHORT( p ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
    cmap->cur_gindex   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
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
  static FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
  tt_cmap4_set_range( TT_CMap4  cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
                      FT_UInt   range_index )
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
    FT_Byte*  table = cmap->cmap.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    FT_UInt   num_ranges = cmap->num_ranges;
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
    while ( range_index < num_ranges )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
      FT_UInt  offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
      p             = table + 14 + range_index * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
      cmap->cur_end = FT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
      p              += 2 + num_ranges * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
      cmap->cur_start = FT_PEEK_USHORT( p );
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
      p              += num_ranges * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
      cmap->cur_delta = FT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
      p     += num_ranges * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
      offset = FT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
      /* some fonts have an incorrect last segment; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
      /* we have to catch it                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
      if ( range_index     >= num_ranges - 1 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
           cmap->cur_start == 0xFFFFU        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
           cmap->cur_end   == 0xFFFFU        )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
        TT_Face   face  = (TT_Face)cmap->cmap.cmap.charmap.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
        FT_Byte*  limit = face->cmap_table + face->cmap_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
        if ( offset && p + offset + 2 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
          cmap->cur_delta = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
          offset          = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
      if ( offset != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
        cmap->cur_values = offset ? p + offset : NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
        cmap->cur_range  = range_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
        return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
      /* we skip empty segments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      range_index++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
    return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
  /* search the index of the charcode next to cmap->cur_charcode; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
  /* caller should call tt_cmap4_set_range with proper range      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
  /* before calling this function                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
  /*                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
  tt_cmap4_next( TT_CMap4  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    FT_UInt  charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    if ( cmap->cur_charcode >= 0xFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
    charcode = (FT_UInt)cmap->cur_charcode + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    if ( charcode < cmap->cur_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
      charcode = cmap->cur_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    for ( ;; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      FT_Byte*  values = cmap->cur_values;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
      FT_UInt   end    = cmap->cur_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
      FT_Int    delta  = cmap->cur_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
      if ( charcode <= end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
        if ( values )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
          FT_Byte*  p = values + 2 * ( charcode - cmap->cur_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
            FT_UInt  gindex = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
            if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
              gindex = (FT_UInt)( ( gindex + delta ) & 0xFFFFU );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
              if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
                cmap->cur_charcode = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
                cmap->cur_gindex   = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
                return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
          } while ( ++charcode <= end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
            FT_UInt  gindex = (FT_UInt)( ( charcode + delta ) & 0xFFFFU );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
            if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
              cmap->cur_charcode = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
              cmap->cur_gindex   = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
              return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
          } while ( ++charcode <= end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
      /* we need to find another range */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
      if ( tt_cmap4_set_range( cmap, cmap->cur_range + 1 ) < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
      if ( charcode < cmap->cur_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
        charcode = cmap->cur_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    cmap->cur_gindex   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
  tt_cmap4_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
                     FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
    FT_Byte*  p      = table + 2;               /* skip format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    FT_UInt   length = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
    FT_Byte   *ends, *starts, *offsets, *deltas, *glyph_ids;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
    FT_UInt   num_segs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
    FT_Error  error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
    if ( length < 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
    /* in certain fonts, the `length' field is invalid and goes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
    /* out of bound.  We try to correct this here...            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
    if ( table + length > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
      if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
        FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
      length = (FT_UInt)( valid->limit - table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
    p        = table + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
    num_segs = TT_NEXT_USHORT( p );   /* read segCountX2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
    if ( valid->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
      /* check that we have an even value here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
      if ( num_segs & 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
        FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
    num_segs /= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
    if ( length < 16 + num_segs * 2 * 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
    /* check the search parameters - even though we never use them */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
    /*                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    if ( valid->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
      /* check the values of `searchRange', `entrySelector', `rangeShift' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
      FT_UInt  search_range   = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
      FT_UInt  entry_selector = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
      FT_UInt  range_shift    = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
      if ( ( search_range | range_shift ) & 1 )  /* must be even values */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
        FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
      search_range /= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
      range_shift  /= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
      /* `search range' is the greatest power of 2 that is <= num_segs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      if ( search_range                > num_segs                 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
           search_range * 2            < num_segs                 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
           search_range + range_shift != num_segs                 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
           search_range               != ( 1U << entry_selector ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
        FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    ends      = table   + 14;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
    starts    = table   + 16 + num_segs * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
    deltas    = starts  + num_segs * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
    offsets   = deltas  + num_segs * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
    glyph_ids = offsets + num_segs * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
    /* check last segment; its end count value must be 0xFFFF */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    if ( valid->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
      p = ends + ( num_segs - 1 ) * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
      if ( TT_PEEK_USHORT( p ) != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
        FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      FT_UInt   start, end, offset, n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
      FT_UInt   last_start = 0, last_end = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
      FT_Int    delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
      FT_Byte*  p_start   = starts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
      FT_Byte*  p_end     = ends;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
      FT_Byte*  p_delta   = deltas;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
      FT_Byte*  p_offset  = offsets;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
      for ( n = 0; n < num_segs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
        p      = p_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
        start  = TT_NEXT_USHORT( p_start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
        end    = TT_NEXT_USHORT( p_end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
        delta  = TT_NEXT_SHORT( p_delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
        offset = TT_NEXT_USHORT( p_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
        if ( start > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
        /* this test should be performed at default validation level; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
        /* unfortunately, some popular Asian fonts have overlapping   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
        /* ranges in their charmaps                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
        /*                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
        if ( start <= last_end && n > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
          if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
            FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
            /* allow overlapping segments, provided their start points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
            /* and end points, respectively, are in ascending order    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
            /*                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
            if ( last_start > start || last_end > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
              error |= TT_CMAP_FLAG_UNSORTED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
              error |= TT_CMAP_FLAG_OVERLAPPING;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
        if ( offset && offset != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
          p += offset;  /* start of glyph ID array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
          /* check that we point within the glyph IDs table only */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
          if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
            if ( p < glyph_ids                                ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
                 p + ( end - start + 1 ) * 2 > table + length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
          /* Some fonts handle the last segment incorrectly.  In */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
          /* theory, 0xFFFF might point to an ordinary glyph --  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
          /* a cmap 4 is versatile and could be used for any     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
          /* encoding, not only Unicode.  However, reality shows */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
          /* that far too many fonts are sloppy and incorrectly  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
          /* set all fields but `start' and `end' for the last   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
          /* segment if it contains only a single character.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
          /*                                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
          /* We thus omit the test here, delaying it to the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
          /* routines which actually access the cmap.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
          else if ( n != num_segs - 1                       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
                    !( start == 0xFFFFU && end == 0xFFFFU ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
            if ( p < glyph_ids                              ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
                 p + ( end - start + 1 ) * 2 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
          /* check glyph indices within the segment range */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
          if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
            FT_UInt  i, idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
            for ( i = start; i < end; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
              idx = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
              if ( idx != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
                idx = (FT_UInt)( idx + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
                if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
                  FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
        else if ( offset == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
          /* some fonts (erroneously?) use a range offset of 0xFFFF */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
          /* to mean missing glyph in cmap table                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
          /*                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
          if ( valid->level >= FT_VALIDATE_PARANOID    ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
               n != num_segs - 1                       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
               !( start == 0xFFFFU && end == 0xFFFFU ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
            FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
        last_start = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
        last_end   = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
  tt_cmap4_char_map_linear( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
                            FT_UInt32*  pcharcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
                            FT_Bool     next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
    FT_UInt    num_segs2, start, end, offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
    FT_Int     delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    FT_UInt    i, num_segs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
    FT_UInt32  charcode = *pcharcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
    FT_UInt    gindex   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
    FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
    p = cmap->data + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
    num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
    num_segs = num_segs2 >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
    if ( !num_segs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
      charcode++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    /* linear search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
    for ( ; charcode <= 0xFFFFU; charcode++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
      FT_Byte*  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
      p = cmap->data + 14;               /* ends table   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
      q = cmap->data + 16 + num_segs2;   /* starts table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
      for ( i = 0; i < num_segs; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
        end   = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
        start = TT_NEXT_USHORT( q );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
        if ( charcode >= start && charcode <= end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
          p       = q - 2 + num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
          delta   = TT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
          p      += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
          offset  = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
          /* some fonts have an incorrect last segment; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
          /* we have to catch it                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
          if ( i >= num_segs - 1                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
               start == 0xFFFFU && end == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
            TT_Face   face  = (TT_Face)cmap->cmap.charmap.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
            FT_Byte*  limit = face->cmap_table + face->cmap_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
            if ( offset && p + offset + 2 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
              delta  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
              offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
          if ( offset == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
            continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
          if ( offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
            p += offset + ( charcode - start ) * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
            gindex = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
            if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
              gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
            gindex = (FT_UInt)( charcode + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
      if ( !next || gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
    if ( next && gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
      *pcharcode = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
  tt_cmap4_char_map_binary( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
                            FT_UInt32*  pcharcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
                            FT_Bool     next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
    FT_UInt   num_segs2, start, end, offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
    FT_Int    delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
    FT_UInt   max, min, mid, num_segs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
    FT_UInt   charcode = (FT_UInt)*pcharcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
    FT_UInt   gindex   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
    p = cmap->data + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
    num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
    if ( !num_segs2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
    num_segs = num_segs2 >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
    /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
    mid = num_segs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
    end = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
      charcode++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
    min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
    max = num_segs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    /* binary search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
    while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
      mid    = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
      p      = cmap->data + 14 + mid * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
      end    = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
      p     += 2 + num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
      start  = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
      if ( charcode < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
        max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
      else if ( charcode > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
        p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
        delta  = TT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
        p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
        offset = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
        /* some fonts have an incorrect last segment; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
        /* we have to catch it                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
        if ( mid >= num_segs - 1                &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
             start == 0xFFFFU && end == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
          TT_Face   face  = (TT_Face)cmap->cmap.charmap.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
          FT_Byte*  limit = face->cmap_table + face->cmap_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
          if ( offset && p + offset + 2 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
            delta  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
            offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
        /* search the first segment containing `charcode' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
        if ( cmap->flags & TT_CMAP_FLAG_OVERLAPPING )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
          FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
          /* call the current segment `max' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
          max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
          if ( offset == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
            mid = max + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
          /* search in segments before the current segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
          for ( i = max ; i > 0; i-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
            FT_UInt   prev_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
            FT_Byte*  old_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
            old_p    = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
            p        = cmap->data + 14 + ( i - 1 ) * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
            prev_end = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
            if ( charcode > prev_end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
              p = old_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
            end    = prev_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
            p     += 2 + num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
            start  = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
            p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
            delta  = TT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
            p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
            offset = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
            if ( offset != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
              mid = i - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
          /* no luck */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
          if ( mid == max + 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
            if ( i != max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
              p      = cmap->data + 14 + max * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
              end    = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
              p     += 2 + num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
              start  = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
              p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
              delta  = TT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
              p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
              offset = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
            mid = max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
            /* search in segments after the current segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
            for ( i = max + 1; i < num_segs; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
              FT_UInt  next_end, next_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
              p          = cmap->data + 14 + i * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
              next_end   = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
              p         += 2 + num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
              next_start = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
              if ( charcode < next_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
                break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
              end    = next_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
              start  = next_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
              p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
              delta  = TT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
              p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
              offset = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
              if ( offset != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
                mid = i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
            i--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
            /* still no luck */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
            if ( mid == max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
              mid = i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
          /* end, start, delta, and offset are for the i'th segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
          if ( mid != i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
            p      = cmap->data + 14 + mid * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
            end    = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
            p     += 2 + num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
            start  = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
            p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
            delta  = TT_PEEK_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
            p     += num_segs2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
            offset = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
          if ( offset == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
        if ( offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
          p += offset + ( charcode - start ) * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
          gindex = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
          if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
            gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
          gindex = (FT_UInt)( charcode + delta ) & 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
      TT_CMap4  cmap4 = (TT_CMap4)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
      /* if `charcode' is not in any segment, then `mid' is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
      /* the segment nearest to `charcode'                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
      /*                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
      if ( charcode > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
        mid++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
        if ( mid == num_segs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
          return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
      if ( tt_cmap4_set_range( cmap4, mid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
          *pcharcode = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
        cmap4->cur_charcode = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
          cmap4->cur_gindex = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
          cmap4->cur_charcode = charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
          tt_cmap4_next( cmap4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
          gindex = cmap4->cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
          *pcharcode = cmap4->cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
  tt_cmap4_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
                       FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
    if ( char_code >= 0x10000UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
    if ( cmap->flags & TT_CMAP_FLAG_UNSORTED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
      return tt_cmap4_char_map_linear( cmap, &char_code, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
      return tt_cmap4_char_map_binary( cmap, &char_code, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
  tt_cmap4_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
                      FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
    FT_UInt  gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
    if ( *pchar_code >= 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
    if ( cmap->flags & TT_CMAP_FLAG_UNSORTED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
      gindex = tt_cmap4_char_map_linear( cmap, pchar_code, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
      TT_CMap4  cmap4 = (TT_CMap4)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
      /* no need to search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
      if ( *pchar_code == cmap4->cur_charcode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
        tt_cmap4_next( cmap4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
        gindex = cmap4->cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
          *pchar_code = cmap4->cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
        gindex = tt_cmap4_char_map_binary( cmap, pchar_code, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
  tt_cmap4_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
                     TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
    FT_Byte*  p = cmap->data + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
    cmap_info->format   = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
  FT_DEFINE_TT_CMAP(tt_cmap4_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
      sizeof ( TT_CMap4Rec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
      (FT_CMap_InitFunc)     tt_cmap4_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
      (FT_CMap_CharIndexFunc)tt_cmap4_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
      (FT_CMap_CharNextFunc) tt_cmap4_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
    4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
    (TT_CMap_ValidateFunc)   tt_cmap4_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
    (TT_CMap_Info_GetFunc)   tt_cmap4_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
#endif /* TT_CONFIG_CMAP_FORMAT_4 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
  /*****                          FORMAT 6                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
  /*   NAME        OFFSET          TYPE             DESCRIPTION            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
  /*   format       0              USHORT           must be 4              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
  /*   length       2              USHORT           table length in bytes  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
  /*   language     4              USHORT           Mac language code      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
  /*   first        6              USHORT           first segment code     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
  /*   count        8              USHORT           segment size in chars  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
  /*   glyphIds     10             USHORT[count]    glyph IDs              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
  /* A very simplified segment mapping.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
#ifdef TT_CONFIG_CMAP_FORMAT_6
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
  tt_cmap6_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
                     FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
    FT_UInt   length, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
    if ( table + 10 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
    p      = table + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
    length = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
    p      = table + 8;             /* skip language and start index */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
    count  = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
    if ( table + length > valid->limit || length < 10 + count * 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
    /* check glyph indices */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
    if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
      FT_UInt  gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
      for ( ; count > 0; count-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
        gindex = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
        if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
  tt_cmap6_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
                       FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
    FT_Byte*  table  = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
    FT_UInt   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
    FT_Byte*  p      = table + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
    FT_UInt   start  = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
    FT_UInt   count  = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
    FT_UInt   idx    = (FT_UInt)( char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
    if ( idx < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
      p += 2 * idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
      result = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
  tt_cmap6_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
                      FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
    FT_Byte*   table     = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
    FT_UInt32  result    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
    FT_UInt32  char_code = *pchar_code + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
    FT_UInt    gindex    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
    FT_Byte*   p         = table + 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
    FT_UInt    start     = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
    FT_UInt    count     = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
    FT_UInt    idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
    if ( char_code >= 0x10000UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
    if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
      char_code = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
    idx = (FT_UInt)( char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
    p  += 2 * idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
    for ( ; idx < count; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
      gindex = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
      if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
        result = char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
      char_code++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
    *pchar_code = result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
  tt_cmap6_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
                     TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
    FT_Byte*  p = cmap->data + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
    cmap_info->format   = 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
    cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
  FT_DEFINE_TT_CMAP(tt_cmap6_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
      sizeof ( TT_CMapRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
      (FT_CMap_InitFunc)     tt_cmap_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
      (FT_CMap_CharIndexFunc)tt_cmap6_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
      (FT_CMap_CharNextFunc) tt_cmap6_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
    6,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
    (TT_CMap_ValidateFunc)   tt_cmap6_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
    (TT_CMap_Info_GetFunc)   tt_cmap6_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
#endif /* TT_CONFIG_CMAP_FORMAT_6 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
  /*****                          FORMAT 8                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
  /***** It is hard to completely understand what the OpenType spec    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
  /***** says about this format, but here is my conclusion.            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
  /***** The purpose of this format is to easily map UTF-16 text to    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
  /***** glyph indices.  Basically, the `char_code' must be in one of  *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
  /***** the following formats:                                        *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
  /*****   - A 16-bit value that isn't part of the Unicode Surrogates  *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
  /*****     Area (i.e. U+D800-U+DFFF).                                *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
  /*****   - A 32-bit value, made of two surrogate values, i.e.. if    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
  /*****     `char_code = (char_hi << 16) | char_lo', then both        *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
  /*****     `char_hi' and `char_lo' must be in the Surrogates Area.   *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
  /*****      Area.                                                    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
  /***** The `is32' table embedded in the charmap indicates whether a  *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
  /***** given 16-bit value is in the surrogates area or not.          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
  /***** So, for any given `char_code', we can assert the following:   *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
  /*****   If `char_hi == 0' then we must have `is32[char_lo] == 0'.   *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
  /*****   If `char_hi != 0' then we must have both                    *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
  /*****   `is32[char_hi] != 0' and `is32[char_lo] != 0'.              *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
  /*   NAME        OFFSET         TYPE        DESCRIPTION                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
  /*   format      0              USHORT      must be 8                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
  /*   reserved    2              USHORT      reserved                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
  /*   length      4              ULONG       length in bytes              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
  /*   language    8              ULONG       Mac language code            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
  /*   is32        12             BYTE[8192]  32-bitness bitmap            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
  /*   count       8204           ULONG       number of groups             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
  /* This header is followed by `count' groups of the following format:    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
  /*   start       0              ULONG       first charcode               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
  /*   end         4              ULONG       last charcode                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
  /*   startId     8              ULONG       start glyph ID for the group */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
#ifdef TT_CONFIG_CMAP_FORMAT_8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
  tt_cmap8_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
                     FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
    FT_Byte*   p = table + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
    FT_Byte*   is32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
    FT_UInt32  length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
    FT_UInt32  num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
    if ( table + 16 + 8192 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
    length = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
    if ( length > (FT_UInt32)( valid->limit - table ) || length < 8192 + 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
    is32       = table + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
    p          = is32  + 8192;          /* skip `is32' array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
    num_groups = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
    if ( p + num_groups * 12 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
    /* check groups, they must be in increasing order */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
      FT_UInt32  n, start, end, start_id, count, last = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
      for ( n = 0; n < num_groups; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
        FT_UInt   hi, lo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
        start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
        end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
        start_id = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
        if ( start > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
        if ( n > 0 && start <= last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
        if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
          if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
            FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
          count = (FT_UInt32)( end - start + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
          if ( start & ~0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
            /* start_hi != 0; check that is32[i] is 1 for each i in */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
            /* the `hi' and `lo' of the range [start..end]          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
            for ( ; count > 0; count--, start++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
              hi = (FT_UInt)( start >> 16 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
              lo = (FT_UInt)( start & 0xFFFFU );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
              if ( (is32[hi >> 3] & ( 0x80 >> ( hi & 7 ) ) ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
                FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
              if ( (is32[lo >> 3] & ( 0x80 >> ( lo & 7 ) ) ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
                FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
            /* start_hi == 0; check that is32[i] is 0 for each i in */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
            /* the range [start..end]                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
            /* end_hi cannot be != 0! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
            if ( end & ~0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
            for ( ; count > 0; count--, start++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
              lo = (FT_UInt)( start & 0xFFFFU );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
              if ( (is32[lo >> 3] & ( 0x80 >> ( lo & 7 ) ) ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
                FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
        last = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
  tt_cmap8_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
                       FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
    FT_Byte*   table      = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
    FT_UInt    result     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
    FT_Byte*   p          = table + 8204;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
    FT_UInt32  num_groups = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
    FT_UInt32  start, end, start_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
    for ( ; num_groups > 0; num_groups-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
      start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
      end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
      start_id = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
      if ( char_code <= end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
        result = (FT_UInt)( start_id + char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
  tt_cmap8_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
                      FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
    FT_UInt32  result     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
    FT_UInt32  char_code  = *pchar_code + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
    FT_UInt    gindex     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
    FT_Byte*   table      = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
    FT_Byte*   p          = table + 8204;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
    FT_UInt32  num_groups = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
    FT_UInt32  start, end, start_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
    p = table + 8208;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
    for ( ; num_groups > 0; num_groups-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
      start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
      end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
      start_id = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
        char_code = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1761
      if ( char_code <= end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
        gindex = (FT_UInt)( char_code - start + start_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
        if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
          result = char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
    *pchar_code = result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
  tt_cmap8_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
                     TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
    FT_Byte*  p = cmap->data + 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
    cmap_info->format   = 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
  FT_DEFINE_TT_CMAP(tt_cmap8_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
      sizeof ( TT_CMapRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1794
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1795
      (FT_CMap_InitFunc)     tt_cmap_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
      (FT_CMap_CharIndexFunc)tt_cmap8_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1798
      (FT_CMap_CharNextFunc) tt_cmap8_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1800
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
    8,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
    (TT_CMap_ValidateFunc)   tt_cmap8_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
    (TT_CMap_Info_GetFunc)   tt_cmap8_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
#endif /* TT_CONFIG_CMAP_FORMAT_8 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
  /*****                          FORMAT 10                            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
  /*   NAME      OFFSET  TYPE               DESCRIPTION                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
  /*   format     0      USHORT             must be 10                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
  /*   reserved   2      USHORT             reserved                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
  /*   length     4      ULONG              length in bytes                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
  /*   language   8      ULONG              Mac language code              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
  /*   start     12      ULONG              first char in range            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
  /*   count     16      ULONG              number of chars in range       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
  /*   glyphIds  20      USHORT[count]      glyph indices covered          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
#ifdef TT_CONFIG_CMAP_FORMAT_10
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
  tt_cmap10_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
                      FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
    FT_Byte*  p = table + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
    FT_ULong  length, count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
    if ( table + 20 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
    length = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
    p      = table + 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
    count  = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
    if ( length > (FT_ULong)( valid->limit - table ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
         length < 20 + count * 2                     )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1856
    /* check glyph indices */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
    if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
      FT_UInt  gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
      for ( ; count > 0; count-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
        gindex = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
        if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
  tt_cmap10_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
                        FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
    FT_Byte*   table  = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
    FT_UInt    result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
    FT_Byte*   p      = table + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
    FT_UInt32  start  = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
    FT_UInt32  count  = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
    FT_UInt32  idx    = (FT_ULong)( char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
    if ( idx < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
      p     += 2 * idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
      result = TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
  tt_cmap10_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
                       FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1898
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1899
    FT_Byte*   table     = cmap->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
    FT_UInt32  char_code = *pchar_code + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
    FT_UInt    gindex    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
    FT_Byte*   p         = table + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
    FT_UInt32  start     = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
    FT_UInt32  count     = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
    FT_UInt32  idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
    if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
      char_code = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
    idx = (FT_UInt32)( char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
    p  += 2 * idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
    for ( ; idx < count; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
      gindex = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
      if ( gindex != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
      char_code++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
    *pchar_code = char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
  tt_cmap10_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
                      TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
    FT_Byte*  p = cmap->data + 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
    cmap_info->format   = 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
  FT_DEFINE_TT_CMAP(tt_cmap10_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
      sizeof ( TT_CMapRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
      (FT_CMap_InitFunc)     tt_cmap_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
      (FT_CMap_CharIndexFunc)tt_cmap10_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
      (FT_CMap_CharNextFunc) tt_cmap10_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
    10,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
    (TT_CMap_ValidateFunc)   tt_cmap10_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
    (TT_CMap_Info_GetFunc)   tt_cmap10_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
#endif /* TT_CONFIG_CMAP_FORMAT_10 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
  /*****                          FORMAT 12                            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
  /*   NAME        OFFSET     TYPE       DESCRIPTION                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
  /*   format      0          USHORT     must be 12                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
  /*   reserved    2          USHORT     reserved                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
  /*   length      4          ULONG      length in bytes                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
  /*   language    8          ULONG      Mac language code                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
  /*   count       12         ULONG      number of groups                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
  /*               16                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
  /* This header is followed by `count' groups of the following format:    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
  /*   start       0          ULONG      first charcode                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
  /*   end         4          ULONG      last charcode                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
  /*   startId     8          ULONG      start glyph ID for the group      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
#ifdef TT_CONFIG_CMAP_FORMAT_12
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
  typedef struct  TT_CMap12Rec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
    TT_CMapRec  cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
    FT_Bool     valid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
    FT_ULong    cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
    FT_UInt     cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
    FT_ULong    cur_group;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
    FT_ULong    num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
  } TT_CMap12Rec, *TT_CMap12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
  tt_cmap12_init( TT_CMap12  cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
                  FT_Byte*   table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
    cmap->cmap.data  = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
    table           += 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
    cmap->num_groups = FT_PEEK_ULONG( table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
    cmap->valid      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
  tt_cmap12_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
                      FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
    FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
    FT_ULong   length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
    FT_ULong   num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
    if ( table + 16 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
    p      = table + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
    length = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
    p          = table + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
    num_groups = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
    if ( length > (FT_ULong)( valid->limit - table ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
         length < 16 + 12 * num_groups               )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
    /* check groups, they must be in increasing order */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
      FT_ULong  n, start, end, start_id, last = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
      for ( n = 0; n < num_groups; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
        start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
        end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
        start_id = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
        if ( start > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
        if ( n > 0 && start <= last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
        if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
          if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
            FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2060
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2061
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
        last = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2066
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2068
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2069
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2070
  /* search the index of the charcode next to cmap->cur_charcode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2071
  /* cmap->cur_group should be set up properly by caller         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2072
  /*                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2073
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2074
  tt_cmap12_next( TT_CMap12  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2075
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2076
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2077
    FT_ULong  start, end, start_id, char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2078
    FT_ULong  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2079
    FT_UInt   gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2080
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2081
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2082
    if ( cmap->cur_charcode >= 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2083
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2084
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2085
    char_code = cmap->cur_charcode + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2086
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2087
    n = cmap->cur_group;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2088
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2089
    for ( n = cmap->cur_group; n < cmap->num_groups; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
      p        = cmap->cmap.data + 16 + 12 * n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2092
      start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2093
      end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
      start_id = TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
        char_code = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2099
      for ( ; char_code <= end; char_code++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2100
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2101
        gindex = (FT_UInt)( start_id + char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2103
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2104
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2105
          cmap->cur_charcode = char_code;;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
          cmap->cur_gindex   = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2107
          cmap->cur_group    = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
          return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2110
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2111
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2112
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2114
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2115
    cmap->valid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2116
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2119
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2120
  tt_cmap12_char_map_binary( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2121
                             FT_UInt32*  pchar_code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2122
                             FT_Bool     next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2123
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2124
    FT_UInt    gindex     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2125
    FT_Byte*   p          = cmap->data + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2126
    FT_UInt32  num_groups = TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2127
    FT_UInt32  char_code  = *pchar_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2128
    FT_UInt32  start, end, start_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
    FT_UInt32  max, min, mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2132
    if ( !num_groups )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2135
    /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
    mid = num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2137
    end = 0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
      char_code++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
    min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
    max = num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2145
    /* binary search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
    while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
      mid = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
      p   = cmap->data + 16 + 12 * mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2151
      start = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
      end   = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2154
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
        max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
      else if ( char_code > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2158
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2159
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2160
        start_id = TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
        gindex = (FT_UInt)( start_id + char_code - start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2164
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2165
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2168
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2169
      TT_CMap12  cmap12 = (TT_CMap12)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2172
      /* if `char_code' is not in any group, then `mid' is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2173
      /* the group nearest to `char_code'                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
      /*                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2176
      if ( char_code > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2177
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2178
        mid++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2179
        if ( mid == num_groups )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2180
          return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2181
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
      cmap12->valid        = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
      cmap12->cur_charcode = char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2185
      cmap12->cur_group    = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
      if ( !gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2188
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2189
        tt_cmap12_next( cmap12 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
        if ( cmap12->valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
          gindex = cmap12->cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
        cmap12->cur_gindex = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2197
      if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2198
        *pchar_code = cmap12->cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2199
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2201
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2202
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
  tt_cmap12_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
                        FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2208
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
    return tt_cmap12_char_map_binary( cmap, &char_code, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2210
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
  tt_cmap12_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
                       FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2216
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
    TT_CMap12  cmap12 = (TT_CMap12)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2218
    FT_ULong   gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
    if ( cmap12->cur_charcode >= 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2222
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
    /* no need to search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
    if ( cmap12->valid && cmap12->cur_charcode == *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
      tt_cmap12_next( cmap12 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
      if ( cmap12->valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2229
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2230
        gindex = cmap12->cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
        /* XXX: check cur_charcode overflow is expected */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2233
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2234
          *pchar_code = (FT_UInt32)cmap12->cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
        gindex = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2238
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2239
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2240
      gindex = tt_cmap12_char_map_binary( cmap, pchar_code, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2242
    /* XXX: check gindex overflow is expected */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2243
    return (FT_UInt32)gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2244
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2247
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2248
  tt_cmap12_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2249
                      TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2250
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2251
    FT_Byte*  p = cmap->data + 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2254
    cmap_info->format   = 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2255
    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2257
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2258
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2261
  FT_DEFINE_TT_CMAP(tt_cmap12_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2262
      sizeof ( TT_CMap12Rec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2264
      (FT_CMap_InitFunc)     tt_cmap12_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2265
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2266
      (FT_CMap_CharIndexFunc)tt_cmap12_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2267
      (FT_CMap_CharNextFunc) tt_cmap12_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2269
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2270
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2271
    12,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2272
    (TT_CMap_ValidateFunc)   tt_cmap12_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2273
    (TT_CMap_Info_GetFunc)   tt_cmap12_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2274
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2276
#endif /* TT_CONFIG_CMAP_FORMAT_12 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2279
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2280
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2281
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2282
  /*****                          FORMAT 13                            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2283
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2284
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2285
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2287
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2288
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2289
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2290
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2291
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2292
  /*   NAME        OFFSET     TYPE       DESCRIPTION                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2293
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2294
  /*   format      0          USHORT     must be 13                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2295
  /*   reserved    2          USHORT     reserved                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2296
  /*   length      4          ULONG      length in bytes                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2297
  /*   language    8          ULONG      Mac language code                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2298
  /*   count       12         ULONG      number of groups                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2299
  /*               16                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2300
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2301
  /* This header is followed by `count' groups of the following format:    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2302
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2303
  /*   start       0          ULONG      first charcode                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2304
  /*   end         4          ULONG      last charcode                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2305
  /*   glyphId     8          ULONG      glyph ID for the whole group      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2306
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2308
#ifdef TT_CONFIG_CMAP_FORMAT_13
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2310
  typedef struct  TT_CMap13Rec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2311
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2312
    TT_CMapRec  cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2313
    FT_Bool     valid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2314
    FT_ULong    cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2315
    FT_UInt     cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2316
    FT_ULong    cur_group;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2317
    FT_ULong    num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2319
  } TT_CMap13Rec, *TT_CMap13;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2322
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2323
  tt_cmap13_init( TT_CMap13  cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2324
                  FT_Byte*   table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2325
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2326
    cmap->cmap.data  = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2328
    table           += 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2329
    cmap->num_groups = FT_PEEK_ULONG( table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2331
    cmap->valid      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2333
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2334
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2335
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2337
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2338
  tt_cmap13_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2339
                      FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2340
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2341
    FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2342
    FT_ULong   length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2343
    FT_ULong   num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2346
    if ( table + 16 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2347
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2349
    p      = table + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2350
    length = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2352
    p          = table + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2353
    num_groups = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2355
    if ( length > (FT_ULong)( valid->limit - table ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2356
         length < 16 + 12 * num_groups               )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2357
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2359
    /* check groups, they must be in increasing order */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2360
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2361
      FT_ULong  n, start, end, glyph_id, last = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2364
      for ( n = 0; n < num_groups; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2365
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2366
        start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2367
        end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2368
        glyph_id = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2370
        if ( start > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2371
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2373
        if ( n > 0 && start <= last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2374
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2376
        if ( valid->level >= FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2377
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2378
          if ( glyph_id >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2379
            FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2380
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2382
        last = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2383
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2384
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2386
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2387
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2390
  /* search the index of the charcode next to cmap->cur_charcode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2391
  /* cmap->cur_group should be set up properly by caller         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2392
  /*                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2393
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2394
  tt_cmap13_next( TT_CMap13  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2395
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2396
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2397
    FT_ULong  start, end, glyph_id, char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2398
    FT_ULong  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2399
    FT_UInt   gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2402
    if ( cmap->cur_charcode >= 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2403
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2405
    char_code = cmap->cur_charcode + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2407
    n = cmap->cur_group;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2409
    for ( n = cmap->cur_group; n < cmap->num_groups; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2410
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2411
      p        = cmap->cmap.data + 16 + 12 * n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2412
      start    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2413
      end      = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2414
      glyph_id = TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2416
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2417
        char_code = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2419
      if ( char_code <= end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2420
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2421
        gindex = (FT_UInt)glyph_id;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2423
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2424
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2425
          cmap->cur_charcode = char_code;;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2426
          cmap->cur_gindex   = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2427
          cmap->cur_group    = n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2429
          return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2430
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2431
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2432
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2434
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2435
    cmap->valid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2436
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2439
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2440
  tt_cmap13_char_map_binary( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2441
                             FT_UInt32*  pchar_code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2442
                             FT_Bool     next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2443
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2444
    FT_UInt    gindex     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2445
    FT_Byte*   p          = cmap->data + 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2446
    FT_UInt32  num_groups = TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2447
    FT_UInt32  char_code  = *pchar_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2448
    FT_UInt32  start, end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2449
    FT_UInt32  max, min, mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2452
    if ( !num_groups )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2453
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2455
    /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2456
    mid = num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2457
    end = 0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2459
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2460
      char_code++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2462
    min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2463
    max = num_groups;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2465
    /* binary search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2466
    while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2467
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2468
      mid = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2469
      p   = cmap->data + 16 + 12 * mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2471
      start = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2472
      end   = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2474
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2475
        max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2476
      else if ( char_code > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2477
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2478
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2479
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2480
        gindex = (FT_UInt)TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2482
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2483
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2484
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2486
    if ( next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2487
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2488
      TT_CMap13  cmap13 = (TT_CMap13)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2491
      /* if `char_code' is not in any group, then `mid' is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2492
      /* the group nearest to `char_code'                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2493
      /*                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2495
      if ( char_code > end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2496
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2497
        mid++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2498
        if ( mid == num_groups )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2499
          return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2500
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2502
      cmap13->valid        = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2503
      cmap13->cur_charcode = char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2504
      cmap13->cur_group    = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2506
      if ( !gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2507
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2508
        tt_cmap13_next( cmap13 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2509
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2510
        if ( cmap13->valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2511
          gindex = cmap13->cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2512
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2513
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2514
        cmap13->cur_gindex = gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2516
      if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2517
        *pchar_code = cmap13->cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2518
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2520
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2521
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2524
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2525
  tt_cmap13_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2526
                        FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2527
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2528
    return tt_cmap13_char_map_binary( cmap, &char_code, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2529
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2532
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2533
  tt_cmap13_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2534
                       FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2535
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2536
    TT_CMap13  cmap13 = (TT_CMap13)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2537
    FT_UInt    gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2540
    if ( cmap13->cur_charcode >= 0xFFFFFFFFUL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2541
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2542
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2543
    /* no need to search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2544
    if ( cmap13->valid && cmap13->cur_charcode == *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2545
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2546
      tt_cmap13_next( cmap13 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2547
      if ( cmap13->valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2548
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2549
        gindex = cmap13->cur_gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2550
        if ( gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2551
          *pchar_code = cmap13->cur_charcode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2552
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2553
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2554
        gindex = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2555
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2556
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2557
      gindex = tt_cmap13_char_map_binary( cmap, pchar_code, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2558
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2559
    return gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2560
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2562
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2563
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2564
  tt_cmap13_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2565
                      TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2566
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2567
    FT_Byte*  p = cmap->data + 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2570
    cmap_info->format   = 13;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2571
    cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2573
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2574
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2576
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2577
  FT_DEFINE_TT_CMAP(tt_cmap13_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2578
      sizeof ( TT_CMap13Rec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2580
      (FT_CMap_InitFunc)     tt_cmap13_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2581
      (FT_CMap_DoneFunc)     NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2582
      (FT_CMap_CharIndexFunc)tt_cmap13_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2583
      (FT_CMap_CharNextFunc) tt_cmap13_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2585
      NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2586
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2587
    13,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2588
    (TT_CMap_ValidateFunc)   tt_cmap13_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2589
    (TT_CMap_Info_GetFunc)   tt_cmap13_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2590
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2592
#endif /* TT_CONFIG_CMAP_FORMAT_13 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2594
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2595
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2596
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2597
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2598
  /*****                           FORMAT 14                           *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2599
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2600
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2601
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2602
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2603
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2604
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2605
  /* TABLE OVERVIEW                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2606
  /* --------------                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2607
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2608
  /*   NAME         OFFSET  TYPE    DESCRIPTION                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2609
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2610
  /*   format         0     USHORT  must be 14                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2611
  /*   length         2     ULONG   table length in bytes                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2612
  /*   numSelector    6     ULONG   number of variation sel. records       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2613
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2614
  /* Followed by numSelector records, each of which looks like             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2615
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2616
  /*   varSelector    0     UINT24  Unicode codepoint of sel.              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2617
  /*   defaultOff     3     ULONG   offset to a default UVS table          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2618
  /*                                describing any variants to be found in */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2619
  /*                                the normal Unicode subtable.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2620
  /*   nonDefOff      7     ULONG   offset to a non-default UVS table      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2621
  /*                                describing any variants not in the     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2622
  /*                                standard cmap, with GIDs here          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2623
  /* (either offset may be 0 NULL)                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2624
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2625
  /* Selectors are sorted by code point.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2626
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2627
  /* A default Unicode Variation Selector (UVS) subtable is just a list of */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2628
  /* ranges of code points which are to be found in the standard cmap.  No */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2629
  /* glyph IDs (GIDs) here.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2630
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2631
  /*   numRanges      0     ULONG   number of ranges following             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2632
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2633
  /* A range looks like                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2634
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2635
  /*   uniStart       0     UINT24  code point of the first character in   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2636
  /*                                this range                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2637
  /*   additionalCnt  3     UBYTE   count of additional characters in this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2638
  /*                                range (zero means a range of a single  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2639
  /*                                character)                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2640
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2641
  /* Ranges are sorted by `uniStart'.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2642
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2643
  /* A non-default Unicode Variation Selector (UVS) subtable is a list of  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2644
  /* mappings from codepoint to GID.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2645
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2646
  /*   numMappings    0     ULONG   number of mappings                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2647
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2648
  /* A range looks like                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2649
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2650
  /*   uniStart       0     UINT24  code point of the first character in   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2651
  /*                                this range                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2652
  /*   GID            3     USHORT  and its GID                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2653
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2654
  /* Ranges are sorted by `uniStart'.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2656
#ifdef TT_CONFIG_CMAP_FORMAT_14
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2658
  typedef struct  TT_CMap14Rec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2659
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2660
    TT_CMapRec  cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2661
    FT_ULong    num_selectors;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2663
    /* This array is used to store the results of various
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2664
     * cmap 14 query functions.  The data is overwritten
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2665
     * on each call to these functions.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2666
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2667
    FT_UInt32   max_results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2668
    FT_UInt32*  results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2669
    FT_Memory   memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2670
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2671
  } TT_CMap14Rec, *TT_CMap14;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2674
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2675
  tt_cmap14_done( TT_CMap14  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2676
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2677
    FT_Memory  memory = cmap->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2679
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2680
    cmap->max_results = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2681
    if ( memory != NULL && cmap->results != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2682
      FT_FREE( cmap->results );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2683
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2686
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2687
  tt_cmap14_ensure( TT_CMap14  cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2688
                    FT_UInt32  num_results,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2689
                    FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2690
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2691
    FT_UInt32 old_max = cmap->max_results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2692
    FT_Error  error   = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2695
    if ( num_results > cmap->max_results )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2696
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2697
       cmap->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2699
       if ( FT_QRENEW_ARRAY( cmap->results, old_max, num_results ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2700
         return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2701
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2702
       cmap->max_results = num_results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2703
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2705
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2706
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2709
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2710
  tt_cmap14_init( TT_CMap14  cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2711
                  FT_Byte*   table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2712
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2713
    cmap->cmap.data = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2715
    table               += 6;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2716
    cmap->num_selectors = FT_PEEK_ULONG( table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2717
    cmap->max_results   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2718
    cmap->results       = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2720
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2721
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2724
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2725
  tt_cmap14_validate( FT_Byte*      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2726
                      FT_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2727
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2728
    FT_Byte*  p             = table + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2729
    FT_ULong  length        = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2730
    FT_ULong  num_selectors = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2731
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2733
    if ( length > (FT_ULong)( valid->limit - table ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2734
         length < 10 + 11 * num_selectors            )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2735
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2737
    /* check selectors, they must be in increasing order */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2738
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2739
      /* we start lastVarSel at 1 because a variant selector value of 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2740
       * isn't valid.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2741
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2742
      FT_ULong  n, lastVarSel = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2743
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2745
      for ( n = 0; n < num_selectors; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2746
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2747
        FT_ULong  varSel    = TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2748
        FT_ULong  defOff    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2749
        FT_ULong  nondefOff = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2751
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2752
        if ( defOff >= length || nondefOff >= length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2753
          FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2755
        if ( varSel < lastVarSel )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2756
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2758
        lastVarSel = varSel + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2760
        /* check the default table (these glyphs should be reached     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2761
        /* through the normal Unicode cmap, no GIDs, just check order) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2762
        if ( defOff != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2763
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2764
          FT_Byte*  defp      = table + defOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2765
          FT_ULong  numRanges = TT_NEXT_ULONG( defp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2766
          FT_ULong  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2767
          FT_ULong  lastBase  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2769
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2770
          if ( defp + numRanges * 4 > valid->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2771
            FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2772
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2773
          for ( i = 0; i < numRanges; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2774
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2775
            FT_ULong  base = TT_NEXT_UINT24( defp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2776
            FT_ULong  cnt  = FT_NEXT_BYTE( defp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2778
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2779
            if ( base + cnt >= 0x110000UL )              /* end of Unicode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2780
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2782
            if ( base < lastBase )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2783
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2785
            lastBase = base + cnt + 1U;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2786
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2787
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2789
        /* and the non-default table (these glyphs are specified here) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2790
        if ( nondefOff != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2791
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2792
          FT_Byte*  ndp         = table + nondefOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2793
          FT_ULong  numMappings = TT_NEXT_ULONG( ndp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2794
          FT_ULong  i, lastUni = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2797
          if ( numMappings * 4 > (FT_ULong)( valid->limit - ndp ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2798
            FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2800
          for ( i = 0; i < numMappings; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2801
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2802
            FT_ULong  uni = TT_NEXT_UINT24( ndp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2803
            FT_ULong  gid = TT_NEXT_USHORT( ndp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2806
            if ( uni >= 0x110000UL )                     /* end of Unicode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2807
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2808
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2809
            if ( uni < lastUni )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2810
              FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2812
            lastUni = uni + 1U;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2814
            if ( valid->level >= FT_VALIDATE_TIGHT    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2815
                 gid >= TT_VALID_GLYPH_COUNT( valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2816
              FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2817
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2818
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2819
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2820
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2821
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2822
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2823
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2824
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2826
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2827
  tt_cmap14_char_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2828
                        FT_UInt32  char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2829
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2830
    FT_UNUSED( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2831
    FT_UNUSED( char_code );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2832
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2833
    /* This can't happen */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2834
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2835
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2838
  FT_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2839
  tt_cmap14_char_next( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2840
                       FT_UInt32  *pchar_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2841
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2842
    FT_UNUSED( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2843
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2844
    /* This can't happen */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2845
    *pchar_code = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2846
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2847
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2848
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2850
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2851
  tt_cmap14_get_info( TT_CMap       cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2852
                      TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2853
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2854
    FT_UNUSED( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2855
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2856
    cmap_info->format   = 14;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2857
    /* subtable 14 does not define a language field */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2858
    cmap_info->language = 0xFFFFFFFFUL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2859
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2860
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2861
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2864
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2865
  tt_cmap14_char_map_def_binary( FT_Byte    *base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2866
                                 FT_UInt32   char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2867
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2868
    FT_UInt32  numRanges = TT_PEEK_ULONG( base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2869
    FT_UInt32  max, min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2870
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2871
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2872
    min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2873
    max = numRanges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2875
    base += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2876
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2877
    /* binary search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2878
    while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2879
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2880
      FT_UInt32  mid   = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2881
      FT_Byte*   p     = base + 4 * mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2882
      FT_ULong   start = TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2883
      FT_UInt    cnt   = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2886
      if ( char_code < start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2887
        max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2888
      else if ( char_code > start+cnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2889
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2890
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2891
        return TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2892
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2894
    return FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2895
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2897
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2898
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2899
  tt_cmap14_char_map_nondef_binary( FT_Byte    *base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2900
                                    FT_UInt32   char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2901
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2902
    FT_UInt32  numMappings = TT_PEEK_ULONG( base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2903
    FT_UInt32  max, min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2904
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2906
    min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2907
    max = numMappings;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2908
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2909
    base += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2910
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2911
    /* binary search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2912
    while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2913
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2914
      FT_UInt32  mid = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2915
      FT_Byte*   p   = base + 5 * mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2916
      FT_UInt32  uni = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2918
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2919
      if ( char_code < uni )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2920
        max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2921
      else if ( char_code > uni )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2922
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2923
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2924
        return TT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2925
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2927
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2928
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2931
  static FT_Byte*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2932
  tt_cmap14_find_variant( FT_Byte    *base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2933
                          FT_UInt32   variantCode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2934
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2935
    FT_UInt32  numVar = TT_PEEK_ULONG( base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2936
    FT_UInt32  max, min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2937
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2939
    min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2940
    max = numVar;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2942
    base += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2943
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2944
    /* binary search */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2945
    while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2946
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2947
      FT_UInt32  mid    = ( min + max ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2948
      FT_Byte*   p      = base + 11 * mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2949
      FT_ULong   varSel = TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2950
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2951
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2952
      if ( variantCode < varSel )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2953
        max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2954
      else if ( variantCode > varSel )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2955
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2956
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2957
        return p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2958
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2959
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2960
    return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2961
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2964
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2965
  tt_cmap14_char_var_index( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2966
                            TT_CMap    ucmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2967
                            FT_UInt32  charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2968
                            FT_UInt32  variantSelector)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2969
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2970
    FT_Byte*  p = tt_cmap14_find_variant( cmap->data + 6, variantSelector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2971
    FT_ULong  defOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2972
    FT_ULong  nondefOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2973
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2974
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2975
    if ( !p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2976
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2978
    defOff    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2979
    nondefOff = TT_PEEK_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2980
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2981
    if ( defOff != 0                                                    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2982
         tt_cmap14_char_map_def_binary( cmap->data + defOff, charcode ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2983
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2984
      /* This is the default variant of this charcode.  GID not stored */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2985
      /* here; stored in the normal Unicode charmap instead.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2986
      return ucmap->cmap.clazz->char_index( &ucmap->cmap, charcode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2987
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2988
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2989
    if ( nondefOff != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2990
      return tt_cmap14_char_map_nondef_binary( cmap->data + nondefOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2991
                                               charcode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2992
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2993
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2994
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2995
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2996
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2997
  FT_CALLBACK_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2998
  tt_cmap14_char_var_isdefault( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2999
                                FT_UInt32  charcode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3000
                                FT_UInt32  variantSelector )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3001
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3002
    FT_Byte*  p = tt_cmap14_find_variant( cmap->data + 6, variantSelector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3003
    FT_ULong  defOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3004
    FT_ULong  nondefOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3005
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3007
    if ( !p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3008
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3010
    defOff    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3011
    nondefOff = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3012
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3013
    if ( defOff != 0                                                    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3014
         tt_cmap14_char_map_def_binary( cmap->data + defOff, charcode ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3015
      return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3017
    if ( nondefOff != 0                                            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3018
         tt_cmap14_char_map_nondef_binary( cmap->data + nondefOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3019
                                           charcode ) != 0         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3020
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3021
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3022
    return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3023
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3026
  FT_CALLBACK_DEF( FT_UInt32* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3027
  tt_cmap14_variants( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3028
                      FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3029
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3030
    TT_CMap14   cmap14 = (TT_CMap14)cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3031
    FT_UInt32   count  = cmap14->num_selectors;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3032
    FT_Byte*    p      = cmap->data + 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3033
    FT_UInt32*  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3034
    FT_UInt32   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3035
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3036
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3037
    if ( tt_cmap14_ensure( cmap14, ( count + 1 ), memory ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3038
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3040
    result = cmap14->results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3041
    for ( i = 0; i < count; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3042
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3043
      result[i] = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3044
      p        += 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3045
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3046
    result[i] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3048
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3049
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3052
  FT_CALLBACK_DEF( FT_UInt32 * )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3053
  tt_cmap14_char_variants( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3054
                           FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3055
                           FT_UInt32  charCode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3056
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3057
    TT_CMap14   cmap14 = (TT_CMap14)  cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3058
    FT_UInt32   count  = cmap14->num_selectors;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3059
    FT_Byte*    p      = cmap->data + 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3060
    FT_UInt32*  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3061
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3062
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3063
    if ( tt_cmap14_ensure( cmap14, ( count + 1 ), memory ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3064
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3066
    for ( q = cmap14->results; count > 0; --count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3067
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3068
      FT_UInt32  varSel    = TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3069
      FT_ULong   defOff    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3070
      FT_ULong   nondefOff = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3072
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3073
      if ( ( defOff != 0                                               &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3074
             tt_cmap14_char_map_def_binary( cmap->data + defOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3075
                                            charCode )                 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3076
           ( nondefOff != 0                                            &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3077
             tt_cmap14_char_map_nondef_binary( cmap->data + nondefOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3078
                                               charCode ) != 0         ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3079
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3080
        q[0] = varSel;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3081
        q++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3082
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3083
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3084
    q[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3085
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3086
    return cmap14->results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3087
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3088
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3089
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3090
  static FT_UInt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3091
  tt_cmap14_def_char_count( FT_Byte  *p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3092
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3093
    FT_UInt32  numRanges = (FT_UInt32)TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3094
    FT_UInt    tot       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3095
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3096
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3097
    p += 3;  /* point to the first `cnt' field */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3098
    for ( ; numRanges > 0; numRanges-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3099
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3100
      tot += 1 + p[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3101
      p   += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3102
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3104
    return tot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3105
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3108
  static FT_UInt32*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3109
  tt_cmap14_get_def_chars( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3110
                           FT_Byte*    p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3111
                           FT_Memory   memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3112
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3113
    TT_CMap14   cmap14 = (TT_CMap14) cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3114
    FT_UInt32   numRanges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3115
    FT_UInt     cnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3116
    FT_UInt32*  q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3119
    cnt       = tt_cmap14_def_char_count( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3120
    numRanges = (FT_UInt32)TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3122
    if ( tt_cmap14_ensure( cmap14, ( cnt + 1 ), memory ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3123
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3125
    for ( q = cmap14->results; numRanges > 0; --numRanges )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3126
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3127
      FT_UInt32 uni = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3130
      cnt = FT_NEXT_BYTE( p ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3131
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3132
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3133
        q[0]  = uni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3134
        uni  += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3135
        q    += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3136
      } while ( --cnt != 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3137
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3138
    q[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3140
    return cmap14->results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3141
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3144
  static FT_UInt32*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3145
  tt_cmap14_get_nondef_chars( TT_CMap     cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3146
                              FT_Byte    *p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3147
                              FT_Memory   memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3148
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3149
    TT_CMap14   cmap14 = (TT_CMap14) cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3150
    FT_UInt32   numMappings;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3151
    FT_UInt     i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3152
    FT_UInt32  *ret;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3155
    numMappings = (FT_UInt32)TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3157
    if ( tt_cmap14_ensure( cmap14, ( numMappings + 1 ), memory ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3158
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3160
    ret = cmap14->results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3161
    for ( i = 0; i < numMappings; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3162
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3163
      ret[i] = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3164
      p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3165
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3166
    ret[i] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3168
    return ret;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3169
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3172
  FT_CALLBACK_DEF( FT_UInt32 * )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3173
  tt_cmap14_variant_chars( TT_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3174
                           FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3175
                           FT_UInt32  variantSelector )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3176
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3177
    FT_Byte    *p  = tt_cmap14_find_variant( cmap->data + 6,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3178
                                             variantSelector );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3179
    FT_UInt32  *ret;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3180
    FT_Int      i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3181
    FT_ULong    defOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3182
    FT_ULong    nondefOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3185
    if ( !p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3186
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3188
    defOff    = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3189
    nondefOff = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3191
    if ( defOff == 0 && nondefOff == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3192
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3194
    if ( defOff == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3195
      return tt_cmap14_get_nondef_chars( cmap, cmap->data + nondefOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3196
                                         memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3197
    else if ( nondefOff == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3198
      return tt_cmap14_get_def_chars( cmap, cmap->data + defOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3199
                                      memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3200
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3201
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3202
      /* Both a default and a non-default glyph set?  That's probably not */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3203
      /* good font design, but the spec allows for it...                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3204
      TT_CMap14  cmap14 = (TT_CMap14) cmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3205
      FT_UInt32  numRanges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3206
      FT_UInt32  numMappings;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3207
      FT_UInt32  duni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3208
      FT_UInt32  dcnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3209
      FT_UInt32  nuni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3210
      FT_Byte*   dp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3211
      FT_UInt    di, ni, k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3214
      p  = cmap->data + nondefOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3215
      dp = cmap->data + defOff;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3217
      numMappings = (FT_UInt32)TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3218
      dcnt        = tt_cmap14_def_char_count( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3219
      numRanges   = (FT_UInt32)TT_NEXT_ULONG( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3221
      if ( numMappings == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3222
        return tt_cmap14_get_def_chars( cmap, cmap->data + defOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3223
                                        memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3224
      if ( dcnt == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3225
        return tt_cmap14_get_nondef_chars( cmap, cmap->data + nondefOff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3226
                                           memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3228
      if ( tt_cmap14_ensure( cmap14, ( dcnt + numMappings + 1 ), memory ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3229
        return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3231
      ret  = cmap14->results;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3232
      duni = (FT_UInt32)TT_NEXT_UINT24( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3233
      dcnt = FT_NEXT_BYTE( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3234
      di   = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3235
      nuni = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3236
      p   += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3237
      ni   = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3238
      i    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3240
      for ( ;; )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3241
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3242
        if ( nuni > duni + dcnt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3243
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3244
          for ( k = 0; k <= dcnt; ++k )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3245
            ret[i++] = duni + k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3247
          ++di;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3249
          if ( di > numRanges )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3250
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3252
          duni = (FT_UInt32)TT_NEXT_UINT24( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3253
          dcnt = FT_NEXT_BYTE( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3254
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3255
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3256
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3257
          if ( nuni < duni )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3258
            ret[i++] = nuni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3259
          /* If it is within the default range then ignore it -- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3260
          /* that should not have happened                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3261
          ++ni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3262
          if ( ni > numMappings )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3263
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3265
          nuni = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3266
          p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3267
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3268
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3270
      if ( ni <= numMappings )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3271
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3272
        /* If we get here then we have run out of all default ranges.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3273
        /* We have read one non-default mapping which we haven't stored */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3274
        /* and there may be others that need to be read.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3275
        ret[i++] = nuni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3276
        while ( ni < numMappings )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3277
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3278
          ret[i++] = (FT_UInt32)TT_NEXT_UINT24( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3279
          p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3280
          ++ni;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3281
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3282
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3283
      else if ( di <= numRanges )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3284
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3285
        /* If we get here then we have run out of all non-default     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3286
        /* mappings.  We have read one default range which we haven't */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3287
        /* stored and there may be others that need to be read.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3288
        for ( k = 0; k <= dcnt; ++k )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3289
          ret[i++] = duni + k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3291
        while ( di < numRanges )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3292
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3293
          duni = (FT_UInt32)TT_NEXT_UINT24( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3294
          dcnt = FT_NEXT_BYTE( dp );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3296
          for ( k = 0; k <= dcnt; ++k )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3297
            ret[i++] = duni + k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3298
          ++di;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3299
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3300
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3302
      ret[i] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3304
      return ret;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3305
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3306
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3309
  FT_DEFINE_TT_CMAP(tt_cmap14_class_rec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3310
      sizeof ( TT_CMap14Rec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3312
      (FT_CMap_InitFunc)     tt_cmap14_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3313
      (FT_CMap_DoneFunc)     tt_cmap14_done,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3314
      (FT_CMap_CharIndexFunc)tt_cmap14_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3315
      (FT_CMap_CharNextFunc) tt_cmap14_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3317
      /* Format 14 extension functions */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3318
      (FT_CMap_CharVarIndexFunc)    tt_cmap14_char_var_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3319
      (FT_CMap_CharVarIsDefaultFunc)tt_cmap14_char_var_isdefault,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3320
      (FT_CMap_VariantListFunc)     tt_cmap14_variants,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3321
      (FT_CMap_CharVariantListFunc) tt_cmap14_char_variants,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3322
      (FT_CMap_VariantCharListFunc) tt_cmap14_variant_chars
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3323
    ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3324
    14,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3325
    (TT_CMap_ValidateFunc)tt_cmap14_validate,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3326
    (TT_CMap_Info_GetFunc)tt_cmap14_get_info
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3327
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3329
#endif /* TT_CONFIG_CMAP_FORMAT_14 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3332
#ifndef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3334
  static const TT_CMap_Class  tt_cmap_classes[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3335
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3336
#define TTCMAPCITEM(a) &a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3337
#include "ttcmapc.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3338
    NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3339
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3341
#else /*FT_CONFIG_OPTION_PIC*/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3343
  void FT_Destroy_Class_tt_cmap_classes(FT_Library library, TT_CMap_Class* clazz)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3344
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3345
    FT_Memory memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3346
    if ( clazz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3347
      FT_FREE( clazz );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3348
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3350
  FT_Error FT_Create_Class_tt_cmap_classes(FT_Library library, TT_CMap_Class** output_class)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3351
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3352
    TT_CMap_Class*  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3353
    TT_CMap_ClassRec* recs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3354
    FT_Error          error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3355
    FT_Memory memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3356
    int i = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3358
#define TTCMAPCITEM(a) i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3359
#include "ttcmapc.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3361
    /* allocate enough space for both the pointers +terminator and the class instances */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3362
    if ( FT_ALLOC( clazz, sizeof(*clazz)*(i+1)+sizeof(TT_CMap_ClassRec)*i ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3363
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3365
    /* the location of the class instances follows the array of pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3366
    recs = (TT_CMap_ClassRec*) (((char*)clazz)+(sizeof(*clazz)*(i+1))); 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3367
    i=0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3369
#undef TTCMAPCITEM
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3370
#define TTCMAPCITEM(a)           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3371
    FT_Init_Class_##a(&recs[i]); \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3372
    clazz[i] = &recs[i];         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3373
    i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3374
#include "ttcmapc.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3376
    clazz[i] = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3378
    *output_class = clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3379
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3380
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3382
#endif /*FT_CONFIG_OPTION_PIC*/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3385
  /* parse the `cmap' table and build the corresponding TT_CMap objects */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3386
  /* in the current face                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3387
  /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3388
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3389
  tt_face_build_cmaps( TT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3390
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3391
    FT_Byte*           table = face->cmap_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3392
    FT_Byte*           limit = table + face->cmap_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3393
    FT_UInt volatile   num_cmaps;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3394
    FT_Byte* volatile  p     = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3395
    FT_Library         library = FT_FACE_LIBRARY( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3397
    FT_UNUSED( library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3399
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3400
    if ( !p || p + 4 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3401
      return SFNT_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3403
    /* only recognize format 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3404
    if ( TT_NEXT_USHORT( p ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3405
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3406
      p -= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3407
      FT_ERROR(( "tt_face_build_cmaps:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3408
                 " unsupported `cmap' table format = %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3409
                 TT_PEEK_USHORT( p ) ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3410
      return SFNT_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3411
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3413
    num_cmaps = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3414
#ifdef FT_MAX_CHARMAP_CACHEABLE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3415
    if ( num_cmaps > FT_MAX_CHARMAP_CACHEABLE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3416
      FT_ERROR(( "tt_face_build_cmaps: too many cmap subtables(%d) "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3417
                 "subtable#%d and later are loaded but cannot be searched\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3418
                 num_cmaps, FT_MAX_CHARMAP_CACHEABLE + 1 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3419
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3421
    for ( ; num_cmaps > 0 && p + 8 <= limit; num_cmaps-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3422
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3423
      FT_CharMapRec  charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3424
      FT_UInt32      offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3427
      charmap.platform_id = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3428
      charmap.encoding_id = TT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3429
      charmap.face        = FT_FACE( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3430
      charmap.encoding    = FT_ENCODING_NONE;  /* will be filled later */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3431
      offset              = TT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3433
      if ( offset && offset <= face->cmap_size - 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3434
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3435
        FT_Byte* volatile              cmap   = table + offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3436
        volatile FT_UInt               format = TT_PEEK_USHORT( cmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3437
        const TT_CMap_Class* volatile  pclazz = FT_TT_CMAP_CLASSES_GET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3438
        TT_CMap_Class volatile         clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3441
        for ( ; *pclazz; pclazz++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3442
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3443
          clazz = *pclazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3444
          if ( clazz->format == format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3445
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3446
            volatile TT_ValidatorRec  valid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3447
            volatile FT_Error         error = SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3449
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3450
            ft_validator_init( FT_VALIDATOR( &valid ), cmap, limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3451
                               FT_VALIDATE_DEFAULT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3453
            valid.num_glyphs = (FT_UInt)face->max_profile.numGlyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3455
            if ( ft_setjmp(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3456
              *((ft_jmp_buf*)&FT_VALIDATOR( &valid )->jump_buffer) ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3457
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3458
              /* validate this cmap sub-table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3459
              error = clazz->validate( cmap, FT_VALIDATOR( &valid ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3460
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3462
            if ( valid.validator.error == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3463
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3464
              FT_CMap  ttcmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3467
              /* It might make sense to store the single variation selector */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3468
              /* cmap somewhere special.  But it would have to be in the    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3469
              /* public FT_FaceRec, and we can't change that.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3471
              if ( !FT_CMap_New( (FT_CMap_Class)clazz,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3472
                                 cmap, &charmap, &ttcmap ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3473
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3474
                /* it is simpler to directly set `flags' than adding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3475
                /* a parameter to FT_CMap_New                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3476
                ((TT_CMap)ttcmap)->flags = (FT_Int)error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3477
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3478
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3479
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3480
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3481
              FT_TRACE0(( "tt_face_build_cmaps:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3482
                          " broken cmap sub-table ignored\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3483
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3484
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3485
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3486
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3488
        if ( *pclazz == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3489
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3490
          FT_TRACE0(( "tt_face_build_cmaps:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3491
                      " unsupported cmap sub-table ignored\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3492
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3493
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3494
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3496
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3497
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3500
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3501
  tt_get_cmap_info( FT_CharMap    charmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3502
                    TT_CMapInfo  *cmap_info )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3503
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3504
    FT_CMap        cmap  = (FT_CMap)charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3505
    TT_CMap_Class  clazz = (TT_CMap_Class)cmap->clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3508
    return clazz->get_cmap_info( charmap, cmap_info );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3509
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  3512
/* END */