Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
afcjk.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* afcjk.c */
4 /* */
5 /* Auto-fitter hinting routines for CJK script (body). */
6 /* */
7 /* Copyright 2006-2013 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 <ft2build.h>
26 #include FT_ADVANCES_H
27 #include FT_INTERNAL_DEBUG_H
28 
29 #include "aftypes.h"
30 #include "aflatin.h"
31 
32 
33 #ifdef AF_CONFIG_OPTION_CJK
34 
35 #undef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
36 
37 #include "afcjk.h"
38 #include "aferrors.h"
39 
40 
41 #ifdef AF_CONFIG_OPTION_USE_WARPER
42 #include "afwarp.h"
43 #endif
44 
45 
46  /*************************************************************************/
47  /* */
48  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
49  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
50  /* messages during execution. */
51  /* */
52 #undef FT_COMPONENT
53 #define FT_COMPONENT trace_afcjk
54 
55 
56  /*************************************************************************/
57  /*************************************************************************/
58  /***** *****/
59  /***** C J K G L O B A L M E T R I C S *****/
60  /***** *****/
61  /*************************************************************************/
62  /*************************************************************************/
63 
64 
65  /* Basically the Latin version with AF_CJKMetrics */
66  /* to replace AF_LatinMetrics. */
67 
68  FT_LOCAL_DEF( void )
69  af_cjk_metrics_init_widths( AF_CJKMetrics metrics,
70  FT_Face face )
71  {
72  /* scan the array of segments in each direction */
73  AF_GlyphHintsRec hints[1];
74 
75 
76  af_glyph_hints_init( hints, face->memory );
77 
78  metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
79  metrics->axis[AF_DIMENSION_VERT].width_count = 0;
80 
81  {
83  FT_UInt glyph_index;
84  int dim;
85  AF_CJKMetricsRec dummy[1];
86  AF_Scaler scaler = &dummy->root.scaler;
87 
88 
89  glyph_index = FT_Get_Char_Index( face,
90  metrics->root.clazz->standard_char );
91  if ( glyph_index == 0 )
92  goto Exit;
93 
94  error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
95  if ( error || face->glyph->outline.n_points <= 0 )
96  goto Exit;
97 
98  FT_ZERO( dummy );
99 
100  dummy->units_per_em = metrics->units_per_em;
101 
102  scaler->x_scale = 0x10000L;
103  scaler->y_scale = 0x10000L;
104  scaler->x_delta = 0;
105  scaler->y_delta = 0;
106 
107  scaler->face = face;
109  scaler->flags = 0;
110 
111  af_glyph_hints_rescale( hints, (AF_ScriptMetrics)dummy );
112 
113  error = af_glyph_hints_reload( hints, &face->glyph->outline );
114  if ( error )
115  goto Exit;
116 
117  for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
118  {
119  AF_CJKAxis axis = &metrics->axis[dim];
120  AF_AxisHints axhints = &hints->axis[dim];
121  AF_Segment seg, limit, link;
122  FT_UInt num_widths = 0;
123 
124 
125  error = af_latin_hints_compute_segments( hints, (AF_Dimension)dim );
126  if ( error )
127  goto Exit;
128 
130 
131  seg = axhints->segments;
132  limit = seg + axhints->num_segments;
133 
134  for ( ; seg < limit; seg++ )
135  {
136  link = seg->link;
137 
138  /* we only consider stem segments there! */
139  if ( link && link->link == seg && link > seg )
140  {
141  FT_Pos dist;
142 
143 
144  dist = seg->pos - link->pos;
145  if ( dist < 0 )
146  dist = -dist;
147 
148  if ( num_widths < AF_CJK_MAX_WIDTHS )
149  axis->widths[num_widths++].org = dist;
150  }
151  }
152 
153  /* this also replaces multiple almost identical stem widths */
154  /* with a single one (the value 100 is heuristic) */
155  af_sort_and_quantize_widths( &num_widths, axis->widths,
156  dummy->units_per_em / 100 );
157  axis->width_count = num_widths;
158  }
159 
160  Exit:
161  for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
162  {
163  AF_CJKAxis axis = &metrics->axis[dim];
164  FT_Pos stdw;
165 
166 
167  stdw = ( axis->width_count > 0 ) ? axis->widths[0].org
168  : AF_LATIN_CONSTANT( metrics, 50 );
169 
170  /* let's try 20% of the smallest width */
171  axis->edge_distance_threshold = stdw / 5;
172  axis->standard_width = stdw;
173  axis->extra_light = 0;
174  }
175  }
176 
177  af_glyph_hints_done( hints );
178  }
179 
180 
181 #define AF_CJK_MAX_TEST_CHARACTERS 32
182 
183 
184  /* Each blue zone has two types of fill and unfill, this is, */
185  /* filling the entire glyph square or not. */
186 
187  enum
188  {
189  AF_CJK_BLUE_TYPE_FILL,
190  AF_CJK_BLUE_TYPE_UNFILL,
191  AF_CJK_BLUE_TYPE_MAX
192  };
193 
194 
195  /* Put some common and representative Han Ideographs characters here. */
196  static const FT_ULong af_cjk_hani_blue_chars[AF_CJK_BLUE_MAX]
197  [AF_CJK_BLUE_TYPE_MAX]
198  [AF_CJK_MAX_TEST_CHARACTERS] =
199  {
200  {
201  {
202  0x4ED6, 0x4EEC, 0x4F60, 0x4F86, 0x5011, 0x5230, 0x548C, 0x5730,
203  0x5BF9, 0x5C0D, 0x5C31, 0x5E2D, 0x6211, 0x65F6, 0x6642, 0x6703,
204  0x6765, 0x70BA, 0x80FD, 0x8230, 0x8AAA, 0x8BF4, 0x8FD9, 0x9019,
205  0x9F4A /* top fill */
206  },
207  {
208  0x519B, 0x540C, 0x5DF2, 0x613F, 0x65E2, 0x661F, 0x662F, 0x666F,
209  0x6C11, 0x7167, 0x73B0, 0x73FE, 0x7406, 0x7528, 0x7F6E, 0x8981,
210  0x8ECD, 0x90A3, 0x914D, 0x91CC, 0x958B, 0x96F7, 0x9732, 0x9762,
211  0x987E /* top unfill */
212  }
213  },
214  {
215  {
216  0x4E2A, 0x4E3A, 0x4EBA, 0x4ED6, 0x4EE5, 0x4EEC, 0x4F60, 0x4F86,
217  0x500B, 0x5011, 0x5230, 0x548C, 0x5927, 0x5BF9, 0x5C0D, 0x5C31,
218  0x6211, 0x65F6, 0x6642, 0x6709, 0x6765, 0x70BA, 0x8981, 0x8AAA,
219  0x8BF4 /* bottom fill */
220  },
221  {
222  0x4E3B, 0x4E9B, 0x56E0, 0x5B83, 0x60F3, 0x610F, 0x7406, 0x751F,
223  0x7576, 0x770B, 0x7740, 0x7F6E, 0x8005, 0x81EA, 0x8457, 0x88E1,
224  0x8FC7, 0x8FD8, 0x8FDB, 0x9032, 0x904E, 0x9053, 0x9084, 0x91CC,
225  0x9762 /* bottom unfill */
226  }
227  },
228 #ifndef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
229  { {0x0000}, {0x0000} },
230  { {0x0000}, {0x0000} }
231 #else
232  {
233  {
234  0x4E9B, 0x4EEC, 0x4F60, 0x4F86, 0x5011, 0x5230, 0x548C, 0x5730,
235  0x5979, 0x5C06, 0x5C07, 0x5C31, 0x5E74, 0x5F97, 0x60C5, 0x6700,
236  0x6837, 0x6A23, 0x7406, 0x80FD, 0x8AAA, 0x8BF4, 0x8FD9, 0x9019,
237  0x901A /* left fill */
238  },
239  {
240  0x5373, 0x5417, 0x5427, 0x542C, 0x5462, 0x54C1, 0x54CD, 0x55CE,
241  0x5E08, 0x5E2B, 0x6536, 0x65AD, 0x65B7, 0x660E, 0x773C, 0x9593,
242  0x95F4, 0x9645, 0x9648, 0x9650, 0x9664, 0x9673, 0x968F, 0x969B,
243  0x96A8 /* left unfill */
244  }
245  },
246  {
247  {
248  0x4E8B, 0x524D, 0x5B78, 0x5C06, 0x5C07, 0x60C5, 0x60F3, 0x6216,
249  0x653F, 0x65AF, 0x65B0, 0x6837, 0x6A23, 0x6C11, 0x6C92, 0x6CA1,
250  0x7136, 0x7279, 0x73B0, 0x73FE, 0x7403, 0x7B2C, 0x7D93, 0x8C01,
251  0x8D77 /* right fill */
252  },
253  {
254  0x4F8B, 0x5225, 0x522B, 0x5236, 0x52A8, 0x52D5, 0x5417, 0x55CE,
255  0x589E, 0x6307, 0x660E, 0x671D, 0x671F, 0x6784, 0x7269, 0x786E,
256  0x79CD, 0x8ABF, 0x8C03, 0x8CBB, 0x8D39, 0x90A3, 0x90FD, 0x9593,
257  0x95F4 /* right unfill */
258  }
259  }
260 #endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
261  };
262 
263 
264  /* Calculate blue zones for all the CJK_BLUE_XXX's. */
265 
266  static void
267  af_cjk_metrics_init_blues( AF_CJKMetrics metrics,
268  FT_Face face,
269  const FT_ULong blue_chars
271  [AF_CJK_BLUE_TYPE_MAX]
272  [AF_CJK_MAX_TEST_CHARACTERS] )
273  {
274  FT_Pos fills[AF_CJK_MAX_TEST_CHARACTERS];
275  FT_Pos flats[AF_CJK_MAX_TEST_CHARACTERS];
276 
277  FT_Int num_fills;
278  FT_Int num_flats;
279 
280  FT_Int bb;
282  FT_Error error;
283  AF_CJKAxis axis;
284  FT_GlyphSlot glyph = face->glyph;
285 
286 #ifdef FT_DEBUG_LEVEL_TRACE
287  FT_String* cjk_blue_name[AF_CJK_BLUE_MAX] = {
288  (FT_String*)"top",
289  (FT_String*)"bottom",
290  (FT_String*)"left",
291  (FT_String*)"right"
292  };
293  FT_String* cjk_blue_type_name[AF_CJK_BLUE_TYPE_MAX] = {
294  (FT_String*)"filled",
295  (FT_String*)"unfilled"
296  };
297 #endif
298 
299 
300  /* We compute the blues simply by loading each character from the */
301  /* `blue_chars[blues]' string, then computing its extreme points */
302  /* (depending blue zone type etc.). */
303 
304  FT_TRACE5(( "cjk blue zones computation\n" ));
305  FT_TRACE5(( "------------------------------------------------\n" ));
306 
307  for ( bb = 0; bb < AF_CJK_BLUE_MAX; bb++ )
308  {
309  FT_Int fill_type;
310  FT_Pos* blue_ref;
311  FT_Pos* blue_shoot;
312 
313 
314  num_fills = 0;
315  num_flats = 0;
316 
317  for ( fill_type = 0; fill_type < AF_CJK_BLUE_TYPE_MAX; fill_type++ )
318  {
319  const FT_ULong* p = blue_chars[bb][fill_type];
320  const FT_ULong* limit = p + AF_CJK_MAX_TEST_CHARACTERS;
321  FT_Bool fill = FT_BOOL(
322  fill_type == AF_CJK_BLUE_TYPE_FILL );
323 
324 
325  FT_TRACE5(( "cjk blue %s/%s\n", cjk_blue_name[bb],
326  cjk_blue_type_name[fill_type] ));
327 
328 
329  for ( ; p < limit && *p; p++ )
330  {
331  FT_UInt glyph_index;
332  FT_Pos best_pos; /* same as points.y */
333  FT_Int best_point;
334  FT_Vector* points;
335 
336 
337  FT_TRACE5(( " U+%lX...", *p ));
338 
339  /* load the character in the face -- skip unknown or empty ones */
340  glyph_index = FT_Get_Char_Index( face, *p );
341  if ( glyph_index == 0 )
342  {
343  FT_TRACE5(( "unavailable\n" ));
344  continue;
345  }
346 
347  error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
348  if ( error || glyph->outline.n_points <= 0 )
349  {
350  FT_TRACE5(( "no outline\n" ));
351  continue;
352  }
353 
354  /* now compute min or max point indices and coordinates */
355  points = glyph->outline.points;
356  best_point = -1;
357  best_pos = 0; /* make compiler happy */
358 
359  {
360  FT_Int nn;
361  FT_Int first = 0;
362  FT_Int last = -1;
363 
364 
365  for ( nn = 0;
366  nn < glyph->outline.n_contours;
367  first = last + 1, nn++ )
368  {
369  FT_Int pp;
370 
371 
372  last = glyph->outline.contours[nn];
373 
374  /* Avoid single-point contours since they are never */
375  /* rasterized. In some fonts, they correspond to mark */
376  /* attachment points which are way outside of the glyph's */
377  /* real outline. */
378  if ( last <= first )
379  continue;
380 
381  switch ( bb )
382  {
383  case AF_CJK_BLUE_TOP:
384  for ( pp = first; pp <= last; pp++ )
385  if ( best_point < 0 || points[pp].y > best_pos )
386  {
387  best_point = pp;
388  best_pos = points[pp].y;
389  }
390  break;
391 
392  case AF_CJK_BLUE_BOTTOM:
393  for ( pp = first; pp <= last; pp++ )
394  if ( best_point < 0 || points[pp].y < best_pos )
395  {
396  best_point = pp;
397  best_pos = points[pp].y;
398  }
399  break;
400 
401  case AF_CJK_BLUE_LEFT:
402  for ( pp = first; pp <= last; pp++ )
403  if ( best_point < 0 || points[pp].x < best_pos )
404  {
405  best_point = pp;
406  best_pos = points[pp].x;
407  }
408  break;
409 
410  case AF_CJK_BLUE_RIGHT:
411  for ( pp = first; pp <= last; pp++ )
412  if ( best_point < 0 || points[pp].x > best_pos )
413  {
414  best_point = pp;
415  best_pos = points[pp].x;
416  }
417  break;
418 
419  default:
420  ;
421  }
422  }
423  FT_TRACE5(( "best_pos=%5ld\n", best_pos ));
424  }
425 
426  if ( fill )
427  fills[num_fills++] = best_pos;
428  else
429  flats[num_flats++] = best_pos;
430  }
431  }
432 
433  if ( num_flats == 0 && num_fills == 0 )
434  {
435  /*
436  * we couldn't find a single glyph to compute this blue zone,
437  * we will simply ignore it then
438  */
439  FT_TRACE5(( "empty\n" ));
440  continue;
441  }
442 
443  /* we have computed the contents of the `fill' and `flats' tables, */
444  /* now determine the reference position of the blue -- */
445  /* we simply take the median value after a simple sort */
446  af_sort_pos( num_flats, flats );
447  af_sort_pos( num_fills, fills );
448 
449  if ( AF_CJK_BLUE_TOP == bb || AF_CJK_BLUE_BOTTOM == bb )
450  axis = &metrics->axis[AF_DIMENSION_VERT];
451  else
452  axis = &metrics->axis[AF_DIMENSION_HORZ];
453 
454  blue = & axis->blues[axis->blue_count];
455  blue_ref = & blue->ref.org;
456  blue_shoot = & blue->shoot.org;
457 
458  axis->blue_count++;
459  if ( num_flats == 0 )
460  {
461  *blue_ref = fills[num_fills / 2];
462  *blue_shoot = fills[num_fills / 2];
463  }
464  else if ( num_fills == 0 )
465  {
466  *blue_ref = flats[num_flats / 2];
467  *blue_shoot = flats[num_flats / 2];
468  }
469  else
470  {
471  *blue_ref = fills[num_fills / 2];
472  *blue_shoot = flats[num_flats / 2];
473  }
474 
475  /* make sure blue_ref >= blue_shoot for top/right or */
476  /* vice versa for bottom/left */
477  if ( *blue_shoot != *blue_ref )
478  {
479  FT_Pos ref = *blue_ref;
480  FT_Pos shoot = *blue_shoot;
481  FT_Bool under_ref = FT_BOOL( shoot < ref );
482 
483 
484  if ( ( AF_CJK_BLUE_TOP == bb ||
485  AF_CJK_BLUE_RIGHT == bb ) ^ under_ref )
486  *blue_shoot = *blue_ref = ( shoot + ref ) / 2;
487  }
488 
489  blue->flags = 0;
490  if ( AF_CJK_BLUE_TOP == bb )
491  blue->flags |= AF_CJK_BLUE_IS_TOP;
492  else if ( AF_CJK_BLUE_RIGHT == bb )
493  blue->flags |= AF_CJK_BLUE_IS_RIGHT;
494 
495  FT_TRACE5(( "-- cjk %s bluezone ref = %ld shoot = %ld\n",
496  cjk_blue_name[bb], *blue_ref, *blue_shoot ));
497  }
498 
499  return;
500  }
501 
502 
503  /* Basically the Latin version with type AF_CJKMetrics for metrics. */
504  FT_LOCAL_DEF( void )
505  af_cjk_metrics_check_digits( AF_CJKMetrics metrics,
506  FT_Face face )
507  {
508  FT_UInt i;
509  FT_Bool started = 0, same_width = 1;
510  FT_Fixed advance, old_advance = 0;
511 
512 
513  /* check whether all ASCII digits have the same advance width; */
514  /* digit `0' is 0x30 in all supported charmaps */
515  for ( i = 0x30; i <= 0x39; i++ )
516  {
517  FT_UInt glyph_index;
518 
519 
520  glyph_index = FT_Get_Char_Index( face, i );
521  if ( glyph_index == 0 )
522  continue;
523 
524  if ( FT_Get_Advance( face, glyph_index,
528  &advance ) )
529  continue;
530 
531  if ( started )
532  {
533  if ( advance != old_advance )
534  {
535  same_width = 0;
536  break;
537  }
538  }
539  else
540  {
541  old_advance = advance;
542  started = 1;
543  }
544  }
545 
546  metrics->root.digits_have_same_width = same_width;
547  }
548 
549 
551  af_cjk_metrics_init( AF_CJKMetrics metrics,
552  FT_Face face )
553  {
554  FT_CharMap oldmap = face->charmap;
555 
556 
557  metrics->units_per_em = face->units_per_EM;
558 
559  if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
560  face->charmap = NULL;
561  else
562  {
563  af_cjk_metrics_init_widths( metrics, face );
564  af_cjk_metrics_init_blues( metrics, face, af_cjk_hani_blue_chars );
565  af_cjk_metrics_check_digits( metrics, face );
566  }
567 
568  FT_Set_Charmap( face, oldmap );
569 
570  return FT_Err_Ok;
571  }
572 
573 
574  static void
575  af_cjk_metrics_scale_dim( AF_CJKMetrics metrics,
576  AF_Scaler scaler,
577  AF_Dimension dim )
578  {
579  FT_Fixed scale;
580  FT_Pos delta;
581  AF_CJKAxis axis;
582  FT_UInt nn;
583 
584 
585  axis = &metrics->axis[dim];
586 
587  if ( dim == AF_DIMENSION_HORZ )
588  {
589  scale = scaler->x_scale;
590  delta = scaler->x_delta;
591  }
592  else
593  {
594  scale = scaler->y_scale;
595  delta = scaler->y_delta;
596  }
597 
598  if ( axis->org_scale == scale && axis->org_delta == delta )
599  return;
600 
601  axis->org_scale = scale;
602  axis->org_delta = delta;
603 
604  axis->scale = scale;
605  axis->delta = delta;
606 
607  /* scale the blue zones */
608  for ( nn = 0; nn < axis->blue_count; nn++ )
609  {
610  AF_CJKBlue blue = &axis->blues[nn];
611  FT_Pos dist;
612 
613 
614  blue->ref.cur = FT_MulFix( blue->ref.org, scale ) + delta;
615  blue->ref.fit = blue->ref.cur;
616  blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta;
617  blue->shoot.fit = blue->shoot.cur;
618  blue->flags &= ~AF_CJK_BLUE_ACTIVE;
619 
620  /* a blue zone is only active if it is less than 3/4 pixels tall */
621  dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
622  if ( dist <= 48 && dist >= -48 )
623  {
624  FT_Pos delta1, delta2;
625 
626 
627  blue->ref.fit = FT_PIX_ROUND( blue->ref.cur );
628 
629  /* shoot is under shoot for cjk */
630  delta1 = FT_DivFix( blue->ref.fit, scale ) - blue->shoot.org;
631  delta2 = delta1;
632  if ( delta1 < 0 )
633  delta2 = -delta2;
634 
635  delta2 = FT_MulFix( delta2, scale );
636 
637  FT_TRACE5(( "delta: %d", delta1 ));
638  if ( delta2 < 32 )
639  delta2 = 0;
640 #if 0
641  else if ( delta2 < 64 )
642  delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
643 #endif
644  else
645  delta2 = FT_PIX_ROUND( delta2 );
646  FT_TRACE5(( "/%d\n", delta2 ));
647 
648  if ( delta1 < 0 )
649  delta2 = -delta2;
650 
651  blue->shoot.fit = blue->ref.fit - delta2;
652 
653  FT_TRACE5(( ">> active cjk blue zone %c%d[%ld/%ld]: "
654  "ref: cur=%.2f fit=%.2f shoot: cur=%.2f fit=%.2f\n",
655  ( dim == AF_DIMENSION_HORZ ) ? 'H' : 'V',
656  nn, blue->ref.org, blue->shoot.org,
657  blue->ref.cur / 64.0, blue->ref.fit / 64.0,
658  blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
659 
660  blue->flags |= AF_CJK_BLUE_ACTIVE;
661  }
662  }
663  }
664 
665 
666  FT_LOCAL_DEF( void )
667  af_cjk_metrics_scale( AF_CJKMetrics metrics,
668  AF_Scaler scaler )
669  {
670  metrics->root.scaler = *scaler;
671 
672  af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
673  af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
674  }
675 
676 
677  /*************************************************************************/
678  /*************************************************************************/
679  /***** *****/
680  /***** C J K G L Y P H A N A L Y S I S *****/
681  /***** *****/
682  /*************************************************************************/
683  /*************************************************************************/
684 
685  static FT_Error
686  af_cjk_hints_compute_segments( AF_GlyphHints hints,
687  AF_Dimension dim )
688  {
689  AF_AxisHints axis = &hints->axis[dim];
690  AF_Segment segments = axis->segments;
691  AF_Segment segment_limit = segments + axis->num_segments;
692  FT_Error error;
693  AF_Segment seg;
694 
695 
696  error = af_latin_hints_compute_segments( hints, dim );
697  if ( error )
698  return error;
699 
700  /* a segment is round if it doesn't have successive */
701  /* on-curve points. */
702  for ( seg = segments; seg < segment_limit; seg++ )
703  {
704  AF_Point pt = seg->first;
705  AF_Point last = seg->last;
706  AF_Flags f0 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
707  AF_Flags f1;
708 
709 
710  seg->flags &= ~AF_EDGE_ROUND;
711 
712  for ( ; pt != last; f0 = f1 )
713  {
714  pt = pt->next;
715  f1 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
716 
717  if ( !f0 && !f1 )
718  break;
719 
720  if ( pt == last )
721  seg->flags |= AF_EDGE_ROUND;
722  }
723  }
724 
725  return FT_Err_Ok;
726  }
727 
728 
729  static void
730  af_cjk_hints_link_segments( AF_GlyphHints hints,
731  AF_Dimension dim )
732  {
733  AF_AxisHints axis = &hints->axis[dim];
734  AF_Segment segments = axis->segments;
735  AF_Segment segment_limit = segments + axis->num_segments;
736  AF_Direction major_dir = axis->major_dir;
737  AF_Segment seg1, seg2;
738  FT_Pos len_threshold;
739  FT_Pos dist_threshold;
740 
741 
742  len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
743 
744  dist_threshold = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
745  : hints->y_scale;
746  dist_threshold = FT_DivFix( 64 * 3, dist_threshold );
747 
748  /* now compare each segment to the others */
749  for ( seg1 = segments; seg1 < segment_limit; seg1++ )
750  {
751  /* the fake segments are for metrics hinting only */
752  if ( seg1->first == seg1->last )
753  continue;
754 
755  if ( seg1->dir != major_dir )
756  continue;
757 
758  for ( seg2 = segments; seg2 < segment_limit; seg2++ )
759  if ( seg2 != seg1 && seg1->dir + seg2->dir == 0 )
760  {
761  FT_Pos dist = seg2->pos - seg1->pos;
762 
763 
764  if ( dist < 0 )
765  continue;
766 
767  {
768  FT_Pos min = seg1->min_coord;
769  FT_Pos max = seg1->max_coord;
770  FT_Pos len;
771 
772 
773  if ( min < seg2->min_coord )
774  min = seg2->min_coord;
775 
776  if ( max > seg2->max_coord )
777  max = seg2->max_coord;
778 
779  len = max - min;
780  if ( len >= len_threshold )
781  {
782  if ( dist * 8 < seg1->score * 9 &&
783  ( dist * 8 < seg1->score * 7 || seg1->len < len ) )
784  {
785  seg1->score = dist;
786  seg1->len = len;
787  seg1->link = seg2;
788  }
789 
790  if ( dist * 8 < seg2->score * 9 &&
791  ( dist * 8 < seg2->score * 7 || seg2->len < len ) )
792  {
793  seg2->score = dist;
794  seg2->len = len;
795  seg2->link = seg1;
796  }
797  }
798  }
799  }
800  }
801 
802  /*
803  * now compute the `serif' segments
804  *
805  * In Hanzi, some strokes are wider on one or both of the ends.
806  * We either identify the stems on the ends as serifs or remove
807  * the linkage, depending on the length of the stems.
808  *
809  */
810 
811  {
812  AF_Segment link1, link2;
813 
814 
815  for ( seg1 = segments; seg1 < segment_limit; seg1++ )
816  {
817  link1 = seg1->link;
818  if ( !link1 || link1->link != seg1 || link1->pos <= seg1->pos )
819  continue;
820 
821  if ( seg1->score >= dist_threshold )
822  continue;
823 
824  for ( seg2 = segments; seg2 < segment_limit; seg2++ )
825  {
826  if ( seg2->pos > seg1->pos || seg1 == seg2 )
827  continue;
828 
829  link2 = seg2->link;
830  if ( !link2 || link2->link != seg2 || link2->pos < link1->pos )
831  continue;
832 
833  if ( seg1->pos == seg2->pos && link1->pos == link2->pos )
834  continue;
835 
836  if ( seg2->score <= seg1->score || seg1->score * 4 <= seg2->score )
837  continue;
838 
839  /* seg2 < seg1 < link1 < link2 */
840 
841  if ( seg1->len >= seg2->len * 3 )
842  {
843  AF_Segment seg;
844 
845 
846  for ( seg = segments; seg < segment_limit; seg++ )
847  {
848  AF_Segment link = seg->link;
849 
850 
851  if ( link == seg2 )
852  {
853  seg->link = 0;
854  seg->serif = link1;
855  }
856  else if ( link == link2 )
857  {
858  seg->link = 0;
859  seg->serif = seg1;
860  }
861  }
862  }
863  else
864  {
865  seg1->link = link1->link = 0;
866 
867  break;
868  }
869  }
870  }
871  }
872 
873  for ( seg1 = segments; seg1 < segment_limit; seg1++ )
874  {
875  seg2 = seg1->link;
876 
877  if ( seg2 )
878  {
879  seg2->num_linked++;
880  if ( seg2->link != seg1 )
881  {
882  seg1->link = 0;
883 
884  if ( seg2->score < dist_threshold || seg1->score < seg2->score * 4 )
885  seg1->serif = seg2->link;
886  else
887  seg2->num_linked--;
888  }
889  }
890  }
891  }
892 
893 
894  static FT_Error
895  af_cjk_hints_compute_edges( AF_GlyphHints hints,
896  AF_Dimension dim )
897  {
898  AF_AxisHints axis = &hints->axis[dim];
899  FT_Error error = FT_Err_Ok;
900  FT_Memory memory = hints->memory;
901  AF_CJKAxis laxis = &((AF_CJKMetrics)hints->metrics)->axis[dim];
902 
903  AF_Segment segments = axis->segments;
904  AF_Segment segment_limit = segments + axis->num_segments;
905  AF_Segment seg;
906 
907  FT_Fixed scale;
908  FT_Pos edge_distance_threshold;
909 
910 
911  axis->num_edges = 0;
912 
913  scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
914  : hints->y_scale;
915 
916  /*********************************************************************/
917  /* */
918  /* We begin by generating a sorted table of edges for the current */
919  /* direction. To do so, we simply scan each segment and try to find */
920  /* an edge in our table that corresponds to its position. */
921  /* */
922  /* If no edge is found, we create and insert a new edge in the */
923  /* sorted table. Otherwise, we simply add the segment to the edge's */
924  /* list which is then processed in the second step to compute the */
925  /* edge's properties. */
926  /* */
927  /* Note that the edges table is sorted along the segment/edge */
928  /* position. */
929  /* */
930  /*********************************************************************/
931 
932  edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
933  scale );
934  if ( edge_distance_threshold > 64 / 4 )
935  edge_distance_threshold = FT_DivFix( 64 / 4, scale );
936  else
937  edge_distance_threshold = laxis->edge_distance_threshold;
938 
939  for ( seg = segments; seg < segment_limit; seg++ )
940  {
941  AF_Edge found = 0;
942  FT_Pos best = 0xFFFFU;
943  FT_Int ee;
944 
945 
946  /* look for an edge corresponding to the segment */
947  for ( ee = 0; ee < axis->num_edges; ee++ )
948  {
949  AF_Edge edge = axis->edges + ee;
950  FT_Pos dist;
951 
952 
953  if ( edge->dir != seg->dir )
954  continue;
955 
956  dist = seg->pos - edge->fpos;
957  if ( dist < 0 )
958  dist = -dist;
959 
960  if ( dist < edge_distance_threshold && dist < best )
961  {
962  AF_Segment link = seg->link;
963 
964 
965  /* check whether all linked segments of the candidate edge */
966  /* can make a single edge. */
967  if ( link )
968  {
969  AF_Segment seg1 = edge->first;
970  AF_Segment link1;
971  FT_Pos dist2 = 0;
972 
973 
974  do
975  {
976  link1 = seg1->link;
977  if ( link1 )
978  {
979  dist2 = AF_SEGMENT_DIST( link, link1 );
980  if ( dist2 >= edge_distance_threshold )
981  break;
982  }
983 
984  } while ( ( seg1 = seg1->edge_next ) != edge->first );
985 
986  if ( dist2 >= edge_distance_threshold )
987  continue;
988  }
989 
990  best = dist;
991  found = edge;
992  }
993  }
994 
995  if ( !found )
996  {
997  AF_Edge edge;
998 
999 
1000  /* insert a new edge in the list and */
1001  /* sort according to the position */
1002  error = af_axis_hints_new_edge( axis, seg->pos,
1003  (AF_Direction)seg->dir,
1004  memory, &edge );
1005  if ( error )
1006  goto Exit;
1007 
1008  /* add the segment to the new edge's list */
1009  FT_ZERO( edge );
1010 
1011  edge->first = seg;
1012  edge->last = seg;
1013  edge->fpos = seg->pos;
1014  edge->opos = edge->pos = FT_MulFix( seg->pos, scale );
1015  seg->edge_next = seg;
1016  edge->dir = seg->dir;
1017  }
1018  else
1019  {
1020  /* if an edge was found, simply add the segment to the edge's */
1021  /* list */
1022  seg->edge_next = found->first;
1023  found->last->edge_next = seg;
1024  found->last = seg;
1025  }
1026  }
1027 
1028  /*********************************************************************/
1029  /* */
1030  /* Good, we now compute each edge's properties according to segments */
1031  /* found on its position. Basically, these are as follows. */
1032  /* */
1033  /* - edge's main direction */
1034  /* - stem edge, serif edge or both (which defaults to stem then) */
1035  /* - rounded edge, straight or both (which defaults to straight) */
1036  /* - link for edge */
1037  /* */
1038  /*********************************************************************/
1039 
1040  /* first of all, set the `edge' field in each segment -- this is */
1041  /* required in order to compute edge links */
1042  /* */
1043  /* Note that removing this loop and setting the `edge' field of each */
1044  /* segment directly in the code above slows down execution speed for */
1045  /* some reasons on platforms like the Sun. */
1046 
1047  {
1048  AF_Edge edges = axis->edges;
1049  AF_Edge edge_limit = edges + axis->num_edges;
1050  AF_Edge edge;
1051 
1052 
1053  for ( edge = edges; edge < edge_limit; edge++ )
1054  {
1055  seg = edge->first;
1056  if ( seg )
1057  do
1058  {
1059  seg->edge = edge;
1060  seg = seg->edge_next;
1061 
1062  } while ( seg != edge->first );
1063  }
1064 
1065  /* now compute each edge properties */
1066  for ( edge = edges; edge < edge_limit; edge++ )
1067  {
1068  FT_Int is_round = 0; /* does it contain round segments? */
1069  FT_Int is_straight = 0; /* does it contain straight segments? */
1070 
1071 
1072  seg = edge->first;
1073 
1074  do
1075  {
1076  FT_Bool is_serif;
1077 
1078 
1079  /* check for roundness of segment */
1080  if ( seg->flags & AF_EDGE_ROUND )
1081  is_round++;
1082  else
1083  is_straight++;
1084 
1085  /* check for links -- if seg->serif is set, then seg->link must */
1086  /* be ignored */
1087  is_serif = (FT_Bool)( seg->serif && seg->serif->edge != edge );
1088 
1089  if ( seg->link || is_serif )
1090  {
1091  AF_Edge edge2;
1092  AF_Segment seg2;
1093 
1094 
1095  edge2 = edge->link;
1096  seg2 = seg->link;
1097 
1098  if ( is_serif )
1099  {
1100  seg2 = seg->serif;
1101  edge2 = edge->serif;
1102  }
1103 
1104  if ( edge2 )
1105  {
1106  FT_Pos edge_delta;
1107  FT_Pos seg_delta;
1108 
1109 
1110  edge_delta = edge->fpos - edge2->fpos;
1111  if ( edge_delta < 0 )
1112  edge_delta = -edge_delta;
1113 
1114  seg_delta = AF_SEGMENT_DIST( seg, seg2 );
1115 
1116  if ( seg_delta < edge_delta )
1117  edge2 = seg2->edge;
1118  }
1119  else
1120  edge2 = seg2->edge;
1121 
1122  if ( is_serif )
1123  {
1124  edge->serif = edge2;
1125  edge2->flags |= AF_EDGE_SERIF;
1126  }
1127  else
1128  edge->link = edge2;
1129  }
1130 
1131  seg = seg->edge_next;
1132 
1133  } while ( seg != edge->first );
1134 
1135  /* set the round/straight flags */
1136  edge->flags = AF_EDGE_NORMAL;
1137 
1138  if ( is_round > 0 && is_round >= is_straight )
1139  edge->flags |= AF_EDGE_ROUND;
1140 
1141  /* get rid of serifs if link is set */
1142  /* XXX: This gets rid of many unpleasant artefacts! */
1143  /* Example: the `c' in cour.pfa at size 13 */
1144 
1145  if ( edge->serif && edge->link )
1146  edge->serif = 0;
1147  }
1148  }
1149 
1150  Exit:
1151  return error;
1152  }
1153 
1154 
1155  static FT_Error
1156  af_cjk_hints_detect_features( AF_GlyphHints hints,
1157  AF_Dimension dim )
1158  {
1159  FT_Error error;
1160 
1161 
1162  error = af_cjk_hints_compute_segments( hints, dim );
1163  if ( !error )
1164  {
1165  af_cjk_hints_link_segments( hints, dim );
1166 
1167  error = af_cjk_hints_compute_edges( hints, dim );
1168  }
1169  return error;
1170  }
1171 
1172 
1173  FT_LOCAL_DEF( void )
1174  af_cjk_hints_compute_blue_edges( AF_GlyphHints hints,
1175  AF_CJKMetrics metrics,
1176  AF_Dimension dim )
1177  {
1178  AF_AxisHints axis = &hints->axis[dim];
1179  AF_Edge edge = axis->edges;
1180  AF_Edge edge_limit = edge + axis->num_edges;
1181  AF_CJKAxis cjk = &metrics->axis[dim];
1182  FT_Fixed scale = cjk->scale;
1183  FT_Pos best_dist0; /* initial threshold */
1184 
1185 
1186  /* compute the initial threshold as a fraction of the EM size */
1187  best_dist0 = FT_MulFix( metrics->units_per_em / 40, scale );
1188 
1189  if ( best_dist0 > 64 / 2 ) /* maximum 1/2 pixel */
1190  best_dist0 = 64 / 2;
1191 
1192  /* compute which blue zones are active, i.e. have their scaled */
1193  /* size < 3/4 pixels */
1194 
1195  /* If the distant between an edge and a blue zone is shorter than */
1196  /* best_dist0, set the blue zone for the edge. Then search for */
1197  /* the blue zone with the smallest best_dist to the edge. */
1198 
1199  for ( ; edge < edge_limit; edge++ )
1200  {
1201  FT_UInt bb;
1202  AF_Width best_blue = NULL;
1203  FT_Pos best_dist = best_dist0;
1204 
1205 
1206  for ( bb = 0; bb < cjk->blue_count; bb++ )
1207  {
1208  AF_CJKBlue blue = cjk->blues + bb;
1209  FT_Bool is_top_right_blue, is_major_dir;
1210 
1211 
1212  /* skip inactive blue zones (i.e., those that are too small) */
1213  if ( !( blue->flags & AF_CJK_BLUE_ACTIVE ) )
1214  continue;
1215 
1216  /* if it is a top zone, check for right edges -- if it is a bottom */
1217  /* zone, check for left edges */
1218  /* */
1219  /* of course, that's for TrueType */
1220  is_top_right_blue =
1221  FT_BOOL( ( ( blue->flags & AF_CJK_BLUE_IS_TOP ) != 0 ) ||
1222  ( ( blue->flags & AF_CJK_BLUE_IS_RIGHT ) != 0 ) );
1223  is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
1224 
1225  /* if it is a top zone, the edge must be against the major */
1226  /* direction; if it is a bottom zone, it must be in the major */
1227  /* direction */
1228  if ( is_top_right_blue ^ is_major_dir )
1229  {
1230  FT_Pos dist;
1231  AF_Width compare;
1232 
1233 
1234  /* Compare the edge to the closest blue zone type */
1235  if ( FT_ABS( edge->fpos - blue->ref.org ) >
1236  FT_ABS( edge->fpos - blue->shoot.org ) )
1237  compare = &blue->shoot;
1238  else
1239  compare = &blue->ref;
1240 
1241  dist = edge->fpos - compare->org;
1242  if ( dist < 0 )
1243  dist = -dist;
1244 
1245  dist = FT_MulFix( dist, scale );
1246  if ( dist < best_dist )
1247  {
1248  best_dist = dist;
1249  best_blue = compare;
1250  }
1251  }
1252  }
1253 
1254  if ( best_blue )
1255  edge->blue_edge = best_blue;
1256  }
1257  }
1258 
1259 
1261  af_cjk_hints_init( AF_GlyphHints hints,
1262  AF_CJKMetrics metrics )
1263  {
1265  FT_UInt32 scaler_flags, other_flags;
1266 
1267 
1268  af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
1269 
1270  /*
1271  * correct x_scale and y_scale when needed, since they may have
1272  * been modified af_cjk_scale_dim above
1273  */
1274  hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
1275  hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
1276  hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
1277  hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
1278 
1279  /* compute flags depending on render mode, etc. */
1280  mode = metrics->root.scaler.render_mode;
1281 
1282 #ifdef AF_CONFIG_OPTION_USE_WARPER
1283  if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
1284  metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
1285 #endif
1286 
1287  scaler_flags = hints->scaler_flags;
1288  other_flags = 0;
1289 
1290  /*
1291  * We snap the width of vertical stems for the monochrome and
1292  * horizontal LCD rendering targets only.
1293  */
1294  if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
1295  other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
1296 
1297  /*
1298  * We snap the width of horizontal stems for the monochrome and
1299  * vertical LCD rendering targets only.
1300  */
1301  if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
1302  other_flags |= AF_LATIN_HINTS_VERT_SNAP;
1303 
1304  /*
1305  * We adjust stems to full pixels only if we don't use the `light' mode.
1306  */
1307  if ( mode != FT_RENDER_MODE_LIGHT )
1308  other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
1309 
1310  if ( mode == FT_RENDER_MODE_MONO )
1311  other_flags |= AF_LATIN_HINTS_MONO;
1312 
1313  scaler_flags |= AF_SCALER_FLAG_NO_ADVANCE;
1314 
1315  hints->scaler_flags = scaler_flags;
1316  hints->other_flags = other_flags;
1317 
1318  return 0;
1319  }
1320 
1321 
1322  /*************************************************************************/
1323  /*************************************************************************/
1324  /***** *****/
1325  /***** C J K G L Y P H G R I D - F I T T I N G *****/
1326  /***** *****/
1327  /*************************************************************************/
1328  /*************************************************************************/
1329 
1330  /* snap a given width in scaled coordinates to one of the */
1331  /* current standard widths */
1332 
1333  static FT_Pos
1334  af_cjk_snap_width( AF_Width widths,
1335  FT_Int count,
1336  FT_Pos width )
1337  {
1338  int n;
1339  FT_Pos best = 64 + 32 + 2;
1341  FT_Pos scaled;
1342 
1343 
1344  for ( n = 0; n < count; n++ )
1345  {
1346  FT_Pos w;
1347  FT_Pos dist;
1348 
1349 
1350  w = widths[n].cur;
1351  dist = width - w;
1352  if ( dist < 0 )
1353  dist = -dist;
1354  if ( dist < best )
1355  {
1356  best = dist;
1357  reference = w;
1358  }
1359  }
1360 
1361  scaled = FT_PIX_ROUND( reference );
1362 
1363  if ( width >= reference )
1364  {
1365  if ( width < scaled + 48 )
1366  width = reference;
1367  }
1368  else
1369  {
1370  if ( width > scaled - 48 )
1371  width = reference;
1372  }
1373 
1374  return width;
1375  }
1376 
1377 
1378  /* compute the snapped width of a given stem */
1379 
1380  static FT_Pos
1381  af_cjk_compute_stem_width( AF_GlyphHints hints,
1382  AF_Dimension dim,
1383  FT_Pos width,
1384  AF_Edge_Flags base_flags,
1385  AF_Edge_Flags stem_flags )
1386  {
1387  AF_CJKMetrics metrics = (AF_CJKMetrics) hints->metrics;
1388  AF_CJKAxis axis = & metrics->axis[dim];
1389  FT_Pos dist = width;
1390  FT_Int sign = 0;
1391  FT_Bool vertical = FT_BOOL( dim == AF_DIMENSION_VERT );
1392 
1393  FT_UNUSED( base_flags );
1394  FT_UNUSED( stem_flags );
1395 
1396 
1397  if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1398  return width;
1399 
1400  if ( dist < 0 )
1401  {
1402  dist = -width;
1403  sign = 1;
1404  }
1405 
1406  if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
1407  ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
1408  {
1409  /* smooth hinting process: very lightly quantize the stem width */
1410 
1411  if ( axis->width_count > 0 )
1412  {
1413  if ( FT_ABS( dist - axis->widths[0].cur ) < 40 )
1414  {
1415  dist = axis->widths[0].cur;
1416  if ( dist < 48 )
1417  dist = 48;
1418 
1419  goto Done_Width;
1420  }
1421  }
1422 
1423  if ( dist < 54 )
1424  dist += ( 54 - dist ) / 2 ;
1425  else if ( dist < 3 * 64 )
1426  {
1427  FT_Pos delta;
1428 
1429 
1430  delta = dist & 63;
1431  dist &= -64;
1432 
1433  if ( delta < 10 )
1434  dist += delta;
1435  else if ( delta < 22 )
1436  dist += 10;
1437  else if ( delta < 42 )
1438  dist += delta;
1439  else if ( delta < 54 )
1440  dist += 54;
1441  else
1442  dist += delta;
1443  }
1444  }
1445  else
1446  {
1447  /* strong hinting process: snap the stem width to integer pixels */
1448 
1449  dist = af_cjk_snap_width( axis->widths, axis->width_count, dist );
1450 
1451  if ( vertical )
1452  {
1453  /* in the case of vertical hinting, always round */
1454  /* the stem heights to integer pixels */
1455 
1456  if ( dist >= 64 )
1457  dist = ( dist + 16 ) & ~63;
1458  else
1459  dist = 64;
1460  }
1461  else
1462  {
1463  if ( AF_LATIN_HINTS_DO_MONO( hints ) )
1464  {
1465  /* monochrome horizontal hinting: snap widths to integer pixels */
1466  /* with a different threshold */
1467 
1468  if ( dist < 64 )
1469  dist = 64;
1470  else
1471  dist = ( dist + 32 ) & ~63;
1472  }
1473  else
1474  {
1475  /* for horizontal anti-aliased hinting, we adopt a more subtle */
1476  /* approach: we strengthen small stems, round stems whose size */
1477  /* is between 1 and 2 pixels to an integer, otherwise nothing */
1478 
1479  if ( dist < 48 )
1480  dist = ( dist + 64 ) >> 1;
1481 
1482  else if ( dist < 128 )
1483  dist = ( dist + 22 ) & ~63;
1484  else
1485  /* round otherwise to prevent color fringes in LCD mode */
1486  dist = ( dist + 32 ) & ~63;
1487  }
1488  }
1489  }
1490 
1491  Done_Width:
1492  if ( sign )
1493  dist = -dist;
1494 
1495  return dist;
1496  }
1497 
1498 
1499  /* align one stem edge relative to the previous stem edge */
1500 
1501  static void
1502  af_cjk_align_linked_edge( AF_GlyphHints hints,
1503  AF_Dimension dim,
1504  AF_Edge base_edge,
1505  AF_Edge stem_edge )
1506  {
1507  FT_Pos dist = stem_edge->opos - base_edge->opos;
1508 
1509  FT_Pos fitted_width = af_cjk_compute_stem_width(
1510  hints, dim, dist,
1511  (AF_Edge_Flags)base_edge->flags,
1512  (AF_Edge_Flags)stem_edge->flags );
1513 
1514 
1515  stem_edge->pos = base_edge->pos + fitted_width;
1516  }
1517 
1518 
1519  static void
1520  af_cjk_align_serif_edge( AF_GlyphHints hints,
1521  AF_Edge base,
1522  AF_Edge serif )
1523  {
1524  FT_UNUSED( hints );
1525 
1526  serif->pos = base->pos + ( serif->opos - base->opos );
1527  }
1528 
1529 
1530  /*************************************************************************/
1531  /*************************************************************************/
1532  /*************************************************************************/
1533  /**** ****/
1534  /**** E D G E H I N T I N G ****/
1535  /**** ****/
1536  /*************************************************************************/
1537  /*************************************************************************/
1538  /*************************************************************************/
1539 
1540 
1541 #define AF_LIGHT_MODE_MAX_HORZ_GAP 9
1542 #define AF_LIGHT_MODE_MAX_VERT_GAP 15
1543 #define AF_LIGHT_MODE_MAX_DELTA_ABS 14
1544 
1545 
1546  static FT_Pos
1547  af_hint_normal_stem( AF_GlyphHints hints,
1548  AF_Edge edge,
1549  AF_Edge edge2,
1550  FT_Pos anchor,
1551  AF_Dimension dim )
1552  {
1553  FT_Pos org_len, cur_len, org_center;
1554  FT_Pos cur_pos1, cur_pos2;
1555  FT_Pos d_off1, u_off1, d_off2, u_off2, delta;
1556  FT_Pos offset;
1557  FT_Pos threshold = 64;
1558 
1559 
1560  if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1561  {
1562  if ( ( edge->flags & AF_EDGE_ROUND ) &&
1563  ( edge2->flags & AF_EDGE_ROUND ) )
1564  {
1565  if ( dim == AF_DIMENSION_VERT )
1566  threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP;
1567  else
1568  threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP;
1569  }
1570  else
1571  {
1572  if ( dim == AF_DIMENSION_VERT )
1573  threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP / 3;
1574  else
1575  threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP / 3;
1576  }
1577  }
1578 
1579  org_len = edge2->opos - edge->opos;
1580  cur_len = af_cjk_compute_stem_width( hints, dim, org_len,
1581  (AF_Edge_Flags)edge->flags,
1582  (AF_Edge_Flags)edge2->flags );
1583 
1584  org_center = ( edge->opos + edge2->opos ) / 2 + anchor;
1585  cur_pos1 = org_center - cur_len / 2;
1586  cur_pos2 = cur_pos1 + cur_len;
1587  d_off1 = cur_pos1 - FT_PIX_FLOOR( cur_pos1 );
1588  d_off2 = cur_pos2 - FT_PIX_FLOOR( cur_pos2 );
1589  u_off1 = 64 - d_off1;
1590  u_off2 = 64 - d_off2;
1591  delta = 0;
1592 
1593 
1594  if ( d_off1 == 0 || d_off2 == 0 )
1595  goto Exit;
1596 
1597  if ( cur_len <= threshold )
1598  {
1599  if ( d_off2 < cur_len )
1600  {
1601  if ( u_off1 <= d_off2 )
1602  delta = u_off1;
1603  else
1604  delta = -d_off2;
1605  }
1606 
1607  goto Exit;
1608  }
1609 
1610  if ( threshold < 64 )
1611  {
1612  if ( d_off1 >= threshold || u_off1 >= threshold ||
1613  d_off2 >= threshold || u_off2 >= threshold )
1614  goto Exit;
1615  }
1616 
1617  offset = cur_len & 63;
1618 
1619  if ( offset < 32 )
1620  {
1621  if ( u_off1 <= offset || d_off2 <= offset )
1622  goto Exit;
1623  }
1624  else
1625  offset = 64 - threshold;
1626 
1627  d_off1 = threshold - u_off1;
1628  u_off1 = u_off1 - offset;
1629  u_off2 = threshold - d_off2;
1630  d_off2 = d_off2 - offset;
1631 
1632  if ( d_off1 <= u_off1 )
1633  u_off1 = -d_off1;
1634 
1635  if ( d_off2 <= u_off2 )
1636  u_off2 = -d_off2;
1637 
1638  if ( FT_ABS( u_off1 ) <= FT_ABS( u_off2 ) )
1639  delta = u_off1;
1640  else
1641  delta = u_off2;
1642 
1643  Exit:
1644 
1645 #if 1
1646  if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1647  {
1648  if ( delta > AF_LIGHT_MODE_MAX_DELTA_ABS )
1649  delta = AF_LIGHT_MODE_MAX_DELTA_ABS;
1650  else if ( delta < -AF_LIGHT_MODE_MAX_DELTA_ABS )
1651  delta = -AF_LIGHT_MODE_MAX_DELTA_ABS;
1652  }
1653 #endif
1654 
1655  cur_pos1 += delta;
1656 
1657  if ( edge->opos < edge2->opos )
1658  {
1659  edge->pos = cur_pos1;
1660  edge2->pos = cur_pos1 + cur_len;
1661  }
1662  else
1663  {
1664  edge->pos = cur_pos1 + cur_len;
1665  edge2->pos = cur_pos1;
1666  }
1667 
1668  return delta;
1669  }
1670 
1671 
1672  static void
1673  af_cjk_hint_edges( AF_GlyphHints hints,
1674  AF_Dimension dim )
1675  {
1676  AF_AxisHints axis = &hints->axis[dim];
1677  AF_Edge edges = axis->edges;
1678  AF_Edge edge_limit = edges + axis->num_edges;
1679  FT_PtrDist n_edges;
1680  AF_Edge edge;
1681  AF_Edge anchor = 0;
1682  FT_Pos delta = 0;
1683  FT_Int skipped = 0;
1684  FT_Bool has_last_stem = FALSE;
1685  FT_Pos last_stem_pos = 0;
1686 
1687 
1688  /* we begin by aligning all stems relative to the blue zone */
1689  FT_TRACE5(( "==== cjk hinting %s edges =====\n",
1690  dim == AF_DIMENSION_HORZ ? "vertical" : "horizontal" ));
1691 
1692  if ( AF_HINTS_DO_BLUES( hints ) )
1693  {
1694  for ( edge = edges; edge < edge_limit; edge++ )
1695  {
1696  AF_Width blue;
1697  AF_Edge edge1, edge2;
1698 
1699 
1700  if ( edge->flags & AF_EDGE_DONE )
1701  continue;
1702 
1703  blue = edge->blue_edge;
1704  edge1 = NULL;
1705  edge2 = edge->link;
1706 
1707  if ( blue )
1708  {
1709  edge1 = edge;
1710  }
1711  else if ( edge2 && edge2->blue_edge )
1712  {
1713  blue = edge2->blue_edge;
1714  edge1 = edge2;
1715  edge2 = edge;
1716  }
1717 
1718  if ( !edge1 )
1719  continue;
1720 
1721  FT_TRACE5(( "CJKBLUE: edge %d @%d (opos=%.2f) snapped to (%.2f), "
1722  "was (%.2f)\n",
1723  edge1-edges, edge1->fpos, edge1->opos / 64.0, blue->fit / 64.0,
1724  edge1->pos / 64.0 ));
1725 
1726  edge1->pos = blue->fit;
1727  edge1->flags |= AF_EDGE_DONE;
1728 
1729  if ( edge2 && !edge2->blue_edge )
1730  {
1731  af_cjk_align_linked_edge( hints, dim, edge1, edge2 );
1732  edge2->flags |= AF_EDGE_DONE;
1733  }
1734 
1735  if ( !anchor )
1736  anchor = edge;
1737  }
1738  }
1739 
1740  /* now we align all stem edges. */
1741  for ( edge = edges; edge < edge_limit; edge++ )
1742  {
1743  AF_Edge edge2;
1744 
1745 
1746  if ( edge->flags & AF_EDGE_DONE )
1747  continue;
1748 
1749  /* skip all non-stem edges */
1750  edge2 = edge->link;
1751  if ( !edge2 )
1752  {
1753  skipped++;
1754  continue;
1755  }
1756 
1757  /* Some CJK characters have so many stems that
1758  * the hinter is likely to merge two adjacent ones.
1759  * To solve this problem, if either edge of a stem
1760  * is too close to the previous one, we avoid
1761  * aligning the two edges, but rather interpolate
1762  * their locations at the end of this function in
1763  * order to preserve the space between the stems.
1764  */
1765  if ( has_last_stem &&
1766  ( edge->pos < last_stem_pos + 64 ||
1767  edge2->pos < last_stem_pos + 64 ) )
1768  {
1769  skipped++;
1770  continue;
1771  }
1772 
1773  /* now align the stem */
1774  /* this should not happen, but it's better to be safe */
1775  if ( edge2->blue_edge )
1776  {
1777  FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges ));
1778 
1779  af_cjk_align_linked_edge( hints, dim, edge2, edge );
1780  edge->flags |= AF_EDGE_DONE;
1781  continue;
1782  }
1783 
1784  if ( edge2 < edge )
1785  {
1786  af_cjk_align_linked_edge( hints, dim, edge2, edge );
1787  edge->flags |= AF_EDGE_DONE;
1788  /* We rarely reaches here it seems;
1789  * usually the two edges belonging
1790  * to one stem are marked as DONE together
1791  */
1792  has_last_stem = TRUE;
1793  last_stem_pos = edge->pos;
1794  continue;
1795  }
1796 
1797  if ( dim != AF_DIMENSION_VERT && !anchor )
1798  {
1799 
1800 #if 0
1801  if ( fixedpitch )
1802  {
1803  AF_Edge left = edge;
1804  AF_Edge right = edge_limit - 1;
1805  AF_EdgeRec left1, left2, right1, right2;
1806  FT_Pos target, center1, center2;
1807  FT_Pos delta1, delta2, d1, d2;
1808 
1809 
1810  while ( right > left && !right->link )
1811  right--;
1812 
1813  left1 = *left;
1814  left2 = *left->link;
1815  right1 = *right->link;
1816  right2 = *right;
1817 
1818  delta = ( ( ( hinter->pp2.x + 32 ) & -64 ) - hinter->pp2.x ) / 2;
1819  target = left->opos + ( right->opos - left->opos ) / 2 + delta - 16;
1820 
1821  delta1 = delta;
1822  delta1 += af_hint_normal_stem( hints, left, left->link,
1823  delta1, 0 );
1824 
1825  if ( left->link != right )
1826  af_hint_normal_stem( hints, right->link, right, delta1, 0 );
1827 
1828  center1 = left->pos + ( right->pos - left->pos ) / 2;
1829 
1830  if ( center1 >= target )
1831  delta2 = delta - 32;
1832  else
1833  delta2 = delta + 32;
1834 
1835  delta2 += af_hint_normal_stem( hints, &left1, &left2, delta2, 0 );
1836 
1837  if ( delta1 != delta2 )
1838  {
1839  if ( left->link != right )
1840  af_hint_normal_stem( hints, &right1, &right2, delta2, 0 );
1841 
1842  center2 = left1.pos + ( right2.pos - left1.pos ) / 2;
1843 
1844  d1 = center1 - target;
1845  d2 = center2 - target;
1846 
1847  if ( FT_ABS( d2 ) < FT_ABS( d1 ) )
1848  {
1849  left->pos = left1.pos;
1850  left->link->pos = left2.pos;
1851 
1852  if ( left->link != right )
1853  {
1854  right->link->pos = right1.pos;
1855  right->pos = right2.pos;
1856  }
1857 
1858  delta1 = delta2;
1859  }
1860  }
1861 
1862  delta = delta1;
1863  right->link->flags |= AF_EDGE_DONE;
1864  right->flags |= AF_EDGE_DONE;
1865  }
1866  else
1867 
1868 #endif /* 0 */
1869 
1870  delta = af_hint_normal_stem( hints, edge, edge2, 0,
1872  }
1873  else
1874  af_hint_normal_stem( hints, edge, edge2, delta, dim );
1875 
1876 #if 0
1877  printf( "stem (%d,%d) adjusted (%.1f,%.1f)\n",
1878  edge - edges, edge2 - edges,
1879  ( edge->pos - edge->opos ) / 64.0,
1880  ( edge2->pos - edge2->opos ) / 64.0 );
1881 #endif
1882 
1883  anchor = edge;
1884  edge->flags |= AF_EDGE_DONE;
1885  edge2->flags |= AF_EDGE_DONE;
1886  has_last_stem = TRUE;
1887  last_stem_pos = edge2->pos;
1888  }
1889 
1890  /* make sure that lowercase m's maintain their symmetry */
1891 
1892  /* In general, lowercase m's have six vertical edges if they are sans */
1893  /* serif, or twelve if they are with serifs. This implementation is */
1894  /* based on that assumption, and seems to work very well with most */
1895  /* faces. However, if for a certain face this assumption is not */
1896  /* true, the m is just rendered like before. In addition, any stem */
1897  /* correction will only be applied to symmetrical glyphs (even if the */
1898  /* glyph is not an m), so the potential for unwanted distortion is */
1899  /* relatively low. */
1900 
1901  /* We don't handle horizontal edges since we can't easily assure that */
1902  /* the third (lowest) stem aligns with the base line; it might end up */
1903  /* one pixel higher or lower. */
1904 
1905  n_edges = edge_limit - edges;
1906  if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
1907  {
1908  AF_Edge edge1, edge2, edge3;
1909  FT_Pos dist1, dist2, span;
1910 
1911 
1912  if ( n_edges == 6 )
1913  {
1914  edge1 = edges;
1915  edge2 = edges + 2;
1916  edge3 = edges + 4;
1917  }
1918  else
1919  {
1920  edge1 = edges + 1;
1921  edge2 = edges + 5;
1922  edge3 = edges + 9;
1923  }
1924 
1925  dist1 = edge2->opos - edge1->opos;
1926  dist2 = edge3->opos - edge2->opos;
1927 
1928  span = dist1 - dist2;
1929  if ( span < 0 )
1930  span = -span;
1931 
1932  if ( edge1->link == edge1 + 1 &&
1933  edge2->link == edge2 + 1 &&
1934  edge3->link == edge3 + 1 && span < 8 )
1935  {
1936  delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
1937  edge3->pos -= delta;
1938  if ( edge3->link )
1939  edge3->link->pos -= delta;
1940 
1941  /* move the serifs along with the stem */
1942  if ( n_edges == 12 )
1943  {
1944  ( edges + 8 )->pos -= delta;
1945  ( edges + 11 )->pos -= delta;
1946  }
1947 
1948  edge3->flags |= AF_EDGE_DONE;
1949  if ( edge3->link )
1950  edge3->link->flags |= AF_EDGE_DONE;
1951  }
1952  }
1953 
1954  if ( !skipped )
1955  return;
1956 
1957  /*
1958  * now hint the remaining edges (serifs and single) in order
1959  * to complete our processing
1960  */
1961  for ( edge = edges; edge < edge_limit; edge++ )
1962  {
1963  if ( edge->flags & AF_EDGE_DONE )
1964  continue;
1965 
1966  if ( edge->serif )
1967  {
1968  af_cjk_align_serif_edge( hints, edge->serif, edge );
1969  edge->flags |= AF_EDGE_DONE;
1970  skipped--;
1971  }
1972  }
1973 
1974  if ( !skipped )
1975  return;
1976 
1977  for ( edge = edges; edge < edge_limit; edge++ )
1978  {
1979  AF_Edge before, after;
1980 
1981 
1982  if ( edge->flags & AF_EDGE_DONE )
1983  continue;
1984 
1985  before = after = edge;
1986 
1987  while ( --before >= edges )
1988  if ( before->flags & AF_EDGE_DONE )
1989  break;
1990 
1991  while ( ++after < edge_limit )
1992  if ( after->flags & AF_EDGE_DONE )
1993  break;
1994 
1995  if ( before >= edges || after < edge_limit )
1996  {
1997  if ( before < edges )
1998  af_cjk_align_serif_edge( hints, after, edge );
1999  else if ( after >= edge_limit )
2000  af_cjk_align_serif_edge( hints, before, edge );
2001  else
2002  {
2003  if ( after->fpos == before->fpos )
2004  edge->pos = before->pos;
2005  else
2006  edge->pos = before->pos +
2007  FT_MulDiv( edge->fpos - before->fpos,
2008  after->pos - before->pos,
2009  after->fpos - before->fpos );
2010  }
2011  }
2012  }
2013  }
2014 
2015 
2016  static void
2017  af_cjk_align_edge_points( AF_GlyphHints hints,
2018  AF_Dimension dim )
2019  {
2020  AF_AxisHints axis = & hints->axis[dim];
2021  AF_Edge edges = axis->edges;
2022  AF_Edge edge_limit = edges + axis->num_edges;
2023  AF_Edge edge;
2024  FT_Bool snapping;
2025 
2026 
2027  snapping = FT_BOOL( ( dim == AF_DIMENSION_HORZ &&
2028  AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ||
2029  ( dim == AF_DIMENSION_VERT &&
2030  AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) );
2031 
2032  for ( edge = edges; edge < edge_limit; edge++ )
2033  {
2034  /* move the points of each segment */
2035  /* in each edge to the edge's position */
2036  AF_Segment seg = edge->first;
2037 
2038 
2039  if ( snapping )
2040  {
2041  do
2042  {
2043  AF_Point point = seg->first;
2044 
2045 
2046  for (;;)
2047  {
2048  if ( dim == AF_DIMENSION_HORZ )
2049  {
2050  point->x = edge->pos;
2051  point->flags |= AF_FLAG_TOUCH_X;
2052  }
2053  else
2054  {
2055  point->y = edge->pos;
2056  point->flags |= AF_FLAG_TOUCH_Y;
2057  }
2058 
2059  if ( point == seg->last )
2060  break;
2061 
2062  point = point->next;
2063  }
2064 
2065  seg = seg->edge_next;
2066 
2067  } while ( seg != edge->first );
2068  }
2069  else
2070  {
2071  FT_Pos delta = edge->pos - edge->opos;
2072 
2073 
2074  do
2075  {
2076  AF_Point point = seg->first;
2077 
2078 
2079  for (;;)
2080  {
2081  if ( dim == AF_DIMENSION_HORZ )
2082  {
2083  point->x += delta;
2084  point->flags |= AF_FLAG_TOUCH_X;
2085  }
2086  else
2087  {
2088  point->y += delta;
2089  point->flags |= AF_FLAG_TOUCH_Y;
2090  }
2091 
2092  if ( point == seg->last )
2093  break;
2094 
2095  point = point->next;
2096  }
2097 
2098  seg = seg->edge_next;
2099 
2100  } while ( seg != edge->first );
2101  }
2102  }
2103  }
2104 
2105 
2107  af_cjk_hints_apply( AF_GlyphHints hints,
2108  FT_Outline* outline,
2109  AF_CJKMetrics metrics )
2110  {
2111  FT_Error error;
2112  int dim;
2113 
2114  FT_UNUSED( metrics );
2115 
2116 
2117  error = af_glyph_hints_reload( hints, outline );
2118  if ( error )
2119  goto Exit;
2120 
2121  /* analyze glyph outline */
2122  if ( AF_HINTS_DO_HORIZONTAL( hints ) )
2123  {
2124  error = af_cjk_hints_detect_features( hints, AF_DIMENSION_HORZ );
2125  if ( error )
2126  goto Exit;
2127 
2128  af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_HORZ );
2129  }
2130 
2131  if ( AF_HINTS_DO_VERTICAL( hints ) )
2132  {
2133  error = af_cjk_hints_detect_features( hints, AF_DIMENSION_VERT );
2134  if ( error )
2135  goto Exit;
2136 
2137  af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_VERT );
2138  }
2139 
2140  /* grid-fit the outline */
2141  for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
2142  {
2143  if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
2144  ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) ) )
2145  {
2146 
2147 #ifdef AF_CONFIG_OPTION_USE_WARPER
2148  if ( dim == AF_DIMENSION_HORZ &&
2150  {
2151  AF_WarperRec warper;
2152  FT_Fixed scale;
2153  FT_Pos delta;
2154 
2155 
2156  af_warper_compute( &warper, hints, (AF_Dimension)dim,
2157  &scale, &delta );
2158  af_glyph_hints_scale_dim( hints, (AF_Dimension)dim,
2159  scale, delta );
2160  continue;
2161  }
2162 #endif /* AF_CONFIG_OPTION_USE_WARPER */
2163 
2164  af_cjk_hint_edges( hints, (AF_Dimension)dim );
2165  af_cjk_align_edge_points( hints, (AF_Dimension)dim );
2168  }
2169  }
2170 
2171 #if 0
2172  af_glyph_hints_dump_points( hints );
2174  af_glyph_hints_dump_edges( hints );
2175 #endif
2176 
2177  af_glyph_hints_save( hints, outline );
2178 
2179  Exit:
2180  return error;
2181  }
2182 
2183 
2184  /*************************************************************************/
2185  /*************************************************************************/
2186  /***** *****/
2187  /***** C J K S C R I P T C L A S S *****/
2188  /***** *****/
2189  /*************************************************************************/
2190  /*************************************************************************/
2191 
2192 
2193  /* this corresponds to Unicode 6.0 */
2194 
2195  static const AF_Script_UniRangeRec af_cjk_uniranges[] =
2196  {
2197  AF_UNIRANGE_REC( 0x1100UL, 0x11FFUL ), /* Hangul Jamo */
2198  AF_UNIRANGE_REC( 0x2E80UL, 0x2EFFUL ), /* CJK Radicals Supplement */
2199  AF_UNIRANGE_REC( 0x2F00UL, 0x2FDFUL ), /* Kangxi Radicals */
2200  AF_UNIRANGE_REC( 0x2FF0UL, 0x2FFFUL ), /* Ideographic Description Characters */
2201  AF_UNIRANGE_REC( 0x3000UL, 0x303FUL ), /* CJK Symbols and Punctuation */
2202  AF_UNIRANGE_REC( 0x3040UL, 0x309FUL ), /* Hiragana */
2203  AF_UNIRANGE_REC( 0x30A0UL, 0x30FFUL ), /* Katakana */
2204  AF_UNIRANGE_REC( 0x3100UL, 0x312FUL ), /* Bopomofo */
2205  AF_UNIRANGE_REC( 0x3130UL, 0x318FUL ), /* Hangul Compatibility Jamo */
2206  AF_UNIRANGE_REC( 0x3190UL, 0x319FUL ), /* Kanbun */
2207  AF_UNIRANGE_REC( 0x31A0UL, 0x31BFUL ), /* Bopomofo Extended */
2208  AF_UNIRANGE_REC( 0x31C0UL, 0x31EFUL ), /* CJK Strokes */
2209  AF_UNIRANGE_REC( 0x31F0UL, 0x31FFUL ), /* Katakana Phonetic Extensions */
2210  AF_UNIRANGE_REC( 0x3200UL, 0x32FFUL ), /* Enclosed CJK Letters and Months */
2211  AF_UNIRANGE_REC( 0x3300UL, 0x33FFUL ), /* CJK Compatibility */
2212  AF_UNIRANGE_REC( 0x3400UL, 0x4DBFUL ), /* CJK Unified Ideographs Extension A */
2213  AF_UNIRANGE_REC( 0x4DC0UL, 0x4DFFUL ), /* Yijing Hexagram Symbols */
2214  AF_UNIRANGE_REC( 0x4E00UL, 0x9FFFUL ), /* CJK Unified Ideographs */
2215  AF_UNIRANGE_REC( 0xA960UL, 0xA97FUL ), /* Hangul Jamo Extended-A */
2216  AF_UNIRANGE_REC( 0xAC00UL, 0xD7AFUL ), /* Hangul Syllables */
2217  AF_UNIRANGE_REC( 0xD7B0UL, 0xD7FFUL ), /* Hangul Jamo Extended-B */
2218  AF_UNIRANGE_REC( 0xF900UL, 0xFAFFUL ), /* CJK Compatibility Ideographs */
2219  AF_UNIRANGE_REC( 0xFE10UL, 0xFE1FUL ), /* Vertical forms */
2220  AF_UNIRANGE_REC( 0xFE30UL, 0xFE4FUL ), /* CJK Compatibility Forms */
2221  AF_UNIRANGE_REC( 0xFF00UL, 0xFFEFUL ), /* Halfwidth and Fullwidth Forms */
2222  AF_UNIRANGE_REC( 0x1B000UL, 0x1B0FFUL ), /* Kana Supplement */
2223  AF_UNIRANGE_REC( 0x1D300UL, 0x1D35FUL ), /* Tai Xuan Hing Symbols */
2224  AF_UNIRANGE_REC( 0x1F200UL, 0x1F2FFUL ), /* Enclosed Ideographic Supplement */
2225  AF_UNIRANGE_REC( 0x20000UL, 0x2A6DFUL ), /* CJK Unified Ideographs Extension B */
2226  AF_UNIRANGE_REC( 0x2A700UL, 0x2B73FUL ), /* CJK Unified Ideographs Extension C */
2227  AF_UNIRANGE_REC( 0x2B740UL, 0x2B81FUL ), /* CJK Unified Ideographs Extension D */
2228  AF_UNIRANGE_REC( 0x2F800UL, 0x2FA1FUL ), /* CJK Compatibility Ideographs Supplement */
2229  AF_UNIRANGE_REC( 0UL, 0UL )
2230  };
2231 
2232 
2233  AF_DEFINE_SCRIPT_CLASS( af_cjk_script_class,
2234  AF_SCRIPT_CJK,
2235  af_cjk_uniranges,
2236  0x7530, /* ç”° */
2237 
2238  sizeof ( AF_CJKMetricsRec ),
2239 
2240  (AF_Script_InitMetricsFunc) af_cjk_metrics_init,
2241  (AF_Script_ScaleMetricsFunc)af_cjk_metrics_scale,
2243 
2244  (AF_Script_InitHintsFunc) af_cjk_hints_init,
2245  (AF_Script_ApplyHintsFunc) af_cjk_hints_apply
2246  )
2247 
2248 #else /* !AF_CONFIG_OPTION_CJK */
2249 
2250  static const AF_Script_UniRangeRec af_cjk_uniranges[] =
2251  {
2252  AF_UNIRANGE_REC( 0UL, 0UL )
2253  };
2254 
2255 
2256  AF_DEFINE_SCRIPT_CLASS( af_cjk_script_class,
2257  AF_SCRIPT_CJK,
2258  af_cjk_uniranges,
2259  0,
2260 
2261  sizeof ( AF_CJKMetricsRec ),
2262 
2266 
2267  (AF_Script_InitHintsFunc) NULL,
2269  )
2270 
2271 #endif /* !AF_CONFIG_OPTION_CJK */
2272 
2273 
2274 /* END */
AF_CJKAxisRec axis[AF_DIMENSION_MAX]
Definition: afcjk.h:101
FT_UShort units_per_EM
Definition: freetype.h:945
FT_UInt blue_count
Definition: afcjk.h:88
af_glyph_hints_save(AF_GlyphHints hints, FT_Outline *outline)
Definition: afhints.c:801
AF_ScriptMetricsRec root
Definition: afcjk.h:99
int FT_Error
Definition: fttypes.h:296
#define AF_HINTS_DO_VERTICAL(h)
Definition: afhints.h:386
FT_DivFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:586
ft_ptrdiff_t FT_PtrDist
Definition: fttypes.h:333
GLenum GLenum GLenum GLenum GLenum scale
FT_UInt units_per_em
Definition: afcjk.h:100
unsigned long FT_ULong
Definition: fttypes.h:249
af_glyph_hints_done(AF_GlyphHints hints)
Definition: afhints.c:539
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:59
GLsizei const GLfloat * points
FT_Pos pos
Definition: afhints.h:295
AF_Point next
Definition: afhints.h:261
AF_CJKBlueRec blues[AF_CJK_BLUE_MAX]
Definition: afcjk.h:89
GLfloat GLfloat p
FT_Bool digits_have_same_width
Definition: aftypes.h:255
FT_CharMap charmap
Definition: freetype.h:958
FT_UShort flags
Definition: afhints.h:252
FT_Memory memory
Definition: afhints.h:333
AF_ScriptMetrics metrics
Definition: afhints.h:354
#define NULL
Definition: ftobjs.h:61
T sign(T a)
Definition: glsl_math.hpp:669
FT_Fixed y_scale
Definition: afhints.h:338
GLint GLint GLint GLint GLint GLint y
struct AF_CJKMetricsRec_ * AF_CJKMetrics
signed int FT_Int
Definition: fttypes.h:216
FT_Pos x
Definition: afhints.h:258
short n_contours
Definition: ftimage.h:385
AF_WidthRec shoot
Definition: afcjk.h:69
FT_Pos y_delta
Definition: aftypes.h:187
#define FT_ABS(a)
Definition: ftobjs.h:73
af_glyph_hints_init(AF_GlyphHints hints, FT_Memory memory)
Definition: afhints.c:530
enum FT_Render_Mode_ FT_Render_Mode
void(* AF_Script_DoneMetricsFunc)(AF_ScriptMetrics metrics)
Definition: aftypes.h:274
#define FT_LOAD_NO_HINTING
Definition: freetype.h:2550
AF_WidthRec ref
Definition: afcjk.h:68
short * contours
Definition: ftimage.h:390
FT_Pos x_delta
Definition: aftypes.h:186
FT_Fixed scale
Definition: afcjk.h:77
#define FT_UNUSED(arg)
Definition: ftconfig.h:76
FT_Pos score
Definition: afhints.h:282
af_latin_hints_compute_segments(AF_GlyphHints hints, AF_Dimension dim)
Definition: aflatin.c:793
FT_Int num_segments
Definition: afhints.h:315
GLint GLint GLsizei width
unsigned int FT_UInt32
Definition: ftconfig.h:133
FT_UInt flags
Definition: afcjk.h:70
enum AF_Direction_ AF_Direction
GLenum GLenum GLvoid GLvoid GLvoid * span
GLint GLint GLint GLint GLint x
#define AF_UNIRANGE_REC(a, b)
Definition: aftypes.h:294
FT_UInt32 flags
Definition: aftypes.h:189
AF_Edge link
Definition: afhints.h:302
AF_Point last
Definition: afhints.h:286
return FT_Err_Ok
Definition: ftbbox.c:645
af_glyph_hints_reload(AF_GlyphHints hints, FT_Outline *outline)
Definition: afhints.c:593
AF_WidthRec widths[AF_CJK_MAX_WIDTHS]
Definition: afcjk.h:81
png_uint_32 i
Definition: png.h:2640
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:104
FT_Error(* AF_Script_InitHintsFunc)(AF_GlyphHints hints, AF_ScriptMetrics metrics)
Definition: aftypes.h:278
#define FT_LOAD_NO_SCALE
Definition: freetype.h:2549
FT_Byte flags
Definition: afhints.h:269
af_sort_and_quantize_widths(FT_UInt *count, AF_Width table, FT_Pos threshold)
Definition: afangles.c:270
GLenum GLuint GLint GLenum face
AF_Segment link
Definition: afhints.h:279
FT_Outline outline
Definition: freetype.h:1631
FT_Pos len
Definition: afhints.h:283
FT_Byte flags
Definition: afhints.h:297
FT_Short min_coord
Definition: afhints.h:272
FT_Pos x_delta
Definition: afhints.h:336
GLenum GLint ref
FT_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
Definition: ftobjs.c:574
FT_Pos delta
Definition: afcjk.h:78
FT_Get_Advance(FT_Face face, FT_UInt gindex, FT_Int32 load_flags, FT_Fixed *padvance)
Definition: ftadvanc.c:72
FT_Short max_coord
Definition: afhints.h:273
FT_UInt32 scaler_flags
Definition: afhints.h:351
GLfloat GLfloat blue
AF_ScalerRec scaler
Definition: aftypes.h:254
FT_Face face
Definition: aftypes.h:183
#define AF_LATIN_HINTS_DO_STEM_ADJUST(h)
Definition: aflatin.h:168
FT_Fixed x_scale
Definition: aftypes.h:184
af_warper_compute(AF_Warper warper, AF_GlyphHints hints, AF_Dimension dim, FT_Fixed *a_scale, FT_Fixed *a_delta)
#define FT_PIX_FLOOR(x)
Definition: ftobjs.h:80
GLdouble GLdouble right
FT_Bool extra_light
Definition: afcjk.h:84
af_axis_hints_new_edge(AF_AxisHints axis, FT_Int fpos, AF_Direction dir, FT_Memory memory, AF_Edge *anedge)
Definition: afhints.c:80
GLenum GLsizei len
GLenum mode
FT_Get_Char_Index(FT_Face face, FT_ULong charcode)
Definition: ftobjs.c:3302
AF_Point first
Definition: afhints.h:285
GLint left
#define AF_DEFINE_SCRIPT_CLASS(script_class, script_, ranges, def_char, m_size, m_init, m_scale, m_done, h_init, h_apply)
Definition: aftypes.h:323
AF_Segment segments
Definition: afhints.h:317
af_glyph_hints_align_strong_points(AF_GlyphHints hints, AF_Dimension dim)
Definition: afhints.c:911
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
Definition: ftcalc.c:412
AF_Segment edge_next
Definition: afhints.h:277
FT_Error error
Definition: cffdrivr.c:411
void af_glyph_hints_dump_points(AF_GlyphHints hints)
Definition: afhints.c:424
#define AF_HINTS_DO_BLUES(h)
Definition: afhints.h:392
FT_Pos x
Definition: ftimage.h:77
enum AF_Edge_Flags_ AF_Edge_Flags
char FT_String
Definition: fttypes.h:183
#define FT_ZERO(p)
Definition: ftmemory.h:210
FT_Short pos
Definition: afhints.h:271
#define AF_LATIN_CONSTANT(metrics, c)
Definition: aflatin.h:34
FT_Select_Charmap(FT_Face face, FT_Encoding encoding)
Definition: ftobjs.c:3066
FT_Short fpos
Definition: afhints.h:293
AF_Segment last
Definition: afhints.h:308
float min(float a, float b)
Definition: Vector2.hpp:307
AF_Segment first
Definition: afhints.h:307
FT_Pos y
Definition: ftimage.h:78
FT_Fixed x_scale
Definition: afhints.h:335
FT_Pos edge_distance_threshold
Definition: afcjk.h:82
#define AF_LATIN_HINTS_DO_MONO(h)
Definition: aflatin.h:171
af_latin_hints_link_segments(AF_GlyphHints hints, AF_Dimension dim)
Definition: aflatin.c:1013
GLdouble n
void(* AF_Script_ApplyHintsFunc)(AF_GlyphHints hints, FT_Outline *outline, AF_ScriptMetrics metrics)
Definition: aftypes.h:282
#define AF_LATIN_HINTS_DO_VERT_SNAP(h)
Definition: aflatin.h:165
FT_Pos y_delta
Definition: afhints.h:339
FT_Fixed y_scale
Definition: aftypes.h:185
const GLint * first
#define AF_CJK_MAX_WIDTHS
Definition: afcjk.h:51
AF_Edge edge
Definition: afhints.h:276
GLintptr offset
FT_Pos org_delta
Definition: afcjk.h:92
AF_Edge serif
Definition: afhints.h:303
FT_Int num_edges
Definition: afhints.h:322
#define FALSE
Definition: ftobjs.h:57
short n_points
Definition: ftimage.h:386
FT_Set_Charmap(FT_Face face, FT_CharMap charmap)
Definition: ftobjs.c:3117
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
FT_UInt width_count
Definition: afcjk.h:80
local int max
Definition: enough.c:170
#define FT_BOOL(x)
Definition: fttypes.h:574
void af_glyph_hints_dump_edges(AF_GlyphHints hints)
Definition: afhints.c:466
void af_glyph_hints_dump_segments(AF_GlyphHints hints)
Definition: afhints.c:431
FT_MulFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:485
FT_Pos num_linked
Definition: afhints.h:281
#define AF_HINTS_DO_HORIZONTAL(h)
Definition: afhints.h:383
FT_BEGIN_HEADER enum AF_Dimension_ AF_Dimension
FT_Char dir
Definition: afhints.h:270
enum AF_Flags_ AF_Flags
GLubyte GLubyte GLubyte GLubyte w
signed long FT_Fixed
Definition: fttypes.h:284
FT_UInt32 other_flags
Definition: afhints.h:352
FT_BEGIN_HEADER struct AF_WidthRec_ * AF_Width
FT_GlyphSlot glyph
Definition: freetype.h:956
unsigned int FT_UInt
Definition: fttypes.h:227
GLenum target
FT_Error(* AF_Script_InitMetricsFunc)(AF_ScriptMetrics metrics, FT_Face face)
Definition: aftypes.h:266
#define FT_TRACE5(varformat)
Definition: ftdebug.h:162
AF_ScriptClass clazz
Definition: aftypes.h:253
AF_Edge edges
Definition: afhints.h:324
GLuint GLuint GLsizei count
FT_Pos opos
Definition: afhints.h:294
#define AF_SEGMENT_DIST(seg1, seg2)
Definition: afhints.h:457
AF_AxisHintsRec axis[AF_DIMENSION_MAX]
Definition: afhints.h:349
af_glyph_hints_align_weak_points(AF_GlyphHints hints, AF_Dimension dim)
Definition: afhints.c:1166
FT_Fixed org_scale
Definition: afcjk.h:91
GLsizei GLenum const GLvoid GLuint GLsizei GLfloat * metrics
FT_Render_Mode render_mode
Definition: aftypes.h:188
FT_Char dir
Definition: afhints.h:298
#define AF_LATIN_HINTS_DO_HORZ_SNAP(h)
Definition: aflatin.h:162
af_sort_pos(FT_UInt count, FT_Pos *table)
Definition: afangles.c:247
void(* AF_Script_ScaleMetricsFunc)(AF_ScriptMetrics metrics, AF_Scaler scaler)
Definition: aftypes.h:270
#define FT_LOAD_IGNORE_TRANSFORM
Definition: freetype.h:2559
FT_Pos y
Definition: afhints.h:258
AF_Width blue_edge
Definition: afhints.h:301
GLint reference
af_glyph_hints_rescale(AF_GlyphHints hints, AF_ScriptMetrics metrics)
Definition: afhints.c:581
AF_Segment serif
Definition: afhints.h:280
#define TRUE
Definition: ftobjs.h:53
FT_Vector * points
Definition: ftimage.h:388
#define FT_PIX_ROUND(x)
Definition: ftobjs.h:81
GLint limit
AF_Direction major_dir
Definition: afhints.h:326
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:236
FT_Memory memory
Definition: freetype.h:963
FT_Pos standard_width
Definition: afcjk.h:83