misc/libfreetype/src/autofit/afglobal.c
author unc0rr
Sat, 24 Aug 2013 01:37:20 +0400
branch0.9.19
changeset 9142 0dceffbaa4ee
parent 5172 88f2e05288ba
permissions -rw-r--r--
Fix script flaw in detection of best team when sending achievement info
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
/*  afglobal.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
/*    Auto-fitter routines to compute global hinting values (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 2003-2011 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 "afglobal.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "afdummy.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include "aflatin.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include "afcjk.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include "afindic.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "afpic.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include "aferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#ifdef FT_OPTION_AUTOFIT2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include "aflatin2.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#endif
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
#ifndef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* when updating this table, don't forget to update          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* AF_SCRIPT_CLASSES_COUNT and autofit_module_class_pic_init */
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
  /* populate this list when you add new scripts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  static AF_ScriptClass const  af_script_classes[] =
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
    &af_dummy_script_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#ifdef FT_OPTION_AUTOFIT2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    &af_latin2_script_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    &af_latin_script_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
    &af_cjk_script_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    &af_indic_script_class, 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    NULL  /* do not remove */
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
#endif /* !FT_CONFIG_OPTION_PIC */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /* index of default script in `af_script_classes' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
#define AF_SCRIPT_LIST_DEFAULT  2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /* a bit mask indicating an uncovered glyph       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
#define AF_SCRIPT_LIST_NONE     0x7F
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /* if this flag is set, we have an ASCII digit    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
#define AF_DIGIT                0x80
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
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
   *  Note that glyph_scripts[] is used to map each glyph into
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
   *  an index into the `af_script_classes' array.
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
  typedef struct  AF_FaceGlobalsRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    FT_Face           face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    FT_Long           glyph_count;    /* same as face->num_glyphs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    FT_Byte*          glyph_scripts;
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
    AF_ScriptMetrics  metrics[AF_SCRIPT_MAX];
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
  } AF_FaceGlobalsRec;
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
  /* Compute the script index of each glyph within a given face. */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
  af_face_globals_compute_script_coverage( AF_FaceGlobals  globals )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    FT_Error    error       = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    FT_Face     face        = globals->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    FT_CharMap  old_charmap = face->charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    FT_Byte*    gscripts    = globals->glyph_scripts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    FT_UInt     ss, i;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    /* the value AF_SCRIPT_LIST_NONE means `uncovered glyph' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    FT_MEM_SET( globals->glyph_scripts,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
                AF_SCRIPT_LIST_NONE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
                globals->glyph_count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
     /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
      *  Ignore this error; we simply use the default script.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      *  XXX: Shouldn't we rather disable hinting?
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
      error = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      goto Exit;
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
    /* scan each script in a Unicode charmap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    for ( ss = 0; AF_SCRIPT_CLASSES_GET[ss]; ss++ )
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
      AF_ScriptClass      clazz = AF_SCRIPT_CLASSES_GET[ss];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
      AF_Script_UniRange  range;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
      if ( clazz->script_uni_ranges == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
        continue;
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
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
       *  Scan all unicode points in the range and set the corresponding
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
       *  glyph script index.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
      for ( range = clazz->script_uni_ranges; range->first != 0; range++ )
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
        FT_ULong  charcode = range->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        FT_UInt   gindex;
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
        gindex = FT_Get_Char_Index( face, charcode );
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
        if ( gindex != 0                             &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
             gindex < (FT_ULong)globals->glyph_count &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
             gscripts[gindex] == AF_SCRIPT_LIST_NONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
          gscripts[gindex] = (FT_Byte)ss;
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
        for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
          charcode = FT_Get_Next_Char( face, charcode, &gindex );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
          if ( gindex == 0 || charcode > range->last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
            break;
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
          if ( gindex < (FT_ULong)globals->glyph_count &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
               gscripts[gindex] == AF_SCRIPT_LIST_NONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
            gscripts[gindex] = (FT_Byte)ss;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      }
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
    /* mark ASCII digits */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    for ( i = 0x30; i <= 0x39; i++ )
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
      FT_UInt  gindex = FT_Get_Char_Index( face, i );
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
      if ( gindex != 0 && gindex < (FT_ULong)globals->glyph_count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
        gscripts[gindex] |= AF_DIGIT;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  Exit:
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
     *  By default, all uncovered glyphs are set to the latin script.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
     *  XXX: Shouldn't we disable hinting or do something similar?
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
      FT_Long  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      for ( nn = 0; nn < globals->glyph_count; nn++ )
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
        if ( ( gscripts[nn] & ~AF_DIGIT ) == AF_SCRIPT_LIST_NONE )
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
          gscripts[nn] &= ~AF_SCRIPT_LIST_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
          gscripts[nn] |= AF_SCRIPT_LIST_DEFAULT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    FT_Set_Charmap( face, old_charmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
  af_face_globals_new( FT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
                       AF_FaceGlobals  *aglobals )
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
    FT_Error        error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
    FT_Memory       memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    AF_FaceGlobals  globals = NULL;
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
    memory = face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    if ( !FT_ALLOC( globals, sizeof ( *globals ) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
                             face->num_glyphs * sizeof ( FT_Byte ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      globals->face          = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      globals->glyph_count   = face->num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      globals->glyph_scripts = (FT_Byte*)( globals + 1 );
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
      error = af_face_globals_compute_script_coverage( globals );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
        af_face_globals_free( globals );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
        globals = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    *aglobals = globals;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  af_face_globals_free( AF_FaceGlobals  globals )
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
    if ( globals )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      FT_Memory  memory = globals->face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      FT_UInt    nn;
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
      for ( nn = 0; nn < AF_SCRIPT_MAX; nn++ )
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
        if ( globals->metrics[nn] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
          AF_ScriptClass  clazz = AF_SCRIPT_CLASSES_GET[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
          FT_ASSERT( globals->metrics[nn]->clazz == clazz );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
          if ( clazz->script_metrics_done )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
            clazz->script_metrics_done( globals->metrics[nn] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
          FT_FREE( globals->metrics[nn] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      globals->glyph_count   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      globals->glyph_scripts = NULL;  /* no need to free this one! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      globals->face          = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      FT_FREE( globals );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  af_face_globals_get_metrics( AF_FaceGlobals     globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
                               FT_UInt            gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
                               FT_UInt            options,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
                               AF_ScriptMetrics  *ametrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    AF_ScriptMetrics  metrics = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    FT_UInt           gidx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    AF_ScriptClass    clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    FT_UInt           script     = options & 15;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    const FT_Offset   script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) /
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
                                     sizeof ( AF_SCRIPT_CLASSES_GET[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    FT_Error          error      = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    if ( gindex >= (FT_ULong)globals->glyph_count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      error = AF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    gidx = script;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    if ( gidx == 0 || gidx + 1 >= script_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      gidx = globals->glyph_scripts[gindex] & AF_SCRIPT_LIST_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    clazz = AF_SCRIPT_CLASSES_GET[gidx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    if ( script == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      script = clazz->script;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    metrics = globals->metrics[clazz->script];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    if ( metrics == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
      /* create the global metrics object when needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
      FT_Memory  memory = globals->face->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
      if ( FT_ALLOC( metrics, clazz->script_metrics_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
      metrics->clazz = clazz;
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
      if ( clazz->script_metrics_init )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
        error = clazz->script_metrics_init( metrics, globals->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
          if ( clazz->script_metrics_done )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
            clazz->script_metrics_done( metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
          FT_FREE( metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
          goto Exit;
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
      }
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
      globals->metrics[clazz->script] = metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
    *ametrics = metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
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
  FT_LOCAL_DEF( FT_Bool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
  af_face_globals_is_digit( AF_FaceGlobals  globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
                            FT_UInt         gindex )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    if ( gindex < (FT_ULong)globals->glyph_count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
      return (FT_Bool)( globals->glyph_scripts[gindex] & AF_DIGIT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    return (FT_Bool)0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
/* END */