1 /***************************************************************************/
5 /* Auto-fitter hinting routines for CJK writing system (body). */
7 /* Copyright 2006-2014 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
19 * The algorithm is based on akito's autohint patch, available here:
21 * http://www.kde.gr.jp/~akito/patch/freetype2/
26 #include FT_ADVANCES_H
27 #include FT_INTERNAL_DEBUG_H
34 #ifdef AF_CONFIG_OPTION_CJK
36 #undef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
42 #ifdef AF_CONFIG_OPTION_USE_WARPER
47 /*************************************************************************/
49 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
50 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
51 /* messages during execution. */
54 #define FT_COMPONENT trace_afcjk
57 /*************************************************************************/
58 /*************************************************************************/
60 /***** C J K G L O B A L M E T R I C S *****/
62 /*************************************************************************/
63 /*************************************************************************/
66 /* Basically the Latin version with AF_CJKMetrics */
67 /* to replace AF_LatinMetrics. */
70 af_cjk_metrics_init_widths( AF_CJKMetrics metrics,
73 /* scan the array of segments in each direction */
74 AF_GlyphHintsRec hints[1];
78 "cjk standard widths computation (style `%s')\n"
79 "===================================================\n"
81 af_style_names[metrics->root.style_class->style] ));
83 af_glyph_hints_init( hints, face->memory );
85 metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
86 metrics->axis[AF_DIMENSION_VERT].width_count = 0;
93 AF_CJKMetricsRec dummy[1];
94 AF_Scaler scaler = &dummy->root.scaler;
96 #ifdef FT_CONFIG_OPTION_PIC
97 AF_FaceGlobals globals = metrics->root.globals;
100 AF_StyleClass style_class = metrics->root.style_class;
101 AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
102 [style_class->script];
104 FT_UInt32 standard_char;
107 standard_char = script_class->standard_char1;
108 af_get_char_index( &metrics->root,
114 if ( script_class->standard_char2 )
116 standard_char = script_class->standard_char2;
117 af_get_char_index( &metrics->root,
123 if ( script_class->standard_char3 )
125 standard_char = script_class->standard_char3;
126 af_get_char_index( &metrics->root,
141 FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
142 standard_char, glyph_index ));
144 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
145 if ( error || face->glyph->outline.n_points <= 0 )
150 dummy->units_per_em = metrics->units_per_em;
152 scaler->x_scale = 0x10000L;
153 scaler->y_scale = 0x10000L;
158 scaler->render_mode = FT_RENDER_MODE_NORMAL;
161 af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
163 error = af_glyph_hints_reload( hints, &face->glyph->outline );
167 for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
169 AF_CJKAxis axis = &metrics->axis[dim];
170 AF_AxisHints axhints = &hints->axis[dim];
171 AF_Segment seg, limit, link;
172 FT_UInt num_widths = 0;
175 error = af_latin_hints_compute_segments( hints,
180 af_latin_hints_link_segments( hints,
185 seg = axhints->segments;
186 limit = seg + axhints->num_segments;
188 for ( ; seg < limit; seg++ )
192 /* we only consider stem segments there! */
193 if ( link && link->link == seg && link > seg )
198 dist = seg->pos - link->pos;
202 if ( num_widths < AF_CJK_MAX_WIDTHS )
203 axis->widths[num_widths++].org = dist;
207 /* this also replaces multiple almost identical stem widths */
208 /* with a single one (the value 100 is heuristic) */
209 af_sort_and_quantize_widths( &num_widths, axis->widths,
210 dummy->units_per_em / 100 );
211 axis->width_count = num_widths;
215 for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
217 AF_CJKAxis axis = &metrics->axis[dim];
221 stdw = ( axis->width_count > 0 ) ? axis->widths[0].org
222 : AF_LATIN_CONSTANT( metrics, 50 );
224 /* let's try 20% of the smallest width */
225 axis->edge_distance_threshold = stdw / 5;
226 axis->standard_width = stdw;
227 axis->extra_light = 0;
229 #ifdef FT_DEBUG_LEVEL_TRACE
234 FT_TRACE5(( "%s widths:\n",
235 dim == AF_DIMENSION_VERT ? "horizontal"
238 FT_TRACE5(( " %d (standard)", axis->standard_width ));
239 for ( i = 1; i < axis->width_count; i++ )
240 FT_TRACE5(( " %d", axis->widths[i].org ));
250 af_glyph_hints_done( hints );
254 /* Find all blue zones. */
257 af_cjk_metrics_init_blues( AF_CJKMetrics metrics,
260 FT_Pos fills[AF_BLUE_STRING_MAX_LEN];
261 FT_Pos flats[AF_BLUE_STRING_MAX_LEN];
273 AF_StyleClass sc = metrics->root.style_class;
275 AF_Blue_Stringset bss = sc->blue_stringset;
276 const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
279 /* we walk over the blue character strings as specified in the */
280 /* style's entry in the `af_blue_stringset' array, computing its */
281 /* extremum points (depending on the string properties) */
283 FT_TRACE5(( "cjk blue zones computation\n"
284 "==========================\n"
287 for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
289 const char* p = &af_blue_strings[bs->string];
294 if ( AF_CJK_IS_HORIZ_BLUE( bs ) )
295 axis = &metrics->axis[AF_DIMENSION_HORZ];
297 axis = &metrics->axis[AF_DIMENSION_VERT];
299 #ifdef FT_DEBUG_LEVEL_TRACE
301 FT_String* cjk_blue_name[4] =
303 (FT_String*)"bottom", /* -- , -- */
304 (FT_String*)"top", /* -- , TOP */
305 (FT_String*)"left", /* HORIZ, -- */
306 (FT_String*)"right" /* HORIZ, TOP */
310 FT_TRACE5(( "blue zone %d (%s):\n",
312 cjk_blue_name[AF_CJK_IS_HORIZ_BLUE( bs ) |
313 AF_CJK_IS_TOP_BLUE( bs ) ] ));
315 #endif /* FT_DEBUG_LEVEL_TRACE */
320 fill = 1; /* start with characters that define fill values */
321 FT_TRACE5(( " [overshoot values]\n" ));
326 FT_ULong glyph_index;
328 FT_Pos best_pos; /* same as points.y or points.x, resp. */
333 GET_UTF8_CHAR( ch, p );
335 /* switch to characters that define flat values */
339 FT_TRACE5(( " [reference values]\n" ));
343 /* load the character in the face -- skip unknown or empty ones */
344 af_get_char_index( &metrics->root, ch, &glyph_index, &y_offset );
345 if ( glyph_index == 0 )
347 FT_TRACE5(( " U+%04lX unavailable\n", ch ));
351 error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
352 outline = face->glyph->outline;
353 if ( error || outline.n_points <= 0 )
355 FT_TRACE5(( " U+%04lX contains no outlines\n", ch ));
359 /* now compute min or max point indices and coordinates */
360 points = outline.points;
362 best_pos = 0; /* make compiler happy */
370 for ( nn = 0; nn < outline.n_contours; first = last + 1, nn++ )
375 last = outline.contours[nn];
377 /* Avoid single-point contours since they are never rasterized. */
378 /* In some fonts, they correspond to mark attachment points */
379 /* which are way outside of the glyph's real outline. */
383 if ( AF_CJK_IS_HORIZ_BLUE( bs ) )
385 if ( AF_CJK_IS_RIGHT_BLUE( bs ) )
387 for ( pp = first; pp <= last; pp++ )
388 if ( best_point < 0 || points[pp].x > best_pos )
391 best_pos = points[pp].x;
396 for ( pp = first; pp <= last; pp++ )
397 if ( best_point < 0 || points[pp].x < best_pos )
400 best_pos = points[pp].x;
406 if ( AF_CJK_IS_TOP_BLUE( bs ) )
408 for ( pp = first; pp <= last; pp++ )
409 if ( best_point < 0 || points[pp].y > best_pos )
412 best_pos = points[pp].y;
417 for ( pp = first; pp <= last; pp++ )
418 if ( best_point < 0 || points[pp].y < best_pos )
421 best_pos = points[pp].y;
427 FT_TRACE5(( " U+%04lX: best_pos = %5ld\n", ch, best_pos ));
431 fills[num_fills++] = best_pos;
433 flats[num_flats++] = best_pos;
436 if ( num_flats == 0 && num_fills == 0 )
439 * we couldn't find a single glyph to compute this blue zone,
440 * we will simply ignore it then
442 FT_TRACE5(( " empty\n" ));
446 /* we have computed the contents of the `fill' and `flats' tables, */
447 /* now determine the reference and overshoot position of the blue -- */
448 /* we simply take the median value after a simple sort */
449 af_sort_pos( num_fills, fills );
450 af_sort_pos( num_flats, flats );
452 blue = &axis->blues[axis->blue_count];
453 blue_ref = &blue->ref.org;
454 blue_shoot = &blue->shoot.org;
458 if ( num_flats == 0 )
461 *blue_shoot = fills[num_fills / 2];
463 else if ( num_fills == 0 )
466 *blue_shoot = flats[num_flats / 2];
470 *blue_ref = fills[num_fills / 2];
471 *blue_shoot = flats[num_flats / 2];
474 /* make sure blue_ref >= blue_shoot for top/right or */
475 /* vice versa for bottom/left */
476 if ( *blue_shoot != *blue_ref )
478 FT_Pos ref = *blue_ref;
479 FT_Pos shoot = *blue_shoot;
480 FT_Bool under_ref = FT_BOOL( shoot < ref );
483 /* AF_CJK_IS_TOP_BLUE covers `right' and `top' */
484 if ( AF_CJK_IS_TOP_BLUE( bs ) ^ under_ref )
487 *blue_shoot = ( shoot + ref ) / 2;
489 FT_TRACE5(( " [reference smaller than overshoot,"
490 " taking mean value]\n" ));
495 if ( AF_CJK_IS_TOP_BLUE( bs ) )
496 blue->flags |= AF_CJK_BLUE_TOP;
498 FT_TRACE5(( " -> reference = %ld\n"
499 " overshoot = %ld\n",
500 *blue_ref, *blue_shoot ));
509 /* Basically the Latin version with type AF_CJKMetrics for metrics. */
512 af_cjk_metrics_check_digits( AF_CJKMetrics metrics,
516 FT_Bool started = 0, same_width = 1;
517 FT_Fixed advance, old_advance = 0;
520 /* digit `0' is 0x30 in all supported charmaps */
521 for ( i = 0x30; i <= 0x39; i++ )
523 FT_ULong glyph_index;
527 af_get_char_index( &metrics->root, i, &glyph_index, &y_offset );
528 if ( glyph_index == 0 )
531 if ( FT_Get_Advance( face, glyph_index,
534 FT_LOAD_IGNORE_TRANSFORM,
540 if ( advance != old_advance )
548 old_advance = advance;
553 metrics->root.digits_have_same_width = same_width;
557 /* Initialize global metrics. */
559 FT_LOCAL_DEF( FT_Error )
560 af_cjk_metrics_init( AF_CJKMetrics metrics,
563 FT_CharMap oldmap = face->charmap;
566 metrics->units_per_em = face->units_per_EM;
568 if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
570 af_cjk_metrics_init_widths( metrics, face );
571 af_cjk_metrics_init_blues( metrics, face );
572 af_cjk_metrics_check_digits( metrics, face );
575 FT_Set_Charmap( face, oldmap );
580 /* Adjust scaling value, then scale and shift widths */
581 /* and blue zones (if applicable) for given dimension. */
584 af_cjk_metrics_scale_dim( AF_CJKMetrics metrics,
594 if ( dim == AF_DIMENSION_HORZ )
596 scale = scaler->x_scale;
597 delta = scaler->x_delta;
601 scale = scaler->y_scale;
602 delta = scaler->y_delta;
605 axis = &metrics->axis[dim];
607 if ( axis->org_scale == scale && axis->org_delta == delta )
610 axis->org_scale = scale;
611 axis->org_delta = delta;
616 /* scale the blue zones */
617 for ( nn = 0; nn < axis->blue_count; nn++ )
619 AF_CJKBlue blue = &axis->blues[nn];
623 blue->ref.cur = FT_MulFix( blue->ref.org, scale ) + delta;
624 blue->ref.fit = blue->ref.cur;
625 blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta;
626 blue->shoot.fit = blue->shoot.cur;
627 blue->flags &= ~AF_CJK_BLUE_ACTIVE;
629 /* a blue zone is only active if it is less than 3/4 pixels tall */
630 dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
631 if ( dist <= 48 && dist >= -48 )
633 FT_Pos delta1, delta2;
636 blue->ref.fit = FT_PIX_ROUND( blue->ref.cur );
638 /* shoot is under shoot for cjk */
639 delta1 = FT_DivFix( blue->ref.fit, scale ) - blue->shoot.org;
644 delta2 = FT_MulFix( delta2, scale );
646 FT_TRACE5(( "delta: %d", delta1 ));
650 else if ( delta2 < 64 )
651 delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
654 delta2 = FT_PIX_ROUND( delta2 );
655 FT_TRACE5(( "/%d\n", delta2 ));
660 blue->shoot.fit = blue->ref.fit - delta2;
662 FT_TRACE5(( ">> active cjk blue zone %c%d[%ld/%ld]:\n"
663 " ref: cur=%.2f fit=%.2f\n"
664 " shoot: cur=%.2f fit=%.2f\n",
665 ( dim == AF_DIMENSION_HORZ ) ? 'H' : 'V',
666 nn, blue->ref.org, blue->shoot.org,
667 blue->ref.cur / 64.0, blue->ref.fit / 64.0,
668 blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
670 blue->flags |= AF_CJK_BLUE_ACTIVE;
676 /* Scale global values in both directions. */
679 af_cjk_metrics_scale( AF_CJKMetrics metrics,
682 /* we copy the whole structure since the x and y scaling values */
683 /* are not modified, contrary to e.g. the `latin' auto-hinter */
684 metrics->root.scaler = *scaler;
686 af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
687 af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
691 /*************************************************************************/
692 /*************************************************************************/
694 /***** C J K G L Y P H A N A L Y S I S *****/
696 /*************************************************************************/
697 /*************************************************************************/
700 /* Walk over all contours and compute its segments. */
703 af_cjk_hints_compute_segments( AF_GlyphHints hints,
706 AF_AxisHints axis = &hints->axis[dim];
707 AF_Segment segments = axis->segments;
708 AF_Segment segment_limit = segments + axis->num_segments;
713 error = af_latin_hints_compute_segments( hints, dim );
717 /* a segment is round if it doesn't have successive */
718 /* on-curve points. */
719 for ( seg = segments; seg < segment_limit; seg++ )
721 AF_Point pt = seg->first;
722 AF_Point last = seg->last;
723 AF_Flags f0 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
727 seg->flags &= ~AF_EDGE_ROUND;
729 for ( ; pt != last; f0 = f1 )
732 f1 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
738 seg->flags |= AF_EDGE_ROUND;
747 af_cjk_hints_link_segments( AF_GlyphHints hints,
750 AF_AxisHints axis = &hints->axis[dim];
751 AF_Segment segments = axis->segments;
752 AF_Segment segment_limit = segments + axis->num_segments;
753 AF_Direction major_dir = axis->major_dir;
754 AF_Segment seg1, seg2;
755 FT_Pos len_threshold;
756 FT_Pos dist_threshold;
759 len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
761 dist_threshold = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
763 dist_threshold = FT_DivFix( 64 * 3, dist_threshold );
765 /* now compare each segment to the others */
766 for ( seg1 = segments; seg1 < segment_limit; seg1++ )
768 if ( seg1->dir != major_dir )
771 for ( seg2 = segments; seg2 < segment_limit; seg2++ )
772 if ( seg2 != seg1 && seg1->dir + seg2->dir == 0 )
774 FT_Pos dist = seg2->pos - seg1->pos;
781 FT_Pos min = seg1->min_coord;
782 FT_Pos max = seg1->max_coord;
786 if ( min < seg2->min_coord )
787 min = seg2->min_coord;
789 if ( max > seg2->max_coord )
790 max = seg2->max_coord;
793 if ( len >= len_threshold )
795 if ( dist * 8 < seg1->score * 9 &&
796 ( dist * 8 < seg1->score * 7 || seg1->len < len ) )
803 if ( dist * 8 < seg2->score * 9 &&
804 ( dist * 8 < seg2->score * 7 || seg2->len < len ) )
816 * now compute the `serif' segments
818 * In Hanzi, some strokes are wider on one or both of the ends.
819 * We either identify the stems on the ends as serifs or remove
820 * the linkage, depending on the length of the stems.
825 AF_Segment link1, link2;
828 for ( seg1 = segments; seg1 < segment_limit; seg1++ )
831 if ( !link1 || link1->link != seg1 || link1->pos <= seg1->pos )
834 if ( seg1->score >= dist_threshold )
837 for ( seg2 = segments; seg2 < segment_limit; seg2++ )
839 if ( seg2->pos > seg1->pos || seg1 == seg2 )
843 if ( !link2 || link2->link != seg2 || link2->pos < link1->pos )
846 if ( seg1->pos == seg2->pos && link1->pos == link2->pos )
849 if ( seg2->score <= seg1->score || seg1->score * 4 <= seg2->score )
852 /* seg2 < seg1 < link1 < link2 */
854 if ( seg1->len >= seg2->len * 3 )
859 for ( seg = segments; seg < segment_limit; seg++ )
861 AF_Segment link = seg->link;
869 else if ( link == link2 )
878 seg1->link = link1->link = 0;
886 for ( seg1 = segments; seg1 < segment_limit; seg1++ )
893 if ( seg2->link != seg1 )
897 if ( seg2->score < dist_threshold || seg1->score < seg2->score * 4 )
898 seg1->serif = seg2->link;
908 af_cjk_hints_compute_edges( AF_GlyphHints hints,
911 AF_AxisHints axis = &hints->axis[dim];
912 FT_Error error = FT_Err_Ok;
913 FT_Memory memory = hints->memory;
914 AF_CJKAxis laxis = &((AF_CJKMetrics)hints->metrics)->axis[dim];
916 AF_Segment segments = axis->segments;
917 AF_Segment segment_limit = segments + axis->num_segments;
921 FT_Pos edge_distance_threshold;
926 scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
929 /*********************************************************************/
931 /* We begin by generating a sorted table of edges for the current */
932 /* direction. To do so, we simply scan each segment and try to find */
933 /* an edge in our table that corresponds to its position. */
935 /* If no edge is found, we create and insert a new edge in the */
936 /* sorted table. Otherwise, we simply add the segment to the edge's */
937 /* list which is then processed in the second step to compute the */
938 /* edge's properties. */
940 /* Note that the edges table is sorted along the segment/edge */
943 /*********************************************************************/
945 edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
947 if ( edge_distance_threshold > 64 / 4 )
948 edge_distance_threshold = FT_DivFix( 64 / 4, scale );
950 edge_distance_threshold = laxis->edge_distance_threshold;
952 for ( seg = segments; seg < segment_limit; seg++ )
954 AF_Edge found = NULL;
955 FT_Pos best = 0xFFFFU;
959 /* look for an edge corresponding to the segment */
960 for ( ee = 0; ee < axis->num_edges; ee++ )
962 AF_Edge edge = axis->edges + ee;
966 if ( edge->dir != seg->dir )
969 dist = seg->pos - edge->fpos;
973 if ( dist < edge_distance_threshold && dist < best )
975 AF_Segment link = seg->link;
978 /* check whether all linked segments of the candidate edge */
979 /* can make a single edge. */
982 AF_Segment seg1 = edge->first;
988 AF_Segment link1 = seg1->link;
993 dist2 = AF_SEGMENT_DIST( link, link1 );
994 if ( dist2 >= edge_distance_threshold )
998 } while ( ( seg1 = seg1->edge_next ) != edge->first );
1000 if ( dist2 >= edge_distance_threshold )
1014 /* insert a new edge in the list and */
1015 /* sort according to the position */
1016 error = af_axis_hints_new_edge( axis, seg->pos,
1017 (AF_Direction)seg->dir,
1022 /* add the segment to the new edge's list */
1027 edge->dir = seg->dir;
1028 edge->fpos = seg->pos;
1029 edge->opos = FT_MulFix( seg->pos, scale );
1030 edge->pos = edge->opos;
1031 seg->edge_next = seg;
1035 /* if an edge was found, simply add the segment to the edge's */
1037 seg->edge_next = found->first;
1038 found->last->edge_next = seg;
1043 /******************************************************************/
1045 /* Good, we now compute each edge's properties according to the */
1046 /* segments found on its position. Basically, these are */
1048 /* - the edge's main direction */
1049 /* - stem edge, serif edge or both (which defaults to stem then) */
1050 /* - rounded edge, straight or both (which defaults to straight) */
1051 /* - link for edge */
1053 /******************************************************************/
1055 /* first of all, set the `edge' field in each segment -- this is */
1056 /* required in order to compute edge links */
1059 * Note that removing this loop and setting the `edge' field of each
1060 * segment directly in the code above slows down execution speed for
1061 * some reasons on platforms like the Sun.
1064 AF_Edge edges = axis->edges;
1065 AF_Edge edge_limit = edges + axis->num_edges;
1069 for ( edge = edges; edge < edge_limit; edge++ )
1076 seg = seg->edge_next;
1078 } while ( seg != edge->first );
1081 /* now compute each edge properties */
1082 for ( edge = edges; edge < edge_limit; edge++ )
1084 FT_Int is_round = 0; /* does it contain round segments? */
1085 FT_Int is_straight = 0; /* does it contain straight segments? */
1095 /* check for roundness of segment */
1096 if ( seg->flags & AF_EDGE_ROUND )
1101 /* check for links -- if seg->serif is set, then seg->link must */
1103 is_serif = (FT_Bool)( seg->serif && seg->serif->edge != edge );
1105 if ( seg->link || is_serif )
1117 edge2 = edge->serif;
1126 edge_delta = edge->fpos - edge2->fpos;
1127 if ( edge_delta < 0 )
1128 edge_delta = -edge_delta;
1130 seg_delta = AF_SEGMENT_DIST( seg, seg2 );
1132 if ( seg_delta < edge_delta )
1140 edge->serif = edge2;
1141 edge2->flags |= AF_EDGE_SERIF;
1147 seg = seg->edge_next;
1149 } while ( seg != edge->first );
1151 /* set the round/straight flags */
1152 edge->flags = AF_EDGE_NORMAL;
1154 if ( is_round > 0 && is_round >= is_straight )
1155 edge->flags |= AF_EDGE_ROUND;
1157 /* get rid of serifs if link is set */
1158 /* XXX: This gets rid of many unpleasant artefacts! */
1159 /* Example: the `c' in cour.pfa at size 13 */
1161 if ( edge->serif && edge->link )
1171 /* Detect segments and edges for given dimension. */
1174 af_cjk_hints_detect_features( AF_GlyphHints hints,
1180 error = af_cjk_hints_compute_segments( hints, dim );
1183 af_cjk_hints_link_segments( hints, dim );
1185 error = af_cjk_hints_compute_edges( hints, dim );
1191 /* Compute all edges which lie within blue zones. */
1193 FT_LOCAL_DEF( void )
1194 af_cjk_hints_compute_blue_edges( AF_GlyphHints hints,
1195 AF_CJKMetrics metrics,
1198 AF_AxisHints axis = &hints->axis[dim];
1199 AF_Edge edge = axis->edges;
1200 AF_Edge edge_limit = edge + axis->num_edges;
1201 AF_CJKAxis cjk = &metrics->axis[dim];
1202 FT_Fixed scale = cjk->scale;
1203 FT_Pos best_dist0; /* initial threshold */
1206 /* compute the initial threshold as a fraction of the EM size */
1207 best_dist0 = FT_MulFix( metrics->units_per_em / 40, scale );
1209 if ( best_dist0 > 64 / 2 ) /* maximum 1/2 pixel */
1210 best_dist0 = 64 / 2;
1212 /* compute which blue zones are active, i.e. have their scaled */
1213 /* size < 3/4 pixels */
1215 /* If the distant between an edge and a blue zone is shorter than */
1216 /* best_dist0, set the blue zone for the edge. Then search for */
1217 /* the blue zone with the smallest best_dist to the edge. */
1219 for ( ; edge < edge_limit; edge++ )
1222 AF_Width best_blue = NULL;
1223 FT_Pos best_dist = best_dist0;
1226 for ( bb = 0; bb < cjk->blue_count; bb++ )
1228 AF_CJKBlue blue = cjk->blues + bb;
1229 FT_Bool is_top_right_blue, is_major_dir;
1232 /* skip inactive blue zones (i.e., those that are too small) */
1233 if ( !( blue->flags & AF_CJK_BLUE_ACTIVE ) )
1236 /* if it is a top zone, check for right edges -- if it is a bottom */
1237 /* zone, check for left edges */
1239 /* of course, that's for TrueType */
1241 (FT_Byte)( ( blue->flags & AF_CJK_BLUE_TOP ) != 0 );
1243 FT_BOOL( edge->dir == axis->major_dir );
1245 /* if it is a top zone, the edge must be against the major */
1246 /* direction; if it is a bottom zone, it must be in the major */
1248 if ( is_top_right_blue ^ is_major_dir )
1254 /* Compare the edge to the closest blue zone type */
1255 if ( FT_ABS( edge->fpos - blue->ref.org ) >
1256 FT_ABS( edge->fpos - blue->shoot.org ) )
1257 compare = &blue->shoot;
1259 compare = &blue->ref;
1261 dist = edge->fpos - compare->org;
1265 dist = FT_MulFix( dist, scale );
1266 if ( dist < best_dist )
1269 best_blue = compare;
1275 edge->blue_edge = best_blue;
1280 /* Initalize hinting engine. */
1282 FT_LOCAL_DEF( FT_Error )
1283 af_cjk_hints_init( AF_GlyphHints hints,
1284 AF_CJKMetrics metrics )
1286 FT_Render_Mode mode;
1287 FT_UInt32 scaler_flags, other_flags;
1290 af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
1293 * correct x_scale and y_scale when needed, since they may have
1294 * been modified af_cjk_scale_dim above
1296 hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
1297 hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
1298 hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
1299 hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
1301 /* compute flags depending on render mode, etc. */
1302 mode = metrics->root.scaler.render_mode;
1304 #ifdef AF_CONFIG_OPTION_USE_WARPER
1305 if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
1306 metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
1309 scaler_flags = hints->scaler_flags;
1313 * We snap the width of vertical stems for the monochrome and
1314 * horizontal LCD rendering targets only.
1316 if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
1317 other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
1320 * We snap the width of horizontal stems for the monochrome and
1321 * vertical LCD rendering targets only.
1323 if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
1324 other_flags |= AF_LATIN_HINTS_VERT_SNAP;
1327 * We adjust stems to full pixels only if we don't use the `light' mode.
1329 if ( mode != FT_RENDER_MODE_LIGHT )
1330 other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
1332 if ( mode == FT_RENDER_MODE_MONO )
1333 other_flags |= AF_LATIN_HINTS_MONO;
1335 scaler_flags |= AF_SCALER_FLAG_NO_ADVANCE;
1337 hints->scaler_flags = scaler_flags;
1338 hints->other_flags = other_flags;
1344 /*************************************************************************/
1345 /*************************************************************************/
1347 /***** C J K G L Y P H G R I D - F I T T I N G *****/
1349 /*************************************************************************/
1350 /*************************************************************************/
1352 /* Snap a given width in scaled coordinates to one of the */
1353 /* current standard widths. */
1356 af_cjk_snap_width( AF_Width widths,
1361 FT_Pos best = 64 + 32 + 2;
1362 FT_Pos reference = width;
1366 for ( n = 0; n < count; n++ )
1383 scaled = FT_PIX_ROUND( reference );
1385 if ( width >= reference )
1387 if ( width < scaled + 48 )
1392 if ( width > scaled - 48 )
1400 /* Compute the snapped width of a given stem. */
1401 /* There is a lot of voodoo in this function; changing the hard-coded */
1402 /* parameters influence the whole hinting process. */
1405 af_cjk_compute_stem_width( AF_GlyphHints hints,
1408 AF_Edge_Flags base_flags,
1409 AF_Edge_Flags stem_flags )
1411 AF_CJKMetrics metrics = (AF_CJKMetrics)hints->metrics;
1412 AF_CJKAxis axis = &metrics->axis[dim];
1413 FT_Pos dist = width;
1415 FT_Bool vertical = FT_BOOL( dim == AF_DIMENSION_VERT );
1417 FT_UNUSED( base_flags );
1418 FT_UNUSED( stem_flags );
1421 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1430 if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
1431 ( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
1433 /* smooth hinting process: very lightly quantize the stem width */
1435 if ( axis->width_count > 0 )
1437 if ( FT_ABS( dist - axis->widths[0].cur ) < 40 )
1439 dist = axis->widths[0].cur;
1448 dist += ( 54 - dist ) / 2 ;
1449 else if ( dist < 3 * 64 )
1459 else if ( delta < 22 )
1461 else if ( delta < 42 )
1463 else if ( delta < 54 )
1471 /* strong hinting process: snap the stem width to integer pixels */
1473 dist = af_cjk_snap_width( axis->widths, axis->width_count, dist );
1477 /* in the case of vertical hinting, always round */
1478 /* the stem heights to integer pixels */
1481 dist = ( dist + 16 ) & ~63;
1487 if ( AF_LATIN_HINTS_DO_MONO( hints ) )
1489 /* monochrome horizontal hinting: snap widths to integer pixels */
1490 /* with a different threshold */
1495 dist = ( dist + 32 ) & ~63;
1499 /* for horizontal anti-aliased hinting, we adopt a more subtle */
1500 /* approach: we strengthen small stems, round stems whose size */
1501 /* is between 1 and 2 pixels to an integer, otherwise nothing */
1504 dist = ( dist + 64 ) >> 1;
1506 else if ( dist < 128 )
1507 dist = ( dist + 22 ) & ~63;
1509 /* round otherwise to prevent color fringes in LCD mode */
1510 dist = ( dist + 32 ) & ~63;
1523 /* Align one stem edge relative to the previous stem edge. */
1526 af_cjk_align_linked_edge( AF_GlyphHints hints,
1531 FT_Pos dist = stem_edge->opos - base_edge->opos;
1533 FT_Pos fitted_width = af_cjk_compute_stem_width(
1535 (AF_Edge_Flags)base_edge->flags,
1536 (AF_Edge_Flags)stem_edge->flags );
1539 stem_edge->pos = base_edge->pos + fitted_width;
1541 FT_TRACE5(( " CJKLINK: edge %d @%d (opos=%.2f) linked to %.2f,"
1542 " dist was %.2f, now %.2f\n",
1543 stem_edge - hints->axis[dim].edges, stem_edge->fpos,
1544 stem_edge->opos / 64.0, stem_edge->pos / 64.0,
1545 dist / 64.0, fitted_width / 64.0 ));
1549 /* Shift the coordinates of the `serif' edge by the same amount */
1550 /* as the corresponding `base' edge has been moved already. */
1553 af_cjk_align_serif_edge( AF_GlyphHints hints,
1559 serif->pos = base->pos + ( serif->opos - base->opos );
1563 /*************************************************************************/
1564 /*************************************************************************/
1565 /*************************************************************************/
1567 /**** E D G E H I N T I N G ****/
1569 /*************************************************************************/
1570 /*************************************************************************/
1571 /*************************************************************************/
1574 #define AF_LIGHT_MODE_MAX_HORZ_GAP 9
1575 #define AF_LIGHT_MODE_MAX_VERT_GAP 15
1576 #define AF_LIGHT_MODE_MAX_DELTA_ABS 14
1580 af_hint_normal_stem( AF_GlyphHints hints,
1586 FT_Pos org_len, cur_len, org_center;
1587 FT_Pos cur_pos1, cur_pos2;
1588 FT_Pos d_off1, u_off1, d_off2, u_off2, delta;
1590 FT_Pos threshold = 64;
1593 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1595 if ( ( edge->flags & AF_EDGE_ROUND ) &&
1596 ( edge2->flags & AF_EDGE_ROUND ) )
1598 if ( dim == AF_DIMENSION_VERT )
1599 threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP;
1601 threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP;
1605 if ( dim == AF_DIMENSION_VERT )
1606 threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP / 3;
1608 threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP / 3;
1612 org_len = edge2->opos - edge->opos;
1613 cur_len = af_cjk_compute_stem_width( hints, dim, org_len,
1614 (AF_Edge_Flags)edge->flags,
1615 (AF_Edge_Flags)edge2->flags );
1617 org_center = ( edge->opos + edge2->opos ) / 2 + anchor;
1618 cur_pos1 = org_center - cur_len / 2;
1619 cur_pos2 = cur_pos1 + cur_len;
1620 d_off1 = cur_pos1 - FT_PIX_FLOOR( cur_pos1 );
1621 d_off2 = cur_pos2 - FT_PIX_FLOOR( cur_pos2 );
1622 u_off1 = 64 - d_off1;
1623 u_off2 = 64 - d_off2;
1627 if ( d_off1 == 0 || d_off2 == 0 )
1630 if ( cur_len <= threshold )
1632 if ( d_off2 < cur_len )
1634 if ( u_off1 <= d_off2 )
1643 if ( threshold < 64 )
1645 if ( d_off1 >= threshold || u_off1 >= threshold ||
1646 d_off2 >= threshold || u_off2 >= threshold )
1650 offset = cur_len & 63;
1654 if ( u_off1 <= offset || d_off2 <= offset )
1658 offset = 64 - threshold;
1660 d_off1 = threshold - u_off1;
1661 u_off1 = u_off1 - offset;
1662 u_off2 = threshold - d_off2;
1663 d_off2 = d_off2 - offset;
1665 if ( d_off1 <= u_off1 )
1668 if ( d_off2 <= u_off2 )
1671 if ( FT_ABS( u_off1 ) <= FT_ABS( u_off2 ) )
1679 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
1681 if ( delta > AF_LIGHT_MODE_MAX_DELTA_ABS )
1682 delta = AF_LIGHT_MODE_MAX_DELTA_ABS;
1683 else if ( delta < -AF_LIGHT_MODE_MAX_DELTA_ABS )
1684 delta = -AF_LIGHT_MODE_MAX_DELTA_ABS;
1690 if ( edge->opos < edge2->opos )
1692 edge->pos = cur_pos1;
1693 edge2->pos = cur_pos1 + cur_len;
1697 edge->pos = cur_pos1 + cur_len;
1698 edge2->pos = cur_pos1;
1705 /* The main grid-fitting routine. */
1708 af_cjk_hint_edges( AF_GlyphHints hints,
1711 AF_AxisHints axis = &hints->axis[dim];
1712 AF_Edge edges = axis->edges;
1713 AF_Edge edge_limit = edges + axis->num_edges;
1719 FT_Bool has_last_stem = FALSE;
1720 FT_Pos last_stem_pos = 0;
1722 #ifdef FT_DEBUG_LEVEL_TRACE
1723 FT_UInt num_actions = 0;
1727 FT_TRACE5(( "cjk %s edge hinting (style `%s')\n",
1728 dim == AF_DIMENSION_VERT ? "horizontal" : "vertical",
1729 af_style_names[hints->metrics->style_class->style] ));
1731 /* we begin by aligning all stems relative to the blue zone */
1733 if ( AF_HINTS_DO_BLUES( hints ) )
1735 for ( edge = edges; edge < edge_limit; edge++ )
1738 AF_Edge edge1, edge2;
1741 if ( edge->flags & AF_EDGE_DONE )
1744 blue = edge->blue_edge;
1752 else if ( edge2 && edge2->blue_edge )
1754 blue = edge2->blue_edge;
1762 #ifdef FT_DEBUG_LEVEL_TRACE
1763 FT_TRACE5(( " CJKBLUE: edge %d @%d (opos=%.2f) snapped to %.2f,"
1765 edge1 - edges, edge1->fpos, edge1->opos / 64.0,
1766 blue->fit / 64.0, edge1->pos / 64.0 ));
1771 edge1->pos = blue->fit;
1772 edge1->flags |= AF_EDGE_DONE;
1774 if ( edge2 && !edge2->blue_edge )
1776 af_cjk_align_linked_edge( hints, dim, edge1, edge2 );
1777 edge2->flags |= AF_EDGE_DONE;
1779 #ifdef FT_DEBUG_LEVEL_TRACE
1789 /* now we align all stem edges. */
1790 for ( edge = edges; edge < edge_limit; edge++ )
1795 if ( edge->flags & AF_EDGE_DONE )
1798 /* skip all non-stem edges */
1806 /* Some CJK characters have so many stems that
1807 * the hinter is likely to merge two adjacent ones.
1808 * To solve this problem, if either edge of a stem
1809 * is too close to the previous one, we avoid
1810 * aligning the two edges, but rather interpolate
1811 * their locations at the end of this function in
1812 * order to preserve the space between the stems.
1814 if ( has_last_stem &&
1815 ( edge->pos < last_stem_pos + 64 ||
1816 edge2->pos < last_stem_pos + 64 ) )
1822 /* now align the stem */
1824 /* this should not happen, but it's better to be safe */
1825 if ( edge2->blue_edge )
1827 FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges ));
1829 af_cjk_align_linked_edge( hints, dim, edge2, edge );
1830 edge->flags |= AF_EDGE_DONE;
1832 #ifdef FT_DEBUG_LEVEL_TRACE
1841 af_cjk_align_linked_edge( hints, dim, edge2, edge );
1842 edge->flags |= AF_EDGE_DONE;
1844 #ifdef FT_DEBUG_LEVEL_TRACE
1848 /* We rarely reaches here it seems;
1849 * usually the two edges belonging
1850 * to one stem are marked as DONE together
1852 has_last_stem = TRUE;
1853 last_stem_pos = edge->pos;
1857 if ( dim != AF_DIMENSION_VERT && !anchor )
1863 AF_Edge left = edge;
1864 AF_Edge right = edge_limit - 1;
1865 AF_EdgeRec left1, left2, right1, right2;
1866 FT_Pos target, center1, center2;
1867 FT_Pos delta1, delta2, d1, d2;
1870 while ( right > left && !right->link )
1874 left2 = *left->link;
1875 right1 = *right->link;
1878 delta = ( ( ( hinter->pp2.x + 32 ) & -64 ) - hinter->pp2.x ) / 2;
1879 target = left->opos + ( right->opos - left->opos ) / 2 + delta - 16;
1882 delta1 += af_hint_normal_stem( hints, left, left->link,
1885 if ( left->link != right )
1886 af_hint_normal_stem( hints, right->link, right, delta1, 0 );
1888 center1 = left->pos + ( right->pos - left->pos ) / 2;
1890 if ( center1 >= target )
1891 delta2 = delta - 32;
1893 delta2 = delta + 32;
1895 delta2 += af_hint_normal_stem( hints, &left1, &left2, delta2, 0 );
1897 if ( delta1 != delta2 )
1899 if ( left->link != right )
1900 af_hint_normal_stem( hints, &right1, &right2, delta2, 0 );
1902 center2 = left1.pos + ( right2.pos - left1.pos ) / 2;
1904 d1 = center1 - target;
1905 d2 = center2 - target;
1907 if ( FT_ABS( d2 ) < FT_ABS( d1 ) )
1909 left->pos = left1.pos;
1910 left->link->pos = left2.pos;
1912 if ( left->link != right )
1914 right->link->pos = right1.pos;
1915 right->pos = right2.pos;
1923 right->link->flags |= AF_EDGE_DONE;
1924 right->flags |= AF_EDGE_DONE;
1930 delta = af_hint_normal_stem( hints, edge, edge2, 0,
1931 AF_DIMENSION_HORZ );
1934 af_hint_normal_stem( hints, edge, edge2, delta, dim );
1937 printf( "stem (%d,%d) adjusted (%.1f,%.1f)\n",
1938 edge - edges, edge2 - edges,
1939 ( edge->pos - edge->opos ) / 64.0,
1940 ( edge2->pos - edge2->opos ) / 64.0 );
1944 edge->flags |= AF_EDGE_DONE;
1945 edge2->flags |= AF_EDGE_DONE;
1946 has_last_stem = TRUE;
1947 last_stem_pos = edge2->pos;
1950 /* make sure that lowercase m's maintain their symmetry */
1952 /* In general, lowercase m's have six vertical edges if they are sans */
1953 /* serif, or twelve if they are with serifs. This implementation is */
1954 /* based on that assumption, and seems to work very well with most */
1955 /* faces. However, if for a certain face this assumption is not */
1956 /* true, the m is just rendered like before. In addition, any stem */
1957 /* correction will only be applied to symmetrical glyphs (even if the */
1958 /* glyph is not an m), so the potential for unwanted distortion is */
1959 /* relatively low. */
1961 /* We don't handle horizontal edges since we can't easily assure that */
1962 /* the third (lowest) stem aligns with the base line; it might end up */
1963 /* one pixel higher or lower. */
1965 n_edges = edge_limit - edges;
1966 if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
1968 AF_Edge edge1, edge2, edge3;
1969 FT_Pos dist1, dist2, span;
1985 dist1 = edge2->opos - edge1->opos;
1986 dist2 = edge3->opos - edge2->opos;
1988 span = dist1 - dist2;
1992 if ( edge1->link == edge1 + 1 &&
1993 edge2->link == edge2 + 1 &&
1994 edge3->link == edge3 + 1 && span < 8 )
1996 delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
1997 edge3->pos -= delta;
1999 edge3->link->pos -= delta;
2001 /* move the serifs along with the stem */
2002 if ( n_edges == 12 )
2004 ( edges + 8 )->pos -= delta;
2005 ( edges + 11 )->pos -= delta;
2008 edge3->flags |= AF_EDGE_DONE;
2010 edge3->link->flags |= AF_EDGE_DONE;
2018 * now hint the remaining edges (serifs and single) in order
2019 * to complete our processing
2021 for ( edge = edges; edge < edge_limit; edge++ )
2023 if ( edge->flags & AF_EDGE_DONE )
2028 af_cjk_align_serif_edge( hints, edge->serif, edge );
2029 edge->flags |= AF_EDGE_DONE;
2037 for ( edge = edges; edge < edge_limit; edge++ )
2039 AF_Edge before, after;
2042 if ( edge->flags & AF_EDGE_DONE )
2045 before = after = edge;
2047 while ( --before >= edges )
2048 if ( before->flags & AF_EDGE_DONE )
2051 while ( ++after < edge_limit )
2052 if ( after->flags & AF_EDGE_DONE )
2055 if ( before >= edges || after < edge_limit )
2057 if ( before < edges )
2058 af_cjk_align_serif_edge( hints, after, edge );
2059 else if ( after >= edge_limit )
2060 af_cjk_align_serif_edge( hints, before, edge );
2063 if ( after->fpos == before->fpos )
2064 edge->pos = before->pos;
2066 edge->pos = before->pos +
2067 FT_MulDiv( edge->fpos - before->fpos,
2068 after->pos - before->pos,
2069 after->fpos - before->fpos );
2076 #ifdef FT_DEBUG_LEVEL_TRACE
2078 FT_TRACE5(( " (none)\n" ));
2079 FT_TRACE5(( "\n" ));
2087 af_cjk_align_edge_points( AF_GlyphHints hints,
2090 AF_AxisHints axis = & hints->axis[dim];
2091 AF_Edge edges = axis->edges;
2092 AF_Edge edge_limit = edges + axis->num_edges;
2097 snapping = FT_BOOL( ( dim == AF_DIMENSION_HORZ &&
2098 AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ||
2099 ( dim == AF_DIMENSION_VERT &&
2100 AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) );
2102 for ( edge = edges; edge < edge_limit; edge++ )
2104 /* move the points of each segment */
2105 /* in each edge to the edge's position */
2106 AF_Segment seg = edge->first;
2113 AF_Point point = seg->first;
2118 if ( dim == AF_DIMENSION_HORZ )
2120 point->x = edge->pos;
2121 point->flags |= AF_FLAG_TOUCH_X;
2125 point->y = edge->pos;
2126 point->flags |= AF_FLAG_TOUCH_Y;
2129 if ( point == seg->last )
2132 point = point->next;
2135 seg = seg->edge_next;
2137 } while ( seg != edge->first );
2141 FT_Pos delta = edge->pos - edge->opos;
2146 AF_Point point = seg->first;
2151 if ( dim == AF_DIMENSION_HORZ )
2154 point->flags |= AF_FLAG_TOUCH_X;
2159 point->flags |= AF_FLAG_TOUCH_Y;
2162 if ( point == seg->last )
2165 point = point->next;
2168 seg = seg->edge_next;
2170 } while ( seg != edge->first );
2176 /* Apply the complete hinting algorithm to a CJK glyph. */
2178 FT_LOCAL_DEF( FT_Error )
2179 af_cjk_hints_apply( AF_GlyphHints hints,
2180 FT_Outline* outline,
2181 AF_CJKMetrics metrics )
2186 FT_UNUSED( metrics );
2189 error = af_glyph_hints_reload( hints, outline );
2193 /* analyze glyph outline */
2194 if ( AF_HINTS_DO_HORIZONTAL( hints ) )
2196 error = af_cjk_hints_detect_features( hints, AF_DIMENSION_HORZ );
2200 af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_HORZ );
2203 if ( AF_HINTS_DO_VERTICAL( hints ) )
2205 error = af_cjk_hints_detect_features( hints, AF_DIMENSION_VERT );
2209 af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_VERT );
2212 /* grid-fit the outline */
2213 for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
2215 if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
2216 ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) ) )
2219 #ifdef AF_CONFIG_OPTION_USE_WARPER
2220 if ( dim == AF_DIMENSION_HORZ &&
2221 metrics->root.scaler.render_mode == FT_RENDER_MODE_NORMAL )
2223 AF_WarperRec warper;
2228 af_warper_compute( &warper, hints, (AF_Dimension)dim,
2230 af_glyph_hints_scale_dim( hints, (AF_Dimension)dim,
2234 #endif /* AF_CONFIG_OPTION_USE_WARPER */
2236 af_cjk_hint_edges( hints, (AF_Dimension)dim );
2237 af_cjk_align_edge_points( hints, (AF_Dimension)dim );
2238 af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
2239 af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
2244 af_glyph_hints_dump_points( hints );
2245 af_glyph_hints_dump_segments( hints );
2246 af_glyph_hints_dump_edges( hints );
2249 af_glyph_hints_save( hints, outline );
2256 /*************************************************************************/
2257 /*************************************************************************/
2259 /***** C J K S C R I P T C L A S S *****/
2261 /*************************************************************************/
2262 /*************************************************************************/
2265 AF_DEFINE_WRITING_SYSTEM_CLASS(
2266 af_cjk_writing_system_class,
2268 AF_WRITING_SYSTEM_CJK,
2270 sizeof ( AF_CJKMetricsRec ),
2272 (AF_WritingSystem_InitMetricsFunc) af_cjk_metrics_init,
2273 (AF_WritingSystem_ScaleMetricsFunc)af_cjk_metrics_scale,
2274 (AF_WritingSystem_DoneMetricsFunc) NULL,
2276 (AF_WritingSystem_InitHintsFunc) af_cjk_hints_init,
2277 (AF_WritingSystem_ApplyHintsFunc) af_cjk_hints_apply
2281 #else /* !AF_CONFIG_OPTION_CJK */
2284 AF_DEFINE_WRITING_SYSTEM_CLASS(
2285 af_cjk_writing_system_class,
2287 AF_WRITING_SYSTEM_CJK,
2289 sizeof ( AF_CJKMetricsRec ),
2291 (AF_WritingSystem_InitMetricsFunc) NULL,
2292 (AF_WritingSystem_ScaleMetricsFunc)NULL,
2293 (AF_WritingSystem_DoneMetricsFunc) NULL,
2295 (AF_WritingSystem_InitHintsFunc) NULL,
2296 (AF_WritingSystem_ApplyHintsFunc) NULL
2300 #endif /* !AF_CONFIG_OPTION_CJK */