Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 128760 | Differences between
and this patch

Collapse All | Expand All

(-)freetype-2.1.10.old/devel/ftoption.h (+16 lines)
Lines 547-552 Link Here
547
  /*                                                                       */
547
  /*                                                                       */
548
#undef T1_CONFIG_OPTION_NO_MM_SUPPORT
548
#undef T1_CONFIG_OPTION_NO_MM_SUPPORT
549
549
550
  /*************************************************************************/
551
  /*************************************************************************/
552
  /****                                                                 ****/
553
  /****    A U T O F I T   M O D U L E    C O N F I G U R A T I O N     ****/
554
  /****                                                                 ****/
555
  /*************************************************************************/
556
  /*************************************************************************/
557
558
559
  /*************************************************************************/
560
  /*                                                                       */
561
  /* Compile autofit module with CJK script support.                       */
562
  /*                                                                       */
563
#define AF_CONFIG_OPTION_CJK
564
565
550
 /* */
566
 /* */
551
567
552
/*
568
/*
(-)freetype-2.1.10.old/include/freetype/config/ftoption.h (+15 lines)
Lines 547-552 Link Here
547
  /*                                                                       */
547
  /*                                                                       */
548
#undef T1_CONFIG_OPTION_NO_MM_SUPPORT
548
#undef T1_CONFIG_OPTION_NO_MM_SUPPORT
549
549
550
  /*************************************************************************/
551
  /*************************************************************************/
552
  /****                                                                 ****/
553
  /****    A U T O F I T   M O D U L E    C O N F I G U R A T I O N     ****/
554
  /****                                                                 ****/
555
  /*************************************************************************/
556
  /*************************************************************************/
557
558
559
  /*************************************************************************/
560
  /*                                                                       */
561
  /* Compile autofit module with CJK script support.                       */
562
  /*                                                                       */
563
#define AF_CONFIG_OPTION_CJK
564
550
 /* */
565
 /* */
551
566
552
/*
567
/*
(-)freetype-2.1.10.old/include/freetype/internal/ftgloadr.h (+17 lines)
Lines 117-122 Link Here
117
                              FT_UInt         n_points,
117
                              FT_UInt         n_points,
118
                              FT_UInt         n_contours );
118
                              FT_UInt         n_contours );
119
119
120
#define FT_GLYPHLOADER_CHECK_P( _loader, _count )                    \
121
   ( (_count) == 0 || (int)((_loader)->base.outline.n_points    +    \
122
                            (_loader)->current.outline.n_points +    \
123
                            (_count)) <= (int)(_loader)->max_points )
124
125
#define FT_GLYPHLOADER_CHECK_C( _loader, _count )                     \
126
  ( (_count) == 0 || (int)((_loader)->base.outline.n_contours    +    \
127
                           (_loader)->current.outline.n_contours +    \
128
                           (_count)) <= (int)(_loader)->max_contours )
129
130
#define FT_GLYPHLOADER_CHECK_POINTS( _loader, _points,_contours )      \
131
  ( ( FT_GLYPHLOADER_CHECK_P( _loader, _points )   &&                  \
132
      FT_GLYPHLOADER_CHECK_C( _loader, _contours ) )                   \
133
    ? 0                                                                \
134
    : FT_GlyphLoader_CheckPoints( (_loader), (_points), (_contours) ) )
135
136
120
  /* check that there is enough space to add `n_subs' sub-glyphs to */
137
  /* check that there is enough space to add `n_subs' sub-glyphs to */
121
  /* a glyph loader                                                 */
138
  /* a glyph loader                                                 */
122
  FT_BASE( FT_Error )
139
  FT_BASE( FT_Error )
(-)freetype-2.1.10.old/src/autofit/afangles.c (+108 lines)
Lines 20-25 Link Here
20
#include "aftypes.h"
20
#include "aftypes.h"
21
21
22
22
23
#if 1
24
25
  /* the following table has been automatically generated with */
26
  /* the `mather.py' Python script                             */
27
28
#define AF_ATAN_BITS  8
29
30
  static const FT_Byte  af_arctan[1L << AF_ATAN_BITS] =
31
  {
32
     0,  0,  1,  1,  1,  2,  2,  2,
33
     3,  3,  3,  3,  4,  4,  4,  5,
34
     5,  5,  6,  6,  6,  7,  7,  7,
35
     8,  8,  8,  9,  9,  9, 10, 10,
36
    10, 10, 11, 11, 11, 12, 12, 12,
37
    13, 13, 13, 14, 14, 14, 14, 15,
38
    15, 15, 16, 16, 16, 17, 17, 17,
39
    18, 18, 18, 18, 19, 19, 19, 20,
40
    20, 20, 21, 21, 21, 21, 22, 22,
41
    22, 23, 23, 23, 24, 24, 24, 24,
42
    25, 25, 25, 26, 26, 26, 26, 27,
43
    27, 27, 28, 28, 28, 28, 29, 29,
44
    29, 30, 30, 30, 30, 31, 31, 31,
45
    31, 32, 32, 32, 33, 33, 33, 33,
46
    34, 34, 34, 34, 35, 35, 35, 35,
47
    36, 36, 36, 36, 37, 37, 37, 38,
48
    38, 38, 38, 39, 39, 39, 39, 40,
49
    40, 40, 40, 41, 41, 41, 41, 42,
50
    42, 42, 42, 42, 43, 43, 43, 43,
51
    44, 44, 44, 44, 45, 45, 45, 45,
52
    46, 46, 46, 46, 46, 47, 47, 47,
53
    47, 48, 48, 48, 48, 48, 49, 49,
54
    49, 49, 50, 50, 50, 50, 50, 51,
55
    51, 51, 51, 51, 52, 52, 52, 52,
56
    52, 53, 53, 53, 53, 53, 54, 54,
57
    54, 54, 54, 55, 55, 55, 55, 55,
58
    56, 56, 56, 56, 56, 57, 57, 57,
59
    57, 57, 57, 58, 58, 58, 58, 58,
60
    59, 59, 59, 59, 59, 59, 60, 60,
61
    60, 60, 60, 61, 61, 61, 61, 61,
62
    61, 62, 62, 62, 62, 62, 62, 63,
63
    63, 63, 63, 63, 63, 64, 64, 64
64
  };
65
66
67
  FT_LOCAL_DEF( AF_Angle )
68
  af_angle_atan( FT_Fixed  dx,
69
                 FT_Fixed  dy )
70
  {
71
    AF_Angle  angle;
72
73
74
    /* check trivial cases */
75
    if ( dy == 0 )
76
    {
77
      angle = 0;
78
      if ( dx < 0 )
79
        angle = AF_ANGLE_PI;
80
      return angle;
81
    }
82
    else if ( dx == 0 )
83
    {
84
      angle = AF_ANGLE_PI2;
85
      if ( dy < 0 )
86
        angle = -AF_ANGLE_PI2;
87
      return angle;
88
    }
89
90
    angle = 0;
91
    if ( dx < 0 )
92
    {
93
      dx = -dx;
94
      dy = -dy;
95
      angle = AF_ANGLE_PI;
96
    }
97
98
    if ( dy < 0 )
99
    {
100
      FT_Pos  tmp;
101
102
103
      tmp = dx;
104
      dx  = -dy;
105
      dy  = tmp;
106
      angle -= AF_ANGLE_PI2;
107
    }
108
109
    if ( dx == 0 && dy == 0 )
110
      return 0;
111
112
    if ( dx == dy )
113
      angle += AF_ANGLE_PI4;
114
    else if ( dx > dy )
115
      angle += af_arctan[FT_DivFix( dy, dx ) >> ( 16 - AF_ATAN_BITS )];
116
    else
117
      angle += AF_ANGLE_PI2 -
118
               af_arctan[FT_DivFix( dx, dy ) >> ( 16 - AF_ATAN_BITS )];
119
120
    if ( angle > AF_ANGLE_PI )
121
      angle -= AF_ANGLE_2PI;
122
123
    return angle;
124
  }
125
126
127
#else /* 0 */
128
23
/*
129
/*
24
 * a python script used to generate the following table
130
 * a python script used to generate the following table
25
 *
131
 *
Lines 234-239 Link Here
234
    return delta;
340
    return delta;
235
  }
341
  }
236
342
343
#endif /* 0 */
344
237
345
238
  FT_LOCAL_DEF( void )
346
  FT_LOCAL_DEF( void )
