misc/libfreetype/src/autofit/aflatin.c
author sheepluva
Wed, 05 Jun 2013 16:28:30 +0200
changeset 9137 d987230b85ed
parent 5172 88f2e05288ba
permissions -rw-r--r--
fixed all engine compilation hints and notes (that I could see)
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
/*  aflatin.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 hinting routines for latin script (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 <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_ADVANCES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include "aflatin.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "aferrors.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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#ifdef AF_CONFIG_OPTION_USE_WARPER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include "afwarp.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#endif
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* 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
    35
  /* 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
    36
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#define FT_COMPONENT  trace_aflatin
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
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
  /*************************************************************************/
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
  /*****            L A T I N   G L O B A L   M E T R I C S            *****/
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
  /*************************************************************************/
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
  /* Find segments and links, compute all stem widths, and initialize */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /* standard width and height for the glyph with given charcode.     */
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_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  af_latin_metrics_init_widths( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
                                FT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
                                FT_ULong         charcode )
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
    /* scan the array of segments in each direction */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    AF_GlyphHintsRec  hints[1];
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
    af_glyph_hints_init( hints, face->memory );
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
    metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    metrics->axis[AF_DIMENSION_VERT].width_count = 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
      FT_Error             error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
      FT_UInt              glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
      int                  dim;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      AF_LatinMetricsRec   dummy[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
      AF_Scaler            scaler = &dummy->root.scaler;
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
      glyph_index = FT_Get_Char_Index( face, charcode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      if ( glyph_index == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
      error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      if ( error || face->glyph->outline.n_points <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
        goto Exit;
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
      FT_ZERO( dummy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      dummy->units_per_em = metrics->units_per_em;
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
      scaler->x_scale = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      scaler->y_scale = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      scaler->x_delta = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      scaler->y_delta = 0;
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
      scaler->face        = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      scaler->render_mode = FT_RENDER_MODE_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      scaler->flags       = 0;
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
      af_glyph_hints_rescale( hints, (AF_ScriptMetrics)dummy );
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
      error = af_glyph_hints_reload( hints, &face->glyph->outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
      if ( error )
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
      for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
        AF_LatinAxis  axis    = &metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
        AF_AxisHints  axhints = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
        AF_Segment    seg, limit, link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
        FT_UInt       num_widths = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
        error = af_latin_hints_compute_segments( hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
                                                 (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
          goto Exit;
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
        af_latin_hints_link_segments( hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
                                      (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
        seg   = axhints->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
        limit = seg + axhints->num_segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        for ( ; seg < limit; seg++ )
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
          link = seg->link;
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
          /* we only consider stem segments there! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
          if ( link && link->link == seg && link > seg )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
            FT_Pos  dist;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
            dist = seg->pos - link->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
            if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
              dist = -dist;
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
            if ( num_widths < AF_LATIN_MAX_WIDTHS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
              axis->widths[num_widths++].org = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
        af_sort_widths( num_widths, axis->widths );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
        axis->width_count = num_widths;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
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
        AF_LatinAxis  axis = &metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
        FT_Pos        stdw;
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
        stdw = ( axis->width_count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
                 ? axis->widths[0].org
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
                 : AF_LATIN_CONSTANT( metrics, 50 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
        /* let's try 20% of the smallest width */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
        axis->edge_distance_threshold = stdw / 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
        axis->standard_width          = stdw;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
        axis->extra_light             = 0;
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
    }
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
    af_glyph_hints_done( hints );
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
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
#define AF_LATIN_MAX_TEST_CHARACTERS  12
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
  static const char af_latin_blue_chars[AF_LATIN_MAX_BLUES]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
                                       [AF_LATIN_MAX_TEST_CHARACTERS + 1] =
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
    "THEZOCQS",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    "HEZLOCUS",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    "fijkdbh",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    "xzroesc",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    "xzroesc",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    "pqgjy"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
  };
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
  /* Find all blue zones.  Flat segments give the reference points, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  /* round segments the overshoot positions.                        */
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  af_latin_metrics_init_blues( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
                               FT_Face          face )
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
    FT_Pos        flats [AF_LATIN_MAX_TEST_CHARACTERS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    FT_Pos        rounds[AF_LATIN_MAX_TEST_CHARACTERS];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    FT_Int        num_flats;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    FT_Int        num_rounds;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    FT_Int        bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    AF_LatinBlue  blue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    AF_LatinAxis  axis  = &metrics->axis[AF_DIMENSION_VERT];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    FT_GlyphSlot  glyph = face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    /* we compute the blues simply by loading each character from the    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    /* `af_latin_blue_chars[blues]' string, then finding its top-most or */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    /* bottom-most points (depending on `AF_IS_TOP_BLUE')                */
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
    FT_TRACE5(( "blue zones computation\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    FT_TRACE5(( "------------------------------------------------\n" ));
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
    for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ )
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
      const char*  p     = af_latin_blue_chars[bb];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      const char*  limit = p + AF_LATIN_MAX_TEST_CHARACTERS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      FT_Pos*      blue_ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      FT_Pos*      blue_shoot;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      FT_TRACE5(( "blue %3d: ", bb ));
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
      num_flats  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      num_rounds = 0;
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
      for ( ; p < limit && *p; p++ )
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
        FT_UInt     glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
        FT_Pos      best_y;                            /* same as points.y */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
        FT_Int      best_point, best_first, best_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
        FT_Vector*  points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
        FT_Bool     round = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
        FT_TRACE5(( "'%c'", *p ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
        /* load the character in the face -- skip unknown or empty ones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
        glyph_index = FT_Get_Char_Index( face, (FT_UInt)*p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
        if ( glyph_index == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
        error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        if ( error || glyph->outline.n_points <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
          continue;
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
        /* now compute min or max point indices and coordinates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
        points      = glyph->outline.points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        best_point  = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
        best_y      = 0;  /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
        best_first  = 0;  /* ditto */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
        best_last   = 0;  /* ditto */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
          FT_Int  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
          FT_Int  first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
          FT_Int  last  = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
          for ( nn = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
                nn < glyph->outline.n_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
                first = last + 1, nn++ )
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
            FT_Int  old_best_point = best_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
            FT_Int  pp;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
            last = glyph->outline.contours[nn];
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
            /* Avoid single-point contours since they are never rasterized. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
            /* In some fonts, they correspond to mark attachment points     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
            /* which are way outside of the glyph's real outline.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
            if ( last <= first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
              continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
            if ( AF_LATIN_IS_TOP_BLUE( bb ) )
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
              for ( pp = first; pp <= last; pp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
                if ( best_point < 0 || points[pp].y > best_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
                  best_point = pp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
                  best_y     = points[pp].y;
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
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
              for ( pp = first; pp <= last; pp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
                if ( best_point < 0 || points[pp].y < best_y )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
                  best_point = pp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
                  best_y     = points[pp].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
                }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
            if ( best_point != old_best_point )
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
              best_first = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
              best_last  = last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
          FT_TRACE5(( "%5d", best_y ));
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
        /* now check whether the point belongs to a straight or round   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
        /* segment; we first need to find in which contour the extremum */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
        /* lies, then inspect its previous and next points              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
        if ( best_point >= 0 )
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
          FT_Int  prev, next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
          FT_Pos  dist;
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
          /* now look for the previous and next points that are not on the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
          /* same Y coordinate.  Threshold the `closeness'...              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
          prev = best_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
          next = prev;
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
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
            if ( prev > best_first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
              prev--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
              prev = best_last;
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
            dist = points[prev].y - best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
            if ( dist < -5 || dist > 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
              break;
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
          } while ( prev != best_point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
            if ( next < best_last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
              next++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
              next = best_first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
            dist = points[next].y - best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
            if ( dist < -5 || dist > 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
              break;
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
          } while ( next != best_point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
          /* now set the `round' flag depending on the segment's kind */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
          round = FT_BOOL(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
            FT_CURVE_TAG( glyph->outline.tags[prev] ) != FT_CURVE_TAG_ON ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
            FT_CURVE_TAG( glyph->outline.tags[next] ) != FT_CURVE_TAG_ON );
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
          FT_TRACE5(( "%c ", round ? 'r' : 'f' ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        if ( round )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
          rounds[num_rounds++] = best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
          flats[num_flats++]   = best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      FT_TRACE5(( "\n" ));
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
      if ( num_flats == 0 && num_rounds == 0 )
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
        /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
         *  we couldn't find a single glyph to compute this blue zone,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
         *  we will simply ignore it then
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
        FT_TRACE5(( "empty\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
        continue;
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
      /* we have computed the contents of the `rounds' and `flats' tables, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
      /* now determine the reference and overshoot position of the blue -- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
      /* we simply take the median value after a simple sort               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      af_sort_pos( num_rounds, rounds );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      af_sort_pos( num_flats,  flats );
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
      blue       = &axis->blues[axis->blue_count];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
      blue_ref   = &blue->ref.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
      blue_shoot = &blue->shoot.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
      axis->blue_count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      if ( num_flats == 0 )
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
        *blue_ref   =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
        *blue_shoot = rounds[num_rounds / 2];
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
      else if ( num_rounds == 0 )
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
        *blue_ref   =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
        *blue_shoot = flats[num_flats / 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
        *blue_ref   = flats[num_flats / 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
        *blue_shoot = rounds[num_rounds / 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      }
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
      /* there are sometimes problems: if the overshoot position of top     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      /* zones is under its reference position, or the opposite for bottom  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      /* zones.  We must thus check everything there and correct the errors */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      if ( *blue_shoot != *blue_ref )
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
        FT_Pos   ref      = *blue_ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
        FT_Pos   shoot    = *blue_shoot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
        FT_Bool  over_ref = FT_BOOL( shoot > ref );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        if ( AF_LATIN_IS_TOP_BLUE( bb ) ^ over_ref )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
          *blue_ref   =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
          *blue_shoot = ( shoot + ref ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      }
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
      blue->flags = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      if ( AF_LATIN_IS_TOP_BLUE( bb ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        blue->flags |= AF_LATIN_BLUE_TOP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
       * The following flag is used later to adjust the y and x scales
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
       * in order to optimize the pixel grid alignment of the top of small
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
       * letters.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      if ( bb == AF_LATIN_BLUE_SMALL_TOP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
        blue->flags |= AF_LATIN_BLUE_ADJUSTMENT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      FT_TRACE5(( "-- ref = %ld, shoot = %ld\n", *blue_ref, *blue_shoot ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    return;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
  /* Check whether all ASCII digits have the same advance width. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
  af_latin_metrics_check_digits( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
                                 FT_Face          face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    FT_UInt   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
    FT_Bool   started = 0, same_width = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    FT_Fixed  advance, old_advance = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
    /* digit `0' is 0x30 in all supported charmaps */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    for ( i = 0x30; i <= 0x39; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      FT_UInt  glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
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
      glyph_index = FT_Get_Char_Index( face, i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
      if ( glyph_index == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      if ( FT_Get_Advance( face, glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
                           FT_LOAD_NO_SCALE         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
                           FT_LOAD_NO_HINTING       |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
                           FT_LOAD_IGNORE_TRANSFORM,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
                           &advance ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
      if ( started )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
        if ( advance != old_advance )
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
          same_width = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
          break;
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
        old_advance = advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
        started     = 1;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    metrics->root.digits_have_same_width = same_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
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
  /* Initialize global metrics. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
  af_latin_metrics_init( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
                         FT_Face          face )
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_Error    error = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    FT_CharMap  oldmap = face->charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    FT_UInt     ee;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    static const FT_Encoding  latin_encodings[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
      FT_ENCODING_UNICODE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
      FT_ENCODING_APPLE_ROMAN,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      FT_ENCODING_ADOBE_STANDARD,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      FT_ENCODING_ADOBE_LATIN_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      FT_ENCODING_NONE  /* end of list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    };
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    metrics->units_per_em = face->units_per_EM;
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
    /* do we have a latin charmap in there? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    for ( ee = 0; latin_encodings[ee] != FT_ENCODING_NONE; ee++ )
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
      error = FT_Select_Charmap( face, latin_encodings[ee] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    }
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
    if ( !error )
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
      /* For now, compute the standard width and height from the `o'. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      af_latin_metrics_init_widths( metrics, face, 'o' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      af_latin_metrics_init_blues( metrics, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
      af_latin_metrics_check_digits( metrics, face );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    FT_Set_Charmap( face, oldmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    return AF_Err_Ok;
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
  /* Adjust scaling value, then scale and shift widths   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
  /* and blue zones (if applicable) for given dimension. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
  af_latin_metrics_scale_dim( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
                              AF_Scaler        scaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
                              AF_Dimension     dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    FT_Fixed      scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    FT_Pos        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
    AF_LatinAxis  axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
    FT_UInt       nn;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
      scale = scaler->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
      delta = scaler->x_delta;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
      scale = scaler->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
      delta = scaler->y_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    axis = &metrics->axis[dim];
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
    if ( axis->org_scale == scale && axis->org_delta == delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
      return;
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
    axis->org_scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
    axis->org_delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
     * correct X and Y scale to optimize the alignment of the top of small
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
     * letters to the pixel grid
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
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
      AF_LatinAxis  Axis = &metrics->axis[AF_DIMENSION_VERT];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
      AF_LatinBlue  blue = NULL;
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
      for ( nn = 0; nn < Axis->blue_count; nn++ )
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
        if ( Axis->blues[nn].flags & AF_LATIN_BLUE_ADJUSTMENT )
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
          blue = &Axis->blues[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
      }
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
      if ( blue )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
        FT_Pos  scaled = FT_MulFix( blue->shoot.org, scaler->y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
        FT_Pos  fitted = ( scaled + 40 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
        if ( scaled != fitted )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
          if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
            if ( fitted < scaled )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
              scale -= scale / 50;  /* scale *= 0.98 */
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
          if ( dim == AF_DIMENSION_VERT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
            scale = FT_MulDiv( scale, fitted, scaled );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
        }
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
    axis->scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    axis->delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      metrics->root.scaler.x_scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
      metrics->root.scaler.x_delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
      metrics->root.scaler.y_scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      metrics->root.scaler.y_delta = delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
    /* scale the widths */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
    for ( nn = 0; nn < axis->width_count; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      AF_Width  width = axis->widths + nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
      width->cur = FT_MulFix( width->org, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      width->fit = width->cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
    /* an extra-light axis corresponds to a standard width that is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
    /* smaller than 0.75 pixels                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
    axis->extra_light =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      (FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
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 ( dim == AF_DIMENSION_VERT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
      /* scale the blue zones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
      for ( nn = 0; nn < axis->blue_count; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        AF_LatinBlue  blue = &axis->blues[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        FT_Pos        dist;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
        blue->ref.cur   = FT_MulFix( blue->ref.org, scale ) + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
        blue->ref.fit   = blue->ref.cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
        blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
        blue->shoot.fit = blue->shoot.cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
        blue->flags    &= ~AF_LATIN_BLUE_ACTIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
        /* a blue zone is only active if it is less than 3/4 pixels tall */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
        dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
        if ( dist <= 48 && dist >= -48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
          FT_Pos  delta1, delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
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
          delta1 = blue->shoot.org - blue->ref.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
          delta2 = delta1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
          if ( delta1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
            delta2 = -delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
          delta2 = FT_MulFix( delta2, scale );
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
          if ( delta2 < 32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
            delta2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
          else if ( delta2 < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
            delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
            delta2 = FT_PIX_ROUND( delta2 );
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
          if ( delta1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
            delta2 = -delta2;
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
          blue->ref.fit   = FT_PIX_ROUND( blue->ref.cur );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
          blue->shoot.fit = blue->ref.fit + delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
          blue->flags |= AF_LATIN_BLUE_ACTIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      }
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
  }
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
  /* Scale global values in both directions. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
  af_latin_metrics_scale( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
                          AF_Scaler        scaler )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    metrics->root.scaler.render_mode = scaler->render_mode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    metrics->root.scaler.face        = scaler->face;
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
    af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
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
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
  /*****           L A T I N   G L Y P H   A N A L Y S I S             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
  /* Walk over all contours and compute its segments. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
  af_latin_hints_compute_segments( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
                                   AF_Dimension   dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
    AF_AxisHints   axis          = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    FT_Memory      memory        = hints->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    FT_Error       error         = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    AF_Segment     segment       = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
    AF_SegmentRec  seg0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    AF_Point*      contour       = hints->contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    AF_Point*      contour_limit = contour + hints->num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    AF_Direction   major_dir, segment_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
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
    FT_ZERO( &seg0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
    seg0.score = 32000;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    seg0.flags = AF_EDGE_NORMAL;
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
    major_dir   = (AF_Direction)FT_ABS( axis->major_dir );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    segment_dir = major_dir;
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
    axis->num_segments = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
    /* set up (u,v) in each point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    if ( dim == AF_DIMENSION_HORZ )
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
      AF_Point  point = hints->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      AF_Point  limit = point + hints->num_points;
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
      for ( ; point < limit; point++ )
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
        point->u = point->fx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
        point->v = point->fy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
    else
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
      AF_Point  point = hints->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
      AF_Point  limit = point + hints->num_points;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
      for ( ; point < limit; point++ )
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
        point->u = point->fy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
        point->v = point->fx;
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
    }
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
    /* do each contour separately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    for ( ; contour < contour_limit; contour++ )
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
      AF_Point  point   =  contour[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      AF_Point  last    =  point->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
      int       on_edge =  0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
      FT_Pos    min_pos =  32000;  /* minimum segment pos != min_coord */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
      FT_Pos    max_pos = -32000;  /* maximum segment pos != max_coord */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
      FT_Bool   passed;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      if ( point == last )  /* skip singletons -- just in case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
        continue;
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
      if ( FT_ABS( last->out_dir )  == major_dir &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
           FT_ABS( point->out_dir ) == major_dir )
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
        /* we are already on an edge, try to locate its start */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
        last = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
        for (;;)
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
          point = point->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
          if ( FT_ABS( point->out_dir ) != major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
            point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
          if ( point == last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
            break;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
      last   = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
      passed = 0;
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
      for (;;)
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_Pos  u, v;
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 ( on_edge )
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
          u = point->u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
          if ( u < min_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
            min_pos = u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
          if ( u > max_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
            max_pos = u;
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
          if ( point->out_dir != segment_dir || point == last )
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 are just leaving an edge; record a new segment! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
            segment->last = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
            segment->pos  = (FT_Short)( ( min_pos + max_pos ) >> 1 );
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
            /* a segment is round if either its first or last point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
            /* is a control point                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
            if ( ( segment->first->flags | point->flags ) &
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
                 AF_FLAG_CONTROL                          )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
              segment->flags |= AF_EDGE_ROUND;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
            /* compute segment size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
            min_pos = max_pos = point->v;
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
            v = segment->first->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
            if ( v < min_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
              min_pos = v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
            if ( v > max_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
              max_pos = v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
            segment->min_coord = (FT_Short)min_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
            segment->max_coord = (FT_Short)max_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
            segment->height    = (FT_Short)( segment->max_coord -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
                                             segment->min_coord );
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
            on_edge = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
            segment = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
            /* fallthrough */
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
        /* now exit if we are at the start/end point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
        if ( point == last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
          if ( passed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
          passed = 1;
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
        if ( !on_edge && FT_ABS( point->out_dir ) == major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
          /* this is the start of a new segment! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
          segment_dir = (AF_Direction)point->out_dir;
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
          /* clear all segment fields */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
          error = af_axis_hints_new_segment( axis, memory, &segment );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
            goto Exit;
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
          segment[0]        = seg0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
          segment->dir      = (FT_Char)segment_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
          min_pos = max_pos = point->u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
          segment->first    = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
          segment->last     = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
          segment->contour  = contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
          on_edge           = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
        }
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
        point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
    } /* contours */
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
    /* now slightly increase the height of segments when this makes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    /* sense -- this is used to better detect and ignore serifs     */
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
      AF_Segment  segments     = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
      AF_Segment  segments_end = segments + axis->num_segments;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
      for ( segment = segments; segment < segments_end; segment++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
        AF_Point  first   = segment->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
        AF_Point  last    = segment->last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
        FT_Pos    first_v = first->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
        FT_Pos    last_v  = last->v;
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
        if ( first == last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
        if ( first_v < last_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
          AF_Point  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
          p = first->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
          if ( p->v < first_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
                                          ( ( first_v - p->v ) >> 1 ) );
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
          p = last->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
          if ( p->v > last_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
                                          ( ( p->v - last_v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
          AF_Point  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
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
          p = first->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
          if ( p->v > first_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
                                          ( ( p->v - first_v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
          p = last->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
          if ( p->v < last_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
                                          ( ( last_v - p->v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
    return error;
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
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
  /* Link segments to form stems and serifs. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
  af_latin_hints_link_segments( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
                                AF_Dimension   dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
    AF_AxisHints  axis          = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    AF_Segment    segments      = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    AF_Segment    segment_limit = segments + axis->num_segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
    FT_Pos        len_threshold, len_score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
    AF_Segment    seg1, seg2;
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
    len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
    if ( len_threshold == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
      len_threshold = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
    len_score = AF_LATIN_CONSTANT( hints->metrics, 6000 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
    /* now compare each segment to the others */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
      /* the fake segments are introduced to hint the metrics -- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
      /* we must never link them to anything                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
      if ( seg1->dir != axis->major_dir || seg1->first == seg1->last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
      /* search for stems having opposite directions, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
      /* with seg1 to the `left' of seg2              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
      for ( seg2 = segments; seg2 < segment_limit; seg2++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
        FT_Pos  pos1 = seg1->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
        FT_Pos  pos2 = seg2->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
        if ( seg1->dir + seg2->dir == 0 && pos2 > pos1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
          /* compute distance between the two segments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
          FT_Pos  dist = pos2 - pos1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
          FT_Pos  min  = seg1->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
          FT_Pos  max  = seg1->max_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
          FT_Pos  len, score;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
          if ( min < seg2->min_coord )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
            min = seg2->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
          if ( max > seg2->max_coord )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
            max = seg2->max_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
          /* compute maximum coordinate difference of the two segments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
          len = max - min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
          if ( len >= len_threshold )
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
            /* small coordinate differences cause a higher score, and     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
            /* segments with a greater distance cause a higher score also */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
            score = dist + len_score / len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
            /* and we search for the smallest score */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
            /* of the sum of the two values         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
            if ( score < seg1->score )
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
              seg1->score = score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
              seg1->link  = seg2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
            if ( score < seg2->score )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
              seg2->score = score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
              seg2->link  = seg1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
            }
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
    }
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
    /* now compute the `serif' segments, cf. explanations in `afhints.h' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
      seg2 = seg1->link;
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
      if ( seg2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
        if ( seg2->link != seg1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
          seg1->link  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
          seg1->serif = seg2->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
  /* Link segments to edges, using feature analysis for selection. */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
  af_latin_hints_compute_edges( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
                                AF_Dimension   dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
    AF_AxisHints  axis   = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
    FT_Error      error  = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
    FT_Memory     memory = hints->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
    AF_LatinAxis  laxis  = &((AF_LatinMetrics)hints->metrics)->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
    AF_Segment    segments      = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
    AF_Segment    segment_limit = segments + axis->num_segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    AF_Segment    seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
    AF_Direction  up_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
    FT_Fixed      scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
    FT_Pos        edge_distance_threshold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
    FT_Pos        segment_length_threshold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
    axis->num_edges = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
    scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
                                         : hints->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
    up_dir = ( dim == AF_DIMENSION_HORZ ) ? AF_DIR_UP
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
                                          : AF_DIR_RIGHT;
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
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
     *  We ignore all segments that are less than 1 pixel in length
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
     *  to avoid many problems with serif fonts.  We compute the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
     *  corresponding threshold in font units.
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
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
        segment_length_threshold = FT_DivFix( 64, hints->y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
        segment_length_threshold = 0;
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
    /*********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
    /* We begin by generating a sorted table of edges for the current    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
    /* direction.  To do so, we simply scan each segment and try to find */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    /* an edge in our table that corresponds to its position.            */
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
    /* If no edge is found, we create and insert a new edge in the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
    /* sorted table.  Otherwise, we simply add the segment to the edge's */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
    /* list which gets processed in the second step to compute the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
    /* edge's properties.                                                */
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
    /* Note that the table of edges is sorted along the segment/edge     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
    /* position.                                                         */
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
    /*********************************************************************/
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
    /* assure that edge distance threshold is at least 0.25px */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
    edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
                                         scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
    if ( edge_distance_threshold > 64 / 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
      edge_distance_threshold = 64 / 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
    edge_distance_threshold = FT_DivFix( edge_distance_threshold,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
                                         scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
    for ( seg = segments; seg < segment_limit; seg++ )
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
      AF_Edge  found = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
      FT_Int   ee;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
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
      if ( seg->height < segment_length_threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
      /* A special case for serif edges: If they are smaller than */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
      /* 1.5 pixels we ignore them.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
      if ( seg->serif                                     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
           2 * seg->height < 3 * segment_length_threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
      /* look for an edge corresponding to the segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
      for ( ee = 0; ee < axis->num_edges; ee++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
        AF_Edge  edge = axis->edges + ee;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
        FT_Pos   dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
        dist = seg->pos - edge->fpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
        if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
          dist = -dist;
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
        if ( dist < edge_distance_threshold && edge->dir == seg->dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
          found = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
      }
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
      if ( !found )
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
        AF_Edge  edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
        /* insert a new edge in the list and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
        /* sort according to the position    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
        error = af_axis_hints_new_edge( axis, seg->pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
                                        (AF_Direction)seg->dir,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
                                        memory, &edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
        /* add the segment to the new edge's list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
        FT_ZERO( edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
        edge->first    = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
        edge->last     = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
        edge->dir      = seg->dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
        edge->fpos     = seg->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
        edge->opos     = FT_MulFix( seg->pos, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
        edge->pos      = edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
        seg->edge_next = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
        /* if an edge was found, simply add the segment to the edge's */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
        /* list                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
        seg->edge_next         = found->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
        found->last->edge_next = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
        found->last            = seg;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
    /*********************************************************************/
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
    /* Good, we will now compute each edge's properties according to     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
    /* the segments found on its position.  Basically, these are         */
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
    /*  - the edge's main direction                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
    /*  - stem edge, serif edge or both (which defaults to stem then)    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
    /*  - rounded edge, straight or both (which defaults to straight)    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
    /*  - link for edge                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
    /*                                                                   */
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
    /* first of all, set the `edge' field in each segment -- this is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
    /* required in order to compute edge links                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
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
     * Note that removing this loop and setting the `edge' field of each
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
     * segment directly in the code above slows down execution speed for
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
     * some reasons on platforms like the Sun.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
      AF_Edge  edges      = axis->edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
      AF_Edge  edge_limit = edges + axis->num_edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
      AF_Edge  edge;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
      for ( edge = edges; edge < edge_limit; edge++ )
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
        seg = edge->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
        if ( seg )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
          do
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
            seg->edge = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
            seg       = seg->edge_next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
          } while ( seg != edge->first );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
      }
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
      /* now compute each edge properties */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      for ( edge = edges; edge < edge_limit; edge++ )
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
        FT_Int  is_round    = 0;  /* does it contain round segments?    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
        FT_Int  is_straight = 0;  /* does it contain straight segments? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
        FT_Pos  ups         = 0;  /* number of upwards segments         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
        FT_Pos  downs       = 0;  /* number of downwards segments       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
        seg = edge->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
        do
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
          FT_Bool  is_serif;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
          /* check for roundness of segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
          if ( seg->flags & AF_EDGE_ROUND )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
            is_round++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
            is_straight++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
          /* check for segment direction */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
          if ( seg->dir == up_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
            ups   += seg->max_coord - seg->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
            downs += seg->max_coord - seg->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
          /* check for links -- if seg->serif is set, then seg->link must */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
          /* be ignored                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
          is_serif = (FT_Bool)( seg->serif               &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
                                seg->serif->edge         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
                                seg->serif->edge != edge );
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
          if ( ( seg->link && seg->link->edge != NULL ) || is_serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
            AF_Edge     edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
            AF_Segment  seg2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
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
            edge2 = edge->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
            seg2  = seg->link;
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
            if ( is_serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
              seg2  = seg->serif;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
              edge2 = edge->serif;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
            if ( edge2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
              FT_Pos  edge_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
              FT_Pos  seg_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
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
              edge_delta = edge->fpos - edge2->fpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
              if ( edge_delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
                edge_delta = -edge_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
              seg_delta = seg->pos - seg2->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
              if ( seg_delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
                seg_delta = -seg_delta;
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
              if ( seg_delta < edge_delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
                edge2 = seg2->edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
              edge2 = seg2->edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
            if ( is_serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
              edge->serif   = edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
              edge2->flags |= AF_EDGE_SERIF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
              edge->link  = edge2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
          seg = seg->edge_next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
        } while ( seg != edge->first );
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
        /* set the round/straight flags */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
        edge->flags = AF_EDGE_NORMAL;
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
        if ( is_round > 0 && is_round >= is_straight )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
          edge->flags |= AF_EDGE_ROUND;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
        /* set the edge's main direction */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
        edge->dir = AF_DIR_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
        if ( ups > downs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
          edge->dir = (FT_Char)up_dir;
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
        else if ( ups < downs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
          edge->dir = (FT_Char)-up_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
        else if ( ups == downs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
          edge->dir = 0;  /* both up and down! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
#endif
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
        /* get rid of serifs if link is set                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
        /* XXX: This gets rid of many unpleasant artefacts! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
        /*      Example: the `c' in cour.pfa at size 13     */
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 ( edge->serif && edge->link )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
          edge->serif = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
  /* Detect segments and edges for given dimension. */
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
  af_latin_hints_detect_features( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
                                  AF_Dimension   dim )
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
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
    error = af_latin_hints_compute_segments( hints, dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
      af_latin_hints_link_segments( hints, dim );
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
      error = af_latin_hints_compute_edges( hints, dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
  /* Compute all edges which lie within blue zones. */
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
  af_latin_hints_compute_blue_edges( AF_GlyphHints    hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
                                     AF_LatinMetrics  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
    AF_AxisHints  axis       = &hints->axis[AF_DIMENSION_VERT];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
    AF_Edge       edge       = axis->edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
    AF_Edge       edge_limit = edge + axis->num_edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
    AF_LatinAxis  latin      = &metrics->axis[AF_DIMENSION_VERT];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
    FT_Fixed      scale      = latin->scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
    /* compute which blue zones are active, i.e. have their scaled */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
    /* size < 3/4 pixels                                           */
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
    /* for each horizontal edge search the blue zone which is closest */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
    for ( ; edge < edge_limit; edge++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
      FT_Int    bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
      AF_Width  best_blue = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
      FT_Pos    best_dist;  /* initial threshold */
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
      /* compute the initial threshold as a fraction of the EM size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
      /* (the value 40 is heuristic)                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
      best_dist = FT_MulFix( metrics->units_per_em / 40, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
      /* assure a minimum distance of 0.5px */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
      if ( best_dist > 64 / 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
        best_dist = 64 / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
      for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ )
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
        AF_LatinBlue  blue = latin->blues + bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
        FT_Bool       is_top_blue, is_major_dir;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
        /* skip inactive blue zones (i.e., those that are too large) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
        if ( !( blue->flags & AF_LATIN_BLUE_ACTIVE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
          continue;
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
        /* if it is a top zone, check for right edges -- if it is a bottom */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
        /* zone, check for left edges                                      */
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
        /* of course, that's for TrueType                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
        is_top_blue  = (FT_Byte)( ( blue->flags & AF_LATIN_BLUE_TOP ) != 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
        is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
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
        /* if it is a top zone, the edge must be against the major    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
        /* direction; if it is a bottom zone, it must be in the major */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
        /* direction                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
        if ( is_top_blue ^ is_major_dir )
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_Pos  dist;
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
          /* first of all, compare it to the reference position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
          dist = edge->fpos - blue->ref.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
          if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
            dist = -dist;
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
          dist = FT_MulFix( dist, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
          if ( dist < best_dist )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
            best_dist = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
            best_blue = &blue->ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
          /* now compare it to the overshoot position and check whether */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
          /* the edge is rounded, and whether the edge is over the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
          /* reference position of a top zone, or under the reference   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
          /* position of a bottom zone                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
          if ( edge->flags & AF_EDGE_ROUND && dist != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
            FT_Bool  is_under_ref = FT_BOOL( edge->fpos < blue->ref.org );
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
            if ( is_top_blue ^ is_under_ref )
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
              dist = edge->fpos - blue->shoot.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
              if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
                dist = -dist;
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
              dist = FT_MulFix( dist, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
              if ( dist < best_dist )
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
                best_dist = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
                best_blue = &blue->shoot;
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
          }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
      if ( best_blue )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
        edge->blue_edge = best_blue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
  /* Initalize hinting engine. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
  af_latin_hints_init( AF_GlyphHints    hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
                       AF_LatinMetrics  metrics )
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
    FT_Render_Mode  mode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
    FT_UInt32       scaler_flags, other_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
    FT_Face         face = metrics->root.scaler.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
    af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
     *  correct x_scale and y_scale if needed, since they may have
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
     *  been modified by `af_latin_metrics_scale_dim' above
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
    hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
    hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
    hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
    hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
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
    /* compute flags depending on render mode, etc. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
    mode = metrics->root.scaler.render_mode;
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 0 /* #ifdef AF_CONFIG_OPTION_USE_WARPER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
    if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
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
      metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
    scaler_flags = hints->scaler_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
    other_flags  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
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
     *  We snap the width of vertical stems for the monochrome and
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
     *  horizontal LCD rendering targets only.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
      other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
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
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
     *  We snap the width of horizontal stems for the monochrome and
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
     *  vertical LCD rendering targets only.
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
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
      other_flags |= AF_LATIN_HINTS_VERT_SNAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
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
     *  We adjust stems to full pixels only if we don't use the `light' mode.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
    if ( mode != FT_RENDER_MODE_LIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
      other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
    if ( mode == FT_RENDER_MODE_MONO )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
      other_flags |= AF_LATIN_HINTS_MONO;
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
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
     *  In `light' hinting mode we disable horizontal hinting completely.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
     *  We also do it if the face is italic.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
    if ( mode == FT_RENDER_MODE_LIGHT                      ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
         ( face->style_flags & FT_STYLE_FLAG_ITALIC ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
      scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL;
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
    hints->scaler_flags = scaler_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
    hints->other_flags  = other_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
    return AF_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
  /*************************************************************************/
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
  /*****        L A T I N   G L Y P H   G R I D - F I T T I N G        *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
  /*************************************************************************/
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
  /* Snap a given width in scaled coordinates to one of the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
  /* current standard widths.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
  static FT_Pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
  af_latin_snap_width( AF_Width  widths,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
                       FT_Int    count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
                       FT_Pos    width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
    int     n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
    FT_Pos  best      = 64 + 32 + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
    FT_Pos  reference = width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
    FT_Pos  scaled;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
      FT_Pos  w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
      FT_Pos  dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
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
      w = widths[n].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
      dist = width - w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
      if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
        dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
      if ( dist < best )
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
        best      = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
        reference = w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
    }
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
    scaled = FT_PIX_ROUND( reference );
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
    if ( width >= reference )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
      if ( width < scaled + 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
        width = reference;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
    else
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
      if ( width > scaled - 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
        width = reference;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
    }
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
    return width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
  /* Compute the snapped width of a given stem, ignoring very thin ones. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
  /* There is a lot of voodoo in this function; changing the hard-coded  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
  /* parameters influence the whole hinting process.                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
  static FT_Pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
  af_latin_compute_stem_width( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
                               AF_Dimension   dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
                               FT_Pos         width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
                               AF_Edge_Flags  base_flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
                               AF_Edge_Flags  stem_flags )
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
    AF_LatinMetrics  metrics  = (AF_LatinMetrics) hints->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
    AF_LatinAxis     axis     = & metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
    FT_Pos           dist     = width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
    FT_Int           sign     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
    FT_Int           vertical = ( dim == AF_DIMENSION_VERT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
    if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
         axis->extra_light                       )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
      return width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
    if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
      dist = -width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
      sign = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
    if ( (  vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
         ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
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
      /* smooth hinting process: very lightly quantize the stem width */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
      /* leave the widths of serifs alone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
      if ( ( stem_flags & AF_EDGE_SERIF ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
           vertical                       &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
           ( dist < 3 * 64 )              )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
        goto Done_Width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
      else if ( base_flags & AF_EDGE_ROUND )
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
        if ( dist < 80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
          dist = 64;
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
      else if ( dist < 56 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
        dist = 56;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
      if ( axis->width_count > 0 )
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
        FT_Pos  delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
        /* compare to standard width */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
        delta = dist - axis->widths[0].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
        if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
          delta = -delta;
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
        if ( delta < 40 )
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
          dist = axis->widths[0].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
          if ( dist < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
            dist = 48;
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
          goto Done_Width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
        }
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
        if ( dist < 3 * 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
          delta  = dist & 63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
          dist  &= -64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
          if ( delta < 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
            dist += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
          else if ( delta < 32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
            dist += 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
          else if ( delta < 54 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
            dist += 54;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
            dist += delta;
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
          dist = ( dist + 32 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
      }
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
      /* strong hinting process: snap the stem width to integer pixels */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
      FT_Pos  org_dist = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
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
      dist = af_latin_snap_width( axis->widths, axis->width_count, dist );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
      if ( vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
        /* in the case of vertical hinting, always round */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
        /* the stem heights to integer pixels            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
        if ( dist >= 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
          dist = ( dist + 16 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
          dist = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
        if ( AF_LATIN_HINTS_DO_MONO( hints ) )
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
          /* monochrome horizontal hinting: snap widths to integer pixels */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
          /* with a different threshold                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
          if ( dist < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
            dist = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
            dist = ( dist + 32 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
          /* for horizontal anti-aliased hinting, we adopt a more subtle */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
          /* approach: we strengthen small stems, round stems whose size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
          /* is between 1 and 2 pixels to an integer, otherwise nothing  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
          if ( dist < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
            dist = ( dist + 64 ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
          else if ( dist < 128 )
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
            /* We only round to an integer width if the corresponding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
            /* distortion is less than 1/4 pixel.  Otherwise this     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
            /* makes everything worse since the diagonals, which are  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
            /* not hinted, appear a lot bolder or thinner than the    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
            /* vertical stems.                                        */
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
            FT_Pos  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
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
            dist = ( dist + 22 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
            delta = dist - org_dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
            if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
              delta = -delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
            if (delta >= 16)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
              dist = org_dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
              if ( dist < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
                dist = ( dist + 64 ) >> 1;
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
            /* round otherwise to prevent color fringes in LCD mode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
            dist = ( dist + 32 ) & ~63;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
  Done_Width:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
    if ( sign )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
      dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
    return dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
  /* Align one stem edge relative to the previous stem edge. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
  af_latin_align_linked_edge( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
                              AF_Dimension   dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
                              AF_Edge        base_edge,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
                              AF_Edge        stem_edge )
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
    FT_Pos  dist = stem_edge->opos - base_edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
    FT_Pos  fitted_width = af_latin_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
                             hints, dim, dist,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
                             (AF_Edge_Flags)base_edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
                             (AF_Edge_Flags)stem_edge->flags );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
    stem_edge->pos = base_edge->pos + fitted_width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
    FT_TRACE5(( "LINK: edge %d (opos=%.2f) linked to (%.2f),"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
                " dist was %.2f, now %.2f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
                stem_edge-hints->axis[dim].edges, stem_edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
                stem_edge->pos / 64.0, dist / 64.0, fitted_width / 64.0 ));
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
  /* Shift the coordinates of the `serif' edge by the same amount */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
  /* as the corresponding `base' edge has been moved already.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
  af_latin_align_serif_edge( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
                             AF_Edge        base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
                             AF_Edge        serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
    FT_UNUSED( hints );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
    serif->pos = base->pos + ( serif->opos - base->opos );
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
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
  /*************************************************************************/
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
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
  /****                    E D G E   H I N T I N G                      ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
  /****                                                                 ****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
  /* The main grid-fitting routine. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
  af_latin_hint_edges( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
                       AF_Dimension   dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
    AF_AxisHints  axis       = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
    AF_Edge       edges      = axis->edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
    AF_Edge       edge_limit = edges + axis->num_edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
    FT_PtrDist    n_edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
    AF_Edge       edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
    AF_Edge       anchor     = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
    FT_Int        has_serifs = 0;
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
    /* we begin by aligning all stems relative to the blue zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
    /* if needed -- that's only for horizontal edges            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
    if ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_BLUES( hints ) )
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
      for ( edge = edges; edge < edge_limit; edge++ )
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
        AF_Width  blue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
        AF_Edge   edge1, edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
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
        if ( edge->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
          continue;
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
        blue  = edge->blue_edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
        edge1 = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
        edge2 = edge->link;
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
        if ( blue )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
          edge1 = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1798
        else if ( edge2 && edge2->blue_edge )
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
          blue  = edge2->blue_edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
          edge1 = edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
          edge2 = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
        if ( !edge1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
        FT_TRACE5(( "BLUE: edge %d (opos=%.2f) snapped to (%.2f),"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
                    " was (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
                    edge1 - edges, edge1->opos / 64.0, blue->fit / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
                    edge1->pos / 64.0 ));
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
        edge1->pos    = blue->fit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
        edge1->flags |= AF_EDGE_DONE;
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
        if ( edge2 && !edge2->blue_edge )
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
          af_latin_align_linked_edge( hints, dim, edge1, edge2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
          edge2->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
        }
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
        if ( !anchor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
          anchor = edge;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
    /* now we align all stem edges, trying to maintain the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
    /* relative order of stems in the glyph                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
    for ( edge = edges; edge < edge_limit; edge++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
      AF_Edge  edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
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
      if ( edge->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
        continue;
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
      /* skip all non-stem edges */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
      edge2 = edge->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
      if ( !edge2 )
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
        has_serifs++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
        continue;
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
      /* now align the stem */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
      /* this should not happen, but it's better to be safe */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
      if ( edge2->blue_edge )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
        FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges ));
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
        af_latin_align_linked_edge( hints, dim, edge2, edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
        edge->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
        continue;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
      if ( !anchor )
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_Pos  org_len, org_center, cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
        FT_Pos  cur_pos1, error1, error2, u_off, d_off;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
        org_len = edge2->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
        cur_len = af_latin_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
                    hints, dim, org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
                    (AF_Edge_Flags)edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
                    (AF_Edge_Flags)edge2->flags );
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
        /* some voodoo to specially round edges for small stem widths */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
        if ( cur_len <= 64 )
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
          u_off = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
          d_off = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
          u_off = 38;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
          d_off = 26;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
        if ( cur_len < 96 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
          org_center = edge->opos + ( org_len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
          cur_pos1   = FT_PIX_ROUND( org_center );
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
          error1 = org_center - ( cur_pos1 - u_off );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
          if ( error1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
            error1 = -error1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
          error2 = org_center - ( cur_pos1 + d_off );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
          if ( error2 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
            error2 = -error2;
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
          if ( error1 < error2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
            cur_pos1 -= u_off;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
            cur_pos1 += d_off;
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
          edge->pos  = cur_pos1 - cur_len / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
          edge2->pos = edge->pos + cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
          edge->pos = FT_PIX_ROUND( edge->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
        FT_TRACE5(( "ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
                    " snapped to (%.2f) (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
                    edge - edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
                    edge2 - edges, edge2->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
                    edge->pos / 64.0, edge2->pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
        anchor = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
        edge->flags |= AF_EDGE_DONE;
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
        af_latin_align_linked_edge( hints, dim, edge, edge2 );
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
        FT_Pos  org_pos, org_len, org_center, cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
        FT_Pos  cur_pos1, cur_pos2, delta1, delta2;
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
        org_pos    = anchor->pos + ( edge->opos - anchor->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
        org_len    = edge2->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
        org_center = org_pos + ( org_len >> 1 );
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
        cur_len = af_latin_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
                    hints, dim, org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
                    (AF_Edge_Flags)edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
                    (AF_Edge_Flags)edge2->flags );
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
        if ( edge2->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
          edge->pos = edge2->pos - cur_len;
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
        else if ( cur_len < 96 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
          FT_Pos  u_off, d_off;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
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
          cur_pos1 = FT_PIX_ROUND( org_center );
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
          if (cur_len <= 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
            u_off = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
            d_off = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
            u_off = 38;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
            d_off = 26;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
          delta1 = org_center - ( cur_pos1 - u_off );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
          if ( delta1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
            delta1 = -delta1;
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
          delta2 = org_center - ( cur_pos1 + d_off );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
          if ( delta2 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
            delta2 = -delta2;
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
          if ( delta1 < delta2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
            cur_pos1 -= u_off;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
            cur_pos1 += d_off;
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
          edge->pos  = cur_pos1 - cur_len / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
          edge2->pos = cur_pos1 + cur_len / 2;
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
          FT_TRACE5(( "STEM: %d (opos=%.2f) to %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
                      " snapped to (%.2f) and (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
                      edge - edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
                      edge2 - edges, edge2->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
                      edge->pos / 64.0, edge2->pos / 64.0 ));
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
          org_pos    = anchor->pos + ( edge->opos - anchor->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
          org_len    = edge2->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
          org_center = org_pos + ( org_len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
          cur_len    = af_latin_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
                         hints, dim, org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
                         (AF_Edge_Flags)edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
                         (AF_Edge_Flags)edge2->flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
          cur_pos1 = FT_PIX_ROUND( org_pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
          delta1   = cur_pos1 + ( cur_len >> 1 ) - org_center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
          if ( delta1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
            delta1 = -delta1;
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
          cur_pos2 = FT_PIX_ROUND( org_pos + org_len ) - cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
          delta2   = cur_pos2 + ( cur_len >> 1 ) - org_center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
          if ( delta2 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
            delta2 = -delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
          edge->pos  = ( delta1 < delta2 ) ? cur_pos1 : cur_pos2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
          edge2->pos = edge->pos + cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
          FT_TRACE5(( "STEM: %d (opos=%.2f) to %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
                      " snapped to (%.2f) and (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
                      edge - edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
                      edge2 - edges, edge2->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
                      edge->pos / 64.0, edge2->pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
        edge->flags  |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
        edge2->flags |= AF_EDGE_DONE;
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
        if ( edge > edges && edge->pos < edge[-1].pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
          FT_TRACE5(( "BOUND: %d (pos=%.2f) to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
                      edge - edges, edge->pos / 64.0, edge[-1].pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
          edge->pos = edge[-1].pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
        }
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
    /* make sure that lowercase m's maintain their symmetry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
    /* In general, lowercase m's have six vertical edges if they are sans */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
    /* serif, or twelve if they are with serifs.  This implementation is  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
    /* based on that assumption, and seems to work very well with most    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
    /* faces.  However, if for a certain face this assumption is not      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
    /* true, the m is just rendered like before.  In addition, any stem   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
    /* correction will only be applied to symmetrical glyphs (even if the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
    /* glyph is not an m), so the potential for unwanted distortion is    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
    /* relatively low.                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
    /* We don't handle horizontal edges since we can't easily assure that */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
    /* the third (lowest) stem aligns with the base line; it might end up */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
    /* one pixel higher or lower.                                         */
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
    n_edges = edge_limit - edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
    if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
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
      AF_Edge  edge1, edge2, edge3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
      FT_Pos   dist1, dist2, span, delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
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
      if ( n_edges == 6 )
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
        edge1 = edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
        edge2 = edges + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
        edge3 = edges + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
        edge1 = edges + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
        edge2 = edges + 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
        edge3 = edges + 9;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
      dist1 = edge2->opos - edge1->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
      dist2 = edge3->opos - edge2->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
      span = dist1 - dist2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
      if ( span < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
        span = -span;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
      if ( span < 8 )
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
        delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
        edge3->pos -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
        if ( edge3->link )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
          edge3->link->pos -= delta;
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
        /* move the serifs along with the stem */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
        if ( n_edges == 12 )
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
          ( edges + 8 )->pos -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2070
          ( edges + 11 )->pos -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2071
        }
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
        edge3->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2074
        if ( edge3->link )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2075
          edge3->link->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2076
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2077
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2078
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2079
    if ( has_serifs || !anchor )
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
       *  now hint the remaining edges (serifs and single) in order
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2083
       *  to complete our processing
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
      for ( edge = edges; edge < edge_limit; edge++ )
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
        FT_Pos  delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
        if ( edge->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2092
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2093
        delta = 1000;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
        if ( edge->serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
          delta = edge->serif->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
          if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2099
            delta = -delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
        if ( delta < 64 + 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2103
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2104
          af_latin_align_serif_edge( hints, edge->serif, edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2105
          FT_TRACE5(( "SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
                      " aligned to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2107
                      edge - edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2108
                      edge->serif - edges, edge->serif->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
                      edge->pos / 64.0 ));
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
        else if ( !anchor )
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
          FT_TRACE5(( "SERIF_ANCHOR: edge %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2114
                      " snapped to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2115
                      edge-edges, edge->opos / 64.0, edge->pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2116
          edge->pos = FT_PIX_ROUND( edge->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2117
          anchor    = edge;
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2120
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2121
          AF_Edge  before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2122
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
          for ( before = edge - 1; before >= edges; before-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2125
            if ( before->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2126
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2128
          for ( after = edge + 1; after < edge_limit; after++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
            if ( after->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
              break;
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 ( before >= edges && before < edge   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
               after < edge_limit && after > edge )
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
            if ( after->opos == before->opos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
              edge->pos = before->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2137
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2138
              edge->pos = before->pos +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
                          FT_MulDiv( edge->opos - before->opos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
                                     after->pos - before->pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
                                     after->opos - before->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
            FT_TRACE5(( "SERIF_LINK1: edge %d (opos=%.2f) snapped to (%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2144
                        " from %d (opos=%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2145
                        edge - edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
                        edge->pos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
                        before - edges, before->opos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
          else
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
            edge->pos = anchor->pos +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
                        ( ( edge->opos - anchor->opos + 16 ) & ~31 );
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
            FT_TRACE5(( "SERIF_LINK2: edge %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
                        " snapped to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
                        edge - edges, edge->opos / 64.0, edge->pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2158
        }
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
        edge->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2162
        if ( edge > edges && edge->pos < edge[-1].pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
          edge->pos = edge[-1].pos;
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
        if ( edge + 1 < edge_limit        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2166
             edge[1].flags & AF_EDGE_DONE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
             edge->pos > edge[1].pos      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2168
          edge->pos = edge[1].pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2169
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
  /* Apply the complete hinting algorithm to a latin glyph. */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2177
  af_latin_hints_apply( AF_GlyphHints    hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2178
                        FT_Outline*      outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2179
                        AF_LatinMetrics  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2180
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2181
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
    int       dim;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2185
    error = af_glyph_hints_reload( hints, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
      goto Exit;
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
    /* analyze glyph outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
#ifdef AF_CONFIG_OPTION_USE_WARPER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
    if ( metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
         AF_HINTS_DO_HORIZONTAL( hints )                          )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
    if ( AF_HINTS_DO_HORIZONTAL( hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
#endif
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
      error = af_latin_hints_detect_features( hints, AF_DIMENSION_HORZ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2198
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2199
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2202
    if ( AF_HINTS_DO_VERTICAL( hints ) )
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
      error = af_latin_hints_detect_features( hints, AF_DIMENSION_VERT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2208
      af_latin_hints_compute_blue_edges( hints, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
    }
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
    /* grid-fit the outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
    for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
#ifdef AF_CONFIG_OPTION_USE_WARPER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
      if ( dim == AF_DIMENSION_HORZ                                 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2216
           metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2218
        AF_WarperRec  warper;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
        FT_Fixed      scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
        FT_Pos        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2222
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2223
        af_warper_compute( &warper, hints, (AF_Dimension)dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
                           &scale, &delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
        af_glyph_hints_scale_dim( hints, (AF_Dimension)dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
                                  scale, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2229
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2231
      if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
           ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) )   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2233
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2234
        af_latin_hint_edges( hints, (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
        af_glyph_hints_align_edge_points( hints, (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
        af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
        af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2240
    af_glyph_hints_save( hints, outline );
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2243
    return error;
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2248
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2249
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2250
  /*****              L A T I N   S C R I P T   C L A S S              *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2251
  /*****                                                               *****/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2256
  /* XXX: this should probably fine tuned to differentiate better between */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2257
  /*      scripts...                                                      */
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
  static const AF_Script_UniRangeRec  af_latin_uniranges[] =
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
    AF_UNIRANGE_REC(  0x0020UL,  0x007FUL ),  /* Basic Latin (no control chars) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2262
    AF_UNIRANGE_REC(  0x00A0UL,  0x00FFUL ),  /* Latin-1 Supplement (no control chars) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2263
    AF_UNIRANGE_REC(  0x0100UL,  0x017FUL ),  /* Latin Extended-A */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2264
    AF_UNIRANGE_REC(  0x0180UL,  0x024FUL ),  /* Latin Extended-B */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2265
    AF_UNIRANGE_REC(  0x0250UL,  0x02AFUL ),  /* IPA Extensions */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2266
    AF_UNIRANGE_REC(  0x02B0UL,  0x02FFUL ),  /* Spacing Modifier Letters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2267
    AF_UNIRANGE_REC(  0x0300UL,  0x036FUL ),  /* Combining Diacritical Marks */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2268
    AF_UNIRANGE_REC(  0x0370UL,  0x03FFUL ),  /* Greek and Coptic */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2269
    AF_UNIRANGE_REC(  0x0400UL,  0x04FFUL ),  /* Cyrillic */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2270
    AF_UNIRANGE_REC(  0x0500UL,  0x052FUL ),  /* Cyrillic Supplement */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2271
    AF_UNIRANGE_REC(  0x1D00UL,  0x1D7FUL ),  /* Phonetic Extensions */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2272
    AF_UNIRANGE_REC(  0x1D80UL,  0x1DBFUL ),  /* Phonetic Extensions Supplement */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2273
    AF_UNIRANGE_REC(  0x1DC0UL,  0x1DFFUL ),  /* Combining Diacritical Marks Supplement */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2274
    AF_UNIRANGE_REC(  0x1E00UL,  0x1EFFUL ),  /* Latin Extended Additional */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2275
    AF_UNIRANGE_REC(  0x1F00UL,  0x1FFFUL ),  /* Greek Extended */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2276
    AF_UNIRANGE_REC(  0x2000UL,  0x206FUL ),  /* General Punctuation */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2277
    AF_UNIRANGE_REC(  0x2070UL,  0x209FUL ),  /* Superscripts and Subscripts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2278
    AF_UNIRANGE_REC(  0x20A0UL,  0x20CFUL ),  /* Currency Symbols */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2279
    AF_UNIRANGE_REC(  0x2150UL,  0x218FUL ),  /* Number Forms */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2280
    AF_UNIRANGE_REC(  0x2460UL,  0x24FFUL ),  /* Enclosed Alphanumerics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2281
    AF_UNIRANGE_REC(  0x2C60UL,  0x2C7FUL ),  /* Latin Extended-C */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2282
    AF_UNIRANGE_REC(  0x2DE0UL,  0x2DFFUL ),  /* Cyrillic Extended-A */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2283
    AF_UNIRANGE_REC(  0xA640UL,  0xA69FUL ),  /* Cyrillic Extended-B */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2284
    AF_UNIRANGE_REC(  0xA720UL,  0xA7FFUL ),  /* Latin Extended-D */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2285
    AF_UNIRANGE_REC(  0xFB00UL,  0xFB06UL ),  /* Alphab. Present. Forms (Latin Ligs) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2286
    AF_UNIRANGE_REC( 0x1D400UL, 0x1D7FFUL ),  /* Mathematical Alphanumeric Symbols */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2287
    AF_UNIRANGE_REC(       0UL,       0UL )
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
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
  AF_DEFINE_SCRIPT_CLASS(af_latin_script_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2292
    AF_SCRIPT_LATIN,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2293
    af_latin_uniranges,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2295
    sizeof( AF_LatinMetricsRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2297
    (AF_Script_InitMetricsFunc) af_latin_metrics_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2298
    (AF_Script_ScaleMetricsFunc)af_latin_metrics_scale,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2299
    (AF_Script_DoneMetricsFunc) NULL,
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
    (AF_Script_InitHintsFunc)   af_latin_hints_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2302
    (AF_Script_ApplyHintsFunc)  af_latin_hints_apply
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2303
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2306
/* END */