1 /***************************************************************************/
5 /* Auto-fitter hinting routines for latin writing system (body). */
7 /* Copyright 2003-2015 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 /***************************************************************************/
20 #include FT_ADVANCES_H
21 #include FT_INTERNAL_DEBUG_H
29 #ifdef AF_CONFIG_OPTION_USE_WARPER
34 /*************************************************************************/
36 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
37 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
38 /* messages during execution. */
41 #define FT_COMPONENT trace_aflatin
44 /* needed for computation of round vs. flat segments */
45 #define FLAT_THRESHOLD( x ) ( x / 14 )
48 /*************************************************************************/
49 /*************************************************************************/
51 /***** L A T I N G L O B A L M E T R I C S *****/
53 /*************************************************************************/
54 /*************************************************************************/
57 /* Find segments and links, compute all stem widths, and initialize */
58 /* standard width and height for the glyph with given charcode. */
61 af_latin_metrics_init_widths( AF_LatinMetrics metrics
,
64 /* scan the array of segments in each direction */
66 AF_GlyphHintsRec
*hints
= malloc(sizeof(AF_GlyphHintsRec
));
68 AF_GlyphHintsRec hints
[1];
73 "latin standard widths computation (style `%s')\n"
74 "=====================================================\n"
76 af_style_names
[metrics
->root
.style_class
->style
] ));
78 af_glyph_hints_init( hints
, face
->memory
);
80 metrics
->axis
[AF_DIMENSION_HORZ
].width_count
= 0;
81 metrics
->axis
[AF_DIMENSION_VERT
].width_count
= 0;
89 AF_LatinMetricsRec
*dummy
= malloc(sizeof(AF_LatinMetricsRec
));
91 AF_LatinMetricsRec dummy
[1];
93 AF_Scaler scaler
= &dummy
->root
.scaler
;
95 #ifdef FT_CONFIG_OPTION_PIC
96 AF_FaceGlobals globals
= metrics
->root
.globals
;
99 AF_StyleClass style_class
= metrics
->root
.style_class
;
100 AF_ScriptClass script_class
= AF_SCRIPT_CLASSES_GET
101 [style_class
->script
];
103 FT_UInt32 standard_char
;
107 * We check more than a single standard character to catch features
108 * like `c2sc' (small caps from caps) that don't contain lowercase
109 * letters by definition, or other features that mainly operate on
113 standard_char
= script_class
->standard_char1
;
114 af_get_char_index( &metrics
->root
,
120 if ( script_class
->standard_char2
)
122 standard_char
= script_class
->standard_char2
;
123 af_get_char_index( &metrics
->root
,
129 if ( script_class
->standard_char3
)
131 standard_char
= script_class
->standard_char3
;
132 af_get_char_index( &metrics
->root
,
147 FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
148 standard_char
, glyph_index
));
150 error
= FT_Load_Glyph( face
, glyph_index
, FT_LOAD_NO_SCALE
);
151 if ( error
|| face
->glyph
->outline
.n_points
<= 0 )
156 dummy
->units_per_em
= metrics
->units_per_em
;
158 scaler
->x_scale
= 0x10000L
;
159 scaler
->y_scale
= 0x10000L
;
164 scaler
->render_mode
= FT_RENDER_MODE_NORMAL
;
167 af_glyph_hints_rescale( hints
, (AF_StyleMetrics
)dummy
);
169 error
= af_glyph_hints_reload( hints
, &face
->glyph
->outline
);
173 for ( dim
= 0; dim
< AF_DIMENSION_MAX
; dim
++ )
175 AF_LatinAxis axis
= &metrics
->axis
[dim
];
176 AF_AxisHints axhints
= &hints
->axis
[dim
];
177 AF_Segment seg
, limit
, link
;
178 FT_UInt num_widths
= 0;
181 error
= af_latin_hints_compute_segments( hints
,
187 * We assume that the glyphs selected for the stem width
188 * computation are `featureless' enough so that the linking
189 * algorithm works fine without adjustments of its scoring
192 af_latin_hints_link_segments( hints
,
197 seg
= axhints
->segments
;
198 limit
= seg
+ axhints
->num_segments
;
200 for ( ; seg
< limit
; seg
++ )
204 /* we only consider stem segments there! */
205 if ( link
&& link
->link
== seg
&& link
> seg
)
210 dist
= seg
->pos
- link
->pos
;
214 if ( num_widths
< AF_LATIN_MAX_WIDTHS
)
215 axis
->widths
[num_widths
++].org
= dist
;
219 /* this also replaces multiple almost identical stem widths */
220 /* with a single one (the value 100 is heuristic) */
221 af_sort_and_quantize_widths( &num_widths
, axis
->widths
,
222 dummy
->units_per_em
/ 100 );
223 axis
->width_count
= num_widths
;
227 for ( dim
= 0; dim
< AF_DIMENSION_MAX
; dim
++ )
229 AF_LatinAxis axis
= &metrics
->axis
[dim
];
233 stdw
= ( axis
->width_count
> 0 ) ? axis
->widths
[0].org
234 : AF_LATIN_CONSTANT( metrics
, 50 );
236 /* let's try 20% of the smallest width */
237 axis
->edge_distance_threshold
= stdw
/ 5;
238 axis
->standard_width
= stdw
;
239 axis
->extra_light
= 0;
241 #ifdef FT_DEBUG_LEVEL_TRACE
246 FT_TRACE5(( "%s widths:\n",
247 dim
== AF_DIMENSION_VERT
? "horizontal"
250 FT_TRACE5(( " %d (standard)", axis
->standard_width
));
251 for ( i
= 1; i
< axis
->width_count
; i
++ )
252 FT_TRACE5(( " %d", axis
->widths
[i
].org
));
265 af_glyph_hints_done( hints
);
274 /* Find all blue zones. Flat segments give the reference points, */
275 /* round segments the overshoot positions. */
278 af_latin_metrics_init_blues( AF_LatinMetrics metrics
,
281 FT_Pos flats
[AF_BLUE_STRING_MAX_LEN
];
282 FT_Pos rounds
[AF_BLUE_STRING_MAX_LEN
];
289 AF_LatinAxis axis
= &metrics
->axis
[AF_DIMENSION_VERT
];
292 AF_StyleClass sc
= metrics
->root
.style_class
;
294 AF_Blue_Stringset bss
= sc
->blue_stringset
;
295 const AF_Blue_StringRec
* bs
= &af_blue_stringsets
[bss
];
297 FT_Pos flat_threshold
= FLAT_THRESHOLD( metrics
->units_per_em
);
300 /* we walk over the blue character strings as specified in the */
301 /* style's entry in the `af_blue_stringset' array */
303 FT_TRACE5(( "latin blue zones computation\n"
304 "============================\n"
307 for ( ; bs
->string
!= AF_BLUE_STRING_MAX
; bs
++ )
309 const char* p
= &af_blue_strings
[bs
->string
];
316 #ifdef FT_DEBUG_LEVEL_TRACE
318 FT_Bool have_flag
= 0;
321 FT_TRACE5(( "blue zone %d", axis
->blue_count
));
323 if ( bs
->properties
)
327 if ( AF_LATIN_IS_TOP_BLUE( bs
) )
329 FT_TRACE5(( "top" ));
333 if ( AF_LATIN_IS_NEUTRAL_BLUE( bs
) )
337 FT_TRACE5(( "neutral" ));
341 if ( AF_LATIN_IS_X_HEIGHT_BLUE( bs
) )
345 FT_TRACE5(( "small top" ));
349 if ( AF_LATIN_IS_LONG_BLUE( bs
) )
353 FT_TRACE5(( "long" ));
359 FT_TRACE5(( ":\n" ));
361 #endif /* FT_DEBUG_LEVEL_TRACE */
371 FT_ULong glyph_index
;
373 FT_Pos best_y
; /* same as points.y */
374 FT_Int best_point
, best_contour_first
, best_contour_last
;
379 GET_UTF8_CHAR( ch
, p
);
381 /* load the character in the face -- skip unknown or empty ones */
382 af_get_char_index( &metrics
->root
, ch
, &glyph_index
, &y_offset
);
383 if ( glyph_index
== 0 )
385 FT_TRACE5(( " U+%04lX unavailable\n", ch
));
389 error
= FT_Load_Glyph( face
, glyph_index
, FT_LOAD_NO_SCALE
);
390 outline
= face
->glyph
->outline
;
391 /* reject glyphs that don't produce any rendering */
392 if ( error
|| outline
.n_points
<= 2 )
394 FT_TRACE5(( " U+%04lX contains no (usable) outlines\n", ch
));
398 /* now compute min or max point indices and coordinates */
399 points
= outline
.points
;
401 best_y
= 0; /* make compiler happy */
402 best_contour_first
= 0; /* ditto */
403 best_contour_last
= 0; /* ditto */
411 for ( nn
= 0; nn
< outline
.n_contours
; first
= last
+ 1, nn
++ )
413 FT_Int old_best_point
= best_point
;
417 last
= outline
.contours
[nn
];
419 /* Avoid single-point contours since they are never rasterized. */
420 /* In some fonts, they correspond to mark attachment points */
421 /* that are way outside of the glyph's real outline. */
425 if ( AF_LATIN_IS_TOP_BLUE( bs
) )
427 for ( pp
= first
; pp
<= last
; pp
++ )
429 if ( best_point
< 0 || points
[pp
].y
> best_y
)
432 best_y
= points
[pp
].y
;
433 ascender
= FT_MAX( ascender
, best_y
+ y_offset
);
436 descender
= FT_MIN( descender
, points
[pp
].y
+ y_offset
);
441 for ( pp
= first
; pp
<= last
; pp
++ )
443 if ( best_point
< 0 || points
[pp
].y
< best_y
)
446 best_y
= points
[pp
].y
;
447 descender
= FT_MIN( descender
, best_y
+ y_offset
);
450 ascender
= FT_MAX( ascender
, points
[pp
].y
+ y_offset
);
454 if ( best_point
!= old_best_point
)
456 best_contour_first
= first
;
457 best_contour_last
= last
;
462 /* now check whether the point belongs to a straight or round */
463 /* segment; we first need to find in which contour the extremum */
464 /* lies, then inspect its previous and next points */
465 if ( best_point
>= 0 )
467 FT_Pos best_x
= points
[best_point
].x
;
469 FT_Int best_segment_first
, best_segment_last
;
470 FT_Int best_on_point_first
, best_on_point_last
;
474 best_segment_first
= best_point
;
475 best_segment_last
= best_point
;
477 if ( FT_CURVE_TAG( outline
.tags
[best_point
] ) == FT_CURVE_TAG_ON
)
479 best_on_point_first
= best_point
;
480 best_on_point_last
= best_point
;
484 best_on_point_first
= -1;
485 best_on_point_last
= -1;
488 /* look for the previous and next points on the contour */
489 /* that are not on the same Y coordinate, then threshold */
490 /* the `closeness'... */
496 if ( prev
> best_contour_first
)
499 prev
= best_contour_last
;
501 dist
= FT_ABS( points
[prev
].y
- best_y
);
502 /* accept a small distance or a small angle (both values are */
503 /* heuristic; value 20 corresponds to approx. 2.9 degrees) */
505 if ( FT_ABS( points
[prev
].x
- best_x
) <= 20 * dist
)
508 best_segment_first
= prev
;
510 if ( FT_CURVE_TAG( outline
.tags
[prev
] ) == FT_CURVE_TAG_ON
)
512 best_on_point_first
= prev
;
513 if ( best_on_point_last
< 0 )
514 best_on_point_last
= prev
;
517 } while ( prev
!= best_point
);
521 if ( next
< best_contour_last
)
524 next
= best_contour_first
;
526 dist
= FT_ABS( points
[next
].y
- best_y
);
528 if ( FT_ABS( points
[next
].x
- best_x
) <= 20 * dist
)
531 best_segment_last
= next
;
533 if ( FT_CURVE_TAG( outline
.tags
[next
] ) == FT_CURVE_TAG_ON
)
535 best_on_point_last
= next
;
536 if ( best_on_point_first
< 0 )
537 best_on_point_first
= next
;
540 } while ( next
!= best_point
);
542 if ( AF_LATIN_IS_LONG_BLUE( bs
) )
544 /* If this flag is set, we have an additional constraint to */
545 /* get the blue zone distance: Find a segment of the topmost */
546 /* (or bottommost) contour that is longer than a heuristic */
547 /* threshold. This ensures that small bumps in the outline */
548 /* are ignored (for example, the `vertical serifs' found in */
549 /* many Hebrew glyph designs). */
551 /* If this segment is long enough, we are done. Otherwise, */
552 /* search the segment next to the extremum that is long */
553 /* enough, has the same direction, and a not too large */
554 /* vertical distance from the extremum. Note that the */
555 /* algorithm doesn't check whether the found segment is */
556 /* actually the one (vertically) nearest to the extremum. */
558 /* heuristic threshold value */
559 FT_Pos length_threshold
= metrics
->units_per_em
/ 25;
562 dist
= FT_ABS( points
[best_segment_last
].x
-
563 points
[best_segment_first
].x
);
565 if ( dist
< length_threshold
&&
566 best_segment_last
- best_segment_first
+ 2 <=
567 best_contour_last
- best_contour_first
)
569 /* heuristic threshold value */
570 FT_Pos height_threshold
= metrics
->units_per_em
/ 4;
576 /* we intentionally declare these two variables */
577 /* outside of the loop since various compilers emit */
578 /* incorrect warning messages otherwise, talking about */
579 /* `possibly uninitialized variables' */
580 FT_Int p_first
= 0; /* make compiler happy */
586 /* compute direction */
591 if ( prev
> best_contour_first
)
594 prev
= best_contour_last
;
596 if ( points
[prev
].x
!= best_x
)
599 } while ( prev
!= best_point
);
601 /* skip glyph for the degenerate case */
602 if ( prev
== best_point
)
605 left2right
= FT_BOOL( points
[prev
].x
< points
[best_point
].x
);
607 first
= best_segment_last
;
619 /* no hit; adjust first point */
622 /* also adjust first and last on point */
623 if ( FT_CURVE_TAG( outline
.tags
[first
] ) ==
638 if ( last
< best_contour_last
)
641 last
= best_contour_first
;
643 if ( FT_ABS( best_y
- points
[first
].y
) > height_threshold
)
645 /* vertical distance too large */
650 /* same test as above */
651 dist
= FT_ABS( points
[last
].y
- points
[first
].y
);
653 if ( FT_ABS( points
[last
].x
- points
[first
].x
) <=
660 if ( FT_CURVE_TAG( outline
.tags
[last
] ) == FT_CURVE_TAG_ON
)
667 l2r
= FT_BOOL( points
[first
].x
< points
[last
].x
);
668 d
= FT_ABS( points
[last
].x
- points
[first
].x
);
670 if ( l2r
== left2right
&&
671 d
>= length_threshold
)
673 /* all constraints are met; update segment after finding */
677 if ( last
< best_contour_last
)
680 last
= best_contour_first
;
682 d
= FT_ABS( points
[last
].y
- points
[first
].y
);
684 if ( FT_ABS( points
[next
].x
- points
[first
].x
) <=
687 if ( last
> best_contour_first
)
690 last
= best_contour_last
;
696 if ( FT_CURVE_TAG( outline
.tags
[last
] ) ==
704 } while ( last
!= best_segment_first
);
706 best_y
= points
[first
].y
;
708 best_segment_first
= first
;
709 best_segment_last
= last
;
711 best_on_point_first
= p_first
;
712 best_on_point_last
= p_last
;
717 } while ( last
!= best_segment_first
);
721 /* for computing blue zones, we add the y offset as returned */
722 /* by the currently used OpenType feature -- for example, */
723 /* superscript glyphs might be identical to subscript glyphs */
724 /* with a vertical shift */
727 FT_TRACE5(( " U+%04lX: best_y = %5ld", ch
, best_y
));
729 /* now set the `round' flag depending on the segment's kind: */
731 /* - if the horizontal distance between the first and last */
732 /* `on' point is larger than a heuristic threshold */
733 /* we have a flat segment */
734 /* - if either the first or the last point of the segment is */
735 /* an `off' point, the segment is round, otherwise it is */
737 if ( best_on_point_first
>= 0 &&
738 best_on_point_last
>= 0 &&
739 ( FT_ABS( points
[best_on_point_last
].x
-
740 points
[best_on_point_first
].x
) ) >
745 FT_CURVE_TAG( outline
.tags
[best_segment_first
] ) !=
747 FT_CURVE_TAG( outline
.tags
[best_segment_last
] ) !=
750 if ( round
&& AF_LATIN_IS_NEUTRAL_BLUE( bs
) )
752 /* only use flat segments for a neutral blue zone */
753 FT_TRACE5(( " (round, skipped)\n" ));
757 FT_TRACE5(( " (%s)\n", round
? "round" : "flat" ));
761 rounds
[num_rounds
++] = best_y
;
763 flats
[num_flats
++] = best_y
;
766 if ( num_flats
== 0 && num_rounds
== 0 )
769 * we couldn't find a single glyph to compute this blue zone,
770 * we will simply ignore it then
772 FT_TRACE5(( " empty\n" ));
776 /* we have computed the contents of the `rounds' and `flats' tables, */
777 /* now determine the reference and overshoot position of the blue -- */
778 /* we simply take the median value after a simple sort */
779 af_sort_pos( num_rounds
, rounds
);
780 af_sort_pos( num_flats
, flats
);
782 blue
= &axis
->blues
[axis
->blue_count
];
783 blue_ref
= &blue
->ref
.org
;
784 blue_shoot
= &blue
->shoot
.org
;
788 if ( num_flats
== 0 )
791 *blue_shoot
= rounds
[num_rounds
/ 2];
793 else if ( num_rounds
== 0 )
796 *blue_shoot
= flats
[num_flats
/ 2];
800 *blue_ref
= flats
[num_flats
/ 2];
801 *blue_shoot
= rounds
[num_rounds
/ 2];
804 /* there are sometimes problems: if the overshoot position of top */
805 /* zones is under its reference position, or the opposite for bottom */
806 /* zones. We must thus check everything there and correct the errors */
807 if ( *blue_shoot
!= *blue_ref
)
809 FT_Pos ref
= *blue_ref
;
810 FT_Pos shoot
= *blue_shoot
;
811 FT_Bool over_ref
= FT_BOOL( shoot
> ref
);
814 if ( AF_LATIN_IS_TOP_BLUE( bs
) ^ over_ref
)
817 *blue_shoot
= ( shoot
+ ref
) / 2;
819 FT_TRACE5(( " [overshoot smaller than reference,"
820 " taking mean value]\n" ));
824 blue
->ascender
= ascender
;
825 blue
->descender
= descender
;
828 if ( AF_LATIN_IS_TOP_BLUE( bs
) )
829 blue
->flags
|= AF_LATIN_BLUE_TOP
;
830 if ( AF_LATIN_IS_NEUTRAL_BLUE( bs
) )
831 blue
->flags
|= AF_LATIN_BLUE_NEUTRAL
;
834 * The following flag is used later to adjust the y and x scales
835 * in order to optimize the pixel grid alignment of the top of small
838 if ( AF_LATIN_IS_X_HEIGHT_BLUE( bs
) )
839 blue
->flags
|= AF_LATIN_BLUE_ADJUSTMENT
;
841 FT_TRACE5(( " -> reference = %ld\n"
842 " overshoot = %ld\n",
843 *blue_ref
, *blue_shoot
));
852 /* Check whether all ASCII digits have the same advance width. */
855 af_latin_metrics_check_digits( AF_LatinMetrics metrics
,
859 FT_Bool started
= 0, same_width
= 1;
860 FT_Fixed advance
, old_advance
= 0;
863 /* digit `0' is 0x30 in all supported charmaps */
864 for ( i
= 0x30; i
<= 0x39; i
++ )
866 FT_ULong glyph_index
;
870 af_get_char_index( &metrics
->root
, i
, &glyph_index
, &y_offset
);
871 if ( glyph_index
== 0 )
874 if ( FT_Get_Advance( face
, glyph_index
,
877 FT_LOAD_IGNORE_TRANSFORM
,
883 if ( advance
!= old_advance
)
891 old_advance
= advance
;
896 metrics
->root
.digits_have_same_width
= same_width
;
900 /* Initialize global metrics. */
902 FT_LOCAL_DEF( FT_Error
)
903 af_latin_metrics_init( AF_LatinMetrics metrics
,
906 FT_CharMap oldmap
= face
->charmap
;
909 metrics
->units_per_em
= face
->units_per_EM
;
911 if ( !FT_Select_Charmap( face
, FT_ENCODING_UNICODE
) )
913 af_latin_metrics_init_widths( metrics
, face
);
914 af_latin_metrics_init_blues( metrics
, face
);
915 af_latin_metrics_check_digits( metrics
, face
);
918 FT_Set_Charmap( face
, oldmap
);
923 /* Adjust scaling value, then scale and shift widths */
924 /* and blue zones (if applicable) for given dimension. */
927 af_latin_metrics_scale_dim( AF_LatinMetrics metrics
,
937 if ( dim
== AF_DIMENSION_HORZ
)
939 scale
= scaler
->x_scale
;
940 delta
= scaler
->x_delta
;
944 scale
= scaler
->y_scale
;
945 delta
= scaler
->y_delta
;
948 axis
= &metrics
->axis
[dim
];
950 if ( axis
->org_scale
== scale
&& axis
->org_delta
== delta
)
953 axis
->org_scale
= scale
;
954 axis
->org_delta
= delta
;
957 * correct X and Y scale to optimize the alignment of the top of small
958 * letters to the pixel grid
961 AF_LatinAxis Axis
= &metrics
->axis
[AF_DIMENSION_VERT
];
962 AF_LatinBlue blue
= NULL
;
965 for ( nn
= 0; nn
< Axis
->blue_count
; nn
++ )
967 if ( Axis
->blues
[nn
].flags
& AF_LATIN_BLUE_ADJUSTMENT
)
969 blue
= &Axis
->blues
[nn
];
983 scaled
= FT_MulFix( blue
->shoot
.org
, scaler
->y_scale
);
984 ppem
= metrics
->root
.scaler
.face
->size
->metrics
.x_ppem
;
985 limit
= metrics
->root
.globals
->increase_x_height
;
988 /* if the `increase-x-height' property is active, */
989 /* we round up much more often */
992 ppem
>= AF_PROP_INCREASE_X_HEIGHT_MIN
)
995 fitted
= ( scaled
+ threshold
) & ~63;
997 if ( scaled
!= fitted
)
1000 if ( dim
== AF_DIMENSION_HORZ
)
1002 if ( fitted
< scaled
)
1003 scale
-= scale
/ 50; /* scale *= 0.98 */
1007 if ( dim
== AF_DIMENSION_VERT
)
1014 new_scale
= FT_MulDiv( scale
, fitted
, scaled
);
1016 /* the scaling should not change the result by more than two pixels */
1017 max_height
= metrics
->units_per_em
;
1019 for ( nn
= 0; nn
< Axis
->blue_count
; nn
++ )
1021 max_height
= FT_MAX( max_height
, Axis
->blues
[nn
].ascender
);
1022 max_height
= FT_MAX( max_height
, -Axis
->blues
[nn
].descender
);
1025 dist
= FT_ABS( FT_MulFix( max_height
, new_scale
- scale
) );
1033 "af_latin_metrics_scale_dim:"
1034 " x height alignment (style `%s'):\n"
1036 " vertical scaling changed from %.4f to %.4f (by %d%%)\n"
1038 af_style_names
[metrics
->root
.style_class
->style
],
1039 axis
->org_scale
/ 65536.0,
1041 ( fitted
- scaled
) * 100 / scaled
));
1043 #ifdef FT_DEBUG_LEVEL_TRACE
1047 "af_latin_metrics_scale_dim:"
1048 " x height alignment (style `%s'):\n"
1050 " excessive vertical scaling abandoned\n"
1052 af_style_names
[metrics
->root
.style_class
->style
] ));
1060 axis
->scale
= scale
;
1061 axis
->delta
= delta
;
1063 if ( dim
== AF_DIMENSION_HORZ
)
1065 metrics
->root
.scaler
.x_scale
= scale
;
1066 metrics
->root
.scaler
.x_delta
= delta
;
1070 metrics
->root
.scaler
.y_scale
= scale
;
1071 metrics
->root
.scaler
.y_delta
= delta
;
1074 FT_TRACE5(( "%s widths (style `%s')\n",
1075 dim
== AF_DIMENSION_HORZ
? "horizontal" : "vertical",
1076 af_style_names
[metrics
->root
.style_class
->style
] ));
1078 /* scale the widths */
1079 for ( nn
= 0; nn
< axis
->width_count
; nn
++ )
1081 AF_Width width
= axis
->widths
+ nn
;
1084 width
->cur
= FT_MulFix( width
->org
, scale
);
1085 width
->fit
= width
->cur
;
1087 FT_TRACE5(( " %d scaled to %.2f\n",
1089 width
->cur
/ 64.0 ));
1092 FT_TRACE5(( "\n" ));
1094 /* an extra-light axis corresponds to a standard width that is */
1095 /* smaller than 5/8 pixels */
1097 (FT_Bool
)( FT_MulFix( axis
->standard_width
, scale
) < 32 + 8 );
1099 #ifdef FT_DEBUG_LEVEL_TRACE
1100 if ( axis
->extra_light
)
1101 FT_TRACE5(( "`%s' style is extra light (at current resolution)\n"
1103 af_style_names
[metrics
->root
.style_class
->style
] ));
1106 if ( dim
== AF_DIMENSION_VERT
)
1108 #ifdef FT_DEBUG_LEVEL_TRACE
1109 if ( axis
->blue_count
)
1110 FT_TRACE5(( "blue zones (style `%s')\n",
1111 af_style_names
[metrics
->root
.style_class
->style
] ));
1114 /* scale the blue zones */
1115 for ( nn
= 0; nn
< axis
->blue_count
; nn
++ )
1117 AF_LatinBlue blue
= &axis
->blues
[nn
];
1121 blue
->ref
.cur
= FT_MulFix( blue
->ref
.org
, scale
) + delta
;
1122 blue
->ref
.fit
= blue
->ref
.cur
;
1123 blue
->shoot
.cur
= FT_MulFix( blue
->shoot
.org
, scale
) + delta
;
1124 blue
->shoot
.fit
= blue
->shoot
.cur
;
1125 blue
->flags
&= ~AF_LATIN_BLUE_ACTIVE
;
1127 /* a blue zone is only active if it is less than 3/4 pixels tall */
1128 dist
= FT_MulFix( blue
->ref
.org
- blue
->shoot
.org
, scale
);
1129 if ( dist
<= 48 && dist
>= -48 )
1137 /* use discrete values for blue zone widths */
1141 /* generic, original code */
1142 delta1
= blue
->shoot
.org
- blue
->ref
.org
;
1147 delta2
= FT_MulFix( delta2
, scale
);
1151 else if ( delta2
< 64 )
1152 delta2
= 32 + ( ( ( delta2
- 32 ) + 16 ) & ~31 );
1154 delta2
= FT_PIX_ROUND( delta2
);
1159 blue
->ref
.fit
= FT_PIX_ROUND( blue
->ref
.cur
);
1160 blue
->shoot
.fit
= blue
->ref
.fit
+ delta2
;
1164 /* simplified version due to abs(dist) <= 48 */
1171 else if ( delta2
< 48 )
1179 blue
->ref
.fit
= FT_PIX_ROUND( blue
->ref
.cur
);
1180 blue
->shoot
.fit
= blue
->ref
.fit
- delta2
;
1184 blue
->flags
|= AF_LATIN_BLUE_ACTIVE
;
1186 FT_TRACE5(( " reference %d: %d scaled to %.2f%s\n"
1187 " overshoot %d: %d scaled to %.2f%s\n",
1190 blue
->ref
.fit
/ 64.0,
1191 blue
->flags
& AF_LATIN_BLUE_ACTIVE
? ""
1195 blue
->shoot
.fit
/ 64.0,
1196 blue
->flags
& AF_LATIN_BLUE_ACTIVE
? ""
1204 /* Scale global values in both directions. */
1206 FT_LOCAL_DEF( void )
1207 af_latin_metrics_scale( AF_LatinMetrics metrics
,
1210 metrics
->root
.scaler
.render_mode
= scaler
->render_mode
;
1211 metrics
->root
.scaler
.face
= scaler
->face
;
1212 metrics
->root
.scaler
.flags
= scaler
->flags
;
1214 af_latin_metrics_scale_dim( metrics
, scaler
, AF_DIMENSION_HORZ
);
1215 af_latin_metrics_scale_dim( metrics
, scaler
, AF_DIMENSION_VERT
);
1219 /* Extract standard_width from writing system/script specific */
1220 /* metrics class. */
1222 FT_LOCAL_DEF( void )
1223 af_latin_get_standard_widths( AF_LatinMetrics metrics
,
1228 *stdHW
= metrics
->axis
[AF_DIMENSION_VERT
].standard_width
;
1231 *stdVW
= metrics
->axis
[AF_DIMENSION_HORZ
].standard_width
;
1235 /*************************************************************************/
1236 /*************************************************************************/
1238 /***** L A T I N G L Y P H A N A L Y S I S *****/
1240 /*************************************************************************/
1241 /*************************************************************************/
1244 /* Walk over all contours and compute its segments. */
1246 FT_LOCAL_DEF( FT_Error
)
1247 af_latin_hints_compute_segments( AF_GlyphHints hints
,
1250 AF_LatinMetrics metrics
= (AF_LatinMetrics
)hints
->metrics
;
1251 AF_AxisHints axis
= &hints
->axis
[dim
];
1252 FT_Memory memory
= hints
->memory
;
1253 FT_Error error
= FT_Err_Ok
;
1254 AF_Segment segment
= NULL
;
1256 AF_Point
* contour
= hints
->contours
;
1257 AF_Point
* contour_limit
= contour
+ hints
->num_contours
;
1258 AF_Direction major_dir
, segment_dir
;
1260 FT_Pos flat_threshold
= FLAT_THRESHOLD( metrics
->units_per_em
);
1265 seg0
.flags
= AF_EDGE_NORMAL
;
1267 major_dir
= (AF_Direction
)FT_ABS( axis
->major_dir
);
1268 segment_dir
= major_dir
;
1270 axis
->num_segments
= 0;
1272 /* set up (u,v) in each point */
1273 if ( dim
== AF_DIMENSION_HORZ
)
1275 AF_Point point
= hints
->points
;
1276 AF_Point limit
= point
+ hints
->num_points
;
1279 for ( ; point
< limit
; point
++ )
1281 point
->u
= point
->fx
;
1282 point
->v
= point
->fy
;
1287 AF_Point point
= hints
->points
;
1288 AF_Point limit
= point
+ hints
->num_points
;
1291 for ( ; point
< limit
; point
++ )
1293 point
->u
= point
->fy
;
1294 point
->v
= point
->fx
;
1298 /* do each contour separately */
1299 for ( ; contour
< contour_limit
; contour
++ )
1301 AF_Point point
= contour
[0];
1302 AF_Point last
= point
->prev
;
1304 FT_Pos min_pos
= 32000; /* minimum segment pos != min_coord */
1305 FT_Pos max_pos
= -32000; /* maximum segment pos != max_coord */
1306 FT_Pos min_on_pos
= 32000;
1307 FT_Pos max_on_pos
= -32000;
1311 if ( point
== last
) /* skip singletons -- just in case */
1314 if ( FT_ABS( last
->out_dir
) == major_dir
&&
1315 FT_ABS( point
->out_dir
) == major_dir
)
1317 /* we are already on an edge, try to locate its start */
1322 point
= point
->prev
;
1323 if ( FT_ABS( point
->out_dir
) != major_dir
)
1325 point
= point
->next
;
1328 if ( point
== last
)
1349 /* get minimum and maximum coordinate of on points */
1350 if ( !( point
->flags
& AF_FLAG_CONTROL
) )
1353 if ( v
< min_on_pos
)
1355 if ( v
> max_on_pos
)
1359 if ( point
->out_dir
!= segment_dir
|| point
== last
)
1361 /* we are just leaving an edge; record a new segment! */
1362 segment
->last
= point
;
1363 segment
->pos
= (FT_Short
)( ( min_pos
+ max_pos
) >> 1 );
1365 /* a segment is round if either its first or last point */
1366 /* is a control point, and the length of the on points */
1367 /* inbetween doesn't exceed a heuristic limit */
1368 if ( ( segment
->first
->flags
| point
->flags
) & AF_FLAG_CONTROL
&&
1369 ( max_on_pos
- min_on_pos
) < flat_threshold
)
1370 segment
->flags
|= AF_EDGE_ROUND
;
1372 /* compute segment size */
1373 min_pos
= max_pos
= point
->v
;
1375 v
= segment
->first
->v
;
1381 segment
->min_coord
= (FT_Short
)min_pos
;
1382 segment
->max_coord
= (FT_Short
)max_pos
;
1383 segment
->height
= (FT_Short
)( segment
->max_coord
-
1384 segment
->min_coord
);
1392 /* now exit if we are at the start/end point */
1393 if ( point
== last
)
1400 if ( !on_edge
&& FT_ABS( point
->out_dir
) == major_dir
)
1402 /* this is the start of a new segment! */
1403 segment_dir
= (AF_Direction
)point
->out_dir
;
1405 error
= af_axis_hints_new_segment( axis
, memory
, &segment
);
1409 /* clear all segment fields */
1412 segment
->dir
= (FT_Char
)segment_dir
;
1413 segment
->first
= point
;
1414 segment
->last
= point
;
1416 min_pos
= max_pos
= point
->u
;
1418 if ( point
->flags
& AF_FLAG_CONTROL
)
1421 max_on_pos
= -32000;
1424 min_on_pos
= max_on_pos
= point
->v
;
1429 point
= point
->next
;
1435 /* now slightly increase the height of segments if this makes */
1436 /* sense -- this is used to better detect and ignore serifs */
1438 AF_Segment segments
= axis
->segments
;
1439 AF_Segment segments_end
= segments
+ axis
->num_segments
;
1442 for ( segment
= segments
; segment
< segments_end
; segment
++ )
1444 AF_Point first
= segment
->first
;
1445 AF_Point last
= segment
->last
;
1446 FT_Pos first_v
= first
->v
;
1447 FT_Pos last_v
= last
->v
;
1450 if ( first_v
< last_v
)
1456 if ( p
->v
< first_v
)
1457 segment
->height
= (FT_Short
)( segment
->height
+
1458 ( ( first_v
- p
->v
) >> 1 ) );
1461 if ( p
->v
> last_v
)
1462 segment
->height
= (FT_Short
)( segment
->height
+
1463 ( ( p
->v
- last_v
) >> 1 ) );
1471 if ( p
->v
> first_v
)
1472 segment
->height
= (FT_Short
)( segment
->height
+
1473 ( ( p
->v
- first_v
) >> 1 ) );
1476 if ( p
->v
< last_v
)
1477 segment
->height
= (FT_Short
)( segment
->height
+
1478 ( ( last_v
- p
->v
) >> 1 ) );
1488 /* Link segments to form stems and serifs. If `width_count' and */
1489 /* `widths' are non-zero, use them to fine-tune the scoring function. */
1491 FT_LOCAL_DEF( void )
1492 af_latin_hints_link_segments( AF_GlyphHints hints
,
1493 FT_UInt width_count
,
1494 AF_WidthRec
* widths
,
1497 AF_AxisHints axis
= &hints
->axis
[dim
];
1498 AF_Segment segments
= axis
->segments
;
1499 AF_Segment segment_limit
= segments
+ axis
->num_segments
;
1500 FT_Pos len_threshold
, len_score
, dist_score
, max_width
;
1501 AF_Segment seg1
, seg2
;
1505 max_width
= widths
[width_count
- 1].org
;
1509 /* a heuristic value to set up a minimum value for overlapping */
1510 len_threshold
= AF_LATIN_CONSTANT( hints
->metrics
, 8 );
1511 if ( len_threshold
== 0 )
1514 /* a heuristic value to weight lengths */
1515 len_score
= AF_LATIN_CONSTANT( hints
->metrics
, 6000 );
1517 /* a heuristic value to weight distances (no call to */
1518 /* AF_LATIN_CONSTANT needed, since we work on multiples */
1519 /* of the stem width) */
1522 /* now compare each segment to the others */
1523 for ( seg1
= segments
; seg1
< segment_limit
; seg1
++ )
1525 if ( seg1
->dir
!= axis
->major_dir
)
1528 /* search for stems having opposite directions, */
1529 /* with seg1 to the `left' of seg2 */
1530 for ( seg2
= segments
; seg2
< segment_limit
; seg2
++ )
1532 FT_Pos pos1
= seg1
->pos
;
1533 FT_Pos pos2
= seg2
->pos
;
1536 if ( seg1
->dir
+ seg2
->dir
== 0 && pos2
> pos1
)
1538 /* compute distance between the two segments */
1539 FT_Pos min
= seg1
->min_coord
;
1540 FT_Pos max
= seg1
->max_coord
;
1544 if ( min
< seg2
->min_coord
)
1545 min
= seg2
->min_coord
;
1547 if ( max
> seg2
->max_coord
)
1548 max
= seg2
->max_coord
;
1550 /* compute maximum coordinate difference of the two segments */
1551 /* (this is, how much they overlap) */
1553 if ( len
>= len_threshold
)
1556 * The score is the sum of two demerits indicating the
1557 * `badness' of a fit, measured along the segments' main axis
1558 * and orthogonal to it, respectively.
1560 * o The less overlapping along the main axis, the worse it
1561 * is, causing a larger demerit.
1563 * o The nearer the orthogonal distance to a stem width, the
1564 * better it is, causing a smaller demerit. For simplicity,
1565 * however, we only increase the demerit for values that
1566 * exceed the largest stem width.
1569 FT_Pos dist
= pos2
- pos1
;
1571 FT_Pos dist_demerit
, score
;
1576 /* distance demerits are based on multiples of `max_width'; */
1577 /* we scale by 1024 for getting more precision */
1578 FT_Pos delta
= ( dist
<< 10 ) / max_width
- ( 1 << 10 );
1581 if ( delta
> 10000 )
1582 dist_demerit
= 32000;
1583 else if ( delta
> 0 )
1584 dist_demerit
= delta
* delta
/ dist_score
;
1589 dist_demerit
= dist
; /* default if no widths available */
1591 score
= dist_demerit
+ len_score
/ len
;
1593 /* and we search for the smallest score */
1594 if ( score
< seg1
->score
)
1596 seg1
->score
= score
;
1600 if ( score
< seg2
->score
)
1602 seg2
->score
= score
;
1610 /* now compute the `serif' segments, cf. explanations in `afhints.h' */
1611 for ( seg1
= segments
; seg1
< segment_limit
; seg1
++ )
1617 if ( seg2
->link
!= seg1
)
1620 seg1
->serif
= seg2
->link
;
1627 /* Link segments to edges, using feature analysis for selection. */
1629 FT_LOCAL_DEF( FT_Error
)
1630 af_latin_hints_compute_edges( AF_GlyphHints hints
,
1633 AF_AxisHints axis
= &hints
->axis
[dim
];
1634 FT_Error error
= FT_Err_Ok
;
1635 FT_Memory memory
= hints
->memory
;
1636 AF_LatinAxis laxis
= &((AF_LatinMetrics
)hints
->metrics
)->axis
[dim
];
1638 AF_Segment segments
= axis
->segments
;
1639 AF_Segment segment_limit
= segments
+ axis
->num_segments
;
1643 AF_Direction up_dir
;
1646 FT_Pos edge_distance_threshold
;
1647 FT_Pos segment_length_threshold
;
1650 axis
->num_edges
= 0;
1652 scale
= ( dim
== AF_DIMENSION_HORZ
) ? hints
->x_scale
1656 up_dir
= ( dim
== AF_DIMENSION_HORZ
) ? AF_DIR_UP
1661 * We ignore all segments that are less than 1 pixel in length
1662 * to avoid many problems with serif fonts. We compute the
1663 * corresponding threshold in font units.
1665 if ( dim
== AF_DIMENSION_HORZ
)
1666 segment_length_threshold
= FT_DivFix( 64, hints
->y_scale
);
1668 segment_length_threshold
= 0;
1670 /*********************************************************************/
1672 /* We begin by generating a sorted table of edges for the current */
1673 /* direction. To do so, we simply scan each segment and try to find */
1674 /* an edge in our table that corresponds to its position. */
1676 /* If no edge is found, we create and insert a new edge in the */
1677 /* sorted table. Otherwise, we simply add the segment to the edge's */
1678 /* list which gets processed in the second step to compute the */
1679 /* edge's properties. */
1681 /* Note that the table of edges is sorted along the segment/edge */
1684 /*********************************************************************/
1686 /* assure that edge distance threshold is at most 0.25px */
1687 edge_distance_threshold
= FT_MulFix( laxis
->edge_distance_threshold
,
1689 if ( edge_distance_threshold
> 64 / 4 )
1690 edge_distance_threshold
= 64 / 4;
1692 edge_distance_threshold
= FT_DivFix( edge_distance_threshold
,
1695 for ( seg
= segments
; seg
< segment_limit
; seg
++ )
1697 AF_Edge found
= NULL
;
1701 if ( seg
->height
< segment_length_threshold
)
1704 /* A special case for serif edges: If they are smaller than */
1705 /* 1.5 pixels we ignore them. */
1707 2 * seg
->height
< 3 * segment_length_threshold
)
1710 /* look for an edge corresponding to the segment */
1711 for ( ee
= 0; ee
< axis
->num_edges
; ee
++ )
1713 AF_Edge edge
= axis
->edges
+ ee
;
1717 dist
= seg
->pos
- edge
->fpos
;
1721 if ( dist
< edge_distance_threshold
&& edge
->dir
== seg
->dir
)
1733 /* insert a new edge in the list and */
1734 /* sort according to the position */
1735 error
= af_axis_hints_new_edge( axis
, seg
->pos
,
1736 (AF_Direction
)seg
->dir
,
1741 /* add the segment to the new edge's list */
1746 edge
->dir
= seg
->dir
;
1747 edge
->fpos
= seg
->pos
;
1748 edge
->opos
= FT_MulFix( seg
->pos
, scale
);
1749 edge
->pos
= edge
->opos
;
1750 seg
->edge_next
= seg
;
1754 /* if an edge was found, simply add the segment to the edge's */
1756 seg
->edge_next
= found
->first
;
1757 found
->last
->edge_next
= seg
;
1763 /******************************************************************/
1765 /* Good, we now compute each edge's properties according to the */
1766 /* segments found on its position. Basically, these are */
1768 /* - the edge's main direction */
1769 /* - stem edge, serif edge or both (which defaults to stem then) */
1770 /* - rounded edge, straight or both (which defaults to straight) */
1771 /* - link for edge */
1773 /******************************************************************/
1775 /* first of all, set the `edge' field in each segment -- this is */
1776 /* required in order to compute edge links */
1779 * Note that removing this loop and setting the `edge' field of each
1780 * segment directly in the code above slows down execution speed for
1781 * some reasons on platforms like the Sun.
1784 AF_Edge edges
= axis
->edges
;
1785 AF_Edge edge_limit
= edges
+ axis
->num_edges
;
1789 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1796 seg
= seg
->edge_next
;
1798 } while ( seg
!= edge
->first
);
1801 /* now compute each edge properties */
1802 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1804 FT_Int is_round
= 0; /* does it contain round segments? */
1805 FT_Int is_straight
= 0; /* does it contain straight segments? */
1807 FT_Pos ups
= 0; /* number of upwards segments */
1808 FT_Pos downs
= 0; /* number of downwards segments */
1819 /* check for roundness of segment */
1820 if ( seg
->flags
& AF_EDGE_ROUND
)
1826 /* check for segment direction */
1827 if ( seg
->dir
== up_dir
)
1828 ups
+= seg
->max_coord
- seg
->min_coord
;
1830 downs
+= seg
->max_coord
- seg
->min_coord
;
1833 /* check for links -- if seg->serif is set, then seg->link must */
1835 is_serif
= (FT_Bool
)( seg
->serif
&&
1837 seg
->serif
->edge
!= edge
);
1839 if ( ( seg
->link
&& seg
->link
->edge
!= NULL
) || is_serif
)
1851 edge2
= edge
->serif
;
1860 edge_delta
= edge
->fpos
- edge2
->fpos
;
1861 if ( edge_delta
< 0 )
1862 edge_delta
= -edge_delta
;
1864 seg_delta
= seg
->pos
- seg2
->pos
;
1865 if ( seg_delta
< 0 )
1866 seg_delta
= -seg_delta
;
1868 if ( seg_delta
< edge_delta
)
1876 edge
->serif
= edge2
;
1877 edge2
->flags
|= AF_EDGE_SERIF
;
1883 seg
= seg
->edge_next
;
1885 } while ( seg
!= edge
->first
);
1887 /* set the round/straight flags */
1888 edge
->flags
= AF_EDGE_NORMAL
;
1890 if ( is_round
> 0 && is_round
>= is_straight
)
1891 edge
->flags
|= AF_EDGE_ROUND
;
1894 /* set the edge's main direction */
1895 edge
->dir
= AF_DIR_NONE
;
1898 edge
->dir
= (FT_Char
)up_dir
;
1900 else if ( ups
< downs
)
1901 edge
->dir
= (FT_Char
)-up_dir
;
1903 else if ( ups
== downs
)
1904 edge
->dir
= 0; /* both up and down! */
1907 /* get rid of serifs if link is set */
1908 /* XXX: This gets rid of many unpleasant artefacts! */
1909 /* Example: the `c' in cour.pfa at size 13 */
1911 if ( edge
->serif
&& edge
->link
)
1921 /* Detect segments and edges for given dimension. */
1923 FT_LOCAL_DEF( FT_Error
)
1924 af_latin_hints_detect_features( AF_GlyphHints hints
,
1925 FT_UInt width_count
,
1926 AF_WidthRec
* widths
,
1932 error
= af_latin_hints_compute_segments( hints
, dim
);
1935 af_latin_hints_link_segments( hints
, width_count
, widths
, dim
);
1937 error
= af_latin_hints_compute_edges( hints
, dim
);
1944 /* Compute all edges which lie within blue zones. */
1947 af_latin_hints_compute_blue_edges( AF_GlyphHints hints
,
1948 AF_LatinMetrics metrics
)
1950 AF_AxisHints axis
= &hints
->axis
[AF_DIMENSION_VERT
];
1951 AF_Edge edge
= axis
->edges
;
1952 AF_Edge edge_limit
= edge
+ axis
->num_edges
;
1953 AF_LatinAxis latin
= &metrics
->axis
[AF_DIMENSION_VERT
];
1954 FT_Fixed scale
= latin
->scale
;
1957 /* compute which blue zones are active, i.e. have their scaled */
1958 /* size < 3/4 pixels */
1960 /* for each horizontal edge search the blue zone which is closest */
1961 for ( ; edge
< edge_limit
; edge
++ )
1964 AF_Width best_blue
= NULL
;
1965 FT_Bool best_blue_is_neutral
= 0;
1966 FT_Pos best_dist
; /* initial threshold */
1969 /* compute the initial threshold as a fraction of the EM size */
1970 /* (the value 40 is heuristic) */
1971 best_dist
= FT_MulFix( metrics
->units_per_em
/ 40, scale
);
1973 /* assure a minimum distance of 0.5px */
1974 if ( best_dist
> 64 / 2 )
1977 for ( bb
= 0; bb
< latin
->blue_count
; bb
++ )
1979 AF_LatinBlue blue
= latin
->blues
+ bb
;
1980 FT_Bool is_top_blue
, is_neutral_blue
, is_major_dir
;
1983 /* skip inactive blue zones (i.e., those that are too large) */
1984 if ( !( blue
->flags
& AF_LATIN_BLUE_ACTIVE
) )
1987 /* if it is a top zone, check for right edges (against the major */
1988 /* direction); if it is a bottom zone, check for left edges (in */
1989 /* the major direction) -- this assumes the TrueType convention */
1990 /* for the orientation of contours */
1992 (FT_Byte
)( ( blue
->flags
& AF_LATIN_BLUE_TOP
) != 0 );
1994 (FT_Byte
)( ( blue
->flags
& AF_LATIN_BLUE_NEUTRAL
) != 0);
1996 FT_BOOL( edge
->dir
== axis
->major_dir
);
1998 /* neutral blue zones are handled for both directions */
1999 if ( is_top_blue
^ is_major_dir
|| is_neutral_blue
)
2004 /* first of all, compare it to the reference position */
2005 dist
= edge
->fpos
- blue
->ref
.org
;
2009 dist
= FT_MulFix( dist
, scale
);
2010 if ( dist
< best_dist
)
2013 best_blue
= &blue
->ref
;
2014 best_blue_is_neutral
= is_neutral_blue
;
2017 /* now compare it to the overshoot position and check whether */
2018 /* the edge is rounded, and whether the edge is over the */
2019 /* reference position of a top zone, or under the reference */
2020 /* position of a bottom zone (provided we don't have a */
2021 /* neutral blue zone) */
2022 if ( edge
->flags
& AF_EDGE_ROUND
&&
2026 FT_Bool is_under_ref
= FT_BOOL( edge
->fpos
< blue
->ref
.org
);
2029 if ( is_top_blue
^ is_under_ref
)
2031 dist
= edge
->fpos
- blue
->shoot
.org
;
2035 dist
= FT_MulFix( dist
, scale
);
2036 if ( dist
< best_dist
)
2039 best_blue
= &blue
->shoot
;
2040 best_blue_is_neutral
= is_neutral_blue
;
2049 edge
->blue_edge
= best_blue
;
2050 if ( best_blue_is_neutral
)
2051 edge
->flags
|= AF_EDGE_NEUTRAL
;
2057 /* Initalize hinting engine. */
2060 af_latin_hints_init( AF_GlyphHints hints
,
2061 AF_LatinMetrics metrics
)
2063 FT_Render_Mode mode
;
2064 FT_UInt32 scaler_flags
, other_flags
;
2065 FT_Face face
= metrics
->root
.scaler
.face
;
2068 af_glyph_hints_rescale( hints
, (AF_StyleMetrics
)metrics
);
2071 * correct x_scale and y_scale if needed, since they may have
2072 * been modified by `af_latin_metrics_scale_dim' above
2074 hints
->x_scale
= metrics
->axis
[AF_DIMENSION_HORZ
].scale
;
2075 hints
->x_delta
= metrics
->axis
[AF_DIMENSION_HORZ
].delta
;
2076 hints
->y_scale
= metrics
->axis
[AF_DIMENSION_VERT
].scale
;
2077 hints
->y_delta
= metrics
->axis
[AF_DIMENSION_VERT
].delta
;
2079 /* compute flags depending on render mode, etc. */
2080 mode
= metrics
->root
.scaler
.render_mode
;
2082 #if 0 /* #ifdef AF_CONFIG_OPTION_USE_WARPER */
2083 if ( mode
== FT_RENDER_MODE_LCD
|| mode
== FT_RENDER_MODE_LCD_V
)
2084 metrics
->root
.scaler
.render_mode
= mode
= FT_RENDER_MODE_NORMAL
;
2087 scaler_flags
= hints
->scaler_flags
;
2091 * We snap the width of vertical stems for the monochrome and
2092 * horizontal LCD rendering targets only.
2094 if ( mode
== FT_RENDER_MODE_MONO
|| mode
== FT_RENDER_MODE_LCD
)
2095 other_flags
|= AF_LATIN_HINTS_HORZ_SNAP
;
2098 * We snap the width of horizontal stems for the monochrome and
2099 * vertical LCD rendering targets only.
2101 if ( mode
== FT_RENDER_MODE_MONO
|| mode
== FT_RENDER_MODE_LCD_V
)
2102 other_flags
|= AF_LATIN_HINTS_VERT_SNAP
;
2105 * We adjust stems to full pixels only if we don't use the `light' mode.
2107 if ( mode
!= FT_RENDER_MODE_LIGHT
)
2108 other_flags
|= AF_LATIN_HINTS_STEM_ADJUST
;
2110 if ( mode
== FT_RENDER_MODE_MONO
)
2111 other_flags
|= AF_LATIN_HINTS_MONO
;
2114 * In `light' hinting mode we disable horizontal hinting completely.
2115 * We also do it if the face is italic.
2117 * However, if warping is enabled (which only works in `light' hinting
2118 * mode), advance widths get adjusted, too.
2120 if ( mode
== FT_RENDER_MODE_LIGHT
||
2121 ( face
->style_flags
& FT_STYLE_FLAG_ITALIC
) != 0 )
2122 scaler_flags
|= AF_SCALER_FLAG_NO_HORIZONTAL
;
2124 #ifdef AF_CONFIG_OPTION_USE_WARPER
2125 /* get (global) warper flag */
2126 if ( !metrics
->root
.globals
->module
->warping
)
2127 scaler_flags
|= AF_SCALER_FLAG_NO_WARPER
;
2130 hints
->scaler_flags
= scaler_flags
;
2131 hints
->other_flags
= other_flags
;
2137 /*************************************************************************/
2138 /*************************************************************************/
2140 /***** L A T I N G L Y P H G R I D - F I T T I N G *****/
2142 /*************************************************************************/
2143 /*************************************************************************/
2145 /* Snap a given width in scaled coordinates to one of the */
2146 /* current standard widths. */
2149 af_latin_snap_width( AF_Width widths
,
2154 FT_Pos best
= 64 + 32 + 2;
2155 FT_Pos reference
= width
;
2159 for ( n
= 0; n
< count
; n
++ )
2176 scaled
= FT_PIX_ROUND( reference
);
2178 if ( width
>= reference
)
2180 if ( width
< scaled
+ 48 )
2185 if ( width
> scaled
- 48 )
2193 /* Compute the snapped width of a given stem, ignoring very thin ones. */
2194 /* There is a lot of voodoo in this function; changing the hard-coded */
2195 /* parameters influence the whole hinting process. */
2198 af_latin_compute_stem_width( AF_GlyphHints hints
,
2202 FT_UInt stem_flags
)
2204 AF_LatinMetrics metrics
= (AF_LatinMetrics
)hints
->metrics
;
2205 AF_LatinAxis axis
= &metrics
->axis
[dim
];
2206 FT_Pos dist
= width
;
2208 FT_Int vertical
= ( dim
== AF_DIMENSION_VERT
);
2211 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints
) ||
2221 if ( ( vertical
&& !AF_LATIN_HINTS_DO_VERT_SNAP( hints
) ) ||
2222 ( !vertical
&& !AF_LATIN_HINTS_DO_HORZ_SNAP( hints
) ) )
2224 /* smooth hinting process: very lightly quantize the stem width */
2226 /* leave the widths of serifs alone */
2227 if ( ( stem_flags
& AF_EDGE_SERIF
) &&
2232 else if ( base_flags
& AF_EDGE_ROUND
)
2237 else if ( dist
< 56 )
2240 if ( axis
->width_count
> 0 )
2245 /* compare to standard width */
2246 delta
= dist
- axis
->widths
[0].cur
;
2253 dist
= axis
->widths
[0].cur
;
2260 if ( dist
< 3 * 64 )
2268 else if ( delta
< 32 )
2271 else if ( delta
< 54 )
2278 dist
= ( dist
+ 32 ) & ~63;
2283 /* strong hinting process: snap the stem width to integer pixels */
2285 FT_Pos org_dist
= dist
;
2288 dist
= af_latin_snap_width( axis
->widths
, axis
->width_count
, dist
);
2292 /* in the case of vertical hinting, always round */
2293 /* the stem heights to integer pixels */
2296 dist
= ( dist
+ 16 ) & ~63;
2302 if ( AF_LATIN_HINTS_DO_MONO( hints
) )
2304 /* monochrome horizontal hinting: snap widths to integer pixels */
2305 /* with a different threshold */
2310 dist
= ( dist
+ 32 ) & ~63;
2314 /* for horizontal anti-aliased hinting, we adopt a more subtle */
2315 /* approach: we strengthen small stems, round stems whose size */
2316 /* is between 1 and 2 pixels to an integer, otherwise nothing */
2319 dist
= ( dist
+ 64 ) >> 1;
2321 else if ( dist
< 128 )
2323 /* We only round to an integer width if the corresponding */
2324 /* distortion is less than 1/4 pixel. Otherwise this */
2325 /* makes everything worse since the diagonals, which are */
2326 /* not hinted, appear a lot bolder or thinner than the */
2327 /* vertical stems. */
2332 dist
= ( dist
+ 22 ) & ~63;
2333 delta
= dist
- org_dist
;
2341 dist
= ( dist
+ 64 ) >> 1;
2345 /* round otherwise to prevent color fringes in LCD mode */
2346 dist
= ( dist
+ 32 ) & ~63;
2359 /* Align one stem edge relative to the previous stem edge. */
2362 af_latin_align_linked_edge( AF_GlyphHints hints
,
2367 FT_Pos dist
= stem_edge
->opos
- base_edge
->opos
;
2369 FT_Pos fitted_width
= af_latin_compute_stem_width( hints
, dim
, dist
,
2374 stem_edge
->pos
= base_edge
->pos
+ fitted_width
;
2376 FT_TRACE5(( " LINK: edge %d (opos=%.2f) linked to %.2f,"
2377 " dist was %.2f, now %.2f\n",
2378 stem_edge
- hints
->axis
[dim
].edges
, stem_edge
->opos
/ 64.0,
2379 stem_edge
->pos
/ 64.0, dist
/ 64.0, fitted_width
/ 64.0 ));
2383 /* Shift the coordinates of the `serif' edge by the same amount */
2384 /* as the corresponding `base' edge has been moved already. */
2387 af_latin_align_serif_edge( AF_GlyphHints hints
,
2393 serif
->pos
= base
->pos
+ ( serif
->opos
- base
->opos
);
2397 /*************************************************************************/
2398 /*************************************************************************/
2399 /*************************************************************************/
2401 /**** E D G E H I N T I N G ****/
2403 /*************************************************************************/
2404 /*************************************************************************/
2405 /*************************************************************************/
2408 /* The main grid-fitting routine. */
2411 af_latin_hint_edges( AF_GlyphHints hints
,
2414 AF_AxisHints axis
= &hints
->axis
[dim
];
2415 AF_Edge edges
= axis
->edges
;
2416 AF_Edge edge_limit
= edges
+ axis
->num_edges
;
2419 AF_Edge anchor
= NULL
;
2420 FT_Int has_serifs
= 0;
2422 #ifdef FT_DEBUG_LEVEL_TRACE
2423 FT_UInt num_actions
= 0;
2427 FT_TRACE5(( "latin %s edge hinting (style `%s')\n",
2428 dim
== AF_DIMENSION_VERT
? "horizontal" : "vertical",
2429 af_style_names
[hints
->metrics
->style_class
->style
] ));
2431 /* we begin by aligning all stems relative to the blue zone */
2432 /* if needed -- that's only for horizontal edges */
2434 if ( dim
== AF_DIMENSION_VERT
&& AF_HINTS_DO_BLUES( hints
) )
2436 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
2439 AF_Edge edge1
, edge2
; /* these edges form the stem to check */
2442 if ( edge
->flags
& AF_EDGE_DONE
)
2449 * If a stem contains both a neutral and a non-neutral blue zone,
2450 * skip the neutral one. Otherwise, outlines with different
2451 * directions might be incorrectly aligned at the same vertical
2454 * If we have two neutral blue zones, skip one of them.
2457 if ( edge
->blue_edge
&& edge2
&& edge2
->blue_edge
)
2459 FT_Byte neutral
= edge
->flags
& AF_EDGE_NEUTRAL
;
2460 FT_Byte neutral2
= edge2
->flags
& AF_EDGE_NEUTRAL
;
2465 edge2
->blue_edge
= NULL
;
2466 edge2
->flags
&= ~AF_EDGE_NEUTRAL
;
2470 edge
->blue_edge
= NULL
;
2471 edge
->flags
&= ~AF_EDGE_NEUTRAL
;
2475 blue
= edge
->blue_edge
;
2479 /* flip edges if the other edge is aligned to a blue zone */
2480 else if ( edge2
&& edge2
->blue_edge
)
2482 blue
= edge2
->blue_edge
;
2490 #ifdef FT_DEBUG_LEVEL_TRACE
2492 FT_TRACE5(( " BLUE_ANCHOR: edge %d (opos=%.2f) snapped to %.2f,"
2493 " was %.2f (anchor=edge %d)\n",
2494 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
2495 edge1
->pos
/ 64.0, edge
- edges
));
2497 FT_TRACE5(( " BLUE: edge %d (opos=%.2f) snapped to %.2f,"
2499 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
2500 edge1
->pos
/ 64.0 ));
2505 edge1
->pos
= blue
->fit
;
2506 edge1
->flags
|= AF_EDGE_DONE
;
2508 if ( edge2
&& !edge2
->blue_edge
)
2510 af_latin_align_linked_edge( hints
, dim
, edge1
, edge2
);
2511 edge2
->flags
|= AF_EDGE_DONE
;
2513 #ifdef FT_DEBUG_LEVEL_TRACE
2523 /* now we align all other stem edges, trying to maintain the */
2524 /* relative order of stems in the glyph */
2525 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
2530 if ( edge
->flags
& AF_EDGE_DONE
)
2533 /* skip all non-stem edges */
2541 /* now align the stem */
2543 /* this should not happen, but it's better to be safe */
2544 if ( edge2
->blue_edge
)
2546 FT_TRACE5(( " ASSERTION FAILED for edge %d\n", edge2
- edges
));
2548 af_latin_align_linked_edge( hints
, dim
, edge2
, edge
);
2549 edge
->flags
|= AF_EDGE_DONE
;
2551 #ifdef FT_DEBUG_LEVEL_TRACE
2559 /* if we reach this if clause, no stem has been aligned yet */
2561 FT_Pos org_len
, org_center
, cur_len
;
2562 FT_Pos cur_pos1
, error1
, error2
, u_off
, d_off
;
2565 org_len
= edge2
->opos
- edge
->opos
;
2566 cur_len
= af_latin_compute_stem_width( hints
, dim
, org_len
,
2570 /* some voodoo to specially round edges for small stem widths; */
2571 /* the idea is to align the center of a stem, then shifting */
2572 /* the stem edges to suitable positions */
2573 if ( cur_len
<= 64 )
2581 /* 1px < width < 1.5px */
2588 org_center
= edge
->opos
+ ( org_len
>> 1 );
2589 cur_pos1
= FT_PIX_ROUND( org_center
);
2591 error1
= org_center
- ( cur_pos1
- u_off
);
2595 error2
= org_center
- ( cur_pos1
+ d_off
);
2599 if ( error1
< error2
)
2604 edge
->pos
= cur_pos1
- cur_len
/ 2;
2605 edge2
->pos
= edge
->pos
+ cur_len
;
2608 edge
->pos
= FT_PIX_ROUND( edge
->opos
);
2611 edge
->flags
|= AF_EDGE_DONE
;
2613 FT_TRACE5(( " ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
2614 " snapped to %.2f and %.2f\n",
2615 edge
- edges
, edge
->opos
/ 64.0,
2616 edge2
- edges
, edge2
->opos
/ 64.0,
2617 edge
->pos
/ 64.0, edge2
->pos
/ 64.0 ));
2619 af_latin_align_linked_edge( hints
, dim
, edge
, edge2
);
2621 #ifdef FT_DEBUG_LEVEL_TRACE
2627 FT_Pos org_pos
, org_len
, org_center
, cur_len
;
2628 FT_Pos cur_pos1
, cur_pos2
, delta1
, delta2
;
2631 org_pos
= anchor
->pos
+ ( edge
->opos
- anchor
->opos
);
2632 org_len
= edge2
->opos
- edge
->opos
;
2633 org_center
= org_pos
+ ( org_len
>> 1 );
2635 cur_len
= af_latin_compute_stem_width( hints
, dim
, org_len
,
2639 if ( edge2
->flags
& AF_EDGE_DONE
)
2641 FT_TRACE5(( " ADJUST: edge %d (pos=%.2f) moved to %.2f\n",
2642 edge
- edges
, edge
->pos
/ 64.0,
2643 ( edge2
->pos
- cur_len
) / 64.0 ));
2645 edge
->pos
= edge2
->pos
- cur_len
;
2648 else if ( cur_len
< 96 )
2650 FT_Pos u_off
, d_off
;
2653 cur_pos1
= FT_PIX_ROUND( org_center
);
2655 if ( cur_len
<= 64 )
2666 delta1
= org_center
- ( cur_pos1
- u_off
);
2670 delta2
= org_center
- ( cur_pos1
+ d_off
);
2674 if ( delta1
< delta2
)
2679 edge
->pos
= cur_pos1
- cur_len
/ 2;
2680 edge2
->pos
= cur_pos1
+ cur_len
/ 2;
2682 FT_TRACE5(( " STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
2683 " snapped to %.2f and %.2f\n",
2684 edge
- edges
, edge
->opos
/ 64.0,
2685 edge2
- edges
, edge2
->opos
/ 64.0,
2686 edge
->pos
/ 64.0, edge2
->pos
/ 64.0 ));
2691 org_pos
= anchor
->pos
+ ( edge
->opos
- anchor
->opos
);
2692 org_len
= edge2
->opos
- edge
->opos
;
2693 org_center
= org_pos
+ ( org_len
>> 1 );
2695 cur_len
= af_latin_compute_stem_width( hints
, dim
, org_len
,
2699 cur_pos1
= FT_PIX_ROUND( org_pos
);
2700 delta1
= cur_pos1
+ ( cur_len
>> 1 ) - org_center
;
2704 cur_pos2
= FT_PIX_ROUND( org_pos
+ org_len
) - cur_len
;
2705 delta2
= cur_pos2
+ ( cur_len
>> 1 ) - org_center
;
2709 edge
->pos
= ( delta1
< delta2
) ? cur_pos1
: cur_pos2
;
2710 edge2
->pos
= edge
->pos
+ cur_len
;
2712 FT_TRACE5(( " STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
2713 " snapped to %.2f and %.2f\n",
2714 edge
- edges
, edge
->opos
/ 64.0,
2715 edge2
- edges
, edge2
->opos
/ 64.0,
2716 edge
->pos
/ 64.0, edge2
->pos
/ 64.0 ));
2719 #ifdef FT_DEBUG_LEVEL_TRACE
2723 edge
->flags
|= AF_EDGE_DONE
;
2724 edge2
->flags
|= AF_EDGE_DONE
;
2726 if ( edge
> edges
&& edge
->pos
< edge
[-1].pos
)
2728 #ifdef FT_DEBUG_LEVEL_TRACE
2729 FT_TRACE5(( " BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2730 edge
- edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0 ));
2735 edge
->pos
= edge
[-1].pos
;
2740 /* make sure that lowercase m's maintain their symmetry */
2742 /* In general, lowercase m's have six vertical edges if they are sans */
2743 /* serif, or twelve if they are with serifs. This implementation is */
2744 /* based on that assumption, and seems to work very well with most */
2745 /* faces. However, if for a certain face this assumption is not */
2746 /* true, the m is just rendered like before. In addition, any stem */
2747 /* correction will only be applied to symmetrical glyphs (even if the */
2748 /* glyph is not an m), so the potential for unwanted distortion is */
2749 /* relatively low. */
2751 /* We don't handle horizontal edges since we can't easily assure that */
2752 /* the third (lowest) stem aligns with the base line; it might end up */
2753 /* one pixel higher or lower. */
2755 n_edges
= edge_limit
- edges
;
2756 if ( dim
== AF_DIMENSION_HORZ
&& ( n_edges
== 6 || n_edges
== 12 ) )
2758 AF_Edge edge1
, edge2
, edge3
;
2759 FT_Pos dist1
, dist2
, span
, delta
;
2775 dist1
= edge2
->opos
- edge1
->opos
;
2776 dist2
= edge3
->opos
- edge2
->opos
;
2778 span
= dist1
- dist2
;
2784 delta
= edge3
->pos
- ( 2 * edge2
->pos
- edge1
->pos
);
2785 edge3
->pos
-= delta
;
2787 edge3
->link
->pos
-= delta
;
2789 /* move the serifs along with the stem */
2790 if ( n_edges
== 12 )
2792 ( edges
+ 8 )->pos
-= delta
;
2793 ( edges
+ 11 )->pos
-= delta
;
2796 edge3
->flags
|= AF_EDGE_DONE
;
2798 edge3
->link
->flags
|= AF_EDGE_DONE
;
2802 if ( has_serifs
|| !anchor
)
2805 * now hint the remaining edges (serifs and single) in order
2806 * to complete our processing
2808 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
2813 if ( edge
->flags
& AF_EDGE_DONE
)
2820 delta
= edge
->serif
->opos
- edge
->opos
;
2825 if ( delta
< 64 + 16 )
2827 af_latin_align_serif_edge( hints
, edge
->serif
, edge
);
2828 FT_TRACE5(( " SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
2829 " aligned to %.2f\n",
2830 edge
- edges
, edge
->opos
/ 64.0,
2831 edge
->serif
- edges
, edge
->serif
->opos
/ 64.0,
2832 edge
->pos
/ 64.0 ));
2836 edge
->pos
= FT_PIX_ROUND( edge
->opos
);
2838 FT_TRACE5(( " SERIF_ANCHOR: edge %d (opos=%.2f)"
2839 " snapped to %.2f\n",
2840 edge
-edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0 ));
2844 AF_Edge before
, after
;
2847 for ( before
= edge
- 1; before
>= edges
; before
-- )
2848 if ( before
->flags
& AF_EDGE_DONE
)
2851 for ( after
= edge
+ 1; after
< edge_limit
; after
++ )
2852 if ( after
->flags
& AF_EDGE_DONE
)
2855 if ( before
>= edges
&& before
< edge
&&
2856 after
< edge_limit
&& after
> edge
)
2858 if ( after
->opos
== before
->opos
)
2859 edge
->pos
= before
->pos
;
2861 edge
->pos
= before
->pos
+
2862 FT_MulDiv( edge
->opos
- before
->opos
,
2863 after
->pos
- before
->pos
,
2864 after
->opos
- before
->opos
);
2866 FT_TRACE5(( " SERIF_LINK1: edge %d (opos=%.2f) snapped to %.2f"
2867 " from %d (opos=%.2f)\n",
2868 edge
- edges
, edge
->opos
/ 64.0,
2870 before
- edges
, before
->opos
/ 64.0 ));
2874 edge
->pos
= anchor
->pos
+
2875 ( ( edge
->opos
- anchor
->opos
+ 16 ) & ~31 );
2876 FT_TRACE5(( " SERIF_LINK2: edge %d (opos=%.2f)"
2877 " snapped to %.2f\n",
2878 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0 ));
2882 #ifdef FT_DEBUG_LEVEL_TRACE
2885 edge
->flags
|= AF_EDGE_DONE
;
2887 if ( edge
> edges
&& edge
->pos
< edge
[-1].pos
)
2889 #ifdef FT_DEBUG_LEVEL_TRACE
2890 FT_TRACE5(( " BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2891 edge
- edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0 ));
2895 edge
->pos
= edge
[-1].pos
;
2898 if ( edge
+ 1 < edge_limit
&&
2899 edge
[1].flags
& AF_EDGE_DONE
&&
2900 edge
->pos
> edge
[1].pos
)
2902 #ifdef FT_DEBUG_LEVEL_TRACE
2903 FT_TRACE5(( " BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2904 edge
- edges
, edge
->pos
/ 64.0, edge
[1].pos
/ 64.0 ));
2909 edge
->pos
= edge
[1].pos
;
2914 #ifdef FT_DEBUG_LEVEL_TRACE
2916 FT_TRACE5(( " (none)\n" ));
2917 FT_TRACE5(( "\n" ));
2922 /* Apply the complete hinting algorithm to a latin glyph. */
2925 af_latin_hints_apply( FT_UInt glyph_index
,
2926 AF_GlyphHints hints
,
2927 FT_Outline
* outline
,
2928 AF_LatinMetrics metrics
)
2936 error
= af_glyph_hints_reload( hints
, outline
);
2940 /* analyze glyph outline */
2941 #ifdef AF_CONFIG_OPTION_USE_WARPER
2942 if ( ( metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
&&
2943 AF_HINTS_DO_WARP( hints
) ) ||
2944 AF_HINTS_DO_HORIZONTAL( hints
) )
2946 if ( AF_HINTS_DO_HORIZONTAL( hints
) )
2949 axis
= &metrics
->axis
[AF_DIMENSION_HORZ
];
2950 error
= af_latin_hints_detect_features( hints
,
2953 AF_DIMENSION_HORZ
);
2958 if ( AF_HINTS_DO_VERTICAL( hints
) )
2960 axis
= &metrics
->axis
[AF_DIMENSION_VERT
];
2961 error
= af_latin_hints_detect_features( hints
,
2964 AF_DIMENSION_VERT
);
2968 /* apply blue zones to base characters only */
2969 if ( !( metrics
->root
.globals
->glyph_styles
[glyph_index
] & AF_NONBASE
) )
2970 af_latin_hints_compute_blue_edges( hints
, metrics
);
2973 /* grid-fit the outline */
2974 for ( dim
= 0; dim
< AF_DIMENSION_MAX
; dim
++ )
2976 #ifdef AF_CONFIG_OPTION_USE_WARPER
2977 if ( dim
== AF_DIMENSION_HORZ
&&
2978 metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
&&
2979 AF_HINTS_DO_WARP( hints
) )
2981 AF_WarperRec warper
;
2986 af_warper_compute( &warper
, hints
, (AF_Dimension
)dim
,
2988 af_glyph_hints_scale_dim( hints
, (AF_Dimension
)dim
,
2992 #endif /* AF_CONFIG_OPTION_USE_WARPER */
2994 if ( ( dim
== AF_DIMENSION_HORZ
&& AF_HINTS_DO_HORIZONTAL( hints
) ) ||
2995 ( dim
== AF_DIMENSION_VERT
&& AF_HINTS_DO_VERTICAL( hints
) ) )
2997 af_latin_hint_edges( hints
, (AF_Dimension
)dim
);
2998 af_glyph_hints_align_edge_points( hints
, (AF_Dimension
)dim
);
2999 af_glyph_hints_align_strong_points( hints
, (AF_Dimension
)dim
);
3000 af_glyph_hints_align_weak_points( hints
, (AF_Dimension
)dim
);
3004 af_glyph_hints_save( hints
, outline
);
3011 /*************************************************************************/
3012 /*************************************************************************/
3014 /***** L A T I N S C R I P T C L A S S *****/
3016 /*************************************************************************/
3017 /*************************************************************************/
3020 AF_DEFINE_WRITING_SYSTEM_CLASS(
3021 af_latin_writing_system_class
,
3023 AF_WRITING_SYSTEM_LATIN
,
3025 sizeof ( AF_LatinMetricsRec
),
3027 (AF_WritingSystem_InitMetricsFunc
) af_latin_metrics_init
,
3028 (AF_WritingSystem_ScaleMetricsFunc
)af_latin_metrics_scale
,
3029 (AF_WritingSystem_DoneMetricsFunc
) NULL
,
3030 (AF_WritingSystem_GetStdWidthsFunc
)af_latin_get_standard_widths
,
3032 (AF_WritingSystem_InitHintsFunc
) af_latin_hints_init
,
3033 (AF_WritingSystem_ApplyHintsFunc
) af_latin_hints_apply