239
  af_sort_pos( FT_UInt  count,
347
  af_sort_pos( FT_UInt  count,
(-)freetype-2.1.10.old/src/autofit/afcjk.c (+1507 lines)
Line 0 Link Here
1
/***************************************************************************/
2
/*                                                                         */
3
/*  afcjk.c                                                                */
4
/*                                                                         */
5
/*    Auto-fitter hinting routines for CJK script (body).                  */
6
/*                                                                         */
7
/*  Copyright 2006 by                                                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
11
/*  modified, and distributed under the terms of the FreeType project      */
12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13
/*  this file you indicate that you have read the license and              */
14
/*  understand and accept it fully.                                        */
15
/*                                                                         */
16
/***************************************************************************/
17
18
  /*
19
   *  The algorithm is based on akito's autohint patch, available here:
20
   *
21
   *  http://www.kde.gr.jp/~akito/patch/freetype2/
22
   *
23
   */
24
25
#include "aftypes.h"
26
#include "aflatin.h"
27
28
29
#ifdef AF_CONFIG_OPTION_CJK
30
31
#include "afcjk.h"
32
#include "aferrors.h"
33
34
35
#ifdef AF_USE_WARPER
36
#include "afwarp.h"
37
#endif
38
39
40
  /*************************************************************************/
41
  /*************************************************************************/
42
  /*****                                                               *****/
43
  /*****              C J K   G L O B A L   M E T R I C S              *****/
44
  /*****                                                               *****/
45
  /*************************************************************************/
46
  /*************************************************************************/
47
48
  static FT_Error
49
  af_cjk_metrics_init( AF_LatinMetrics  metrics,
50
                       FT_Face          face )
51
  {
52
    FT_CharMap  oldmap = face->charmap;
53
54
55
    metrics->units_per_em = face->units_per_EM;
56
57
    /* TODO are there blues? */
58
59
    if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
60
      face->charmap = NULL;
61
62
    /* latin's version would suffice */
63
    af_latin_metrics_init_widths( metrics, face, 0x7530 );
64
65
    FT_Set_Charmap( face, oldmap );
66
67
    return AF_Err_Ok;
68
  }
69
70
71
  static void
72
  af_cjk_metrics_scale_dim( AF_LatinMetrics  metrics,
73
                            AF_Scaler        scaler,
74
                            AF_Dimension     dim )
75
  {
76
    AF_LatinAxis  axis;
77
78
79
    axis = &metrics->axis[dim];
80
81
    if ( dim == AF_DIMENSION_HORZ )
82
    {
83
      axis->scale = scaler->x_scale;
84
      axis->delta = scaler->x_delta;
85
    }
86
    else
87
    {
88
      axis->scale = scaler->y_scale;
89
      axis->delta = scaler->y_delta;
90
    }
91
  }
92
93
94
  static void
95
  af_cjk_metrics_scale( AF_LatinMetrics  metrics,
96
                        AF_Scaler        scaler )
97
  {
98
    metrics->root.scaler = *scaler;
99
100
    af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
101
    af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
102
  }
103
104
105
  /*************************************************************************/
106
  /*************************************************************************/
107
  /*****                                                               *****/
108
  /*****              C J K   G L Y P H   A N A L Y S I S              *****/
109
  /*****                                                               *****/
110
  /*************************************************************************/
111
  /*************************************************************************/
112
113
  static FT_Error
114
  af_cjk_hints_compute_segments( AF_GlyphHints  hints,
115
                                 AF_Dimension   dim )
116
  {
117
    AF_AxisHints  axis          = &hints->axis[dim];
118
    AF_Segment    segments      = axis->segments;
119
    AF_Segment    segment_limit = segments + axis->num_segments;
120
    FT_Error      error;
121
    AF_Segment    seg;
122
123
124
    error = af_latin_hints_compute_segments( hints, dim );
125
    if ( error )
126
      return error;
127
128
    /* a segment is round if it doesn't have successive */
129
    /* on-curve points.                                 */
130
    for ( seg = segments; seg < segment_limit; seg++ )
131
    {
132
      AF_Point  pt   = seg->first;
133
      AF_Point  last = seg->last;
134
      AF_Flags  f0   = (AF_Flags)(pt->flags & AF_FLAG_CONTROL);
135
      AF_Flags  f1;
136
137
138
      seg->flags &= ~AF_EDGE_ROUND;
139
140
      for ( ; pt != last; f0 = f1 )
141
      {
142
        pt = pt->next;
143
        f1 = (AF_Flags)(pt->flags & AF_FLAG_CONTROL);
144
145
        if ( !f0 && !f1 )
146
          break;
147
148
        if ( pt == last )
149
          seg->flags |= AF_EDGE_ROUND;
150
      }
151
    }
152
153
    return AF_Err_Ok;
154
  }
155
156
157
  static void
158
  af_cjk_hints_link_segments( AF_GlyphHints  hints,
159
                              AF_Dimension   dim )
160
  {
161
    AF_AxisHints  axis          = &hints->axis[dim];
162
    AF_Segment    segments      = axis->segments;
163
    AF_Segment    segment_limit = segments + axis->num_segments;
164
    AF_Direction  major_dir     = axis->major_dir;
165
    AF_Segment    seg1, seg2;
166
    FT_UShort     len_threshold;
167
    FT_Pos        dist_threshold;
168
169
170
    len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
171
172
    dist_threshold = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
173
                                                  : hints->y_scale;
174
    dist_threshold = FT_DivFix( 64 * 3, dist_threshold );
175
176
    /* now compare each segment to the others */
177
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
178
    {
179
      /* the fake segments are for metrics hinting only */
180
      if ( seg1->first == seg1->last )
181
        continue;
182
183
      if ( seg1->dir != major_dir )
184
        continue;
185
186
      for ( seg2 = segments; seg2 < segment_limit; seg2++ )
187
        if ( seg2 != seg1 && seg1->dir + seg2->dir == 0 )
188
        {
189
          FT_Pos  dist = seg2->pos - seg1->pos;
190
191
192
          if ( dist < 0 )
193
            continue;
194
195
          {
196
            FT_Pos  min = seg1->min_coord;
197
            FT_Pos  max = seg1->max_coord;
198
            FT_Pos  len;
199
200
201
            if ( min < seg2->min_coord )
202
              min = seg2->min_coord;
203
204
            if ( max > seg2->max_coord )
205
              max = seg2->max_coord;
206
207
            len = max - min;
208
            if ( len >= len_threshold )
209
            {
210
              if ( dist * 8 < seg1->score * 9                        &&
211
                   ( dist * 8 < seg1->score * 7 || seg1->len < len ) )
212
              {
213
                seg1->score = dist;
214
                seg1->len   = len;
215
                seg1->link  = seg2;
216
              }
217
218
              if ( dist * 8 < seg2->score * 9                        &&
219
                   ( dist * 8 < seg2->score * 7 || seg2->len < len ) )
220
              {
221
                seg2->score = dist;
222
                seg2->len   = len;
223
                seg2->link  = seg1;
224
              }
225
            }
226
          }
227
        }
228
    }
229
230
    /*
231
     *  now compute the `serif' segments
232
     *
233
     *  In Hanzi, some strokes are wider on one or both of the ends.
234
     *  We either identify the stems on the ends as serifs or remove
235
     *  the linkage, depending on the length of the stems.
236
     *
237
     */
238
239
    {
240
      AF_Segment  link1, link2;
241
242
243
      for ( seg1 = segments; seg1 < segment_limit; seg1++ )
244
      {
245
        link1 = seg1->link;
246
        if ( !link1 || link1->link != seg1 || link1->pos <= seg1->pos )
247
          continue;
248
249
        if ( seg1->score >= dist_threshold )
250
          continue;
251
252
        for ( seg2 = segments; seg2 < segment_limit; seg2++ )
253
        {
254
          if ( seg2->pos > seg1->pos || seg1 == seg2 )
255
            continue;
256
257
          link2 = seg2->link;
258
          if ( !link2 || link2->link != seg2 || link2->pos < link1->pos )
259
            continue;
260
261
          if ( seg1->pos == seg2->pos && link1->pos == link2->pos )
262
            continue;
263
264
          if ( seg2->score <= seg1->score || seg1->score * 4 <= seg2->score )
265
            continue;
266
267
          /* seg2 < seg1 < link1 < link2 */
268
269
          if ( seg1->len >= seg2->len * 3 )
270
          {
271
            AF_Segment  seg;
272
273
274
            for ( seg = segments; seg < segment_limit; seg++ )
275
            {
276
              AF_Segment  link = seg->link;
277
278
279
              if ( link == seg2 )
280
              {
281
                seg->link  = 0;
282
                seg->serif = link1;
283
              }
284
              else if ( link == link2 )
285
              {
286
                seg->link  = 0;
287
                seg->serif = seg1;
288
              }
289
            }
290
          }
291
          else
292
          {
293
            seg1->link = link1->link = 0;
294
295
            break;
296
          }
297
        }
298
      }
299
    }
300
301
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
302
    {
303
      seg2 = seg1->link;
304
305
      if ( seg2 )
306
      {
307
        seg2->num_linked++;
308
        if ( seg2->link != seg1 )
309
        {
310
          seg1->link = 0;
311
312
          if ( seg2->score < dist_threshold || seg1->score < seg2->score * 4 )
313
            seg1->serif = seg2->link;
314
          else
315
            seg2->num_linked--;
316
        }
317
      }
318
    }
319
  }
320
321
322
  static FT_Error
323
  af_cjk_hints_compute_edges( AF_GlyphHints  hints,
324
                              AF_Dimension   dim )
325
  {
326
    AF_AxisHints  axis   = &hints->axis[dim];
327
    FT_Error      error  = AF_Err_Ok;
328
    FT_Memory     memory = hints->memory;
329
    AF_LatinAxis  laxis  = &((AF_LatinMetrics)hints->metrics)->axis[dim];
330
331
    AF_Segment    segments      = axis->segments;
332
    AF_Segment    segment_limit = segments + axis->num_segments;
333
    AF_Segment    seg;
334
335
    AF_Direction  up_dir;
336
    FT_Fixed      scale;
337
    FT_Pos        edge_distance_threshold;
338
339
340
    axis->num_edges = 0;
341
342
    scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
343
                                         : hints->y_scale;
344
345
    up_dir = ( dim == AF_DIMENSION_HORZ ) ? AF_DIR_UP
346
                                          : AF_DIR_RIGHT;
347
348
    /*********************************************************************/
349
    /*                                                                   */
350
    /* We begin by generating a sorted table of edges for the current    */
351
    /* direction.  To do so, we simply scan each segment and try to find */
352
    /* an edge in our table that corresponds to its position.            */
353
    /*                                                                   */
354
    /* If no edge is found, we create and insert a new edge in the       */
355
    /* sorted table.  Otherwise, we simply add the segment to the edge's */
356
    /* list which is then processed in the second step to compute the    */
357
    /* edge's properties.                                                */
358
    /*                                                                   */
359
    /* Note that the edges table is sorted along the segment/edge        */
360
    /* position.                                                         */
361
    /*                                                                   */
362
    /*********************************************************************/
363
364
    edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
365
                                         scale );
366
    if ( edge_distance_threshold > 64 / 4 )
367
      edge_distance_threshold = FT_DivFix( 64 / 4, scale );
368
    else
369
      edge_distance_threshold = laxis->edge_distance_threshold;
370
371
    for ( seg = segments; seg < segment_limit; seg++ )
372
    {
373
      AF_Edge  found = 0;
374
      FT_Pos   best  = 0xFFFFU;
375
      FT_Int   ee;
376
377
378
      /* look for an edge corresponding to the segment */
379
      for ( ee = 0; ee < axis->num_edges; ee++ )
380
      {
381
        AF_Edge  edge = axis->edges + ee;
382
        FT_Pos   dist;
383
384
385
        if ( edge->dir != seg->dir )
386
          continue;
387
388
        dist = seg->pos - edge->fpos;
389
        if ( dist < 0 )
390
          dist = -dist;
391
392
        if ( dist < edge_distance_threshold && dist < best )
393
        {
394
          AF_Segment  link = seg->link;
395
396
397
          /* check whether all linked segments of the candidate edge */
398
          /* can make a single edge.                                 */
399
          if ( link )
400
          {
401
            AF_Segment  seg1 = edge->first;
402
            AF_Segment  link1;
403
            FT_Pos      dist2 = 0;
404
405
406
            do
407
            {
408
              link1 = seg1->link;
409
              if ( link1 )
410
              {
411
                dist2 = AF_SEGMENT_DIST( link, link1 );
412
                if ( dist2 >= edge_distance_threshold )
413
                  break;
414
              }
415
416
            } while ( ( seg1 = seg1->edge_next ) != edge->first );
417
418
            if ( dist2 >= edge_distance_threshold )
419
              continue;
420
          }
421
422
          best  = dist;
423
          found = edge;
424
        }
425
      }
426
427
      if ( !found )
428
      {
429
        AF_Edge  edge;
430
431
432
        /* insert a new edge in the list and */
433
        /* sort according to the position    */
434
        error = af_axis_hints_new_edge( axis, seg->pos, memory, &edge );
435
        if ( error )
436
          goto Exit;
437
438
        /* add the segment to the new edge's list */
439
        FT_ZERO( edge );
440
441
        edge->first    = seg;
442
        edge->last     = seg;
443
        edge->fpos     = seg->pos;
444
        edge->opos     = edge->pos = FT_MulFix( seg->pos, scale );
445
        seg->edge_next = seg;
446
        edge->dir      = seg->dir;
447
      }
448
      else
449
      {
450
        /* if an edge was found, simply add the segment to the edge's */
451
        /* list                                                       */
452
        seg->edge_next         = found->first;
453
        found->last->edge_next = seg;
454
        found->last            = seg;
455
      }
456
    }
457
458
    /*********************************************************************/
459
    /*                                                                   */
460
    /* Good, we now compute each edge's properties according to segments */
461
    /* found on its position.  Basically, these are as follows.          */
462
    /*                                                                   */
463
    /*  - edge's main direction                                          */
464
    /*  - stem edge, serif edge or both (which defaults to stem then)    */
465
    /*  - rounded edge, straight or both (which defaults to straight)    */
466
    /*  - link for edge                                                  */
467
    /*                                                                   */
468
    /*********************************************************************/
469
470
    /* first of all, set the `edge' field in each segment -- this is     */
471
    /* required in order to compute edge links                           */
472
    /*                                                                   */
473
    /* Note that removing this loop and setting the `edge' field of each */
474
    /* segment directly in the code above slows down execution speed for */
475
    /* some reasons on platforms like the Sun.                           */
476
477
    {
478
      AF_Edge  edges      = axis->edges;
479
      AF_Edge  edge_limit = edges + axis->num_edges;
480
      AF_Edge  edge;
481
482
483
      for ( edge = edges; edge < edge_limit; edge++ )
484
      {
485
        seg = edge->first;
486
        if ( seg )
487
          do
488
          {
489
            seg->edge = edge;
490
            seg       = seg->edge_next;
491
492
          } while ( seg != edge->first );
493
      }
494
495
      /* now compute each edge properties */
496
      for ( edge = edges; edge < edge_limit; edge++ )
497
      {
498
        FT_Int  is_round    = 0;  /* does it contain round segments?    */
499
        FT_Int  is_straight = 0;  /* does it contain straight segments? */
500
501
502
        seg = edge->first;
503
504
        do
505
        {
506
          FT_Bool  is_serif;
507
508
509
          /* check for roundness of segment */
510
          if ( seg->flags & AF_EDGE_ROUND )
511
            is_round++;
512
          else
513
            is_straight++;
514
515
          /* check for links -- if seg->serif is set, then seg->link must */
516
          /* be ignored                                                   */
517
          is_serif = (FT_Bool)( seg->serif && seg->serif->edge != edge );
518
519
          if ( seg->link || is_serif )
520
          {
521
            AF_Edge     edge2;
522
            AF_Segment  seg2;
523
524
525
            edge2 = edge->link;
526
            seg2  = seg->link;
527
528
            if ( is_serif )
529
            {
530
              seg2  = seg->serif;
531
              edge2 = edge->serif;
532
            }
533
534
            if ( edge2 )
535
            {
536
              FT_Pos  edge_delta;
537
              FT_Pos  seg_delta;
538
539
540
              edge_delta = edge->fpos - edge2->fpos;
541
              if ( edge_delta < 0 )
542
                edge_delta = -edge_delta;
543
544
              seg_delta = AF_SEGMENT_DIST( seg, seg2 );
545
546
              if ( seg_delta < edge_delta )
547
                edge2 = seg2->edge;
548
            }
549
            else
550
              edge2 = seg2->edge;
551
552
            if ( is_serif )
553
            {
554
              edge->serif   = edge2;
555
              edge2->flags |= AF_EDGE_SERIF;
556
            }
557
            else
558
              edge->link  = edge2;
559
          }
560
561
          seg = seg->edge_next;
562
563
        } while ( seg != edge->first );
564
565
        /* set the round/straight flags */
566
        edge->flags = AF_EDGE_NORMAL;
567
568
        if ( is_round > 0 && is_round >= is_straight )
569
          edge->flags |= AF_EDGE_ROUND;
570
571
        /* get rid of serifs if link is set                 */
572
        /* XXX: This gets rid of many unpleasant artefacts! */
573
        /*      Example: the `c' in cour.pfa at size 13     */
574
575
        if ( edge->serif && edge->link )
576
          edge->serif = 0;
577
      }
578
    }
579
580
  Exit:
581
    return error;
582
  }
583
584
585
  static FT_Error
586
  af_cjk_hints_detect_features( AF_GlyphHints  hints,
587
                                AF_Dimension   dim )
588
  {
589
    FT_Error  error;
590
591
592
    error = af_cjk_hints_compute_segments( hints, dim );
593
    if ( !error )
594
    {
595
      af_cjk_hints_link_segments( hints, dim );
596
597
      error = af_cjk_hints_compute_edges( hints, dim );
598
    }
599
    return error;
600
  }
601
602
603
  static FT_Error
604
  af_cjk_hints_init( AF_GlyphHints    hints,
605
                     AF_LatinMetrics  metrics )
606
  {
607
    FT_Render_Mode  mode;
608
    FT_UInt32       scaler_flags, other_flags;
609
610
611
    af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
612
613
    /*
614
     *  correct x_scale and y_scale when needed, since they may have
615
     *  been modified af_cjk_scale_dim above
616
     */
617
    hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
618
    hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
619
    hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
620
    hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
621
622
    /* compute flags depending on render mode, etc. */
623
    mode = metrics->root.scaler.render_mode;
624
625
#ifdef AF_USE_WARPER
626
    if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
627
      metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
628
#endif
629
630
    scaler_flags = hints->scaler_flags;
631
    other_flags  = 0;
632
633
    /*
634
     *  We snap the width of vertical stems for the monochrome and
635
     *  horizontal LCD rendering targets only.
636
     */
637
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
638
      other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
639
640
    /*
641
     *  We snap the width of horizontal stems for the monochrome and
642
     *  vertical LCD rendering targets only.
643
     */
644
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
645
      other_flags |= AF_LATIN_HINTS_VERT_SNAP;
646
647
    /*
648
     *  We adjust stems to full pixels only if we don't use the `light' mode.
649
     */
650
    if ( mode != FT_RENDER_MODE_LIGHT )
651
      other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
652
653
    if ( mode == FT_RENDER_MODE_MONO )
654
      other_flags |= AF_LATIN_HINTS_MONO;
655
656
    scaler_flags |= AF_SCALER_FLAG_NO_ADVANCE;
657
658
    hints->scaler_flags = scaler_flags;
659
    hints->other_flags  = other_flags;
660
661
    return 0;
662
  }
663
664
665
  /*************************************************************************/
666
  /*************************************************************************/
667
  /*****                                                               *****/
668
  /*****          C J K   G L Y P H   G R I D - F I T T I N G          *****/
669
  /*****                                                               *****/
670
  /*************************************************************************/
671
  /*************************************************************************/
672
673
  /* snap a given width in scaled coordinates to one of the */
674
  /* current standard widths                                */
675
676
  static FT_Pos
677
  af_cjk_snap_width( AF_Width  widths,
678
                     FT_Int    count,
679
                     FT_Pos    width )
680
  {
681
    int     n;
682
    FT_Pos  best      = 64 + 32 + 2;
683
    FT_Pos  reference = width;
684
    FT_Pos  scaled;
685
686
687
    for ( n = 0; n < count; n++ )
688
    {
689
      FT_Pos  w;
690
      FT_Pos  dist;
691
692
693
      w = widths[n].cur;
694
      dist = width - w;
695
      if ( dist < 0 )
696
        dist = -dist;
697
      if ( dist < best )
698
      {
699
        best      = dist;
700
        reference = w;
701
      }
702
    }
703
704
    scaled = FT_PIX_ROUND( reference );
705
706
    if ( width >= reference )
707
    {
708
      if ( width < scaled + 48 )
709
        width = reference;
710
    }
711
    else
712
    {
713
      if ( width > scaled - 48 )
714
        width = reference;
715
    }
716
717
    return width;
718
  }
719
720
721
  /* compute the snapped width of a given stem */
722
723
  static FT_Pos
724
  af_cjk_compute_stem_width( AF_GlyphHints  hints,
725
                             AF_Dimension   dim,
726
                             FT_Pos         width,
727
                             AF_Edge_Flags  base_flags,
728
                             AF_Edge_Flags  stem_flags )
729
  {
730
    AF_LatinMetrics  metrics  = (AF_LatinMetrics) hints->metrics;
731
    AF_LatinAxis     axis     = & metrics->axis[dim];
732
    FT_Pos           dist     = width;
733
    FT_Int           sign     = 0;
734
    FT_Int           vertical = ( dim == AF_DIMENSION_VERT );
735
736
    FT_UNUSED( base_flags );
737
    FT_UNUSED( stem_flags );
738
739
740
    if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
741
      return width;
742
743
    if ( dist < 0 )
744
    {
745
      dist = -width;
746
      sign = 1;
747
    }
748
749
    if ( (  vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
750
         ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
751
    {
752
      /* smooth hinting process: very lightly quantize the stem width */
753
754
      if ( axis->width_count > 0 )
755
      {
756
        if ( FT_ABS( dist - axis->widths[0].cur ) < 40 )
757
        {
758
          dist = axis->widths[0].cur;
759
          if ( dist < 48 )
760
            dist = 48;
761
762
          goto Done_Width;
763
        }
764
      }
765
766
      if ( dist < 54 )
767
        dist += ( 54 - dist ) / 2 ;
768
      else if ( dist < 3 * 64 )
769
      {
770
        FT_Pos  delta;
771
772
773
        delta  = dist & 63;
774
        dist  &= -64;
775
776
        if ( delta < 10 )
777
          dist += delta;
778
        else if ( delta < 22 )
779
          dist += 10;
780
        else if ( delta < 42 )
781
          dist += delta;
782
        else if ( delta < 54 )
783
          dist += 54;
784
        else
785
          dist += delta;
786
      }
787
    }
788
    else
789
    {
790
      /* strong hinting process: snap the stem width to integer pixels */
791
792
      dist = af_cjk_snap_width( axis->widths, axis->width_count, dist );
793
794
      if ( vertical )
795
      {
796
        /* in the case of vertical hinting, always round */
797
        /* the stem heights to integer pixels            */
798
799
        if ( dist >= 64 )
800
          dist = ( dist + 16 ) & ~63;
801
        else
802
          dist = 64;
803
      }
804
      else
805
      {
806
        if ( AF_LATIN_HINTS_DO_MONO( hints ) )
807
        {
808
          /* monochrome horizontal hinting: snap widths to integer pixels */
809
          /* with a different threshold                                   */
810
811
          if ( dist < 64 )
812
            dist = 64;
813
          else
814
            dist = ( dist + 32 ) & ~63;
815
        }
816
        else
817
        {
818
          /* for horizontal anti-aliased hinting, we adopt a more subtle */
819
          /* approach: we strengthen small stems, round stems whose size */
820
          /* is between 1 and 2 pixels to an integer, otherwise nothing  */
821
822
          if ( dist < 48 )
823
            dist = ( dist + 64 ) >> 1;
824
825
          else if ( dist < 128 )
826
            dist = ( dist + 22 ) & ~63;
827
          else
828
            /* round otherwise to prevent color fringes in LCD mode */
829
            dist = ( dist + 32 ) & ~63;
830
        }
831
      }
832
    }
833
834
  Done_Width:
835
    if ( sign )
836
      dist = -dist;
837
838
    return dist;
839
  }
840
841
842
  /* align one stem edge relative to the previous stem edge */
843
844
  static void
845
  af_cjk_align_linked_edge( AF_GlyphHints  hints,
846
                            AF_Dimension   dim,
847
                            AF_Edge        base_edge,
848
                            AF_Edge        stem_edge )
849
  {
850
    FT_Pos  dist = stem_edge->opos - base_edge->opos;
851
852
    FT_Pos  fitted_width = af_cjk_compute_stem_width(
853
                             hints, dim, dist,
854
                             (AF_Edge_Flags)base_edge->flags,
855
                             (AF_Edge_Flags)stem_edge->flags );
856
857
858
    stem_edge->pos = base_edge->pos + fitted_width;
859
  }
860
861
862
  static void
863
  af_cjk_align_serif_edge( AF_GlyphHints  hints,
864
                           AF_Edge        base,
865
                           AF_Edge        serif )
866
  {
867
    FT_UNUSED( hints );
868
869
    serif->pos = base->pos + ( serif->opos - base->opos );
870
  }
871
872
873
  /*************************************************************************/
874
  /*************************************************************************/
875
  /*************************************************************************/
876
  /****                                                                 ****/
877
  /****                    E D G E   H I N T I N G                      ****/
878
  /****                                                                 ****/
879
  /*************************************************************************/
880
  /*************************************************************************/
881
  /*************************************************************************/
882
883
884
#define AF_LIGHT_MODE_MAX_HORZ_GAP    9
885
#define AF_LIGHT_MODE_MAX_VERT_GAP   15
886
#define AF_LIGHT_MODE_MAX_DELTA_ABS  14
887
888
889
  static FT_Pos
890
  af_hint_normal_stem( AF_GlyphHints  hints,
891
                       AF_Edge        edge,
892
                       AF_Edge        edge2,
893
                       FT_Pos         anchor,
894
                       AF_Dimension   dim )
895
  {
896
    FT_Pos  org_len, cur_len, org_center;
897
    FT_Pos  cur_pos1, cur_pos2;
898
    FT_Pos  d_off1, u_off1, d_off2, u_off2, delta;
899
    FT_Pos  offset;
900
    FT_Pos  threshold = 64;
901
902
903
    if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
904
    {
905
      if ( ( edge->flags  & AF_EDGE_ROUND ) &&
906
           ( edge2->flags & AF_EDGE_ROUND ) )
907
      {
908
        if ( dim == AF_DIMENSION_VERT )
909
          threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP;
910
        else
911
          threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP;
912
      }
913
      else
914
      {
915
        if ( dim == AF_DIMENSION_VERT )
916
          threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP / 3;
917
        else
918
          threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP / 3;
919
      }
920
    }
921
922
    org_len    = edge2->opos - edge->opos;
923
    cur_len    = af_cjk_compute_stem_width( hints, dim, org_len,
924
                                            (AF_Edge_Flags)edge->flags,
925
                                            (AF_Edge_Flags)edge2->flags );
926
927
    org_center = ( edge->opos + edge2->opos ) / 2 + anchor;
928
    cur_pos1   = org_center - cur_len / 2;
929
    cur_pos2   = cur_pos1 + cur_len;
930
    d_off1     = cur_pos1 - FT_PIX_FLOOR( cur_pos1 );
931
    d_off2     = cur_pos2 - FT_PIX_FLOOR( cur_pos2 );
932
    u_off1     = 64 - d_off1;
933
    u_off2     = 64 - d_off2;
934
    delta      = 0;
935
936
937
    if ( d_off1 == 0 || d_off2 == 0 )
938
      goto Exit;
939
940
    if ( cur_len <= threshold )
941
    {
942
      if ( d_off2 < cur_len )
943
      {
944
        if ( u_off1 <= d_off2 )
945
          delta =  u_off1;
946
        else
947
          delta = -d_off2;
948
      }
949
950
      goto Exit;
951
    }
952
953
    if ( threshold < 64 )
954
    {
955
      if ( d_off1 >= threshold || u_off1 >= threshold ||
956
           d_off2 >= threshold || u_off2 >= threshold )
957
        goto Exit;
958
    }
959
960
    offset = cur_len % 64;
961
962
    if ( offset < 32 )
963
    {
964
      if ( u_off1 <= offset || d_off2 <= offset )
965
        goto Exit;
966
    }
967
    else
968
      offset = 64 - threshold;
969
970
    d_off1 = threshold - u_off1;
971
    u_off1 = u_off1    - offset;
972
    u_off2 = threshold - d_off2;
973
    d_off2 = d_off2    - offset;
974
975
    if ( d_off1 <= u_off1 )
976
      u_off1 = -d_off1;
977
978
    if ( d_off2 <= u_off2 )
979
      u_off2 = -d_off2;
980
981
    if ( FT_ABS( u_off1 ) <= FT_ABS( u_off2 ) )
982
      delta = u_off1;
983
    else
984
      delta = u_off2;
985
986
  Exit:
987
988
#if 1
989
    if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
990
    {
991
      if ( delta > AF_LIGHT_MODE_MAX_DELTA_ABS )
992
        delta = AF_LIGHT_MODE_MAX_DELTA_ABS;
993
      else if ( delta < -AF_LIGHT_MODE_MAX_DELTA_ABS )
994
        delta = -AF_LIGHT_MODE_MAX_DELTA_ABS;
995
    }
996
#endif
997
998
    cur_pos1 += delta;
999
1000
    if ( edge->opos < edge2->opos )
1001
    {
1002
      edge->pos  = cur_pos1;
1003
      edge2->pos = cur_pos1 + cur_len;
1004
    }
1005
    else
1006
    {
1007
      edge->pos  = cur_pos1 + cur_len;
1008
      edge2->pos = cur_pos1;
1009
    }
1010
1011
    return delta;
1012
  }
1013
1014
1015
  static void
1016
  af_cjk_hint_edges( AF_GlyphHints  hints,
1017
                     AF_Dimension   dim )
1018
  {
1019
    AF_AxisHints  axis       = &hints->axis[dim];
1020
    AF_Edge       edges      = axis->edges;
1021
    AF_Edge       edge_limit = edges + axis->num_edges;
1022
    FT_Int        n_edges;
1023
    AF_Edge       edge;
1024
    AF_Edge       anchor   = 0;
1025
    FT_Pos        delta    = 0;
1026
    FT_Int        skipped  = 0;
1027
1028
1029
    /* now we align all stem edges. */
1030
    for ( edge = edges; edge < edge_limit; edge++ )
1031
    {
1032
      AF_Edge  edge2;
1033
1034
1035
      if ( edge->flags & AF_EDGE_DONE )
1036
        continue;
1037
1038
      /* skip all non-stem edges */
1039
      edge2 = edge->link;
1040
      if ( !edge2 )
1041
      {
1042
        skipped++;
1043
        continue;
1044
      }
1045
1046
      /* now align the stem */
1047
1048
      if ( edge2 < edge )
1049
      {
1050
        af_cjk_align_linked_edge( hints, dim, edge2, edge );
1051
        edge->flags |= AF_EDGE_DONE;
1052
        continue;
1053
      }
1054
1055
      if ( dim != AF_DIMENSION_VERT && !anchor )
1056
      {
1057
1058
#if 0
1059
        if ( fixedpitch )
1060
        {
1061
          AF_Edge     left  = edge;
1062
          AF_Edge     right = edge_limit - 1;
1063
          AF_EdgeRec  left1, left2, right1, right2;
1064
          FT_Pos      target, center1, center2;
1065
          FT_Pos      delta1, delta2, d1, d2;
1066
1067
1068
          while ( right > left && !right->link )
1069
            right--;
1070
1071
          left1  = *left;
1072
          left2  = *left->link;
1073
          right1 = *right->link;
1074
          right2 = *right;
1075
1076
          delta  = ( ( ( hinter->pp2.x + 32 ) & -64 ) - hinter->pp2.x ) / 2;
1077
          target = left->opos + ( right->opos - left->opos ) / 2 + delta - 16;
1078
1079
          delta1  = delta;
1080
          delta1 += af_hint_normal_stem( hints, left, left->link,
1081
                                         delta1, 0 );
1082
1083
          if ( left->link != right )
1084
            af_hint_normal_stem( hints, right->link, right, delta1, 0 );
1085
1086
          center1 = left->pos + ( right->pos - left->pos ) / 2;
1087
1088
          if ( center1 >= target )
1089
            delta2 = delta - 32;
1090
          else
1091
            delta2 = delta + 32;
1092
1093
          delta2 += af_hint_normal_stem( hints, &left1, &left2, delta2, 0 );
1094
1095
          if ( delta1 != delta2 )
1096
          {
1097
            if ( left->link != right )
1098
              af_hint_normal_stem( hints, &right1, &right2, delta2, 0 );
1099
1100
            center2 = left1.pos + ( right2.pos - left1.pos ) / 2;
1101
1102
            d1 = center1 - target;
1103
            d2 = center2 - target;
1104
1105
            if ( FT_ABS( d2 ) < FT_ABS( d1 ) )
1106
            {
1107
              left->pos       = left1.pos;
1108
              left->link->pos = left2.pos;
1109
1110
              if ( left->link != right )
1111
              {
1112
                right->link->pos = right1.pos;
1113
                right->pos       = right2.pos;
1114
              }
1115
1116
              delta1 = delta2;
1117
            }
1118
          }
1119
1120
          delta               = delta1;
1121
          right->link->flags |= AF_EDGE_DONE;
1122
          right->flags       |= AF_EDGE_DONE;
1123
        }
1124
        else
1125
1126
#endif /* 0 */
1127
1128
          delta = af_hint_normal_stem( hints, edge, edge2, 0,
1129
                                       AF_DIMENSION_HORZ );
1130
      }
1131
      else
1132
        af_hint_normal_stem( hints, edge, edge2, delta, dim );
1133
1134
#if 0
1135
      printf( "stem (%d,%d) adjusted (%.1f,%.1f)\n",
1136
               edge - edges, edge2 - edges,
1137
               ( edge->pos - edge->opos ) / 64.0,
1138
               ( edge2->pos - edge2->opos ) / 64.0 );
1139
#endif
1140
1141
      anchor = edge;
1142
      edge->flags  |= AF_EDGE_DONE;
1143
      edge2->flags |= AF_EDGE_DONE;
1144
    }
1145
1146
    /* make sure that lowercase m's maintain their symmetry */
1147
1148
    /* In general, lowercase m's have six vertical edges if they are sans */
1149
    /* serif, or twelve if they are with serifs.  This implementation is  */
1150
    /* based on that assumption, and seems to work very well with most    */
1151
    /* faces.  However, if for a certain face this assumption is not      */
1152
    /* true, the m is just rendered like before.  In addition, any stem   */
1153
    /* correction will only be applied to symmetrical glyphs (even if the */
1154
    /* glyph is not an m), so the potential for unwanted distortion is    */
1155
    /* relatively low.                                                    */
1156
1157
    /* We don't handle horizontal edges since we can't easily assure that */
1158
    /* the third (lowest) stem aligns with the base line; it might end up */
1159
    /* one pixel higher or lower.                                         */
1160
1161
    n_edges = edge_limit - edges;
1162
    if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
1163
    {
1164
      AF_Edge  edge1, edge2, edge3;
1165
      FT_Pos   dist1, dist2, span;
1166
1167
1168
      if ( n_edges == 6 )
1169
      {
1170
        edge1 = edges;
1171
        edge2 = edges + 2;
1172
        edge3 = edges + 4;
1173
      }
1174
      else
1175
      {
1176
        edge1 = edges + 1;
1177
        edge2 = edges + 5;
1178
        edge3 = edges + 9;
1179
      }
1180
1181
      dist1 = edge2->opos - edge1->opos;
1182
      dist2 = edge3->opos - edge2->opos;
1183
1184
      span = dist1 - dist2;
1185
      if ( span < 0 )
1186
        span = -span;
1187
1188
      if ( edge1->link == edge1 + 1 &&
1189
           edge2->link == edge2 + 1 &&
1190
           edge3->link == edge3 + 1 && span < 8 )
1191
      {
1192
        delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
1193
        edge3->pos -= delta;
1194
        if ( edge3->link )
1195
          edge3->link->pos -= delta;
1196
1197
        /* move the serifs along with the stem */
1198
        if ( n_edges == 12 )
1199
        {
1200
          ( edges + 8 )->pos -= delta;
1201
          ( edges + 11 )->pos -= delta;
1202
        }
1203
1204
        edge3->flags |= AF_EDGE_DONE;
1205
        if ( edge3->link )
1206
          edge3->link->flags |= AF_EDGE_DONE;
1207
      }
1208
    }
1209
1210
    if ( !skipped )
1211
      return;
1212
1213
    /*
1214
     *  now hint the remaining edges (serifs and single) in order
1215
     *  to complete our processing
1216
     */
1217
    for ( edge = edges; edge < edge_limit; edge++ )
1218
    {
1219
      if ( edge->flags & AF_EDGE_DONE )
1220
        continue;
1221
1222
      if ( edge->serif )
1223
      {
1224
        af_cjk_align_serif_edge( hints, edge->serif, edge );
1225
        edge->flags |= AF_EDGE_DONE;
1226
        skipped--;
1227
      }
1228
    }
1229
1230
    if ( !skipped )
1231
      return;
1232
1233
    for ( edge = edges; edge < edge_limit; edge++ )
1234
    {
1235
      AF_Edge  before, after;
1236
1237
1238
      if ( edge->flags & AF_EDGE_DONE )
1239
        continue;
1240
1241
      before = after = edge;
1242
1243
      while ( --before >= edges )
1244
        if ( before->flags & AF_EDGE_DONE )
1245
          break;
1246
1247
      while ( ++after < edge_limit )
1248
        if ( after->flags & AF_EDGE_DONE )
1249
          break;
1250
1251
      if ( before >= edges || after < edge_limit )
1252
      {
1253
        if ( before < edges )
1254
          af_cjk_align_serif_edge( hints, after, edge );
1255
        else if ( after >= edge_limit )
1256
          af_cjk_align_serif_edge( hints, before, edge );
1257
        else
1258
          edge->pos = before->pos +
1259
            FT_MulDiv( edge->fpos - before->fpos,
1260
                       after->pos - before->pos,
1261
                       after->fpos - before->fpos );
1262
      }
1263
    }
1264
  }
1265
1266
1267
  static void
1268
  af_cjk_align_edge_points( AF_GlyphHints  hints,
1269
                            AF_Dimension   dim )
1270
  {
1271
    AF_AxisHints  axis       = & hints->axis[dim];
1272
    AF_Edge       edges      = axis->edges;
1273
    AF_Edge       edge_limit = edges + axis->num_edges;
1274
    AF_Edge       edge;
1275
    FT_Bool       snapping;
1276
1277
1278
    snapping = ( ( dim == AF_DIMENSION_HORZ             &&
1279
                   AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ||
1280
                 ( dim == AF_DIMENSION_VERT             &&
1281
                   AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) );
1282
1283
    for ( edge = edges; edge < edge_limit; edge++ )
1284
    {
1285
      /* move the points of each segment     */
1286
      /* in each edge to the edge's position */
1287
      AF_Segment  seg = edge->first;
1288
1289
1290
      if ( snapping )
1291
      {
1292
        do
1293
        {
1294
          AF_Point  point = seg->first;
1295
1296
1297
          for (;;)
1298
          {
1299
            if ( dim == AF_DIMENSION_HORZ )
1300
            {
1301
              point->x      = edge->pos;
1302
              point->flags |= AF_FLAG_TOUCH_X;
1303
            }
1304
            else
1305
            {
1306
              point->y      = edge->pos;
1307
              point->flags |= AF_FLAG_TOUCH_Y;
1308
            }
1309
1310
            if ( point == seg->last )
1311
              break;
1312
1313
            point = point->next;
1314
          }
1315
1316
          seg = seg->edge_next;
1317
1318
        } while ( seg != edge->first );
1319
      }
1320
      else
1321
      {
1322
        FT_Pos  delta = edge->pos - edge->opos;
1323
1324
1325
        do
1326
        {
1327
          AF_Point  point = seg->first;
1328
1329
1330
          for (;;)
1331
          {
1332
            if ( dim == AF_DIMENSION_HORZ )
1333
            {
1334
              point->x     += delta;
1335
              point->flags |= AF_FLAG_TOUCH_X;
1336
            }
1337
            else
1338
            {
1339
              point->y     += delta;
1340
              point->flags |= AF_FLAG_TOUCH_Y;
1341
            }
1342
1343
            if ( point == seg->last )
1344
              break;
1345
1346
            point = point->next;
1347
          }
1348
1349
          seg = seg->edge_next;
1350
1351
        } while ( seg != edge->first );
1352
      }
1353
    }
1354
  }
1355
1356
1357
  static FT_Error
1358
  af_cjk_hints_apply( AF_GlyphHints    hints,
1359
                      FT_Outline*      outline,
1360
                      AF_LatinMetrics  metrics )
1361
  {
1362
    FT_Error  error;
1363
    int       dim;
1364
1365
    FT_UNUSED( metrics );
1366
1367
1368
    error = af_glyph_hints_reload( hints, outline );
1369
    if ( error )
1370
      goto Exit;
1371
1372
    /* analyze glyph outline */
1373
    if ( AF_HINTS_DO_HORIZONTAL( hints ) )
1374
    {
1375
      error = af_cjk_hints_detect_features( hints, AF_DIMENSION_HORZ );
1376
      if ( error )
1377
        goto Exit;
1378
    }
1379
1380
    if ( AF_HINTS_DO_VERTICAL( hints ) )
1381
    {
1382
      error = af_cjk_hints_detect_features( hints, AF_DIMENSION_VERT );
1383
      if ( error )
1384
        goto Exit;
1385
    }
1386
1387
    /* grid-fit the outline */
1388
    for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
1389
    {
1390
      if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
1391
           ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) )   )
1392
      {
1393
1394
#ifdef AF_USE_WARPER
1395
        if ( dim == AF_DIMENSION_HORZ                                  &&
1396
             metrics->root.scaler.render_mode == FT_RENDER_MODE_NORMAL )
1397
        {
1398
          AF_WarperRec  warper;
1399
          FT_Fixed      scale;
1400
          FT_Pos        delta;
1401
1402
1403
          af_warper_compute( &warper, hints, dim, &scale, &delta );
1404
          af_glyph_hints_scale_dim( hints, dim, scale, delta );
1405
          continue;
1406
        }
1407
#endif /* AF_USE_WARPER */
1408
1409
        af_cjk_hint_edges( hints, (AF_Dimension)dim );
1410
        af_cjk_align_edge_points( hints, (AF_Dimension)dim );
1411
        af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
1412
        af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
1413
      }
1414
    }
1415
1416
#if 0
1417
    af_glyph_hints_dump_points( hints );
1418
    af_glyph_hints_dump_segments( hints );
1419
    af_glyph_hints_dump_edges( hints );
1420
#endif
1421
1422
    af_glyph_hints_save( hints, outline );
1423
1424
  Exit:
1425
    return error;
1426
  }
1427
1428
1429
  /*************************************************************************/
1430
  /*************************************************************************/
1431
  /*****                                                               *****/
1432
  /*****                C J K   S C R I P T   C L A S S                *****/
1433
  /*****                                                               *****/
1434
  /*************************************************************************/
1435
  /*************************************************************************/
1436
1437
1438
  static const AF_Script_UniRangeRec  af_cjk_uniranges[] =
1439
  {
1440
    { 0x2E80,  0x2EFF },  /* CJK Radicals Supplement */
1441
    { 0x2F00,  0x2FDF },  /* Kangxi Radicals */
1442
    { 0x3000,  0x303F },  /* CJK Symbols and Punctuation */
1443
    { 0x3040,  0x309F },  /* Hiragana */
1444
    { 0x30A0,  0x30FF },  /* Katakana */
1445
    { 0x3100,  0x312F },  /* Bopomofo */
1446
    { 0x3130,  0x318F },  /* Hangul Compatibility Jamo */
1447
    { 0x31A0,  0x31BF },  /* Bopomofo Extended */
1448
    { 0x31C0,  0x31EF },  /* CJK Strokes */
1449
    { 0x31F0,  0x31FF },  /* Katakana Phonetic Extensions */
1450
    { 0x3200,  0x32FF },  /* Enclosed CJK Letters and Months */
1451
    { 0x3300,  0x33FF },  /* CJK Compatibility */
1452
    { 0x3400,  0x4DBF },  /* CJK Unified Ideographs Extension A */
1453
    { 0x4DC0,  0x4DFF },  /* Yijing Hexagram Symbols */
1454
    { 0x4E00,  0x9FFF },  /* CJK Unified Ideographs */
1455
    { 0xF900,  0xFAFF },  /* CJK Compatibility Ideographs */
1456
    { 0xFE30,  0xFE4F },  /* CJK Compatibility Forms */
1457
    { 0xFF00,  0xFFEF },  /* Halfwidth and Fullwidth Forms */
1458
    { 0x20000, 0x2A6DF }, /* CJK Unified Ideographs Extension B */
1459
    { 0x2F800, 0x2FA1F }, /* CJK Compatibility Ideographs Supplement */
1460
    { 0,       0 }
1461
  };
1462
1463
1464
  FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec
1465
  af_cjk_script_class =
1466
  {
1467
    AF_SCRIPT_CJK,
1468
    af_cjk_uniranges,
1469
1470
    sizeof( AF_LatinMetricsRec ),
1471
1472
    (AF_Script_InitMetricsFunc) af_cjk_metrics_init,
1473
    (AF_Script_ScaleMetricsFunc)af_cjk_metrics_scale,
1474
    (AF_Script_DoneMetricsFunc) NULL,
1475
1476
    (AF_Script_InitHintsFunc)   af_cjk_hints_init,
1477
    (AF_Script_ApplyHintsFunc)  af_cjk_hints_apply
1478
  };
1479
1480
#else /* !AF_CONFIG_OPTION_CJK */
1481
1482
  static const AF_Script_UniRangeRec  af_cjk_uniranges[] =
1483
  {
1484
    { 0, 0 }
1485
  };
1486
1487
1488
  FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec
1489
  af_cjk_script_class =
1490
  {
1491
    AF_SCRIPT_CJK,
1492
    af_cjk_uniranges,
1493
1494
    sizeof( AF_LatinMetricsRec ),
1495
1496
    (AF_Script_InitMetricsFunc) NULL,
1497
    (AF_Script_ScaleMetricsFunc)NULL,
1498
    (AF_Script_DoneMetricsFunc) NULL,
1499
1500
    (AF_Script_InitHintsFunc)   NULL,
1501
    (AF_Script_ApplyHintsFunc)  NULL
1502
  };
1503
1504
#endif /* !AF_CONFIG_OPTION_CJK */
1505
1506
1507
/* END */
(-)freetype-2.1.10.old/src/autofit/afcjk.h (+41 lines)
Line 0 Link Here
1
/***************************************************************************/
2
/*                                                                         */
3
/*  afcjk.h                                                                */
4
/*                                                                         */
5
/*    Auto-fitter hinting routines for CJK script (specification).         */
6
/*                                                                         */
7
/*  Copyright 2006 by                                                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
11
/*  modified, and distributed under the terms of the FreeType project      */
12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13
/*  this file you indicate that you have read the license and              */
14
/*  understand and accept it fully.                                        */
15
/*                                                                         */
16
/***************************************************************************/
17
18
19
#ifndef __AFCJK_H__
20
#define __AFCJK_H__
21
22
#include "afhints.h"
23
24
25
FT_BEGIN_HEADER
26
27
28
  /* the CJK-specific script class */
29
30
  FT_CALLBACK_TABLE const AF_ScriptClassRec
31
  af_cjk_script_class;
32
33
34
/* */
35
36
FT_END_HEADER
37
38
#endif /* __AFCJK_H__ */
39
40
41
/* END */
(-)freetype-2.1.10.old/src/autofit/afglobal.c (-1 / +3 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter routines to compute global hinting values (body).        */
5
/*    Auto-fitter routines to compute global hinting values (body).        */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 19-24 Link Here
19
#include "afglobal.h"
19
#include "afglobal.h"
20
#include "afdummy.h"
20
#include "afdummy.h"
21
#include "aflatin.h"
21
#include "aflatin.h"
22
#include "afcjk.h"
22
#include "aferrors.h"
23
#include "aferrors.h"
23
24
24
25
Lines 27-32 Link Here
27
  {
28
  {
28
    &af_dummy_script_class,
29
    &af_dummy_script_class,
29
    &af_latin_script_class,
30
    &af_latin_script_class,
31
    &af_cjk_script_class,
30
32
31
    NULL  /* do not remove */
33
    NULL  /* do not remove */
32
  };
34
  };
(-)freetype-2.1.10.old/src/autofit/afhints.c (-8 / +89 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter hinting routines (body).                                 */
5
/*    Auto-fitter hinting routines (body).                                 */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 265-275 Link Here
265
#endif /* AF_DEBUG */
265
#endif /* AF_DEBUG */
266
266
267
267
268
268
  /* compute the direction value of a given vector */
269
  /* compute the direction value of a given vector */
269
  FT_LOCAL_DEF( AF_Direction )
270
  FT_LOCAL_DEF( AF_Direction )
270
  af_direction_compute( FT_Pos  dx,
271
  af_direction_compute( FT_Pos  dx,
271
                        FT_Pos  dy )
272
                        FT_Pos  dy )
272
  {
273
  {
274
#if 1
275
    AF_Direction  dir = AF_DIR_NONE;
276
277
278
    /* atan(1/12) == 4.7 degrees */
279
280
    if ( dx < 0 )
281
    {
282
      if ( dy < 0 )
283
      {
284
        if ( -dx * 12 < -dy )
285
          dir = AF_DIR_DOWN;
286
287
        else if ( -dy * 12 < -dx )
288
          dir = AF_DIR_LEFT;
289
      }
290
      else /* dy >= 0 */
291
      {
292
        if ( -dx * 12 < dy )
293
          dir = AF_DIR_UP;
294
295
        else if ( dy * 12 < -dx )
296
          dir = AF_DIR_LEFT;
297
      }
298
    }
299
    else /* dx >= 0 */
300
    {
301
      if ( dy < 0 )
302
      {
303
        if ( dx * 12 < -dy )
304
          dir = AF_DIR_DOWN;
305
306
        else if ( -dy * 12 < dx )
307
          dir = AF_DIR_RIGHT;
308
      }
309
      else  /* dy >= 0 */
310
      {
311
        if ( dx * 12 < dy )
312
          dir = AF_DIR_UP;
313
314
        else if ( dy * 12 < dx )
315
          dir = AF_DIR_RIGHT;
316
      }
317
    }
318
319
    return dir;
320
321
#else /* 0 */
322
273
    AF_Direction  dir;
323
    AF_Direction  dir;
274
    FT_Pos        ax = FT_ABS( dx );
324
    FT_Pos        ax = FT_ABS( dx );
275
    FT_Pos        ay = FT_ABS( dy );
325
    FT_Pos        ay = FT_ABS( dy );
Lines 291-296 Link Here
291
    }
341
    }
292
342
293
    return dir;
343
    return dir;
344
345
#endif /* 0 */
346
294
  }
347
  }
295
348
296
349
Lines 349-356 Link Here
349
402
350
      } while ( angle_in == angle_seg );
