misc/libfreetype/src/pfr/pfrcmap.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
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
/*  pfrcmap.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType PFR cmap handling (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, 2007, 2009 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 "pfrcmap.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "pfrobjs.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 "pfrerror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  pfr_cmap_init( PFR_CMap  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
    FT_Error  error = PFR_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
    PFR_Face  face  = (PFR_Face)FT_CMAP_FACE( cmap );
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
    cmap->num_chars = face->phy_font.num_chars;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    cmap->chars     = face->phy_font.chars;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    /* just for safety, check that the character entries are correctly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
    /* sorted in increasing character code order                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
      FT_UInt  n;
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
      for ( n = 1; n < cmap->num_chars; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
        if ( cmap->chars[n - 1].char_code >= cmap->chars[n].char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
          error = PFR_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  pfr_cmap_done( PFR_CMap  cmap )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    cmap->chars     = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    cmap->num_chars = 0;
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
  FT_CALLBACK_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  pfr_cmap_char_index( PFR_CMap   cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
                       FT_UInt32  char_code )
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
    FT_UInt   min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    FT_UInt   max = cmap->num_chars;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    FT_UInt   mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    PFR_Char  gchar;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    while ( min < max )
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
      mid   = min + ( max - min ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      gchar = cmap->chars + mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      if ( gchar->char_code == char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
        return mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      if ( gchar->char_code < char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
        min = mid + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
        max = mid;
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
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
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_CALLBACK_DEF( FT_UInt32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  pfr_cmap_char_next( PFR_CMap    cmap,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
                      FT_UInt32  *pchar_code )
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
    FT_UInt    result    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    FT_UInt32  char_code = *pchar_code + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  Restart:
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   min = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      FT_UInt   max = cmap->num_chars;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
      FT_UInt   mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
      PFR_Char  gchar;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
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
      while ( min < max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
        mid   = min + ( ( max - min ) >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        gchar = cmap->chars + mid;
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
        if ( gchar->char_code == char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
          result = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
          if ( result != 0 )
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
            result++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
          char_code++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
          goto Restart;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
        if ( gchar->char_code < char_code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
          min = mid+1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
          max = mid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
      /* we didn't find it, but we have a pair just above it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
      char_code = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      if ( min < cmap->num_chars )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
        gchar  = cmap->chars + min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
        result = min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
        if ( result != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
          result++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
          char_code = gchar->char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    *pchar_code = char_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
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
  FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
  pfr_cmap_class_rec =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    sizeof ( PFR_CMapRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    (FT_CMap_InitFunc)     pfr_cmap_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    (FT_CMap_DoneFunc)     pfr_cmap_done,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    (FT_CMap_CharIndexFunc)pfr_cmap_char_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    (FT_CMap_CharNextFunc) pfr_cmap_char_next,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    NULL, NULL, NULL, NULL, NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
/* END */