misc/libfreetype/src/autofit/aflatin2.c
author belphegorr <szabibibi@gmail.com>
Mon, 23 Jul 2012 19:15:59 +0300
changeset 7263 644eabbc9218
parent 5172 88f2e05288ba
permissions -rw-r--r--
Added a new function: AddNewEvent, which only adds an event to the list if it doesn't already exist. Kept the old one as it might me useful to be able to add an event more than once.
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
/*  aflatin2.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 FT_ADVANCES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include "aflatin.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include "aflatin2.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include "aferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#ifdef AF_CONFIG_OPTION_USE_WARPER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include "afwarp.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#define FT_COMPONENT  trace_aflatin2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  af_latin2_hints_compute_segments( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                                    AF_Dimension   dim );
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  af_latin2_hints_link_segments( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
                                 AF_Dimension   dim );
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /*****            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
    53
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  af_latin2_metrics_init_widths( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
                                 FT_Face          face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
                                 FT_ULong         charcode )
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
    /* 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
    63
    AF_GlyphHintsRec  hints[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    af_glyph_hints_init( hints, face->memory );
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
    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
    69
    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
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      FT_Error             error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
      FT_UInt              glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
      int                  dim;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
      AF_LatinMetricsRec   dummy[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
      AF_Scaler            scaler = &dummy->root.scaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      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
    80
      if ( glyph_index == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
      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
    84
      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
    85
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
      FT_ZERO( dummy );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      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
    90
      scaler->x_scale     = scaler->y_scale = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      scaler->x_delta     = scaler->y_delta = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
      scaler->face        = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
      scaler->render_mode = FT_RENDER_MODE_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      scaler->flags       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      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
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      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
    99
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      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
   103
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
        AF_LatinAxis  axis    = &metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
        AF_AxisHints  axhints = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
        AF_Segment    seg, limit, link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
        FT_UInt       num_widths = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        error = af_latin2_hints_compute_segments( hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
                                                 (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
        af_latin2_hints_link_segments( hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
                                      (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
        seg   = axhints->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
        limit = seg + axhints->num_segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        for ( ; seg < limit; seg++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
          link = seg->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
          /* we only consider stem segments there! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
          if ( link && link->link == seg && link > seg )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
            FT_Pos  dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
            dist = seg->pos - link->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
            if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
              dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
            if ( num_widths < AF_LATIN_MAX_WIDTHS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
              axis->widths[ num_widths++ ].org = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
        }
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
        af_sort_widths( num_widths, axis->widths );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
        axis->width_count = num_widths;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
      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
   146
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
        AF_LatinAxis  axis = &metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
        FT_Pos        stdw;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
        stdw = ( axis->width_count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
                 ? axis->widths[0].org
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
                 : AF_LATIN_CONSTANT( metrics, 50 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
        /* 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
   156
        axis->edge_distance_threshold = stdw / 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
        axis->standard_width          = stdw;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
        axis->extra_light             = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    af_glyph_hints_done( hints );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
#define AF_LATIN_MAX_TEST_CHARACTERS  12
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
  static const char af_latin2_blue_chars[AF_LATIN_MAX_BLUES]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
                                        [AF_LATIN_MAX_TEST_CHARACTERS+1] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    "THEZOCQS",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    "HEZLOCUS",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    "fijkdbh",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    "xzroesc",
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
    "pqgjy"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
  af_latin2_metrics_init_blues( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
                                FT_Face          face )
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
    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
   187
    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
   188
    FT_Int        num_flats;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    FT_Int        num_rounds;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    FT_Int        bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    AF_LatinBlue  blue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    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
   194
    FT_GlyphSlot  glyph = face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    /* 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
   198
    /* 'af_latin2_blue_chars[blues]' string, then compute its top-most or */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    /* 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
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    FT_TRACE5(( "blue zones computation\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    FT_TRACE5(( "------------------------------------------------\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    for ( 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
   205
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      const char*  p     = af_latin2_blue_chars[bb];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      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
   208
      FT_Pos*      blue_ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      FT_Pos*      blue_shoot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      FT_TRACE5(( "blue %3d: ", bb ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      num_flats  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      num_rounds = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      for ( ; p < limit && *p; p++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
        FT_UInt     glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
        FT_Int      best_point, best_y, best_first, best_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        FT_Vector*  points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
        FT_Bool     round;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
        FT_TRACE5(( "'%c'", *p ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
        /* 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
   228
        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
   229
        if ( glyph_index == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
          continue;
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
        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
   233
        if ( error || glyph->outline.n_points <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
        /* 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
   237
        points      = glyph->outline.points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        best_point  = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
        best_y      = 0;  /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
        best_first  = 0;  /* ditto */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
        best_last   = 0;  /* ditto */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
          FT_Int  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
          FT_Int  first = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
          FT_Int  last  = -1;
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
          for ( nn = 0; nn < glyph->outline.n_contours; first = last+1, nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
            FT_Int  old_best_point = best_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
            FT_Int  pp;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
            last = glyph->outline.contours[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
            /* 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
   258
            /* 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
   259
            /* 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
   260
            if ( last == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
                continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
            if ( AF_LATIN_IS_TOP_BLUE( bb ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
              for ( pp = first; pp <= last; pp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
                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
   267
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
                  best_point = pp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
                  best_y     = points[pp].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
                }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
              for ( pp = first; pp <= last; pp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
                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
   276
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
                  best_point = pp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
                  best_y     = points[pp].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
                }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
            if ( best_point != old_best_point )
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_first = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
              best_last  = last;
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
          FT_TRACE5(( "%5d", best_y ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
        /* 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
   292
        /* 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
   293
        /* 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
   294
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
          FT_Int  start, end, prev, next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
          FT_Pos  dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
          /* 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
   300
          /* same Y coordinate.  Threshold the `closeness'...              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
          start = end = best_point;
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
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
            prev = start-1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
            if ( prev < best_first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
              prev = best_last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
            dist = points[prev].y - best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
            if ( dist < -5 || dist > 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
            start = prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
          } while ( start != best_point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
          do
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
            next = end+1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
            if ( next > best_last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
              next = best_first;
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
            dist = points[next].y - best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
            if ( dist < -5 || dist > 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
              break;
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
            end = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
          } while ( end != best_point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
          /* 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
   332
          round = FT_BOOL(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
            FT_CURVE_TAG( glyph->outline.tags[start] ) != FT_CURVE_TAG_ON ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
            FT_CURVE_TAG( glyph->outline.tags[ end ] ) != FT_CURVE_TAG_ON );
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
          FT_TRACE5(( "%c ", round ? 'r' : 'f' ));
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
        if ( round )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
          rounds[num_rounds++] = best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
          flats[num_flats++]   = best_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
      }
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
      FT_TRACE5(( "\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      if ( num_flats == 0 && num_rounds == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
        /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
         *  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
   351
         *  we will simply ignore it then
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
        FT_TRACE5(( "empty\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
        continue;
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 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
   358
      /* 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
   359
      /* 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
   360
      af_sort_pos( num_rounds, rounds );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      af_sort_pos( num_flats,  flats );
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
      blue       = & axis->blues[axis->blue_count];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      blue_ref   = & blue->ref.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
      blue_shoot = & blue->shoot.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      axis->blue_count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      if ( num_flats == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
        *blue_ref   =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
        *blue_shoot = rounds[num_rounds / 2];
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
      else if ( num_rounds == 0 )
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
        *blue_ref   =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
        *blue_shoot = flats[num_flats / 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      else
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
        *blue_ref   = flats[num_flats / 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
        *blue_shoot = rounds[num_rounds / 2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      /* 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
   386
      /* 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
   387
      /* 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
   388
      if ( *blue_shoot != *blue_ref )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
        FT_Pos   ref      = *blue_ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
        FT_Pos   shoot    = *blue_shoot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
        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
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
        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
   396
          *blue_shoot = *blue_ref = ( shoot + ref ) / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      blue->flags = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
      if ( AF_LATIN_IS_TOP_BLUE( bb ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
        blue->flags |= AF_LATIN_BLUE_TOP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
       * The following flags 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
   405
       * 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
   406
       * letters.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      if ( bb == AF_LATIN_BLUE_SMALL_TOP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        blue->flags |= AF_LATIN_BLUE_ADJUSTMENT;
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
      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
   412
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
    return;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
  af_latin2_metrics_check_digits( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
                                  FT_Face          face )
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
    FT_UInt   i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    FT_Bool   started = 0, same_width = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    FT_Fixed  advance, old_advance = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    /* 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
   428
    /* 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
   429
    for ( i = 0x30; i <= 0x39; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      FT_UInt  glyph_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      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
   435
      if ( glyph_index == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      if ( FT_Get_Advance( face, glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
                           FT_LOAD_NO_SCALE         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
                           FT_LOAD_NO_HINTING       |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
                           FT_LOAD_IGNORE_TRANSFORM,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
                           &advance ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
      if ( started )
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 ( advance != old_advance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
          same_width = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
        old_advance = advance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
        started     = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    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
   461
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
  af_latin2_metrics_init( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
                          FT_Face          face )
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
    FT_Error    error = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    FT_CharMap  oldmap = face->charmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    FT_UInt     ee;
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
    static const FT_Encoding  latin_encodings[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
      FT_ENCODING_UNICODE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      FT_ENCODING_APPLE_ROMAN,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      FT_ENCODING_ADOBE_STANDARD,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
      FT_ENCODING_ADOBE_LATIN_1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
      FT_ENCODING_NONE  /* end of list */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    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
   483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    /* 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
   485
    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
   486
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      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
   488
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    if ( !error )
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
      /* 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
   495
      af_latin2_metrics_init_widths( metrics, face, 'o' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      af_latin2_metrics_init_blues( metrics, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
      af_latin2_metrics_check_digits( metrics, face );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    FT_Set_Charmap( face, oldmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    return AF_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
  af_latin2_metrics_scale_dim( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
                               AF_Scaler        scaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
                               AF_Dimension     dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    FT_Fixed      scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
    FT_Pos        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    AF_LatinAxis  axis;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    FT_UInt       nn;
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
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
      scale = scaler->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      delta = scaler->x_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
      scale = scaler->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      delta = scaler->y_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
    axis = &metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    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
   530
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    axis->org_scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
    axis->org_delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
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
     * correct 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
   537
     * letters to the pixel grid
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    if ( dim == AF_DIMENSION_VERT )
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
      AF_LatinAxis  vaxis = &metrics->axis[AF_DIMENSION_VERT];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      AF_LatinBlue  blue = NULL;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
      for ( nn = 0; nn < vaxis->blue_count; nn++ )
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
        if ( vaxis->blues[nn].flags & AF_LATIN_BLUE_ADJUSTMENT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
          blue = &vaxis->blues[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
      }
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
      if ( blue )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
        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
   557
        FT_Pos  fitted = ( scaled + 40 ) & ~63;
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
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
        if ( scaled != fitted )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
          scale = FT_MulDiv( scale, fitted, scaled );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
          FT_TRACE5(( "== scaled x-top = %.2g"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
                      "  fitted = %.2g, scaling = %.4g\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
                      scaled / 64.0, fitted / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
                      ( fitted * 1.0 ) / scaled ));
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
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    axis->scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
    axis->delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
      metrics->root.scaler.x_scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      metrics->root.scaler.x_delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
    else
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
      metrics->root.scaler.y_scale = scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
      metrics->root.scaler.y_delta = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    /* scale the standard widths */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    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
   588
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
      AF_Width  width = axis->widths + nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      width->cur = FT_MulFix( width->org, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      width->fit = width->cur;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
    /* 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
   597
    /* smaller than 0.75 pixels                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    axis->extra_light =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
      (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
   600
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
    if ( dim == AF_DIMENSION_VERT )
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
      /* scale the blue zones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
      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
   605
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
        AF_LatinBlue  blue = &axis->blues[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
        FT_Pos        dist;
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
        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
   611
        blue->ref.fit   = blue->ref.cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
        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
   613
        blue->shoot.fit = blue->shoot.cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
        blue->flags    &= ~AF_LATIN_BLUE_ACTIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
        /* 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
   617
        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
   618
        if ( dist <= 48 && dist >= -48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
          FT_Pos  delta1, delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
          delta1 = blue->shoot.org - blue->ref.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
          delta2 = delta1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
          if ( delta1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
            delta2 = -delta2;
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
          delta2 = FT_MulFix( delta2, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
          if ( delta2 < 32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
            delta2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
          else if ( delta2 < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
            delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
            delta2 = FT_PIX_ROUND( delta2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
          if ( delta1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
            delta2 = -delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
          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
   640
          blue->shoot.fit = blue->ref.fit + delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
          FT_TRACE5(( ">> activating blue zone %d:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
                      "  ref.cur=%.2g ref.fit=%.2g"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
                      "  shoot.cur=%.2g shoot.fit=%.2g\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
                      nn, blue->ref.cur / 64.0, blue->ref.fit / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
                      blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
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
          blue->flags |= AF_LATIN_BLUE_ACTIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
  af_latin2_metrics_scale( AF_LatinMetrics  metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
                           AF_Scaler        scaler )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
    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
   660
    metrics->root.scaler.face        = scaler->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    af_latin2_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
   663
    af_latin2_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
   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
  /*************************************************************************/
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
  /*****           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
   671
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
#define  SORT_SEGMENTS
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
  af_latin2_hints_compute_segments( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
                                    AF_Dimension   dim )
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
    AF_AxisHints  axis          = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    FT_Memory     memory        = hints->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    FT_Error      error         = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
    AF_Segment    segment       = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    AF_SegmentRec seg0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
    AF_Point*     contour       = hints->contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    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
   688
    AF_Direction  major_dir, segment_dir;
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
    FT_ZERO( &seg0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
    seg0.score = 32000;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
    seg0.flags = AF_EDGE_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
    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
   696
    segment_dir = major_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
    axis->num_segments = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
    /* set up (u,v) in each point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
      AF_Point  point = hints->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      AF_Point  limit = point + hints->num_points;
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
      for ( ; point < limit; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
        point->u = point->fx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
        point->v = point->fy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
      AF_Point  point = hints->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
      AF_Point  limit = point + hints->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
      for ( ; point < limit; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
        point->u = point->fy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
        point->v = point->fx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    /* do each contour separately */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
    for ( ; contour < contour_limit; contour++ )
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
      AF_Point  point   =  contour[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
      AF_Point  start   =  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      AF_Point  last    =  point->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
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
      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
   735
        continue;
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
      /* already on an edge ?, backtrack to find its start */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      if ( FT_ABS( point->in_dir ) == major_dir )
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
        point = point->prev;
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
        while ( point->in_dir == start->in_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
          point = point->prev;
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
      else  /* otherwise, find first segment start, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
        while ( FT_ABS( point->out_dir ) != major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
          point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
          if ( point == start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
            goto NextContour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
      }
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
      start = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
      for  (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
        AF_Point  first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
        FT_Pos    min_u, min_v, max_u, max_v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
        /* we're at the start of a new segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
        FT_ASSERT( FT_ABS( point->out_dir ) == major_dir &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
                           point->in_dir != point->out_dir );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
        first = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
        min_u = max_u = point->u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
        min_v = max_v = point->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
        point = point->next;
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
        while ( point->out_dir == first->out_dir )
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
          point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
          if ( point->u < min_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
            min_u = point->u;
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
          if ( point->u > max_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
            max_u = point->u;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
        if ( point->v < min_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
          min_v = point->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
        if ( point->v > max_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
          max_v = point->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
        /* record new segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
        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
   792
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
        segment[0]         = seg0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
        segment->dir       = first->out_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
        segment->first     = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
        segment->last      = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
        segment->contour   = contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
        segment->pos       = (FT_Short)(( min_u + max_u ) >> 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
        segment->min_coord = (FT_Short) min_v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
        segment->max_coord = (FT_Short) max_v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
        segment->height    = (FT_Short)(max_v - min_v);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
        /* a segment is round if it doesn't have successive */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
        /* on-curve points.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
          AF_Point  pt   = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
          AF_Point  last = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
          AF_Flags  f0   = (AF_Flags)(pt->flags & AF_FLAG_CONTROL);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
          AF_Flags  f1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
          segment->flags &= ~AF_EDGE_ROUND;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
          for ( ; pt != last; f0 = f1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
            pt = pt->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
            f1 = (AF_Flags)(pt->flags & AF_FLAG_CONTROL);
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
            if ( !f0 && !f1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
            if ( pt == last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
              segment->flags |= AF_EDGE_ROUND;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
       /* this can happen in the case of a degenerate contour
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
        * e.g. a 2-point vertical contour
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
        if ( point == start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
        /* jump to the start of the next segment, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
        while ( FT_ABS(point->out_dir) != major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
          point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
          if ( point == start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
            goto NextContour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
    NextContour:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
      ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
    } /* contours */
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
    /* 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
   850
    /* 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
   851
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
      AF_Segment  segments     = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
      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
   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
      for ( segment = segments; segment < segments_end; segment++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
        AF_Point  first   = segment->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
        AF_Point  last    = segment->last;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
        AF_Point  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
        FT_Pos    first_v = first->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
        FT_Pos    last_v  = last->v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
        if ( first == last )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
        if ( first_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
          p = first->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
          if ( p->v < first_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
                                          ( ( first_v - p->v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
          p = last->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
          if ( p->v > last_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
                                          ( ( p->v - last_v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
          p = first->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
          if ( p->v > first_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
                                          ( ( p->v - first_v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
          p = last->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
          if ( p->v < last_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
            segment->height = (FT_Short)( segment->height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
                                          ( ( last_v - p->v ) >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
        }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
#ifdef AF_SORT_SEGMENTS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
   /* place all segments with a negative direction to the start
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
    * of the array, used to speed up segment linking later...
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
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
      AF_Segment  segments = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
      FT_UInt     count    = axis->num_segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
      FT_UInt     ii, jj;
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
      for (ii = 0; ii < count; ii++)
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
        if ( segments[ii].dir > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
          for (jj = ii+1; jj < count; jj++)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
            if ( segments[jj].dir < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
              AF_SegmentRec  tmp;
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
              tmp          = segments[ii];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
              segments[ii] = segments[jj];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
              segments[jj] = tmp;
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
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
          if ( jj == count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
      axis->mid_segments = ii;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
  af_latin2_hints_link_segments( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
                                 AF_Dimension   dim )
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
    AF_AxisHints  axis          = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
    AF_Segment    segments      = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
    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
   942
#ifdef AF_SORT_SEGMENTS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
    AF_Segment    segment_mid   = segments + axis->mid_segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
    FT_Pos        len_threshold, len_score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
    AF_Segment    seg1, seg2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
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
    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
   950
    if ( len_threshold == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
      len_threshold = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
    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
   954
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
#ifdef AF_SORT_SEGMENTS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
    for ( seg1 = segments; seg1 < segment_mid; seg1++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
      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
   959
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
      for ( seg2 = segment_mid; seg2 < segment_limit; seg2++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    /* now compare each segment to the others */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
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
      /* 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
   967
      /* we must never link them to anything                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
      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
   969
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
      for ( seg2 = segments; seg2 < segment_limit; seg2++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
        if ( seg1->dir + seg2->dir == 0 && seg2->pos > seg1->pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
          FT_Pos  pos1 = seg1->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
          FT_Pos  pos2 = seg2->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
          FT_Pos  dist = pos2 - pos1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
          if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
            continue;
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
            FT_Pos  min = seg1->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
            FT_Pos  max = seg1->max_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
            FT_Pos  len, score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
            if ( min < seg2->min_coord )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
              min = seg2->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
            if ( max > seg2->max_coord )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
              max = seg2->max_coord;
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
            len = max - min;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
            if ( len >= len_threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
              score = dist + len_score / len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
              if ( score < seg1->score )
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
                seg1->score = score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
                seg1->link  = seg2;
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
              if ( score < seg2->score )
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
                seg2->score = score;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
                seg2->link  = seg1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
#if 0
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
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    /* now, compute the `serif' segments */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
      seg2 = seg1->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
      if ( seg2 )
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
        if ( seg2->link != seg1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
          seg1->link  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
          seg1->serif = seg2->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
        }
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
  }
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
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
  af_latin2_hints_compute_edges( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
                                 AF_Dimension   dim )
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
    AF_AxisHints  axis   = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    FT_Error      error  = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
    FT_Memory     memory = hints->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
    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
  1043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
    AF_Segment    segments      = axis->segments;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    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
  1046
    AF_Segment    seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    AF_Direction  up_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
    FT_Fixed      scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
    FT_Pos        edge_distance_threshold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
    FT_Pos        segment_length_threshold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
    axis->num_edges = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
    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
  1057
                                         : hints->y_scale;
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
    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
  1060
                                          : AF_DIR_RIGHT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
     *  We want to ignore very small (mostly serif) segments, we do that
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
     *  by ignoring those that whose length is less than a given fraction
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
     *  of the standard width. If there is no standard width, we ignore
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
     *  those that are less than a given size in pixels
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
     *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
     *  also, unlink serif segments that are linked to segments farther
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
     *  than 50% of the standard width
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
    if ( dim == AF_DIMENSION_HORZ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
      if ( laxis->width_count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
        segment_length_threshold = (laxis->standard_width * 10 ) >> 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
        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
  1077
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
      segment_length_threshold = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
    /*********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
    /* We will begin by generating a sorted table of edges for the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
    /* current direction.  To do so, we simply scan each segment and try */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
    /* to find 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
  1086
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
    /* 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
  1088
    /* 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
  1089
    /* list which will be 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
  1090
    /* edge's properties.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
    /* Note that the edges table is sorted along the segment/edge        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
    /* position.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
    /*********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
    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
  1098
                                         scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
    if ( edge_distance_threshold > 64 / 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
      edge_distance_threshold = 64 / 4;
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
    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
  1103
                                         scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
    for ( seg = segments; seg < segment_limit; seg++ )
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
      AF_Edge  found = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
      FT_Int   ee;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
      if ( seg->height < segment_length_threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
      /* 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
  1115
      /* 1.5 pixels we ignore them.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
      if ( seg->serif )
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
        FT_Pos  dist = seg->serif->pos - seg->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
        if (dist < 0)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
          dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
        if (dist >= laxis->standard_width >> 1)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
          /* unlink this serif, it is too distant from its reference stem */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
          seg->serif = NULL;
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
        else if ( 2*seg->height < 3 * segment_length_threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
      /* 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
  1133
      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
  1134
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
        AF_Edge  edge = axis->edges + ee;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
        FT_Pos   dist;
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
        dist = seg->pos - edge->fpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
        if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
          dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
        if ( 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
  1144
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
          found = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
      if ( !found )
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
        AF_Edge   edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
        /* 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
  1156
        /* sort according to the position    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
        error = af_axis_hints_new_edge( axis, seg->pos, seg->dir,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
                                        memory, &edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
          goto Exit;
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
        /* 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
  1163
        FT_ZERO( 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
        edge->first    = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
        edge->last     = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
        edge->fpos     = seg->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
        edge->dir      = seg->dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
        edge->opos     = edge->pos = FT_MulFix( seg->pos, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
        seg->edge_next = seg;
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
      else
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
        /* 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
  1175
        /* list                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
        seg->edge_next         = found->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
        found->last->edge_next = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
        found->last            = seg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
    /*********************************************************************/
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
    /* 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
  1186
    /* 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
  1187
    /*                                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
    /*  - edge's main direction                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
    /*  - 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
  1190
    /*  - 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
  1191
    /*  - link for edge                                                  */
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
    /*********************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
    /* 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
  1196
    /* required in order to compute edge links                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
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
     * 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
  1200
     * 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
  1201
     * some reasons on platforms like the Sun.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
      AF_Edge  edges      = axis->edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
      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
  1206
      AF_Edge  edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
      for ( edge = edges; edge < edge_limit; edge++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
        seg = edge->first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
        if ( seg )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
          do
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
            seg->edge = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
            seg       = seg->edge_next;
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
          } while ( seg != edge->first );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
      /* now, compute each edge properties */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
      for ( edge = edges; edge < edge_limit; edge++ )
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
        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
  1225
        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
  1226
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
        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
  1228
        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
  1229
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
        seg = edge->first;
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
        do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
          FT_Bool  is_serif;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
          /* check for roundness of segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
          if ( seg->flags & AF_EDGE_ROUND )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
            is_round++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
            is_straight++;
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
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
          /* check for segment direction */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
          if ( seg->dir == up_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
            ups   += seg->max_coord-seg->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
            downs += seg->max_coord-seg->min_coord;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
#endif
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
          /* 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
  1254
          /* be ignored                                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
          is_serif = (FT_Bool)( seg->serif               &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
                                seg->serif->edge         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
                                seg->serif->edge != edge );
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
          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
  1260
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
            AF_Edge     edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
            AF_Segment  seg2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
            edge2 = edge->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
            seg2  = seg->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
            if ( is_serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
              seg2  = seg->serif;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
              edge2 = edge->serif;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
            }
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
            if ( edge2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
              FT_Pos  edge_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
              FT_Pos  seg_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
              edge_delta = edge->fpos - edge2->fpos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
              if ( edge_delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
                edge_delta = -edge_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
              seg_delta = seg->pos - seg2->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
              if ( seg_delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
                seg_delta = -seg_delta;
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
              if ( seg_delta < edge_delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
                edge2 = seg2->edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
              edge2 = seg2->edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
            if ( is_serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
              edge->serif   = edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
              edge2->flags |= AF_EDGE_SERIF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
              edge->link  = edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
          }
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
          seg = seg->edge_next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
        } while ( seg != edge->first );
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
        /* set the round/straight flags */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
        edge->flags = AF_EDGE_NORMAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
        if ( is_round > 0 && is_round >= is_straight )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
          edge->flags |= AF_EDGE_ROUND;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
        /* set the edge's main direction */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
        edge->dir = AF_DIR_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
        if ( ups > downs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
          edge->dir = (FT_Char)up_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
        else if ( ups < downs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
          edge->dir = (FT_Char)-up_dir;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
        else if ( ups == downs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
          edge->dir = 0;  /* both up and down! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
        /* gets rid of serifs if link is set                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
        /* 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
  1329
        /*      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
  1330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
        if ( edge->serif && edge->link )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
          edge->serif = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
  af_latin2_hints_detect_features( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
                                   AF_Dimension   dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
    error = af_latin2_hints_compute_segments( hints, dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
      af_latin2_hints_link_segments( hints, dim );
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
      error = af_latin2_hints_compute_edges( hints, dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
  af_latin2_hints_compute_blue_edges( AF_GlyphHints    hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
                                      AF_LatinMetrics  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
    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
  1364
    AF_Edge       edge       = axis->edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
    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
  1366
    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
  1367
    FT_Fixed      scale      = latin->scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
    FT_Pos        best_dist0;  /* initial threshold */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
    /* 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
  1372
    best_dist0 = 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
  1373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
    if ( best_dist0 > 64 / 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
      best_dist0 = 64 / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
    /* 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
  1378
    /* size < 3/4 pixels                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
    /* 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
  1381
    for ( ; edge < edge_limit; edge++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
      FT_Int    bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
      AF_Width  best_blue = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
      FT_Pos    best_dist = best_dist0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
      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
  1388
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
        AF_LatinBlue  blue = latin->blues + bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
        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
  1391
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
        /* skip inactive blue zones (i.e., those that are too small) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
        if ( !( blue->flags & AF_LATIN_BLUE_ACTIVE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
        /* 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
  1398
        /* zone, check for left edges                                      */
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
        /* of course, that's for TrueType                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
        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
  1402
        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
  1403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
        /* 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
  1405
        /* 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
  1406
        /* direction                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
        if ( is_top_blue ^ is_major_dir )
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
          FT_Pos     dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
          AF_Width   compare;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
          /* if it's a rounded edge, compare it to the overshoot position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
          /* if it's a flat edge, compare it to the reference position    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
          if ( edge->flags & AF_EDGE_ROUND )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
            compare = &blue->shoot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
            compare = &blue->ref;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
          dist = edge->fpos - compare->org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
          if (dist < 0)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
            dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
          dist = FT_MulFix( dist, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
          if ( dist < best_dist )
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
            best_dist = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
            best_blue = compare;
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
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
          /* now, compare it to the overshoot position if the edge is     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
          /* rounded, and if the edge is over the reference position of a */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
          /* top zone, or under the reference position of a bottom zone   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
          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
  1436
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
            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
  1438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
            if ( is_top_blue ^ is_under_ref )
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
              blue = latin->blues + bb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
              dist = edge->fpos - blue->shoot.org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
              if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
                dist = -dist;
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
              dist = FT_MulFix( dist, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
              if ( dist < best_dist )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
                best_dist = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
                best_blue = & blue->shoot;
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
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
      if ( best_blue )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
        edge->blue_edge = best_blue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
  af_latin2_hints_init( AF_GlyphHints    hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
                        AF_LatinMetrics  metrics )
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
    FT_Render_Mode  mode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
    FT_UInt32       scaler_flags, other_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
    FT_Face         face = metrics->root.scaler.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
    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
  1475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
     *  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
  1478
     *  been modified `af_latin2_metrics_scale_dim' above
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    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
  1481
    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
  1482
    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
  1483
    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
  1484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
    /* compute flags depending on render mode, etc. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
    mode = metrics->root.scaler.render_mode;
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
#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
  1489
    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
  1490
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
      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
  1492
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
#endif
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
    scaler_flags = hints->scaler_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
    other_flags  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
     *  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
  1500
     *  horizontal LCD rendering targets only.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
    if ( 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
  1503
      other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
     *  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
  1507
     *  vertical LCD rendering targets only.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
    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
  1510
      other_flags |= AF_LATIN_HINTS_VERT_SNAP;
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
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
     *  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
  1514
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
    if ( mode != FT_RENDER_MODE_LIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
      other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
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
    if ( mode == FT_RENDER_MODE_MONO )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
      other_flags |= AF_LATIN_HINTS_MONO;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
     *  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
  1523
     *  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
  1524
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
    if ( mode == FT_RENDER_MODE_LIGHT                    ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
         (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
  1527
      scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL;
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
    hints->scaler_flags = scaler_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
    hints->other_flags  = other_flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
  /*****        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
  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
  /*************************************************************************/
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
  /* 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
  1545
  /* current standard widths                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
  static FT_Pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
  af_latin2_snap_width( AF_Width  widths,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
                        FT_Int    count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
                        FT_Pos    width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
    int     n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
    FT_Pos  best      = 64 + 32 + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
    FT_Pos  reference = width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
    FT_Pos  scaled;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
    for ( n = 0; n < count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
      FT_Pos  w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
      FT_Pos  dist;
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
      w = widths[n].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
      dist = width - w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
      if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
        dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
      if ( dist < best )
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
        best      = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
        reference = w;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
    scaled = FT_PIX_ROUND( reference );
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
    if ( width >= reference )
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
      if ( width < scaled + 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
        width = reference;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
      if ( width > scaled - 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
        width = reference;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
    return width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
  /* compute the snapped width of a given stem */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
  static FT_Pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
  af_latin2_compute_stem_width( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
                                AF_Dimension   dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
                                FT_Pos         width,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
                                AF_Edge_Flags  base_flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
                                AF_Edge_Flags  stem_flags )
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
    AF_LatinMetrics  metrics  = (AF_LatinMetrics) hints->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
    AF_LatinAxis     axis     = & metrics->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
    FT_Pos           dist     = width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
    FT_Int           sign     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
    FT_Int           vertical = ( dim == AF_DIMENSION_VERT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
    FT_UNUSED(base_flags);
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
    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
  1611
          axis->extra_light                      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
      return width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
    if ( dist < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
      dist = -width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
      sign = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
    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
  1621
         ( !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
  1622
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
      /* 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
  1624
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
      /* leave the widths of serifs alone */
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
      if ( ( stem_flags & AF_EDGE_SERIF ) && vertical && ( dist < 3 * 64 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
        goto Done_Width;
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
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
      else if ( ( base_flags & AF_EDGE_ROUND ) )
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
        if ( dist < 80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
          dist = 64;
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
      else if ( dist < 56 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
        dist = 56;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
      if ( axis->width_count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
        FT_Pos  delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
        /* compare to standard width */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
        if ( axis->width_count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
          delta = dist - axis->widths[0].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
          if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
            delta = -delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
          if ( delta < 40 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
            dist = axis->widths[0].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
            if ( dist < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
              dist = 48;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
            goto Done_Width;
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
        if ( dist < 3 * 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
          delta  = dist & 63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
          dist  &= -64;
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
          if ( delta < 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
            dist += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
          else if ( delta < 32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
            dist += 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
          else if ( delta < 54 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
            dist += 54;
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
            dist += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
          dist = ( dist + 32 ) & ~63;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
    else
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
      /* 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
  1686
      FT_Pos  org_dist = dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
      dist = af_latin2_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
  1690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
      if ( vertical )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
        /* 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
  1694
        /* the stem heights to integer pixels            */
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
        if ( dist >= 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
          dist = ( dist + 16 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
          dist = 64;
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
      else
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
        if ( AF_LATIN_HINTS_DO_MONO( hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
          /* 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
  1706
          /* with a different threshold                                   */
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
          if ( dist < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
            dist = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
            dist = ( dist + 32 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
          /* 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
  1716
          /* 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
  1717
          /* 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
  1718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
          if ( dist < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
            dist = ( dist + 64 ) >> 1;
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
          else if ( dist < 128 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
            /* 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
  1725
            /* 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
  1726
            /* 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
  1727
            /* 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
  1728
            /* vertical stems.                                        */
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_Int  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
            dist = ( dist + 22 ) & ~63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
            delta = dist - org_dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
            if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
              delta = -delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
            if (delta >= 16)
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
              dist = org_dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
              if ( dist < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
                dist = ( dist + 64 ) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
            }
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
            /* 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
  1747
            dist = ( dist + 32 ) & ~63;
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
  Done_Width:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
    if ( sign )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
      dist = -dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
    return dist;
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
  /* 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
  1761
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
  af_latin2_align_linked_edge( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
                               AF_Dimension   dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
                               AF_Edge        base_edge,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
                               AF_Edge        stem_edge )
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
    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
  1769
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
    FT_Pos  fitted_width = af_latin2_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
                             hints, dim, dist,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
                             (AF_Edge_Flags)base_edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
                             (AF_Edge_Flags)stem_edge->flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
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
    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
  1777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
    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
  1779
                "dist was %.2f, now %.2f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
                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
  1781
                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
  1782
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
  af_latin2_align_serif_edge( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
                              AF_Edge        base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
                              AF_Edge        serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
    FT_UNUSED( hints );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
    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
  1793
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
  /*************************************************************************/
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
  /*************************************************************************/
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
  /****                    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
  1801
  /****                                                                 ****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
  af_latin2_hint_edges( AF_GlyphHints  hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
                        AF_Dimension   dim )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
    AF_AxisHints  axis       = &hints->axis[dim];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
    AF_Edge       edges      = axis->edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
    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
  1814
    AF_Edge       edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
    AF_Edge       anchor     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
    FT_Int        has_serifs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
    FT_Pos        anchor_drift = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
    FT_TRACE5(( "==== hinting %s edges =====\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
                dim == AF_DIMENSION_HORZ ? "vertical" : "horizontal" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
    /* 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
  1825
    /* 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
  1826
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
    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
  1828
    {
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_Width  blue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
        AF_Edge   edge1, edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
        if ( edge->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
        blue  = edge->blue_edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
        edge1 = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
        edge2 = edge->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
        if ( blue )
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
          edge1 = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
        else if ( edge2 && edge2->blue_edge )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
          blue  = edge2->blue_edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
          edge1 = edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
          edge2 = edge;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
        if ( !edge1 )
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
        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
  1857
                    "was (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
                    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
  1859
                    edge1->pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
        edge1->pos    = blue->fit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
        edge1->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
        if ( edge2 && !edge2->blue_edge )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
          af_latin2_align_linked_edge( hints, dim, edge1, edge2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
          edge2->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
        if ( !anchor )
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
          anchor = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
          anchor_drift = (anchor->pos - anchor->opos);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
          if (edge2)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
            anchor_drift = (anchor_drift + (edge2->pos - edge2->opos)) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
      }
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
    /* now we will 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
  1882
    /* relative order of stems in the glyph                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
    for ( edge = edges; edge < edge_limit; edge++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
      AF_Edge  edge2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
      if ( edge->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
      /* skip all non-stem edges */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
      edge2 = edge->link;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
      if ( !edge2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
        has_serifs++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
      }
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
      /* now align the stem */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
      /* 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
  1902
      if ( edge2->blue_edge )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
        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
  1905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
        af_latin2_align_linked_edge( hints, dim, edge2, edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
        edge->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
      if ( !anchor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
        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
  1914
        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
  1915
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
        org_len = edge2->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
        cur_len = af_latin2_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
                    hints, dim, org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
                    (AF_Edge_Flags)edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
                    (AF_Edge_Flags)edge2->flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
        if ( cur_len <= 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
          u_off = d_off = 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
        else
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
          u_off = 38;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
          d_off = 26;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
        if ( cur_len < 96 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
          org_center = edge->opos + ( org_len >> 1 );
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
          cur_pos1   = FT_PIX_ROUND( org_center );
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
          error1 = org_center - ( cur_pos1 - u_off );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
          if ( error1 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
            error1 = -error1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
          error2 = org_center - ( cur_pos1 + d_off );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
          if ( error2 < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
            error2 = -error2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
          if ( error1 < error2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
            cur_pos1 -= u_off;
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
            cur_pos1 += d_off;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
          edge->pos  = cur_pos1 - cur_len / 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
          edge2->pos = edge->pos + cur_len;
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
          edge->pos = FT_PIX_ROUND( edge->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
        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
  1956
                    " snapped to (%.2f) (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
                    edge-edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
                    edge2-edges, edge2->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
                    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
  1960
        anchor = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
        edge->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
        af_latin2_align_linked_edge( hints, dim, edge, edge2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
        edge2->flags |= AF_EDGE_DONE;
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
        anchor_drift = ( (anchor->pos - anchor->opos) +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
                         (edge2->pos - edge2->opos)) >> 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
        FT_TRACE5(( "DRIFT: %.2f\n", anchor_drift/64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
        FT_Pos   org_pos, org_len, org_center, cur_center, cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
        FT_Pos   org_left, org_right;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
        org_pos    = edge->opos + anchor_drift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
        org_len    = edge2->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
        org_center = org_pos + ( org_len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
        cur_len = af_latin2_compute_stem_width(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
                   hints, dim, org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
                   (AF_Edge_Flags)edge->flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
                   (AF_Edge_Flags)edge2->flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
        org_left  = org_pos + ((org_len - cur_len) >> 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
        org_right = org_pos + ((org_len + cur_len) >> 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
        FT_TRACE5(( "ALIGN: left=%.2f right=%.2f ",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
                    org_left / 64.0, org_right / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
        cur_center = org_center;
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
        if ( edge2->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
          FT_TRACE5(( "\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
          edge->pos = edge2->pos - cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
         /* we want to compare several displacement, and choose
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
          * the one that increases fitness while minimizing
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
          * distortion as well
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
          FT_Pos   displacements[6], scores[6], org, fit, delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
          FT_UInt  count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
          /* note: don't even try to fit tiny stems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
          if ( cur_len < 32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
            FT_TRACE5(( "tiny stem\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
            goto AlignStem;
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
          /* if the span is within a single pixel, don't touch it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
          if ( FT_PIX_FLOOR(org_left) == FT_PIX_CEIL(org_right) )
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
            FT_TRACE5(( "single pixel stem\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
            goto AlignStem;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
          if (cur_len <= 96)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
           /* we want to avoid the absolute worst case which is
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
            * when the left and right edges of the span each represent
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
            * about 50% of the gray. we'd better want to change this
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
            * to 25/75%, since this is much more pleasant to the eye with
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
            * very acceptable distortion
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
            FT_Pos  frac_left  = (org_left) & 63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
            FT_Pos  frac_right = (org_right) & 63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
            if ( frac_left  >= 22 && frac_left  <= 42 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
                 frac_right >= 22 && frac_right <= 42 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
              org = frac_left;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
              fit = (org <= 32) ? 16 : 48;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
              delta = FT_ABS(fit - org);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
              displacements[count] = fit - org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
              scores[count++]      = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
              FT_TRACE5(( "dispA=%.2f (%d) ", (fit - org) / 64.0, delta ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
              org = frac_right;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
              fit = (org <= 32) ? 16 : 48;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
              delta = FT_ABS(fit - org);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
              displacements[count] = fit - org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
              scores[count++]     = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
              FT_TRACE5(( "dispB=%.2f (%d) ", (fit - org) / 64.0, delta ));
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
          /* snapping the left edge to the grid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
          org   = org_left;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
          fit   = FT_PIX_ROUND(org);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
          delta = FT_ABS(fit - org);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
          displacements[count] = fit - org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
          scores[count++]      = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
          FT_TRACE5(( "dispC=%.2f (%d) ", (fit - org) / 64.0, delta ));
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
          /* snapping the right edge to the grid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
          org   = org_right;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
          fit   = FT_PIX_ROUND(org);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
          delta = FT_ABS(fit - org);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2065
          displacements[count] = fit - org;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2066
          scores[count++]      = delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
          FT_TRACE5(( "dispD=%.2f (%d) ", (fit - org) / 64.0, delta ));
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
          /* now find the best displacement */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2070
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2071
            FT_Pos  best_score = scores[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2072
            FT_Pos  best_disp  = displacements[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2073
            FT_UInt nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2074
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2075
            for (nn = 1; nn < count; nn++)
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
              if (scores[nn] < best_score)
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
                best_score = scores[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2080
                best_disp  = displacements[nn];
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
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2084
            cur_center = org_center + best_disp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2085
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2086
          FT_TRACE5(( "\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2087
        }
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
      AlignStem:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
        edge->pos  = cur_center - (cur_len >> 1);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
        edge2->pos = edge->pos + cur_len;
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
        FT_TRACE5(( "STEM1: %d (opos=%.2f) to %d (opos=%.2f)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
                    " snapped to (%.2f) and (%.2f),"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
                    " org_len=%.2f cur_len=%.2f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
                    edge-edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
                    edge2-edges, edge2->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
                    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
  2099
                    org_len / 64.0, cur_len / 64.0 ));
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
        edge->flags  |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
        edge2->flags |= AF_EDGE_DONE;
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
        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
  2105
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
          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
  2107
                      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
  2108
          edge->pos = edge[-1].pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2110
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2111
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2113
    /* 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
  2114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2115
    /* 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
  2116
    /* 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
  2117
    /* 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
  2118
    /* 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
  2119
    /* 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
  2120
    /* 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
  2121
    /* 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
  2122
    /* relatively low.                                                    */
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
    /* 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
  2125
    /* 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
  2126
    /* one pixel higher or lower.                                         */
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
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
      FT_Int  n_edges = edge_limit - edges;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
      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
  2134
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2135
        AF_Edge  edge1, edge2, edge3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
        FT_Pos   dist1, dist2, span, delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
        if ( n_edges == 6 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
          edge1 = edges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
          edge2 = edges + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
          edge3 = edges + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2144
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2145
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
          edge1 = edges + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
          edge2 = edges + 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
          edge3 = edges + 9;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
        dist1 = edge2->opos - edge1->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2153
        dist2 = edge3->opos - edge2->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
        span = dist1 - dist2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
        if ( span < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
          span = -span;
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
        if ( span < 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2160
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
          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
  2162
          edge3->pos -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
          if ( edge3->link )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2164
            edge3->link->pos -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2166
          /* move the serifs along with the stem */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
          if ( n_edges == 12 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2168
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2169
            ( edges + 8 )->pos -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2170
            ( edges + 11 )->pos -= delta;
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
          edge3->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
          if ( edge3->link )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2175
            edge3->link->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2176
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2177
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2178
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2179
#endif
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
    if ( has_serifs || !anchor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
      /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
       *  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
  2185
       *  to complete our processing
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
      for ( edge = edges; edge < edge_limit; edge++ )
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
        FT_Pos  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
        if ( edge->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
        delta = 1000;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2197
        if ( edge->serif )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2198
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2199
          delta = edge->serif->opos - edge->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2200
          if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2201
            delta = -delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2202
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2204
        if ( delta < 64 + 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
          af_latin2_align_serif_edge( hints, edge->serif, edge );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
          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
  2208
                      " aligned to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
                      edge-edges, edge->opos / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2210
                      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
  2211
                      edge->pos / 64.0 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
        else if ( !anchor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
          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
  2216
                      " snapped to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
                      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
  2218
          edge->pos = FT_PIX_ROUND( edge->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
          anchor    = edge;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
        else
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_Edge  before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
          for ( before = edge - 1; before >= edges; before-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
            if ( before->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2230
          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
  2231
            if ( after->flags & AF_EDGE_DONE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
              break;
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
          if ( before >= edges && before < edge   &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
               after < edge_limit && after > edge )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
            if ( after->opos == before->opos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2238
              edge->pos = before->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2239
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2240
              edge->pos = before->pos +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2241
                          FT_MulDiv( edge->opos - before->opos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2242
                                     after->pos - before->pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2243
                                     after->opos - before->opos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2244
            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
  2245
                        " from %d (opos=%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2246
                        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
  2247
                        before - edges, before->opos / 64.0 ));
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
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2250
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2251
            edge->pos = anchor->pos +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2252
                        ( ( edge->opos - anchor->opos + 16 ) & ~31 );
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
            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
  2255
                        " snapped to (%.2f)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2256
                        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
  2257
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2258
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2260
        edge->flags |= AF_EDGE_DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2262
        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
  2263
          edge->pos = edge[-1].pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2265
        if ( edge + 1 < edge_limit        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2266
             edge[1].flags & AF_EDGE_DONE &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2267
             edge->pos > edge[1].pos      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2268
          edge->pos = edge[1].pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2269
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2270
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2271
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2273
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2274
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2275
  af_latin2_hints_apply( AF_GlyphHints    hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2276
                         FT_Outline*      outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2277
                         AF_LatinMetrics  metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2278
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2279
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2280
    int       dim;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2282
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2283
    error = af_glyph_hints_reload( hints, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2284
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2285
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2287
    /* analyze glyph outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2288
#ifdef AF_CONFIG_OPTION_USE_WARPER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2289
    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
  2290
         AF_HINTS_DO_HORIZONTAL( hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2291
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2292
    if ( AF_HINTS_DO_HORIZONTAL( hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2293
#endif
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
      error = af_latin2_hints_detect_features( hints, AF_DIMENSION_HORZ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2296
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2297
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2298
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2300
    if ( AF_HINTS_DO_VERTICAL( hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2301
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2302
      error = af_latin2_hints_detect_features( hints, AF_DIMENSION_VERT );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2303
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2304
        goto Exit;
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
      af_latin2_hints_compute_blue_edges( hints, metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2307
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2308
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2309
    /* grid-fit the outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2310
    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
  2311
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2312
#ifdef AF_CONFIG_OPTION_USE_WARPER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2313
      if ( ( dim == AF_DIMENSION_HORZ &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2314
             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
  2315
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2316
        AF_WarperRec  warper;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2317
        FT_Fixed      scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2318
        FT_Pos        delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2321
        af_warper_compute( &warper, hints, dim, &scale, &delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2322
        af_glyph_hints_scale_dim( hints, dim, scale, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2323
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2324
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2325
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2327
      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
  2328
           ( 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
  2329
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2330
        af_latin2_hint_edges( hints, (AF_Dimension)dim );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2331
        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
  2332
        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
  2333
        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
  2334
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2335
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2336
    af_glyph_hints_save( hints, outline );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2338
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2339
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2340
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2343
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2344
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2345
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2346
  /*****              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
  2347
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2348
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2349
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2352
  static const AF_Script_UniRangeRec  af_latin2_uniranges[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2353
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2354
    AF_UNIRANGE_REC( 32UL,  127UL ),    /* TODO: Add new Unicode ranges here! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2355
    AF_UNIRANGE_REC( 160UL, 255UL ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2356
    AF_UNIRANGE_REC( 0UL,   0UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2357
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2360
  AF_DEFINE_SCRIPT_CLASS(af_latin2_script_class,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2361
    AF_SCRIPT_LATIN2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2362
    af_latin2_uniranges,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2364
    sizeof( AF_LatinMetricsRec ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2366
    (AF_Script_InitMetricsFunc) af_latin2_metrics_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2367
    (AF_Script_ScaleMetricsFunc)af_latin2_metrics_scale,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2368
    (AF_Script_DoneMetricsFunc) NULL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2370
    (AF_Script_InitHintsFunc)   af_latin2_hints_init,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2371
    (AF_Script_ApplyHintsFunc)  af_latin2_hints_apply
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2372
  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2375
/* END */