403
      } while ( angle_in == angle_seg );
351
404
352
      first   = start;
405
      first = start;
353
      diff_in = af_angle_diff( angle_in, angle_seg );
406
407
      AF_ANGLE_DIFF( diff_in, angle_in, angle_seg );
354
408
355
      /* now, process all segments in the contour */
409
      /* now, process all segments in the contour */
356
      do
410
      do
Lines 373-379 Link Here
373
427
374
        } while ( angle_out == angle_seg );
428
        } while ( angle_out == angle_seg );
375
429
376
        diff_out = af_angle_diff( angle_seg, angle_out );
430
        AF_ANGLE_DIFF( diff_out, angle_seg, angle_out );
377
431
378
        if ( ( diff_in ^ diff_out ) < 0 )
432
        if ( ( diff_in ^ diff_out ) < 0 )
379
        {
433
        {
Lines 455-461 Link Here
455
  af_glyph_hints_rescale( AF_GlyphHints     hints,
509
  af_glyph_hints_rescale( AF_GlyphHints     hints,
456
                          AF_ScriptMetrics  metrics )
510
                          AF_ScriptMetrics  metrics )
457
  {
511
  {
458
    hints->metrics = metrics;
512
    hints->metrics      = metrics;
513
    hints->scaler_flags = metrics->scaler.flags;
459
  }
514
  }
460
515
461
516
Lines 466-472 Link Here
466
    FT_Error   error   = AF_Err_Ok;
521
    FT_Error   error   = AF_Err_Ok;
467
    AF_Point   points;
522
    AF_Point   points;
468
    FT_UInt    old_max, new_max;
523
    FT_UInt    old_max, new_max;
469
    AF_Scaler  scaler  = &hints->metrics->scaler;
470
    FT_Fixed   x_scale = hints->x_scale;
524
    FT_Fixed   x_scale = hints->x_scale;
471
    FT_Fixed   y_scale = hints->y_scale;
525
    FT_Fixed   y_scale = hints->y_scale;
472
    FT_Pos     x_delta = hints->x_delta;
526
    FT_Pos     x_delta = hints->x_delta;
Lines 474-480 Link Here
474
    FT_Memory  memory  = hints->memory;
528
    FT_Memory  memory  = hints->memory;
475
529
476
530
477
    hints->scaler_flags = scaler->flags;
478
    hints->num_points   = 0;
531
    hints->num_points   = 0;
479
    hints->num_contours = 0;
532
    hints->num_contours = 0;
480
533
Lines 657-663 Link Here
657
710
658
            angle_in  = af_angle_atan( in_x, in_y );
711
            angle_in  = af_angle_atan( in_x, in_y );
659
            angle_out = af_angle_atan( out_x, out_y );
712
            angle_out = af_angle_atan( out_x, out_y );
660
            delta     = af_angle_diff( angle_in, angle_out );
713
714
            AF_ANGLE_DIFF( delta, angle_in, angle_out );
661
715
662
            if ( delta < 2 && delta > -2 )
716
            if ( delta < 2 && delta > -2 )
663
              goto Is_Weak_Point;
717
              goto Is_Weak_Point;
Lines 1087-1090 Link Here
1087
  }
1141
  }
