misc/libfreetype/src/pshinter/pshalgo.c
author unc0rr
Wed, 25 Jul 2012 16:24:30 +0400
changeset 7433 c7fff3e61d49
parent 5172 88f2e05288ba
permissions -rw-r--r--
- Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases) - More branching in walk algorythm which allows for better coverage of reachable places. Sometimes makes AI perform ridiculous jumping just to make a tiny step. - Small fixes/adjustments
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
/*  pshalgo.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
/*    PostScript hinting algorithm (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 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*            by                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  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
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  understand and accept it fully.                                        */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_CALC_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "pshalgo.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include "pshnterr.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#define FT_COMPONENT  trace_pshalgo2
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
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  PSH_Hint_Table  ps_debug_hint_table = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  PSH_HintFunc    ps_debug_hint_func  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  PSH_Glyph       ps_debug_glyph      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
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
#define  COMPUTE_INFLEXS  /* compute inflection points to optimize `S' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
                          /* and similar glyphs                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#define  STRONGER         /* slightly increase the contrast of smooth  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                          /* hinting                                   */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /*****                  BASIC HINTS RECORDINGS                       *****/
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
  /*************************************************************************/
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
  /* return true if two stem hints overlap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  static FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  psh_hint_overlap( PSH_Hint  hint1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
                    PSH_Hint  hint2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    return hint1->org_pos + hint1->org_len >= hint2->org_pos &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
           hint2->org_pos + hint2->org_len >= hint1->org_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  /* destroy hints table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  psh_hint_table_done( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
                       FT_Memory       memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    FT_FREE( table->zones );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    table->num_zones = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    table->zone      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    FT_FREE( table->sort );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    FT_FREE( table->hints );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    table->num_hints   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    table->max_hints   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    table->sort_global = 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  /* deactivate all hints in a table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  psh_hint_table_deactivate( PSH_Hint_Table  table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    FT_UInt   count = table->max_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    PSH_Hint  hint  = table->hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    for ( ; count > 0; count--, hint++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      psh_hint_deactivate( hint );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
      hint->order = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  /* internal function to record a new hint */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  psh_hint_table_record( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
                         FT_UInt         idx )
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
    PSH_Hint  hint = table->hints + idx;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    if ( idx >= table->max_hints )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
      FT_TRACE0(( "psh_hint_table_record: invalid hint index %d\n", idx ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    /* ignore active hints */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    if ( psh_hint_is_active( hint ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      return;
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
    psh_hint_activate( hint );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    /* now scan the current active hint set to check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    /* whether `hint' overlaps with another hint     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
      PSH_Hint*  sorted = table->sort_global;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      FT_UInt    count  = table->num_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      PSH_Hint   hint2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      hint->parent = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      for ( ; count > 0; count--, sorted++ )
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
        hint2 = sorted[0];
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
        if ( psh_hint_overlap( hint, hint2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
          hint->parent = hint2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
          break;
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    if ( table->num_hints < table->max_hints )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      table->sort_global[table->num_hints++] = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      FT_TRACE0(( "psh_hint_table_record: too many sorted hints!  BUG!\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  psh_hint_table_record_mask( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
                              PS_Mask         hint_mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    FT_Int    mask = 0, val = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    FT_Byte*  cursor = hint_mask->bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    FT_UInt   idx, limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    limit = hint_mask->num_bits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    for ( idx = 0; idx < limit; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
      if ( mask == 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
        val  = *cursor++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
        mask = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      if ( val & mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
        psh_hint_table_record( table, idx );
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
      mask >>= 1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  /* create hints table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  psh_hint_table_init( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
                       PS_Hint_Table   hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
                       PS_Mask_Table   hint_masks,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
                       PS_Mask_Table   counter_masks,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
                       FT_Memory       memory )
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
    FT_UInt   count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    FT_UNUSED( counter_masks );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    count = hints->num_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    /* allocate our tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    if ( FT_NEW_ARRAY( table->sort,  2 * count     ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
         FT_NEW_ARRAY( table->hints,     count     ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
         FT_NEW_ARRAY( table->zones, 2 * count + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    table->max_hints   = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    table->sort_global = table->sort + count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    table->num_hints   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    table->num_zones   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    table->zone        = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    /* initialize the `table->hints' array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      PSH_Hint  write = table->hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      PS_Hint   read  = hints->hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      for ( ; count > 0; count--, write++, read++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
        write->org_pos = read->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
        write->org_len = read->len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
        write->flags   = read->flags;
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
    }
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
    /* we now need to determine the initial `parent' stems; first  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    /* activate the hints that are given by the initial hint masks */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    if ( hint_masks )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      PS_Mask  mask = hint_masks->masks;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
      count             = hint_masks->num_masks;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
      table->hint_masks = hint_masks;
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
      for ( ; count > 0; count--, mask++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
        psh_hint_table_record_mask( table, mask );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    /* finally, do a linear parse in case some hints were left alone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    if ( table->num_hints != table->max_hints )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      FT_UInt  idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
      FT_TRACE0(( "psh_hint_table_init: missing/incorrect hint masks\n" ));
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
      count = table->max_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      for ( idx = 0; idx < count; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        psh_hint_table_record( table, idx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  psh_hint_table_activate_mask( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
                                PS_Mask         hint_mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    FT_Int    mask = 0, val = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    FT_Byte*  cursor = hint_mask->bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    FT_UInt   idx, limit, count;
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
    limit = hint_mask->num_bits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    psh_hint_table_deactivate( table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    for ( idx = 0; idx < limit; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      if ( mask == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
        val  = *cursor++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
        mask = 0x80;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
      if ( val & mask )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
        PSH_Hint  hint = &table->hints[idx];
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
        if ( !psh_hint_is_active( hint ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
          FT_UInt     count2;
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
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
          PSH_Hint*  sort = table->sort;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
          PSH_Hint   hint2;
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
          for ( count2 = count; count2 > 0; count2--, sort++ )
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
            hint2 = sort[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
            if ( psh_hint_overlap( hint, hint2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
              FT_TRACE0(( "psh_hint_table_activate_mask:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
                          " found overlapping hints\n" ))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
          count2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
          if ( count2 == 0 )
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
            psh_hint_activate( hint );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
            if ( count < table->max_hints )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
              table->sort[count++] = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
              FT_TRACE0(( "psh_hint_tableactivate_mask:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
                          " too many active hints\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
          }
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
      }
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
      mask >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    table->num_hints = count;
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
    /* now, sort the hints; they are guaranteed to not overlap */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
    /* so we can compare their "org_pos" field directly        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
      FT_Int     i1, i2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
      PSH_Hint   hint1, hint2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
      PSH_Hint*  sort = table->sort;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
      /* a simple bubble sort will do, since in 99% of cases, the hints */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
      /* will be already sorted -- and the sort will be linear          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
      for ( i1 = 1; i1 < (FT_Int)count; i1++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
        hint1 = sort[i1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
        for ( i2 = i1 - 1; i2 >= 0; i2-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
          hint2 = sort[i2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
          if ( hint2->org_pos < hint1->org_pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
            break;
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
          sort[i2 + 1] = hint2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
          sort[i2]     = hint1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  }
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
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
  /*****               HINTS GRID-FITTING AND OPTIMIZATION             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  /*************************************************************************/
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
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  static FT_Pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
  psh_dimension_quantize_len( PSH_Dimension  dim,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
                              FT_Pos         len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
                              FT_Bool        do_snapping )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    if ( len <= 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      len = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      FT_Pos  delta = len - dim->stdw.widths[0].cur;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
      if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
        delta = -delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      if ( delta < 40 )
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
        len = dim->stdw.widths[0].cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
        if ( len < 48 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
          len = 48;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      if ( len < 3 * 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
        delta = ( len & 63 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
        len  &= -64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
        if ( delta < 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
          len += delta;
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
        else if ( delta < 32 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
          len += 10;
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 if ( delta < 54 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
          len += 54;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
          len += delta;
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
        len = FT_PIX_ROUND( len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    if ( do_snapping )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      len = FT_PIX_ROUND( len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    return  len;
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
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
#ifdef DEBUG_HINTER
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
  ps_simple_scale( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
                   FT_Fixed        scale,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
                   FT_Fixed        delta,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
                   FT_Int          dimension )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    PSH_Hint  hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    FT_UInt   count;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    for ( count = 0; count < table->max_hints; count++ )
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
      hint = table->hints + count;
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
      hint->cur_pos = FT_MulFix( hint->org_pos, scale ) + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
      hint->cur_len = FT_MulFix( hint->org_len, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      if ( ps_debug_hint_func )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
        ps_debug_hint_func( hint, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
#endif /* DEBUG_HINTER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
  psh_hint_snap_stem_side_delta( FT_Fixed  pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
                                 FT_Fixed  len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    FT_Fixed  delta1 = FT_PIX_ROUND( pos ) - pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    FT_Fixed  delta2 = FT_PIX_ROUND( pos + len ) - pos - len;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    if ( FT_ABS( delta1 ) <= FT_ABS( delta2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      return delta1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      return delta2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
  psh_hint_align( PSH_Hint     hint,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
                  PSH_Globals  globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
                  FT_Int       dimension,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
                  PSH_Glyph    glyph )
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
    PSH_Dimension  dim   = &globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    FT_Fixed       scale = dim->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
    FT_Fixed       delta = dim->scale_delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
    if ( !psh_hint_is_fitted( hint ) )
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
      FT_Pos  pos = FT_MulFix( hint->org_pos, scale ) + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      FT_Pos  len = FT_MulFix( hint->org_len, scale );
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
      FT_Int            do_snapping;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      FT_Pos            fit_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
      PSH_AlignmentRec  align;
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
      /* ignore stem alignments when requested through the hint flags */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
      if ( ( dimension == 0 && !glyph->do_horz_hints ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
           ( dimension == 1 && !glyph->do_vert_hints ) )
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
        hint->cur_pos = pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
        hint->cur_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
        psh_hint_set_fitted( hint );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
      /* perform stem snapping when requested - this is necessary
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
       * for monochrome and LCD hinting modes only
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
      do_snapping = ( dimension == 0 && glyph->do_horz_snapping ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
                    ( dimension == 1 && glyph->do_vert_snapping );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
      hint->cur_len = fit_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
      /* check blue zones for horizontal stems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      align.align     = PSH_BLUE_ALIGN_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
      align.align_bot = align.align_top = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
      if ( dimension == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
        psh_blues_snap_stem( &globals->blues,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
                             hint->org_pos + hint->org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
                             hint->org_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
                             &align );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
      switch ( align.align )
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
      case PSH_BLUE_ALIGN_TOP:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
        /* the top of the stem is aligned against a blue zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
        hint->cur_pos = align.align_top - fit_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      case PSH_BLUE_ALIGN_BOT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
        /* the bottom of the stem is aligned against a blue zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
        hint->cur_pos = align.align_bot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
      case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
        /* both edges of the stem are aligned against blue zones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
        hint->cur_pos = align.align_bot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
        hint->cur_len = align.align_top - align.align_bot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
          PSH_Hint  parent = hint->parent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
          if ( parent )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
            FT_Pos  par_org_center, par_cur_center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
            FT_Pos  cur_org_center, cur_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
            /* ensure that parent is already fitted */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
            if ( !psh_hint_is_fitted( parent ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
              psh_hint_align( parent, globals, dimension, glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
            /* keep original relation between hints, this is, use the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
            /* scaled distance between the centers of the hints to    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
            /* compute the new position                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
            par_org_center = parent->org_pos + ( parent->org_len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
            par_cur_center = parent->cur_pos + ( parent->cur_len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
            cur_org_center = hint->org_pos   + ( hint->org_len   >> 1 );
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
            cur_delta = FT_MulFix( cur_org_center - par_org_center, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
            pos       = par_cur_center + cur_delta - ( len >> 1 );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
          hint->cur_pos = pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
          hint->cur_len = fit_len;
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
          /* Stem adjustment tries to snap stem widths to standard
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
           * ones.  This is important to prevent unpleasant rounding
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
           * artefacts.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
          if ( glyph->do_stem_adjust )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
            if ( len <= 64 )
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
              /* the stem is less than one pixel; we will center it
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
               * around the nearest pixel center
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 ( len >= 32 )
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
                /* This is a special case where we also widen the stem
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
                 * and align it to the pixel grid.
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
                 *   stem_center          = pos + (len/2)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
                 *   nearest_pixel_center = FT_ROUND(stem_center-32)+32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
                 *   new_pos              = nearest_pixel_center-32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
                 *                        = FT_ROUND(stem_center-32)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
                 *                        = FT_FLOOR(stem_center-32+32)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
                 *                        = FT_FLOOR(stem_center)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
                 *   new_len              = 64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
                pos = FT_PIX_FLOOR( pos + ( len >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
                len = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
              else if ( len > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
                /* This is a very small stem; we simply align it to the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
                 * pixel grid, trying to find the minimal displacement.
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
                 * left               = pos
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
                 * right              = pos + len
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
                 * left_nearest_edge  = ROUND(pos)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
                 * right_nearest_edge = ROUND(right)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
                 *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
                 * if ( ABS(left_nearest_edge - left) <=
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
                 *      ABS(right_nearest_edge - right) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
                 *    new_pos = left
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
                 * else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
                 *    new_pos = right
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
                FT_Pos  left_nearest  = FT_PIX_ROUND( pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
                FT_Pos  right_nearest = FT_PIX_ROUND( pos + len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
                FT_Pos  left_disp     = left_nearest - pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
                FT_Pos  right_disp    = right_nearest - ( pos + len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
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
                if ( left_disp < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
                  left_disp = -left_disp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
                if ( right_disp < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
                  right_disp = -right_disp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
                if ( left_disp <= right_disp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
                  pos = left_nearest;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
                else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
                  pos = right_nearest;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
              else
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
                /* this is a ghost stem; we simply round it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
                pos = FT_PIX_ROUND( pos );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
              len = psh_dimension_quantize_len( dim, len, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
          }
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
          /* now that we have a good hinted stem width, try to position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
          /* the stem along a pixel grid integer coordinate             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
          hint->cur_pos = pos + psh_hint_snap_stem_side_delta( pos, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
          hint->cur_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      if ( do_snapping )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
        pos = hint->cur_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
        len = hint->cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
        if ( len < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
          len = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
          len = FT_PIX_ROUND( len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
        switch ( align.align )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
          case PSH_BLUE_ALIGN_TOP:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
            hint->cur_pos = align.align_top - len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
            hint->cur_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
          case PSH_BLUE_ALIGN_BOT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
            hint->cur_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
          case PSH_BLUE_ALIGN_BOT | PSH_BLUE_ALIGN_TOP:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
            /* don't touch */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
          default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
            hint->cur_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
            if ( len & 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
              pos = FT_PIX_FLOOR( pos + ( len >> 1 ) ) + 32;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
              pos = FT_PIX_ROUND( pos + ( len >> 1 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
            hint->cur_pos = pos - ( len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
            hint->cur_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
        }
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
      psh_hint_set_fitted( hint );
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
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
      if ( ps_debug_hint_func )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
        ps_debug_hint_func( hint, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
#if 0  /* not used for now, experimental */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
 /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  *  A variant to perform "light" hinting (i.e. FT_RENDER_MODE_LIGHT)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
  *  of stems
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
  psh_hint_align_light( PSH_Hint     hint,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
                        PSH_Globals  globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
                        FT_Int       dimension,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
                        PSH_Glyph    glyph )
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
    PSH_Dimension  dim   = &globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    FT_Fixed       scale = dim->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    FT_Fixed       delta = dim->scale_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    if ( !psh_hint_is_fitted( hint ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
      FT_Pos  pos = FT_MulFix( hint->org_pos, scale ) + delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
      FT_Pos  len = FT_MulFix( hint->org_len, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
      FT_Pos  fit_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
      PSH_AlignmentRec  align;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
      /* ignore stem alignments when requested through the hint flags */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      if ( ( dimension == 0 && !glyph->do_horz_hints ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
           ( dimension == 1 && !glyph->do_vert_hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
        hint->cur_pos = pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
        hint->cur_len = len;
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
        psh_hint_set_fitted( hint );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
        return;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
      fit_len = len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
      hint->cur_len = fit_len;
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
      /* check blue zones for horizontal stems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      align.align = PSH_BLUE_ALIGN_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
      align.align_bot = align.align_top = 0;
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
      if ( dimension == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
        psh_blues_snap_stem( &globals->blues,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
                             hint->org_pos + hint->org_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
                             hint->org_pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
                             &align );
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
      switch ( align.align )
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
      case PSH_BLUE_ALIGN_TOP:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
        /* the top of the stem is aligned against a blue zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
        hint->cur_pos = align.align_top - fit_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      case PSH_BLUE_ALIGN_BOT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
        /* the bottom of the stem is aligned against a blue zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
        hint->cur_pos = align.align_bot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
        break;
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
      case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
        /* both edges of the stem are aligned against blue zones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
        hint->cur_pos = align.align_bot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
        hint->cur_len = align.align_top - align.align_bot;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      default:
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
          PSH_Hint  parent = hint->parent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
          if ( parent )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
            FT_Pos  par_org_center, par_cur_center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
            FT_Pos  cur_org_center, cur_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
            /* ensure that parent is already fitted */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
            if ( !psh_hint_is_fitted( parent ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
              psh_hint_align_light( parent, globals, dimension, glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
            par_org_center = parent->org_pos + ( parent->org_len / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
            par_cur_center = parent->cur_pos + ( parent->cur_len / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
            cur_org_center = hint->org_pos   + ( hint->org_len   / 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
            cur_delta = FT_MulFix( cur_org_center - par_org_center, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
            pos       = par_cur_center + cur_delta - ( len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
          /* Stems less than one pixel wide are easy -- we want to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
           * make them as dark as possible, so they must fall within
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
           * one pixel.  If the stem is split between two pixels
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
           * then snap the edge that is nearer to the pixel boundary
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
           * to the pixel boundary.
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
          if ( len <= 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
            if ( ( pos + len + 63 ) / 64  != pos / 64 + 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
              pos += psh_hint_snap_stem_side_delta ( pos, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
          /* Position stems other to minimize the amount of mid-grays.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
           * There are, in general, two positions that do this,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
           * illustrated as A) and B) below.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
           *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
           *   +                   +                   +                   +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
           *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
           * A)             |--------------------------------|
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
           * B)   |--------------------------------|
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
           * C)       |--------------------------------|
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
           *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
           * Position A) (split the excess stem equally) should be better
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
           * for stems of width N + f where f < 0.5.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
           *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
           * Position B) (split the deficiency equally) should be better
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
           * for stems of width N + f where f > 0.5.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
           *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
           * It turns out though that minimizing the total number of lit
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
           * pixels is also important, so position C), with one edge
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
           * aligned with a pixel boundary is actually preferable
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
           * to A).  There are also more possibile positions for C) than
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
           * for A) or B), so it involves less distortion of the overall
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
           * character shape.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
          else /* len > 64 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
            FT_Fixed  frac_len = len & 63;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
            FT_Fixed  center = pos + ( len >> 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
            FT_Fixed  delta_a, delta_b;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
            if ( ( len / 64 ) & 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
              delta_a = FT_PIX_FLOOR( center ) + 32 - center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
              delta_b = FT_PIX_ROUND( center ) - center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
              delta_a = FT_PIX_ROUND( center ) - center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
              delta_b = FT_PIX_FLOOR( center ) + 32 - center;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
            /* We choose between B) and C) above based on the amount
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
             * of fractinal stem width; for small amounts, choose
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
             * C) always, for large amounts, B) always, and inbetween,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
             * pick whichever one involves less stem movement.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
            if ( frac_len < 32 )
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
              pos += psh_hint_snap_stem_side_delta ( pos, len );
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
            else if ( frac_len < 48 )
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
              FT_Fixed  side_delta = psh_hint_snap_stem_side_delta ( pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
                                                                     len );
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 ( FT_ABS( side_delta ) < FT_ABS( delta_b ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
                pos += side_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
              else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
                pos += delta_b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
            else
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
              pos += delta_b;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
          hint->cur_pos = pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
      }  /* switch */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
      psh_hint_set_fitted( hint );
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
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
      if ( ps_debug_hint_func )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
        ps_debug_hint_func( hint, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
#endif
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
#endif /* 0 */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
  psh_hint_table_align_hints( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
                              PSH_Globals     globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
                              FT_Int          dimension,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
                              PSH_Glyph       glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
    PSH_Hint       hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
    FT_UInt        count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    PSH_Dimension  dim   = &globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    FT_Fixed       scale = dim->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
    FT_Fixed       delta = dim->scale_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
    if ( ps_debug_no_vert_hints && dimension == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
      ps_simple_scale( table, scale, delta, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
    }
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
    if ( ps_debug_no_horz_hints && dimension == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      ps_simple_scale( table, scale, delta, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
      return;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
#endif /* DEBUG_HINTER*/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    hint  = table->hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
    count = table->max_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
    for ( ; count > 0; count--, hint++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
      psh_hint_align( hint, globals, dimension, glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
  /*****                POINTS INTERPOLATION ROUTINES                  *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
  /*************************************************************************/
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
#define PSH_ZONE_MIN  -3200000L
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
#define PSH_ZONE_MAX  +3200000L
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
#define xxDEBUG_ZONES
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
#ifdef DEBUG_ZONES
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
#include FT_CONFIG_STANDARD_LIBRARY_H
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
  psh_print_zone( PSH_Zone  zone )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
    printf( "zone [scale,delta,min,max] = [%.3f,%.3f,%d,%d]\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
             zone->scale / 65536.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
             zone->delta / 64.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
             zone->min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
             zone->max );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
  }
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
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
#define psh_print_zone( x )  do { } while ( 0 )
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
#endif /* DEBUG_ZONES */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
  /*****                    HINTER GLYPH MANAGEMENT                    *****/
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
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
#define  psh_corner_is_flat      ft_corner_is_flat
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
#define  psh_corner_orientation  ft_corner_orientation
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
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
  psh_corner_is_flat( FT_Pos  x_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
                      FT_Pos  y_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
                      FT_Pos  x_out,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
                      FT_Pos  y_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
    FT_Pos  ax = x_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
    FT_Pos  ay = y_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
    FT_Pos  d_in, d_out, d_corner;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    d_in = ax + ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
    ax = x_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
    ay = y_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    d_out = ax + ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
    ax = x_out + x_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
    ay = y_out + y_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
    d_corner = ax + ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
    return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
  static FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
  psh_corner_orientation( FT_Pos  in_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
                          FT_Pos  in_y,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
                          FT_Pos  out_x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
                          FT_Pos  out_y )
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
    FT_Int  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
    /* deal with the trivial cases quickly */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
    if ( in_y == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
      if ( in_x >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
        result = out_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
        result = -out_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
    else if ( in_x == 0 )
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 ( in_y >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
        result = -out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
        result = out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    else if ( out_y == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
      if ( out_x >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
        result = in_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
        result = -in_y;
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
    else if ( out_x == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
      if ( out_y >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
        result = -in_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
        result =  in_x;
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
    else /* general case */
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
      long long  delta = (long long)in_x * out_y - (long long)in_y * out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
      if ( delta == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
        result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
        result = 1 - 2 * ( delta < 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
#endif /* !1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
#ifdef COMPUTE_INFLEXS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
  /* compute all inflex points in a given glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
  psh_glyph_compute_inflections( PSH_Glyph  glyph )
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
    FT_UInt  n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    for ( n = 0; n < glyph->num_contours; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
      PSH_Point  first, start, end, before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
      FT_Pos     in_x, in_y, out_x, out_y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
      FT_Int     orient_prev, orient_cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
      FT_Int     finished = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
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
      /* we need at least 4 points to create an inflection point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
      if ( glyph->contours[n].count < 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
        continue;
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
      /* compute first segment in contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
      first = glyph->contours[n].start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
      start = end = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
      do
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
        end = end->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
        if ( end == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
          goto Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
        in_x = end->org_u - start->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
        in_y = end->org_v - start->org_v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
      } while ( in_x == 0 && in_y == 0 );
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
      /* extend the segment start whenever possible */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
      before = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
        do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
          start  = before;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
          before = before->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
          if ( before == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
            goto Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
          out_x = start->org_u - before->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
          out_y = start->org_v - before->org_v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
        } while ( out_x == 0 && out_y == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
        orient_prev = psh_corner_orientation( in_x, in_y, out_x, out_y );
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
      } while ( orient_prev == 0 );
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
      first = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
      in_x  = out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
      in_y  = out_y;
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
      /* now, process all segments in the contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
        /* first, extend current segment's end whenever possible */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
        after = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
        do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
          do
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
            end   = after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
            after = after->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
            if ( after == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
              finished = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
            out_x = after->org_u - end->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
            out_y = after->org_v - end->org_v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
          } while ( out_x == 0 && out_y == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
          orient_cur = psh_corner_orientation( in_x, in_y, out_x, out_y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
        } while ( orient_cur == 0 );
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
        if ( ( orient_cur ^ orient_prev ) < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
          do
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
            psh_point_set_inflex( start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
            start = start->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
          while ( start != end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
          psh_point_set_inflex( start );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
        start       = end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
        end         = after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
        orient_prev = orient_cur;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
        in_x        = out_x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
        in_y        = out_y;
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
      } while ( !finished );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
    Skip:
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
#endif /* COMPUTE_INFLEXS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
  psh_glyph_done( PSH_Glyph  glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
    FT_Memory  memory = glyph->memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
    psh_hint_table_done( &glyph->hint_tables[1], memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
    psh_hint_table_done( &glyph->hint_tables[0], memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
    FT_FREE( glyph->points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
    FT_FREE( glyph->contours );
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
    glyph->num_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
    glyph->num_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
    glyph->memory = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
  psh_compute_dir( FT_Pos  dx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
                   FT_Pos  dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
    FT_Pos  ax, ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
    int     result = PSH_DIR_NONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
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
    ax = ( dx >= 0 ) ? dx : -dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
    ay = ( dy >= 0 ) ? dy : -dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
    if ( ay * 12 < ax )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
      /* |dy| <<< |dx|  means a near-horizontal segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
      result = ( dx >= 0 ) ? PSH_DIR_RIGHT : PSH_DIR_LEFT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
    else if ( ax * 12 < ay )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
      /* |dx| <<< |dy|  means a near-vertical segment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
      result = ( dy >= 0 ) ? PSH_DIR_UP : PSH_DIR_DOWN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
    return result;
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
  /* load outline point coordinates into hinter glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
  psh_glyph_load_points( PSH_Glyph  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
                         FT_Int     dimension )
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
    FT_Vector*  vec   = glyph->outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
    PSH_Point   point = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
    FT_UInt     count = glyph->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
    for ( ; count > 0; count--, point++, vec++ )
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
      point->flags2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
      point->hint   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
      if ( dimension == 0 )
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
        point->org_u = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
        point->org_v = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
      else
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
        point->org_u = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
        point->org_v = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
      point->org_x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
      point->org_y = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
  /* save hinted point coordinates back to outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
  psh_glyph_save_points( PSH_Glyph  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
                         FT_Int     dimension )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
    FT_UInt     n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
    PSH_Point   point = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
    FT_Vector*  vec   = glyph->outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
    char*       tags  = glyph->outline->tags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
    for ( n = 0; n < glyph->num_points; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
      if ( dimension == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
        vec[n].x = point->cur_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
        vec[n].y = point->cur_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
      if ( psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
        tags[n] |= (char)( ( dimension == 0 ) ? 32 : 64 );
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
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
      if ( dimension == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
        point->cur_x   = point->cur_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
        point->flags_x = point->flags2 | point->flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
        point->cur_y   = point->cur_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
        point->flags_y = point->flags2 | point->flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
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
      point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
  psh_glyph_init( PSH_Glyph    glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
                  FT_Outline*  outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
                  PS_Hints     ps_hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
                  PSH_Globals  globals )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
    /* clear all fields */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
    FT_MEM_ZERO( glyph, sizeof ( *glyph ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
    memory = glyph->memory = globals->memory;
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
    /* allocate and setup points + contours arrays */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
    if ( FT_NEW_ARRAY( glyph->points,   outline->n_points   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
         FT_NEW_ARRAY( glyph->contours, outline->n_contours ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
    glyph->num_points   = outline->n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
    glyph->num_contours = outline->n_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
      FT_UInt      first = 0, next, n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
      PSH_Point    points  = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
      PSH_Contour  contour = glyph->contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
      for ( n = 0; n < glyph->num_contours; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
        FT_Int     count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
        PSH_Point  point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
        next  = outline->contours[n] + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
        count = next - first;
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
        contour->start = points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
        contour->count = (FT_UInt)count;
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
        if ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
          point = points + first;
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
          point->prev    = points + next - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
          point->contour = contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
          for ( ; count > 1; count-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
            point[0].next = point + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
            point[1].prev = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
            point++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
            point->contour = contour;
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
          point->next = points + first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
        contour++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
        first = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
      PSH_Point   points = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
      PSH_Point   point  = points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
      FT_Vector*  vec    = outline->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
      FT_UInt     n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
      for ( n = 0; n < glyph->num_points; n++, point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
        FT_Int  n_prev = (FT_Int)( point->prev - points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
        FT_Int  n_next = (FT_Int)( point->next - points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
        FT_Pos  dxi, dyi, dxo, dyo;
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
        if ( !( outline->tags[n] & FT_CURVE_TAG_ON ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
          point->flags = PSH_POINT_OFF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
        dxi = vec[n].x - vec[n_prev].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
        dyi = vec[n].y - vec[n_prev].y;
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
        point->dir_in = (FT_Char)psh_compute_dir( dxi, dyi );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
        dxo = vec[n_next].x - vec[n].x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
        dyo = vec[n_next].y - vec[n].y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
        point->dir_out = (FT_Char)psh_compute_dir( dxo, dyo );
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
        /* detect smooth points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
        if ( point->flags & PSH_POINT_OFF )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
          point->flags |= PSH_POINT_SMOOTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
        else if ( point->dir_in == point->dir_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
          if ( point->dir_out != PSH_DIR_NONE           ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
               psh_corner_is_flat( dxi, dyi, dxo, dyo ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
            point->flags |= PSH_POINT_SMOOTH;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
    glyph->outline = outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
    glyph->globals = globals;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
#ifdef COMPUTE_INFLEXS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
    psh_glyph_load_points( glyph, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
    psh_glyph_compute_inflections( glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
#endif /* COMPUTE_INFLEXS */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
    /* now deal with hints tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
    error = psh_hint_table_init( &glyph->hint_tables [0],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
                                 &ps_hints->dimension[0].hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
                                 &ps_hints->dimension[0].masks,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
                                 &ps_hints->dimension[0].counters,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
                                 memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
    error = psh_hint_table_init( &glyph->hint_tables [1],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
                                 &ps_hints->dimension[1].hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
                                 &ps_hints->dimension[1].masks,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
                                 &ps_hints->dimension[1].counters,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
                                 memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
  /* compute all extrema in a glyph for a given dimension */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
  psh_glyph_compute_extrema( PSH_Glyph  glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
    FT_UInt  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
    /* first of all, compute all local extrema */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
    for ( n = 0; n < glyph->num_contours; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
      PSH_Point  first = glyph->contours[n].start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
      PSH_Point  point, before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
      if ( glyph->contours[n].count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
      point  = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
      before = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
      after  = point;
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
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
        before = before->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
        if ( before == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
          goto Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
      } while ( before->org_u == point->org_u );
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
      first = point = before->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
      for (;;)
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
        after = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
        do
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
          after = after->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
          if ( after == first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
            goto Next;
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
        } while ( after->org_u == point->org_u );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
        if ( before->org_u < point->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
          if ( after->org_u < point->org_u )
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
            /* local maximum */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
            goto Extremum;
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
        else /* before->org_u > point->org_u */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
          if ( after->org_u > point->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
            /* local minimum */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
          Extremum:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
            do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
              psh_point_set_extremum( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
              point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
            } while ( point != after );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
        before = after->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
        point  = after;
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
      } /* for  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
    Next:
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
    /* for each extremum, determine its direction along the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
    /* orthogonal axis                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
    for ( n = 0; n < glyph->num_points; n++ )
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
      PSH_Point  point, before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
      point  = &glyph->points[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
      before = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
      after  = point;
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
      if ( psh_point_is_extremum( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
        do
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
          before = before->prev;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
          if ( before == point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
            goto Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
        } while ( before->org_v == point->org_v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
        do
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
          after = after->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
          if ( after == point )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
            goto Skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
        } while ( after->org_v == point->org_v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
      }
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
      if ( before->org_v < point->org_v &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
           after->org_v  > point->org_v )
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
        psh_point_set_positive( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
      else if ( before->org_v > point->org_v &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
                after->org_v  < point->org_v )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
        psh_point_set_negative( point );
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
    Skip:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
      ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
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
  /* major_dir is the direction for points on the bottom/left of the stem; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
  /* Points on the top/right of the stem will have a direction of          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
  /* -major_dir.                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
  psh_hint_table_find_strong_points( PSH_Hint_Table  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
                                     PSH_Point       point,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
                                     FT_UInt         count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
                                     FT_Int          threshold,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
                                     FT_Int          major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
    PSH_Hint*  sort      = table->sort;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
    FT_UInt    num_hints = table->num_hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
    for ( ; count > 0; count--, point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
      FT_Int  point_dir = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
      FT_Pos  org_u     = point->org_u;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
      if ( psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
        continue;
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
      if ( PSH_DIR_COMPARE( point->dir_in, major_dir ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
        point_dir = point->dir_in;
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
      else if ( PSH_DIR_COMPARE( point->dir_out, major_dir ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
        point_dir = point->dir_out;
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
      if ( point_dir )
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
        if ( point_dir == major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
          FT_UInt  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
          for ( nn = 0; nn < num_hints; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
            PSH_Hint  hint = sort[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
            FT_Pos    d    = org_u - hint->org_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
            if ( d < threshold && -d < threshold )
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
              psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
              point->flags2 |= PSH_POINT_EDGE_MIN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
              point->hint    = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
          }
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
        else if ( point_dir == -major_dir )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
          FT_UInt  nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
          for ( nn = 0; nn < num_hints; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
            PSH_Hint  hint = sort[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
            FT_Pos    d    = org_u - hint->org_pos - hint->org_len;
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
            if ( d < threshold && -d < threshold )
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
              psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
              point->flags2 |= PSH_POINT_EDGE_MAX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
              point->hint    = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
              break;
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
          }
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
      else if ( psh_point_is_extremum( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
        /* treat extrema as special cases for stem edge alignment */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
        FT_UInt  nn, min_flag, max_flag;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
        if ( major_dir == PSH_DIR_HORIZONTAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
          min_flag = PSH_POINT_POSITIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
          max_flag = PSH_POINT_NEGATIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
          min_flag = PSH_POINT_NEGATIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
          max_flag = PSH_POINT_POSITIVE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
        if ( point->flags2 & min_flag )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
          for ( nn = 0; nn < num_hints; nn++ )
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
            PSH_Hint  hint = sort[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
            FT_Pos    d    = org_u - hint->org_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
            if ( d < threshold && -d < threshold )
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
              point->flags2 |= PSH_POINT_EDGE_MIN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
              point->hint    = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
              psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
              break;
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
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
        else if ( point->flags2 & max_flag )
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
          for ( nn = 0; nn < num_hints; nn++ )
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
            PSH_Hint  hint = sort[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
            FT_Pos    d    = org_u - hint->org_pos - hint->org_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
            if ( d < threshold && -d < threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
              point->flags2 |= PSH_POINT_EDGE_MAX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
              point->hint    = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
              psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
              break;
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
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
        if ( point->hint == NULL )
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
          for ( nn = 0; nn < num_hints; nn++ )
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
            PSH_Hint  hint = sort[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
            if ( org_u >= hint->org_pos                 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
                org_u <= hint->org_pos + hint->org_len )
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
              point->hint = hint;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
              break;
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
          }
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
#endif /* 1 */
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
  }
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
  /* the accepted shift for strong points in fractional pixels */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
#define PSH_STRONG_THRESHOLD  32
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
  /* the maximum shift value in font units */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
#define PSH_STRONG_THRESHOLD_MAXIMUM  30
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
  /* find strong points in a glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
  psh_glyph_find_strong_points( PSH_Glyph  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
                                FT_Int     dimension )
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
    /* a point is `strong' if it is located on a stem edge and       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
    /* has an `in' or `out' tangent parallel to the hint's direction */
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
    PSH_Hint_Table  table     = &glyph->hint_tables[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
    PS_Mask         mask      = table->hint_masks->masks;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
    FT_UInt         num_masks = table->hint_masks->num_masks;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
    FT_UInt         first     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
    FT_Int          major_dir = dimension == 0 ? PSH_DIR_VERTICAL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
                                               : PSH_DIR_HORIZONTAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
    PSH_Dimension   dim       = &glyph->globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
    FT_Fixed        scale     = dim->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
    FT_Int          threshold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
    threshold = (FT_Int)FT_DivFix( PSH_STRONG_THRESHOLD, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
    if ( threshold > PSH_STRONG_THRESHOLD_MAXIMUM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
      threshold = PSH_STRONG_THRESHOLD_MAXIMUM;
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
    /* process secondary hints to `selected' points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
    if ( num_masks > 1 && glyph->num_points > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
      /* the `endchar' op can reduce the number of points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
      first = mask->end_point > glyph->num_points
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
                ? glyph->num_points
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
                : mask->end_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
      mask++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
      for ( ; num_masks > 1; num_masks--, mask++ )
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
        FT_UInt  next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
        FT_Int   count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
        next  = mask->end_point > glyph->num_points
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
                  ? glyph->num_points
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
                  : mask->end_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
        count = next - first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
        if ( count > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
          PSH_Point  point = glyph->points + first;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
          psh_hint_table_activate_mask( table, mask );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
          psh_hint_table_find_strong_points( table, point, count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
                                             threshold, major_dir );
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
        first = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
      }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
    /* process primary hints for all points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
    if ( num_masks == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
      FT_UInt    count = glyph->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
      PSH_Point  point = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
      psh_hint_table_activate_mask( table, table->hint_masks->masks );
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
      psh_hint_table_find_strong_points( table, point, count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
                                         threshold, major_dir );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
    /* now, certain points may have been attached to a hint and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
    /* not marked as strong; update their flags then            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
      FT_UInt    count = glyph->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
      PSH_Point  point = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
      for ( ; count > 0; count--, point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
        if ( point->hint && !psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
          psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
  }
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
  /* find points in a glyph which are in a blue zone and have `in' or */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
  /* `out' tangents parallel to the horizontal axis                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
  psh_glyph_find_blue_points( PSH_Blues  blues,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
                              PSH_Glyph  glyph )
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
    PSH_Blue_Table  table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
    PSH_Blue_Zone   zone;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
    FT_UInt         glyph_count = glyph->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
    FT_UInt         blue_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
    PSH_Point       point = glyph->points;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
    for ( ; glyph_count > 0; glyph_count--, point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
      FT_Pos  y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
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
      /* check tangents */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
      if ( !PSH_DIR_COMPARE( point->dir_in,  PSH_DIR_HORIZONTAL ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
           !PSH_DIR_COMPARE( point->dir_out, PSH_DIR_HORIZONTAL ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
      /* skip strong points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
      if ( psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
      y = point->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
      /* look up top zones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
      table      = &blues->normal_top;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
      blue_count = table->count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
      zone       = table->zones;
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
      for ( ; blue_count > 0; blue_count--, zone++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
        FT_Pos  delta = y - zone->org_bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
        if ( delta < -blues->blue_fuzz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
          break;
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
        if ( y <= zone->org_top + blues->blue_fuzz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
          if ( blues->no_overshoots || delta <= blues->blue_threshold )
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
            point->cur_u = zone->cur_bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
            psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
            psh_point_set_fitted( point );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
      /* look up bottom zones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
      table      = &blues->normal_bottom;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
      blue_count = table->count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
      zone       = table->zones + blue_count - 1;
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
      for ( ; blue_count > 0; blue_count--, zone-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
        FT_Pos  delta = zone->org_top - y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
        if ( delta < -blues->blue_fuzz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
        if ( y >= zone->org_bottom - blues->blue_fuzz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
          if ( blues->no_overshoots || delta < blues->blue_threshold )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
            point->cur_u = zone->cur_top;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
            psh_point_set_strong( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
            psh_point_set_fitted( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
    }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
  /* interpolate strong points with the help of hinted coordinates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
  psh_glyph_interpolate_strong_points( PSH_Glyph  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
                                       FT_Int     dimension )
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
    PSH_Dimension  dim   = &glyph->globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
    FT_Fixed       scale = dim->scale_mult;
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
    FT_UInt        count = glyph->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
    PSH_Point      point = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
    for ( ; count > 0; count--, point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
      PSH_Hint  hint = point->hint;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
      if ( hint )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
        FT_Pos  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
        if ( psh_point_is_edge_min( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
          point->cur_u = hint->cur_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
        else if ( psh_point_is_edge_max( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
          point->cur_u = hint->cur_pos + hint->cur_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
        else
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
          delta = point->org_u - hint->org_pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
          if ( delta <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
            point->cur_u = hint->cur_pos + FT_MulFix( delta, scale );
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
          else if ( delta >= hint->org_len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
            point->cur_u = hint->cur_pos + hint->cur_len +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
                             FT_MulFix( delta - hint->org_len, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
          else /* hint->org_len > 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
            point->cur_u = hint->cur_pos +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
                             FT_MulDiv( delta, hint->cur_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
                                        hint->org_len );
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
        psh_point_set_fitted( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
#define  PSH_MAX_STRONG_INTERNAL  16
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
  psh_glyph_interpolate_normal_points( PSH_Glyph  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
                                       FT_Int     dimension )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
    /* first technique: a point is strong if it is a local extremum */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
    PSH_Dimension  dim    = &glyph->globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
    FT_Fixed       scale  = dim->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
    FT_Memory      memory = glyph->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
    PSH_Point*     strongs     = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
    PSH_Point      strongs_0[PSH_MAX_STRONG_INTERNAL];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
    FT_UInt        num_strongs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
    PSH_Point      points = glyph->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
    PSH_Point      points_end = points + glyph->num_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
    PSH_Point      point;
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
    /* first count the number of strong points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
    for ( point = points; point < points_end; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
      if ( psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
        num_strongs++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
    if ( num_strongs == 0 )  /* nothing to do here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
    /* allocate an array to store a list of points, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
    /* stored in increasing org_u order             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
    if ( num_strongs <= PSH_MAX_STRONG_INTERNAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
      strongs = strongs_0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
      FT_Error  error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
      if ( FT_NEW_ARRAY( strongs, num_strongs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
    num_strongs = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
    for ( point = points; point < points_end; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
      PSH_Point*  insert;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
      if ( !psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
      for ( insert = strongs + num_strongs; insert > strongs; insert-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
        if ( insert[-1]->org_u <= point->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
          break;
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
        insert[0] = insert[-1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
      insert[0] = point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
      num_strongs++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
    /* now try to interpolate all normal points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
    for ( point = points; point < points_end; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
      if ( psh_point_is_strong( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
      /* sometimes, some local extrema are smooth points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
      if ( psh_point_is_smooth( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
        if ( point->dir_in == PSH_DIR_NONE   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
             point->dir_in != point->dir_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
          continue;
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
        if ( !psh_point_is_extremum( point ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
             !psh_point_is_inflex( point )   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
        point->flags &= ~PSH_POINT_SMOOTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
      /* find best enclosing point coordinates then interpolate */
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
        PSH_Point   before, after;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
        FT_UInt     nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
        for ( nn = 0; nn < num_strongs; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
          if ( strongs[nn]->org_u > point->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
        if ( nn == 0 )  /* point before the first strong point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
          after = strongs[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
          point->cur_u = after->cur_u +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
                           FT_MulFix( point->org_u - after->org_u,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
                                      scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
          before = strongs[nn - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
          for ( nn = num_strongs; nn > 0; nn-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
            if ( strongs[nn - 1]->org_u < point->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
              break;
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
          if ( nn == num_strongs )  /* point is after last strong point */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
            before = strongs[nn - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
            point->cur_u = before->cur_u +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
                             FT_MulFix( point->org_u - before->org_u,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
                                        scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
            FT_Pos  u;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
            after = strongs[nn];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
            /* now interpolate point between before and after */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
            u = point->org_u;
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
            if ( u == before->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
              point->cur_u = before->cur_u;
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
            else if ( u == after->org_u )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
              point->cur_u = after->cur_u;
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
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
              point->cur_u = before->cur_u +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
                               FT_MulDiv( u - before->org_u,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
                                          after->cur_u - before->cur_u,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
                                          after->org_u - before->org_u );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
          }
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
        psh_point_set_fitted( point );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
    }
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 ( strongs != strongs_0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
      FT_FREE( strongs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
#endif /* 1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
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
  /* interpolate other points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
  psh_glyph_interpolate_other_points( PSH_Glyph  glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
                                      FT_Int     dimension )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
    PSH_Dimension  dim          = &glyph->globals->dimension[dimension];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
    FT_Fixed       scale        = dim->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
    FT_Fixed       delta        = dim->scale_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
    PSH_Contour    contour      = glyph->contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
    FT_UInt        num_contours = glyph->num_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
    for ( ; num_contours > 0; num_contours--, contour++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
      PSH_Point  start = contour->start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
      PSH_Point  first, next, point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
      FT_UInt    fit_count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
      /* count the number of strong points in this contour */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
      next      = start + contour->count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
      fit_count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
      first     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
      for ( point = start; point < next; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
        if ( psh_point_is_fitted( point ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
          if ( !first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
            first = point;
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
          fit_count++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
      /* if there are less than 2 fitted points in the contour, we */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2065
      /* simply scale and eventually translate the contour points  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2066
      if ( fit_count < 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2068
        if ( fit_count == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2069
          delta = first->cur_u - FT_MulFix( first->org_u, scale );
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
        for ( point = start; point < next; point++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2072
          if ( point != first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2073
            point->cur_u = FT_MulFix( point->org_u, scale ) + delta;
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
        goto Next_Contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2076
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2077
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2078
      /* there are more than 2 strong points in this contour; we */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2079
      /* need to interpolate weak points between them            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2080
      start = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2081
      do
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
        point = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2084
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2085
        /* skip consecutive fitted points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2086
        for (;;)
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
          next = first->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2089
          if ( next == start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
            goto Next_Contour;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2092
          if ( !psh_point_is_fitted( next ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2093
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
          first = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
        /* find next fitted point after unfitted one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2099
        for (;;)
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
          next = next->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
          if ( psh_point_is_fitted( next ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2103
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2104
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
        /* now interpolate between them */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2107
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2108
          FT_Pos    org_a, org_ab, cur_a, cur_ab;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
          FT_Pos    org_c, org_ac, cur_c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2110
          FT_Fixed  scale_ab;
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
          if ( first->org_u <= next->org_u )
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
            org_a  = first->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2116
            cur_a  = first->cur_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2117
            org_ab = next->org_u - org_a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2118
            cur_ab = next->cur_u - cur_a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2119
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2120
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2121
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2122
            org_a  = next->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2123
            cur_a  = next->cur_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2124
            org_ab = first->org_u - org_a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2125
            cur_ab = first->cur_u - cur_a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2126
          }
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
          scale_ab = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
          if ( org_ab > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
            scale_ab = FT_DivFix( cur_ab, org_ab );
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
          point = first->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
          do
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
            org_c  = point->org_u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
            org_ac = org_c - org_a;
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
            if ( org_ac <= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
              /* on the left of the interpolation zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
              cur_c = cur_a + FT_MulFix( org_ac, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
            else if ( org_ac >= org_ab )
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
              /* on the right on the interpolation zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
              cur_c = cur_a + cur_ab + FT_MulFix( org_ac - org_ab, scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2150
              /* within the interpolation zone */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2151
              cur_c = cur_a + FT_MulFix( org_ac, scale_ab );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2154
            point->cur_u = cur_c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
            point = point->next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2158
          } while ( point != next );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2159
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
        /* keep going until all points in the contours have been processed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2162
        first = next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2164
      } while ( first != start );
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
    Next_Contour:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
      ;
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
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2172
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2173
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2175
  /*****                     HIGH-LEVEL INTERFACE                      *****/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2180
  FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2181
  ps_hints_apply( PS_Hints        ps_hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
                  FT_Outline*     outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
                  PSH_Globals     globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
                  FT_Render_Mode  hint_mode )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2185
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
    PSH_GlyphRec  glyphrec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
    PSH_Glyph     glyph = &glyphrec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2188
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2189
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
    FT_Memory     memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
    FT_Int        dimension;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
    /* something to do? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2196
    if ( outline->n_points == 0 || outline->n_contours == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2197
      return PSH_Err_Ok;
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
#ifdef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2201
    memory = globals->memory;
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
    if ( ps_debug_glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2204
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
      psh_glyph_done( ps_debug_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
      FT_FREE( ps_debug_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
    if ( FT_NEW( glyph ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2210
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
    ps_debug_glyph = glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
#endif /* DEBUG_HINTER */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2216
    error = psh_glyph_init( glyph, outline, ps_hints, globals );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2218
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
    /* try to optimize the y_scale so that the top of non-capital letters
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
     * is aligned on a pixel boundary whenever possible
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
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
      PSH_Dimension  dim_x = &glyph->globals->dimension[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
      PSH_Dimension  dim_y = &glyph->globals->dimension[1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
      FT_Fixed  x_scale = dim_x->scale_mult;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
      FT_Fixed  y_scale = dim_y->scale_mult;
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
      FT_Fixed  old_x_scale = x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2231
      FT_Fixed  old_y_scale = y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2233
      FT_Fixed  scaled;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2234
      FT_Fixed  fitted;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
      FT_Bool  rescale = FALSE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2239
      scaled = FT_MulFix( globals->blues.normal_top.zones->org_ref, y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2240
      fitted = FT_PIX_ROUND( scaled );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2242
      if ( fitted != 0 && scaled != fitted )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2243
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2244
        rescale = TRUE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2246
        y_scale = FT_MulDiv( y_scale, fitted, scaled );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2247
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2248
        if ( fitted < scaled )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2249
          x_scale -= x_scale / 50;
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
        psh_globals_set_scale( glyph->globals, x_scale, y_scale, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2252
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2254
      glyph->do_horz_hints = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2255
      glyph->do_vert_hints = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2257
      glyph->do_horz_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_MONO ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2258
                                         hint_mode == FT_RENDER_MODE_LCD  );
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
      glyph->do_vert_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_MONO  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2261
                                         hint_mode == FT_RENDER_MODE_LCD_V );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2263
      glyph->do_stem_adjust   = FT_BOOL( hint_mode != FT_RENDER_MODE_LIGHT );
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
      for ( dimension = 0; dimension < 2; dimension++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2266
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2267
        /* load outline coordinates into glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2268
        psh_glyph_load_points( glyph, dimension );
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
        /* compute local extrema */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2271
        psh_glyph_compute_extrema( glyph );
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
        /* compute aligned stem/hints positions */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2274
        psh_hint_table_align_hints( &glyph->hint_tables[dimension],
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2275
                                    glyph->globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2276
                                    dimension,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2277
                                    glyph );
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
        /* find strong points, align them, then interpolate others */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2280
        psh_glyph_find_strong_points( glyph, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2281
        if ( dimension == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2282
          psh_glyph_find_blue_points( &globals->blues, glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2283
        psh_glyph_interpolate_strong_points( glyph, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2284
        psh_glyph_interpolate_normal_points( glyph, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2285
        psh_glyph_interpolate_other_points( glyph, dimension );
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
        /* save hinted coordinates back to outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2288
        psh_glyph_save_points( glyph, dimension );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2290
        if ( rescale )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2291
          psh_globals_set_scale( glyph->globals,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2292
                                 old_x_scale, old_y_scale, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2293
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2294
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2296
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2298
#ifndef DEBUG_HINTER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2299
    psh_glyph_done( glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2300
#endif
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2303
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2306
/* END */