1088
1142
1089
1143
1144
#ifdef AF_USE_WARPER
1145
1146
  FT_LOCAL_DEF( void )
1147
  af_glyph_hints_scale_dim( AF_GlyphHints  hints,
1148
                            AF_Dimension   dim,
1149
                            FT_Fixed       scale,
1150
                            FT_Pos         delta )
1151
  {
1152
    AF_Point  points       = hints->points;
1153
    AF_Point  points_limit = points + hints->num_points;
1154
    AF_Point  point;
1155
    
1156
1157
    if ( dim == AF_DIMENSION_HORZ )
1158
    {
1159
      for ( point = points; point < points_limit; point++ )
1160
        point->x = FT_MulFix( point->fx, scale ) + delta;
1161
    }
1162
    else
1163
    {
1164
      for ( point = points; point < points_limit; point++ )
1165
        point->y = FT_MulFix( point->fy, scale ) + delta;
1166
    }
1167
  }
1168
1169
#endif /* AF_USE_WARPER */
1170
1090
/* END */
1171
/* END */
(-)freetype-2.1.10.old/src/autofit/afhints.h (-1 / +16 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter hinting routines (specification).                        */
5
/*    Auto-fitter hinting routines (specification).                        */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 133-138 Link Here
133
    AF_Segment  serif;       /* primary segment for serifs */
133
    AF_Segment  serif;       /* primary segment for serifs */
134
    FT_Pos      num_linked;  /* number of linked segments  */
134
    FT_Pos      num_linked;  /* number of linked segments  */
135
    FT_Pos      score;       /* used during stem matching  */
135
    FT_Pos      score;       /* used during stem matching  */
136
    FT_Pos      len;         /* used during stem matching  */
136
137
137
    AF_Point    first;       /* first point in edge segment             */
138
    AF_Point    first;       /* first point in edge segment             */
138
    AF_Point    last;        /* last point in edge segment              */
139
    AF_Point    last;        /* last point in edge segment              */
Lines 272-282 Link Here
272
  af_glyph_hints_align_weak_points( AF_GlyphHints  hints,
273
  af_glyph_hints_align_weak_points( AF_GlyphHints  hints,
273
                                    AF_Dimension   dim );
274
                                    AF_Dimension   dim );
274
275
276
#ifdef AF_USE_WARPER
277
  FT_LOCAL( void )
278
  af_glyph_hints_scale_dim( AF_GlyphHints  hints,
279
                            AF_Dimension   dim,
280
                            FT_Fixed       scale,
281
                            FT_Pos         delta );
282
#endif
283
275
  FT_LOCAL( void )
284
  FT_LOCAL( void )
276
  af_glyph_hints_done( AF_GlyphHints  hints );
285
  af_glyph_hints_done( AF_GlyphHints  hints );
277
286
278
/* */
287
/* */
279
288
289
#define AF_SEGMENT_LEN( seg )          ( (seg)->max_coord - (seg)->min_coord )
290
291
#define AF_SEGMENT_DIST( seg1, seg2 )  ( ( (seg1)->pos > (seg2)->pos )   \
292
                                           ? (seg1)->pos - (seg2)->pos   \
293
                                           : (seg2)->pos - (seg1)->pos )
294
280
295
281
FT_END_HEADER
296
FT_END_HEADER
282
297
(-)freetype-2.1.10.old/src/autofit/aflatin.c (-33 / +85 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter hinting routines for latin script (body).                */
5
/*    Auto-fitter hinting routines for latin script (body).                */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 20-25 Link Here
20
#include "aferrors.h"
20
#include "aferrors.h"
21
21
22
22
23
#ifdef AF_USE_WARPER
24
#include "afwarp.h"
25
#endif
26
27
23
  /*************************************************************************/
28
  /*************************************************************************/
24
  /*************************************************************************/
29
  /*************************************************************************/
25
  /*****                                                               *****/
30
  /*****                                                               *****/
Lines 28-36 Link Here
28
  /*************************************************************************/
33
  /*************************************************************************/
29
  /*************************************************************************/
34
  /*************************************************************************/
30
35
31
  static void
36
  FT_LOCAL_DEF( void )
32
  af_latin_metrics_init_widths( AF_LatinMetrics  metrics,
37
  af_latin_metrics_init_widths( AF_LatinMetrics  metrics,
33
                                FT_Face          face )
38
                                FT_Face          face,
39
                                FT_ULong         charcode )
34
  {
40
  {
35
    /* scan the array of segments in each direction */
41
    /* scan the array of segments in each direction */
36
    AF_GlyphHintsRec  hints[1];
42
    AF_GlyphHintsRec  hints[1];
Lines 41-56 Link Here
41
    metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
47
    metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
42
    metrics->axis[AF_DIMENSION_VERT].width_count = 0;
48
    metrics->axis[AF_DIMENSION_VERT].width_count = 0;
43
49
44
    /* For now, compute the standard width and height from the `o'. */
45
    {
50
    {
46
      FT_Error             error;
51
      FT_Error             error;
47
      FT_UInt              glyph_index;
52
      FT_UInt              glyph_index;
48
      int                  dim;
53
      int                  dim;
49
      AF_ScriptMetricsRec  dummy[1];
54
      AF_LatinMetricsRec   dummy[1];
50
      AF_Scaler            scaler = &dummy->scaler;
55
      AF_Scaler            scaler = &dummy->root.scaler;
51
56
52
57
53
      glyph_index = FT_Get_Char_Index( face, 'o' );
58
      glyph_index = FT_Get_Char_Index( face, charcode );
54
      if ( glyph_index == 0 )
59
      if ( glyph_index == 0 )
55
        goto Exit;
60
        goto Exit;
56
61
Lines 60-72 Link Here
60
65
61
      FT_ZERO( dummy );
66
      FT_ZERO( dummy );
62
67
68
      dummy->units_per_em = metrics->units_per_em;
63
      scaler->x_scale     = scaler->y_scale = 0x10000L;
69
      scaler->x_scale     = scaler->y_scale = 0x10000L;
64
      scaler->x_delta     = scaler->y_delta = 0;
70
      scaler->x_delta     = scaler->y_delta = 0;
65
      scaler->face        = face;
71
      scaler->face        = face;
66
      scaler->render_mode = FT_RENDER_MODE_NORMAL;
72
      scaler->render_mode = FT_RENDER_MODE_NORMAL;
67
      scaler->flags       = 0;
73
      scaler->flags       = 0;
68
74
69
      af_glyph_hints_rescale( hints, dummy );
75
      af_glyph_hints_rescale( hints, (AF_ScriptMetrics)dummy );
70
76
71
      error = af_glyph_hints_reload( hints, &face->glyph->outline );
77
      error = af_glyph_hints_reload( hints, &face->glyph->outline );
72
      if ( error )
78
      if ( error )
Lines 77-85 Link Here
77
        AF_LatinAxis  axis    = &metrics->axis[dim];
83
        AF_LatinAxis  axis    = &metrics->axis[dim];
78
        AF_AxisHints  axhints = &hints->axis[dim];
84
        AF_AxisHints  axhints = &hints->axis[dim];
79
        AF_Segment    seg, limit, link;
85
        AF_Segment    seg, limit, link;
80
86
        FT_UInt       num_widths = 0;
81
        FT_UInt       num_widths              = 0;
82
        FT_Pos        edge_distance_threshold = 32000;
83
87
84
88
85
        error = af_latin_hints_compute_segments( hints,
89
        error = af_latin_hints_compute_segments( hints,
Lines 114-135 Link Here
114
118
115
        af_sort_widths( num_widths, axis->widths );
119
        af_sort_widths( num_widths, axis->widths );
116
        axis->width_count = num_widths;
120
        axis->width_count = num_widths;
121
      }
122
123
  Exit:
124
      for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
125
      {
126
        AF_LatinAxis  axis = &metrics->axis[dim];
127
        FT_Pos        stdw;
117
128
118
        /* we will now try to find the smallest width */
119
        if ( num_widths > 0 && axis->widths[0].org < edge_distance_threshold )
120
          edge_distance_threshold = axis->widths[0].org;
121
122
        /* Now, compute the edge distance threshold as a fraction of the */
123
        /* smallest width in the font.  Set it in `hinter->glyph' too!   */
124
        if ( edge_distance_threshold == 32000 )
125
          edge_distance_threshold = 50;
126
129
127
        /* let's try 20% */
130
        stdw = ( axis->width_count > 0 )
128
        axis->edge_distance_threshold = edge_distance_threshold / 5;
131
                 ? axis->widths[0].org
132
                 : AF_LATIN_CONSTANT( metrics, 50 );
133
134
        /* let's try 20% of the smallest width */
135
        axis->edge_distance_threshold = stdw / 5;
129
      }
136
      }
130
    }
137
    }
131
138
132
  Exit:
133
    af_glyph_hints_done( hints );
139
    af_glyph_hints_done( hints );
134
  }
140
  }
135
141
Lines 404-410 Link Here
404
410
405
    if ( !error )
411
    if ( !error )
406
    {
412
    {
407
      af_latin_metrics_init_widths( metrics, face );
413
      /* For now, compute the standard width and height from the `o'. */
414
      af_latin_metrics_init_widths( metrics, face, 'o' );
408
      af_latin_metrics_init_blues( metrics, face );
415
      af_latin_metrics_init_blues( metrics, face );
409
    }
416
    }
410
417
Lines 559-564 Link Here
559
  af_latin_metrics_scale( AF_LatinMetrics  metrics,
566
  af_latin_metrics_scale( AF_LatinMetrics  metrics,
560
                          AF_Scaler        scaler )
567
                          AF_Scaler        scaler )
561
  {
568
  {
569
    metrics->root.scaler.render_mode = scaler->render_mode;
570
562
    af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
571
    af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
563
    af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
572
    af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
564
  }
573
  }
Lines 739-744 Link Here
739
          segment->last     = point;
748
          segment->last     = point;
740
          segment->contour  = contour;
749
          segment->contour  = contour;
741
          segment->score    = 32000;
750
          segment->score    = 32000;
751
          segment->len      = 0;
742
          segment->link     = NULL;
752
          segment->link     = NULL;
743
          on_edge           = 1;
753
          on_edge           = 1;
744
754
Lines 805-810 Link Here
805
        segment->last  = min_point;
815
        segment->last  = min_point;
806
        segment->pos   = min_pos;
816
        segment->pos   = min_pos;
807
        segment->score = 32000;
817
        segment->score = 32000;
818
        segment->len   = 0;
808
        segment->link  = NULL;
819
        segment->link  = NULL;
809
820
810
        segment = NULL;
821
        segment = NULL;
Lines 824-829 Link Here
824
        segment->last  = max_point;
835
        segment->last  = max_point;
825
        segment->pos   = max_pos;
836
        segment->pos   = max_pos;
826
        segment->score = 32000;
837
        segment->score = 32000;
838
        segment->len   = 0;
827
        segment->link  = NULL;
839
        segment->link  = NULL;
828
840
829
        segment = NULL;
841
        segment = NULL;
Lines 844-852 Link Here
844
    AF_Segment    segments      = axis->segments;
856
    AF_Segment    segments      = axis->segments;
845
    AF_Segment    segment_limit = segments + axis->num_segments;
857
    AF_Segment    segment_limit = segments + axis->num_segments;
846
    AF_Direction  major_dir     = axis->major_dir;
858
    AF_Direction  major_dir     = axis->major_dir;
859
    FT_UShort     len_threshold, len_score;
847
    AF_Segment    seg1, seg2;
860
    AF_Segment    seg1, seg2;
848
861
849
  
862
863
    len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
864
    if ( len_threshold == 0 )
865
      len_threshold = 1;
866
867
    len_score = AF_LATIN_CONSTANT( hints->metrics, 3000 );
868
850
    /* now compare each segment to the others */
869
    /* now compare each segment to the others */
851
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
870
    for ( seg1 = segments; seg1 < segment_limit; seg1++ )
852
    {
871
    {
Lines 879-887 Link Here
879
              max = seg2->max_coord;
898
              max = seg2->max_coord;
880
899
881
            len = max - min;
900
            len = max - min;
882
            if ( len >= 8 )
901
            if ( len >= len_threshold )
883
            {
902
            {
884
              score = dist + 3000 / len;
903
              score = dist + len_score / len;
885
904
886
              if ( score < seg1->score )
905
              if ( score < seg1->score )
887
              {
906
              {
Lines 1292-1297 Link Here
1292
                       AF_LatinMetrics  metrics )
1311
                       AF_LatinMetrics  metrics )
1293
  {
1312
  {
1294
    FT_Render_Mode  mode;
1313
    FT_Render_Mode  mode;
1314
    FT_UInt32       scaler_flags, other_flags;
1295
1315
1296
1316
1297
    af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
1317
    af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
Lines 1305-1336 Link Here
1305
    hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
1325
    hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
1306
    hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
1326
    hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
1307
1327
1308
    /* compute flags depending on render mode, etc... */
1328
    /* compute flags depending on render mode, etc. */
1309
1310
    mode = metrics->root.scaler.render_mode;
1329
    mode = metrics->root.scaler.render_mode;
1311
1330
1331
#ifdef AF_USE_WARPER
1332
    if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
1333
    {
1334
      metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
1335
    }
1336
#endif
1337
1338
    scaler_flags = hints->scaler_flags;
1339
    other_flags  = 0;
1340
1312
    /*
1341
    /*
1313
     *  We snap the width of vertical stems for the monochrome and
1342
     *  We snap the width of vertical stems for the monochrome and
1314
     *  horizontal LCD rendering targets only.
1343
     *  horizontal LCD rendering targets only.
1315
     */
1344
     */
1316
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
1345
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
1317
      hints->other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
1346
      other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
1318
1347
1319
    /*
1348
    /*
1320
     *  We snap the width of horizontal stems for the monochrome and
1349
     *  We snap the width of horizontal stems for the monochrome and
1321
     *  vertical LCD rendering targets only.
1350
     *  vertical LCD rendering targets only.
1322
     */
1351
     */
1323
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
1352
    if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
1324
      hints->other_flags |= AF_LATIN_HINTS_VERT_SNAP;
1353
      other_flags |= AF_LATIN_HINTS_VERT_SNAP;
1325
1354
1326
    /*
1355
    /*
1327
     *  We adjust stems to full pixels only if we don't use the `light' mode.
1356
     *  We adjust stems to full pixels only if we don't use the `light' mode.
1328
     */
1357
     */
1329
    if ( mode != FT_RENDER_MODE_LIGHT )
1358
    if ( mode != FT_RENDER_MODE_LIGHT )
1330
      hints->other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
1359
      other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
1331
1360
1332
    if ( mode == FT_RENDER_MODE_MONO )
1361
    if ( mode == FT_RENDER_MODE_MONO )
1333
      hints->other_flags |= AF_LATIN_HINTS_MONO;
1362
      other_flags |= AF_LATIN_HINTS_MONO;
1363
1364
    /*
1365
     *  In `light' hinting mode we disable horizontal hinting completely.
1366
     */
1367
    if ( mode == FT_RENDER_MODE_LIGHT )
1368
      scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL;
1369
1370
    hints->scaler_flags = scaler_flags;
1371
    hints->other_flags  = other_flags;
1334
1372
1335
    return 0;
1373
    return 0;
1336
  }
1374
  }
Lines 1405-1411 Link Here
1405
    AF_LatinAxis     axis     = & metrics->axis[dim];
1443
    AF_LatinAxis     axis     = & metrics->axis[dim];
1406
    FT_Pos           dist     = width;
1444
    FT_Pos           dist     = width;
1407
    FT_Int           sign     = 0;
1445
    FT_Int           sign     = 0;
1408
    FT_Int           vertical = AF_HINTS_DO_VERTICAL( hints );
1446
    FT_Int           vertical = ( dim == AF_DIMENSION_VERT );
1409
1447
1410
1448
1411
    if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1449
    if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
Lines 1926-1931 Link Here
1926
      if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
1964
      if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
1927
           ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) )   )
1965
           ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) )   )
1928
      {
1966
      {
1967
#ifdef AF_USE_WARPER
1968
        if ( dim == AF_DIMENSION_HORZ &&
1969
             metrics->root.scaler.render_mode == FT_RENDER_MODE_NORMAL )
1970
        {
1971
          AF_WarperRec  warper;
1972
          FT_Fixed      scale;
1973
          FT_Pos        delta;
1974
1975
1976
          af_warper_compute( &warper, hints, dim, &scale, &delta );
1977
          af_glyph_hints_scale_dim( hints, dim, scale, delta );
1978
          continue;
1979
        }
1980
#endif
1929
        af_latin_hint_edges( hints, (AF_Dimension)dim );
1981
        af_latin_hint_edges( hints, (AF_Dimension)dim );
1930
        af_glyph_hints_align_edge_points( hints, (AF_Dimension)dim );
1982
        af_glyph_hints_align_edge_points( hints, (AF_Dimension)dim );
1931
        af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
1983
        af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
(-)freetype-2.1.10.old/src/autofit/aflatin.h (-1 / +10 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter hinting routines for latin script (specification).       */
5
/*    Auto-fitter hinting routines for latin script (specification).       */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 31-36 Link Here
31
  af_latin_script_class;
31
  af_latin_script_class;
32
32
33
33
34
/* constants are given with units_per_em == 2048 in mind */
35
#define AF_LATIN_CONSTANT( metrics, c ) \
36
  ( ( (c) * (FT_Long)( (AF_LatinMetrics)(metrics) )->units_per_em ) / 2048 )
37
38
34
  /*************************************************************************/
39
  /*************************************************************************/
35
  /*************************************************************************/
40
  /*************************************************************************/
36
  /*****                                                               *****/
41
  /*****                                                               *****/
Lines 126-131 Link Here
126
  af_latin_metrics_scale( AF_LatinMetrics  metrics,
131
  af_latin_metrics_scale( AF_LatinMetrics  metrics,
127
                          AF_Scaler        scaler );
132
                          AF_Scaler        scaler );
128
133
134
  FT_LOCAL( void )
135
  af_latin_metrics_init_widths( AF_LatinMetrics  metrics,
136
                                FT_Face          face,
137
                                FT_ULong         charcode );
129
138
130
139
131
  /*************************************************************************/
140
  /*************************************************************************/
(-)freetype-2.1.10.old/src/autofit/afloader.c (-6 / +24 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter glyph loading routines (body).                           */
5
/*    Auto-fitter glyph loading routines (body).                           */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 138-146 Link Here
138
138
139
      /* copy the outline points in the loader's current               */
139
      /* copy the outline points in the loader's current               */
140
      /* extra points which is used to keep original glyph coordinates */
140
      /* extra points which is used to keep original glyph coordinates */
141
      error = FT_GlyphLoader_CheckPoints( gloader,
141
      error = FT_GLYPHLOADER_CHECK_POINTS( gloader,
142
                                          slot->outline.n_points + 4,
142
                                           slot->outline.n_points + 4,
143
                                          slot->outline.n_contours );
143
                                           slot->outline.n_contours );
144
      if ( error )
144
      if ( error )
145
        goto Exit;
145
        goto Exit;
146
146
Lines 184-189 Link Here
184
      /* we now need to hint the metrics according to the change in */
184
      /* we now need to hint the metrics according to the change in */
185
      /* width/positioning that occured during the hinting process  */
185
      /* width/positioning that occured during the hinting process  */
186
      {
186
      {
187
#ifndef AF_USE_WARPER
187
        FT_Pos        old_advance, old_rsb, old_lsb, new_lsb;
188
        FT_Pos        old_advance, old_rsb, old_lsb, new_lsb;
188
        FT_Pos        pp1x_uh, pp2x_uh;
189
        FT_Pos        pp1x_uh, pp2x_uh;
189
        AF_AxisHints  axis  = &hints->axis[AF_DIMENSION_HORZ];
190
        AF_AxisHints  axis  = &hints->axis[AF_DIMENSION_HORZ];
Lines 192-198 Link Here
192
                              axis->num_edges - 1; /* rightmost edge */
193
                              axis->num_edges - 1; /* rightmost edge */
193
194
194
195
195
        if ( axis->num_edges > 1 )
196
        if ( axis->num_edges > 1 && AF_HINTS_DO_ADVANCE( hints ) )
196
        {
197
        {
197
          old_advance = loader->pp2.x;
198
          old_advance = loader->pp2.x;
198
          old_rsb     = old_advance - edge2->opos;
199
          old_rsb     = old_advance - edge2->opos;
Lines 228-233 Link Here
228
229
229
        }
230
        }
230
        else
231
        else
232
#endif /* !AF_USE_WARPER */
231
        {
233
        {
232
          loader->pp1.x = FT_PIX_ROUND( loader->pp1.x );
234
          loader->pp1.x = FT_PIX_ROUND( loader->pp1.x );
233
          loader->pp2.x = FT_PIX_ROUND( loader->pp2.x );
235
          loader->pp2.x = FT_PIX_ROUND( loader->pp2.x );
Lines 376-387 Link Here
376
  Hint_Metrics:
378
  Hint_Metrics:
377
    if ( depth == 0 )
379
    if ( depth == 0 )
378
    {
380
    {
379
      FT_BBox  bbox;
381
      FT_BBox    bbox;
382
      FT_Vector  vvector;
380
383
381
384
385
      vvector.x = slot->metrics.vertBearingX - slot->metrics.horiBearingX;
386
      vvector.y = slot->metrics.vertBearingY - slot->metrics.horiBearingY;
387
      vvector.x = FT_MulFix( vvector.x, metrics->scaler.x_scale );
388
      vvector.y = FT_MulFix( vvector.y, metrics->scaler.y_scale );
389
382
      /* transform the hinted outline if needed */
390
      /* transform the hinted outline if needed */
383
      if ( loader->transformed )
391
      if ( loader->transformed )
392
      {
384
        FT_Outline_Transform( &gloader->base.outline, &loader->trans_matrix );
393
        FT_Outline_Transform( &gloader->base.outline, &loader->trans_matrix );
394
        FT_Vector_Transform( &vvector, &loader->trans_matrix );
395
      }
385
396
386
      /* we must translate our final outline by -pp1.x and compute */
397
      /* we must translate our final outline by -pp1.x and compute */
387
      /* the new metrics                                           */
398
      /* the new metrics                                           */
Lines 400-405 Link Here
400
      slot->metrics.horiBearingX = bbox.xMin;
411
      slot->metrics.horiBearingX = bbox.xMin;
401
      slot->metrics.horiBearingY = bbox.yMax;
412
      slot->metrics.horiBearingY = bbox.yMax;
402
413
414
      slot->metrics.vertBearingX = FT_PIX_FLOOR( bbox.xMin + vvector.x );
415
      slot->metrics.vertBearingY = FT_PIX_FLOOR( bbox.yMax + vvector.y );
416
403
      /* for mono-width fonts (like Andale, Courier, etc.) we need */
417
      /* for mono-width fonts (like Andale, Courier, etc.) we need */
404
      /* to keep the original rounded advance width                */
418
      /* to keep the original rounded advance width                */
405
#if 0
419
#if 0
Lines 416-422 Link Here
416
                                               metrics->scaler.x_scale );
430
                                               metrics->scaler.x_scale );
417
#endif
431
#endif
418
432
433
      slot->metrics.vertAdvance = FT_MulFix( slot->metrics.vertAdvance,
434
                                              metrics->scaler.y_scale );
435
419
      slot->metrics.horiAdvance = FT_PIX_ROUND( slot->metrics.horiAdvance );
436
      slot->metrics.horiAdvance = FT_PIX_ROUND( slot->metrics.horiAdvance );
437
      slot->metrics.vertAdvance = FT_PIX_ROUND( slot->metrics.vertAdvance );
420
438
421
      /* now copy outline into glyph slot */
439
      /* now copy outline into glyph slot */
422
      FT_GlyphLoader_Rewind( internal->loader );
440
      FT_GlyphLoader_Rewind( internal->loader );
(-)freetype-2.1.10.old/src/autofit/aftypes.h (-15 / +35 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter types (specification only).                              */
5
/*    Auto-fitter types (specification only).                              */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 16-35 Link Here
16
/***************************************************************************/
16
/***************************************************************************/
17
17
18
18
19
/***************************************************************************
19
  /*************************************************************************
20
 *
20
   *
21
 *  The auto-fitter is a complete rewrite of the old auto-hinter.
21
   *  The auto-fitter is a complete rewrite of the old auto-hinter.
22
 *  Its main feature is the ability to differentiate between different
22
   *  Its main feature is the ability to differentiate between different
23
 *  scripts in order to apply language-specific rules.
23
   *  scripts in order to apply language-specific rules.
24
 *
24
   *
25
 *  The code has also been compartimentized into several entities that
25
   *  The code has also been compartimentized into several entities that
26
 *  should make algorithmic experimentation easier than with the old
26
   *  should make algorithmic experimentation easier than with the old
27
 *  code.
27
   *  code.
28
 *
28
   *
29
 *  Finally, we get rid of the Catharon license, since this code is
29
   *  Finally, we get rid of the Catharon license, since this code is
30
 *  released under the FreeType one.
30
   *  released under the FreeType one.
31
 *
31
   *
32
 ***************************************************************************/
32
   *************************************************************************/
33
33
34
34
35
#ifndef __AFTYPES_H__
35
#ifndef __AFTYPES_H__
Lines 53-58 Link Here
53
  /*************************************************************************/
53
  /*************************************************************************/
54
  /*************************************************************************/
54
  /*************************************************************************/
55
55
56
#define xxAF_USE_WARPER  /* only define to use warp hinting */
56
#define xxAF_DEBUG
57
#define xxAF_DEBUG
57
58
58
#ifdef AF_DEBUG
59
#ifdef AF_DEBUG
Lines 125-130 Link Here
125
                 FT_Pos  dy );
126
                 FT_Pos  dy );
126
127
127
128
129
#if 0
128
  /*
130
  /*
129
   *  compute `angle2 - angle1'; the result is always within
131
   *  compute `angle2 - angle1'; the result is always within
130
   *  the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
132
   *  the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
Lines 132-137 Link Here
132
  FT_LOCAL( AF_Angle )
134
  FT_LOCAL( AF_Angle )
133
  af_angle_diff( AF_Angle  angle1,
135
  af_angle_diff( AF_Angle  angle1,
134
                 AF_Angle  angle2 );
136
                 AF_Angle  angle2 );
137
#endif /* 0 */
138
139
140
#define AF_ANGLE_DIFF( result, angle1, angle2 ) \
141
  FT_BEGIN_STMNT                                \
142
    AF_Angle  _delta = (angle2) - (angle1);     \
143
                                                \
144
                                                \
145
    _delta %= AF_ANGLE_2PI;                     \
146
    if ( _delta < 0 )                           \
147
      _delta += AF_ANGLE_2PI;                   \
148
                                                \
149
    if ( _delta > AF_ANGLE_PI )                 \
150
      _delta -= AF_ANGLE_2PI;                   \
151
                                                \
152
    result = _delta;                            \
153
  FT_END_STMNT
135
154
136
155
137
  /*************************************************************************/
156
  /*************************************************************************/
Lines 240-245 Link Here
240
  {
259
  {
241
    AF_SCRIPT_NONE  = 0,
260
    AF_SCRIPT_NONE  = 0,
242
    AF_SCRIPT_LATIN = 1,
261
    AF_SCRIPT_LATIN = 1,
262
    AF_SCRIPT_CJK   = 2,
243
    /* add new scripts here.  Don't forget to update the list in */
263
    /* add new scripts here.  Don't forget to update the list in */
244
    /* `afglobal.c'.                                             */
264
    /* `afglobal.c'.                                             */
245
265
(-)freetype-2.1.10.old/src/autofit/afwarp.c (+313 lines)
Line 0 Link Here
1
/***************************************************************************/
2
/*                                                                         */
3
/*  afwarp.c                                                               */
4
/*                                                                         */
5
/*    Auto-fitter warping algorithm (body).                                */
6
/*                                                                         */
7
/*  Copyright 2006 by                                                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
11
/*  modified, and distributed under the terms of the FreeType project      */
12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13
/*  this file you indicate that you have read the license and              */
14
/*  understand and accept it fully.                                        */
15
/*                                                                         */
16
/***************************************************************************/
17
18
19
#include "afwarp.h"
20
21
#ifdef AF_USE_WARPER
22
23
#if 1
24
  static const AF_WarpScore
25
  af_warper_weights[64] =
26
  {
27
    35, 20, 20, 20, 15, 12, 10,  5,  2,  1,  0,  0,  0,  0,  0,  0,
28
     0,  0,  0,  0,  0,  0, -1, -2, -5, -8,-10,-10,-20,-20,-30,-30,
29
30
   -30,-30,-20,-20,-10,-10, -8, -5, -2, -1,  0,  0,  0,  0,  0,  0,
31
     0,  0,  0,  0,  0,  0,  0,  1,  2,  5, 10, 12, 15, 20, 20, 20,
32
  };
33
#else
34
  static const AF_WarpScore
35
  af_warper_weights[64] =
36
  {
37
    30, 20, 10,  5,  4,  4,  3,  2,  1,  0,  0,  0,  0,  0,  0,  0,
38
     0,  0,  0,  0,  0,  0,  0, -1, -2, -2, -5, -5,-10,-10,-15,-20,
39
40
   -20,-15,-15,-10,-10, -5, -5, -2, -2, -1,  0,  0,  0,  0,  0,  0,
41
     0,  0,  0,  0,  0,  0,  0,  0,  1,  2,  3,  4,  4,  5, 10, 20,
42
  };
43
#endif
44
45
46
  static void
47
  af_warper_compute_line_best( AF_Warper     warper,
48
                               FT_Fixed      scale,
49
                               FT_Pos        delta,
50
                               FT_Pos        xx1,
51
                               FT_Pos        xx2,
52
                               AF_WarpScore  base_distort,
53
                               AF_Segment    segments,
54
                               FT_UInt       num_segments )
55
  {
56
    FT_Int        idx_min, idx_max, idx0;
57
    FT_UInt       nn;
58
    AF_WarpScore  scores[64];
59
60
61
    for ( nn = 0; nn < 64; nn++ )
62
      scores[nn] = 0;
63
64
    idx0 = xx1 - warper->t1;
65
66
    /* compute minimum and maximum indices */
67
    {
68
      FT_Pos  xx1min = warper->x1min;
69
      FT_Pos  xx1max = warper->x1max;
70
      FT_Pos  w      = xx2 - xx1;
71
72
73
      if ( xx1min + w < warper->x2min )
74
        xx1min = warper->x2min - ( xx2 - xx1 );
75
76
      xx1max = warper->x1max;
77
      if ( xx1max + w > warper->x2max )
78
        xx1max = warper->x2max - ( xx2 - xx1 );
79
80
      idx_min = xx1min - warper->t1;
81
      idx_max = xx1max - warper->t1;
82
83
      if ( idx_min > idx_max )
84
      {
85
        AF_LOG(( "invalid indices:\n"
86
                 "  min=%d max=%d, xx1=%ld xx2=%ld,\n"
87
                 "  x1min=%ld x1max=%ld, x2min=%ld x2max=%ld\n",
88
                 idx_min, idx_max, xx1, xx2,
89
                 warper->x1min, warper->x1max,
90
                 warper->x2min, warper->x2max ));
91
        return;
92
      }
93
    }
94
95
    for ( nn = 0; nn < num_segments; nn++ )
96
    {
97
      FT_Pos  len = segments[nn].max_coord - segments[nn].min_coord;
98
      FT_Pos  y0  = FT_MulFix( segments[nn].pos, scale ) + delta;
99
      FT_Pos  y   = y0 + ( idx_min - idx0 );
100
101
      FT_Int  idx;
102
103
104
      for ( idx = idx_min; idx <= idx_max; idx++, y++ )
105
        scores[idx] += af_warper_weights[y & 63] * len;
106
    }
107
108
    /* find best score */
109
    {
110
      FT_Int  idx;
111
112
113
      for ( idx = idx_min; idx <= idx_max; idx++ )
114
      {
115
        AF_WarpScore  score = scores[idx];
116
        AF_WarpScore  distort = base_distort + ( idx - idx0 );
117
118
119
        if ( score > warper->best_score           ||
120
             ( score == warper->best_score    &&
121
               distort < warper->best_distort )   )
122
        {
123
          warper->best_score   = score;
124
          warper->best_distort = distort;
125
          warper->best_scale   = scale;
126
          warper->best_delta   = delta + ( idx - idx0 );
127
        }
128
      }
129
    }
130
  }
131
132
133
  FT_LOCAL_DEF( void )
134
  af_warper_compute( AF_Warper      warper,
135
                     AF_GlyphHints  hints,
136
                     AF_Dimension   dim,
137
                     FT_Fixed      *a_scale,
138
                     FT_Pos        *a_delta )
139
  {
140
    AF_AxisHints  axis;
141
    AF_Point      points;
142
143
    FT_Fixed      org_scale;
144
    FT_Pos        org_delta;
145
146
    FT_UInt       nn, num_points, num_segments;
147
    FT_Int        X1, X2;
148
    FT_Int        w;
149
150
    AF_WarpScore  base_distort;
151
    AF_Segment    segments;
152
153
154
    /* get original scaling transformation */
155
    if ( dim == AF_DIMENSION_VERT )
156
    {
157
      org_scale = hints->y_scale;
158
      org_delta = hints->y_delta;
159
    }
160
    else
161
    {
162
      org_scale = hints->x_scale;
163
      org_delta = hints->x_delta;
164
    }
165
166
    warper->best_scale   = org_scale;
167
    warper->best_delta   = org_delta;
168
    warper->best_score   = 0;
169
    warper->best_distort = 0;
170
171
    axis         = &hints->axis[dim];
172
    segments     = axis->segments;
173
    num_segments = axis->num_segments;
174
    points       = hints->points;
175
    num_points   = hints->num_points;
176
177
    *a_scale = org_scale;
178
    *a_delta = org_delta;
179
180
    /* get X1 and X2, minimum and maximum in original coordinates */
181
    if ( axis->num_segments < 1 )
182
      return;
183
184
#if 1
185
    X1 = X2 = points[0].fx;
186
    for ( nn = 1; nn < num_points; nn++ )
187
    {
188
      FT_Int  X = points[nn].fx;
189
190
191
      if ( X < X1 )
192
        X1 = X;
193
      if ( X > X2 )
194
        X2 = X;
195
    }
196
#else
197
    X1 = X2 = segments[0].pos;
198
    for ( nn = 1; nn < num_segments; nn++ )
199
    {
200
      FT_Int  X = segments[nn].pos;
201
202
203
      if ( X < X1 )
204
        X1 = X;
205
      if ( X > X2 )
206
        X2 = X;
207
    }
208
#endif
209
210
    if ( X1 >= X2 )
211
      return;
212
213
    warper->x1 = FT_MulFix( X1, org_scale ) + org_delta;
214
    warper->x2 = FT_MulFix( X2, org_scale ) + org_delta;
215
216
    warper->t1 = AF_WARPER_FLOOR( warper->x1 );
217
    warper->t2 = AF_WARPER_CEIL( warper->x2 );
218
219
    warper->x1min = warper->x1 & ~31;
220
    warper->x1max = warper->x1min + 32;
221
    warper->x2min = warper->x2 & ~31;
222
    warper->x2max = warper->x2min + 32;
223
224
    if ( warper->x1max > warper->x2 )
225
      warper->x1max = warper->x2;
226
227
    if ( warper->x2min < warper->x1 )
228
      warper->x2min = warper->x1;
229
230
    warper->w0 = warper->x2 - warper->x1;
231
232
    if ( warper->w0 <= 64 )
233
    {
234
      warper->x1max = warper->x1;
235
      warper->x2min = warper->x2;
236
    }
237
238
    warper->wmin = warper->x2min - warper->x1max;
239
    warper->wmax = warper->x2max - warper->x1min;
240
241
    if ( warper->wmin < warper->w0 - 32 )
242
      warper->wmin = warper->w0 - 32;
243
244
    if ( warper->wmax > warper->w0 + 32 )
245
      warper->wmax = warper->w0 + 32;
246
247
    if ( warper->wmin < warper->w0 * 3 / 4 )
248
      warper->wmin = warper->w0 * 3 / 4;
249
250
    if ( warper->wmax > warper->w0 * 5 / 4 )
251
      warper->wmax = warper->w0 * 5 / 4;
252
253
    /* warper->wmin = warper->wmax = warper->w0; */
254
255
    for ( w = warper->wmin; w <= warper->wmax; w++ )
256
    {
257
      FT_Fixed  new_scale;
258
      FT_Pos    new_delta;
259
      FT_Pos    xx1, xx2;
260
261
262
      xx1 = warper->x1;
263
      xx2 = warper->x2;
264
      if ( w >= warper->w0 )
265
      {
266
        xx1 -= w - warper->w0;
267
        if ( xx1 < warper->x1min )
268
        {
269
          xx2 += warper->x1min - xx1;
270
          xx1  = warper->x1min;
271
        }
272
      }
273
      else
274
      {
275
        xx1 -= w - warper->w0;
276
        if ( xx1 > warper->x1max )
277
        {
278
          xx2 -= xx1 - warper->x1max;
279
          xx1  = warper->x1max;
280
        }
281
      }
282
283
      if ( xx1 < warper->x1 )
284
        base_distort = warper->x1 - xx1;
285
      else
286
        base_distort = xx1 - warper->x1;
287
288
      if ( xx2 < warper->x2 )
289
        base_distort += warper->x2 - xx2;
290
      else
291
        base_distort += xx2 - warper->x2;
292
293
      base_distort *= 10;
294
295
      new_scale = org_scale + FT_DivFix( w - warper->w0, X2 - X1 );
296
      new_delta = xx1 - FT_MulFix( X1, new_scale );
297
298
      af_warper_compute_line_best( warper, new_scale, new_delta, xx1, xx2,
299
                                   base_distort,
300
                                   segments, num_segments );
301
    }
302
303
    *a_scale = warper->best_scale;
304
    *a_delta = warper->best_delta;
305
  }
306
307
#else /* !AF_USE_WARPER */
308
309
char  af_warper_dummy = 0;  /* make compiler happy */
310
311
#endif /* !AF_USE_WARPER */
312
313
/* END */
(-)freetype-2.1.10.old/src/autofit/afwarp.h (+65 lines)
Line 0 Link Here
1
/***************************************************************************/
2
/*                                                                         */
3
/*  afwarp.h                                                               */
4
/*                                                                         */
5
/*    Auto-fitter warping algorithm (specification).                       */
6
/*                                                                         */
7
/*  Copyright 2006 by                                                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
11
/*  modified, and distributed under the terms of the FreeType project      */
12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13
/*  this file you indicate that you have read the license and              */
14
/*  understand and accept it fully.                                        */
15
/*                                                                         */
16
/***************************************************************************/
17
18
19
#ifndef __AFWARP_H__
20
#define __AFWARP_H__
21
22
#include "afhints.h"
23
24
FT_BEGIN_HEADER
25
26
#define AF_WARPER_SCALE
27
28
#define AF_WARPER_FLOOR( x )  ( (x) & ~63 )
29
#define AF_WARPER_CEIL( x )   AF_WARPER_FLOOR( (x) + 63 )
30
31
32
  typedef FT_Int32  AF_WarpScore;
33
34
  typedef struct  AF_WarperRec_
35
  {
36
    FT_Int        X1, X2;
37
    FT_Pos        x1, x2;
38
    FT_Pos        t1, t2;
39
    FT_Pos        x1min, x1max;
40
    FT_Pos        x2min, x2max;
41
    FT_Pos        w0, wmin, wmax;
42
43
    FT_Fixed      best_scale;
44
    FT_Pos        best_delta;
45
    AF_WarpScore  best_score;
46
    AF_WarpScore  best_distort;
47
48
  } AF_WarperRec, *AF_Warper;
49
50
51
  FT_LOCAL( void )
52
  af_warper_compute( AF_Warper      warper,
53
                     AF_GlyphHints  hints,
54
                     AF_Dimension   dim,
55
                     FT_Fixed      *a_scale,
56
                     FT_Fixed      *a_delta );
57
58
59
FT_END_HEADER
60
61
62
#endif /* __AFWARP_H__ */
63
64
65
/* END */
(-)freetype-2.1.10.old/src/autofit/autofit.c (-1 / +5 lines)
Lines 4-10 Link Here
4
/*                                                                         */
4
/*                                                                         */
5
/*    Auto-fitter module (body).                                           */
5
/*    Auto-fitter module (body).                                           */
6
/*                                                                         */
6
/*                                                                         */
7
/*  Copyright 2003, 2004, 2005 by                                          */
7
/*  Copyright 2003, 2004, 2005, 2006 by                                    */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9
/*                                                                         */
9
/*                                                                         */
10
/*  This file is part of the FreeType project, and may only be used,       */
10
/*  This file is part of the FreeType project, and may only be used,       */
Lines 23-30 Link Here
23
#include "afhints.c"
23
#include "afhints.c"
24
#include "afdummy.c"
24
#include "afdummy.c"
25
#include "aflatin.c"
25
#include "aflatin.c"
26
#include "afcjk.c"
26
#include "afloader.c"
27
#include "afloader.c"
27
#include "afmodule.c"
28
#include "afmodule.c"
28
29
30
#ifdef AF_USE_WARPER
31
#include "afwarp.c"
32
#endif
29
33
30
/* END */
34
/* END */
(-)freetype-2.1.10.old/src/autofit/Jamfile (-2 / +2 lines)
Lines 1-6 Link Here
1
# FreeType 2 src/autofit Jamfile
1
# FreeType 2 src/autofit Jamfile
2
#
2
#
3
# Copyright 2003, 2004, 2005 by
3
# Copyright 2003, 2004, 2005, 2006 by
4
# David Turner, Robert Wilhelm, and Werner Lemberg.
4
# David Turner, Robert Wilhelm, and Werner Lemberg.
5
#
5
#
6
# This file is part of the FreeType project, and may only be used, modified,
6
# This file is part of the FreeType project, and may only be used, modified,
Lines 16-22 Link Here
16
16
17
  if $(FT2_MULTI)
17
  if $(FT2_MULTI)
18
  {
18
  {
19
    _sources = afangles afglobal afhints aflatin afloader afmodule afdummy ;
19
    _sources = afangles afglobal afhints aflatin afloader afmodule afdummy afwarp afcjk;
20
  }
20
  }
21
  else
21
  else
22
  {
22
  {
(-)freetype-2.1.10.old/src/autofit/rules.mk (-2 / +4 lines)
Lines 3-9 Link Here
3
#
3
#
4
4
5
5
6
# Copyright 2003, 2004, 2005 by
6
# Copyright 2003, 2004, 2005, 2006 by
7
# David Turner, Robert Wilhelm, and Werner Lemberg.
7
# David Turner, Robert Wilhelm, and Werner Lemberg.
8
#
8
#
9
# This file is part of the FreeType project, and may only be used, modified,
9
# This file is part of the FreeType project, and may only be used, modified,
Lines 30-37 Link Here
30
                 $(AUTOF_DIR)/afglobal.c \
30
                 $(AUTOF_DIR)/afglobal.c \
31
                 $(AUTOF_DIR)/afhints.c  \
31
                 $(AUTOF_DIR)/afhints.c  \
32
                 $(AUTOF_DIR)/aflatin.c  \
32
                 $(AUTOF_DIR)/aflatin.c  \
33
                 $(AUTOF_DIR)/afcjk.c    \
33
                 $(AUTOF_DIR)/afloader.c \
34
                 $(AUTOF_DIR)/afloader.c \
34
                 $(AUTOF_DIR)/afmodule.c
35
                 $(AUTOF_DIR)/afmodule.c \
36
                 $(AUTOF_DIR)/afwarp.c
35
37
36
# AUTOF driver headers
38
# AUTOF driver headers
37
#
39
#

Return to bug 128760