4 * Copyright (C) 2011-2014 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
16 /* originally file `aflatin.c' (2011-Mar-28) from FreeType */
18 /* heavily modified 2011 by Werner Lemberg <wl@gnu.org> */
23 #include FT_ADVANCES_H
24 #include FT_TRUETYPE_TABLES_H
31 #ifdef TA_CONFIG_OPTION_USE_WARPER
35 #include <numberset.h>
38 /* find segments and links, compute all stem widths, and initialize */
39 /* standard width and height for the glyph with given charcode */
42 ta_latin_metrics_init_widths(TA_LatinMetrics metrics
,
46 /* scan the array of segments in each direction */
47 TA_GlyphHintsRec hints
[1];
51 "latin standard widths computation (style `%s')\n"
52 "=====================================================\n"
54 ta_style_names
[metrics
->root
.style_class
->style
]));
56 ta_glyph_hints_init(hints
);
58 metrics
->axis
[TA_DIMENSION_HORZ
].width_count
= 0;
59 metrics
->axis
[TA_DIMENSION_VERT
].width_count
= 0;
66 TA_LatinMetricsRec dummy
[1];
67 TA_Scaler scaler
= &dummy
->root
.scaler
;
69 TA_StyleClass style_class
= metrics
->root
.style_class
;
70 TA_ScriptClass script_class
= ta_script_classes
[style_class
->script
];
72 FT_UInt32 standard_char
;
79 * We check more than a single standard character to catch features
80 * like `c2sc' (small caps from caps) that don't contain lowercase
81 * letters by definition, or other features that mainly operate on
84 standard_char
= script_class
->standard_char1
;
85 ta_get_char_index(&metrics
->root
,
91 if (script_class
->standard_char2
)
93 standard_char
= script_class
->standard_char2
;
94 ta_get_char_index(&metrics
->root
,
100 if (script_class
->standard_char3
)
102 standard_char
= script_class
->standard_char3
;
103 ta_get_char_index(&metrics
->root
,
118 TA_LOG_GLOBAL(("standard character: U+%04lX (glyph index %d)\n",
119 standard_char
, glyph_index
));
121 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_SCALE
);
122 if (error
|| face
->glyph
->outline
.n_points
<= 0)
125 memset(dummy
, 0, sizeof (TA_LatinMetricsRec
));
127 dummy
->units_per_em
= metrics
->units_per_em
;
129 scaler
->x_scale
= 0x10000L
;
130 scaler
->y_scale
= 0x10000L
;
135 scaler
->render_mode
= FT_RENDER_MODE_NORMAL
;
138 ta_glyph_hints_rescale(hints
, (TA_StyleMetrics
)dummy
);
140 error
= ta_glyph_hints_reload(hints
, &face
->glyph
->outline
);
144 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
146 TA_LatinAxis axis
= &metrics
->axis
[dim
];
147 TA_AxisHints axhints
= &hints
->axis
[dim
];
149 TA_Segment seg
, limit
, link
;
150 FT_UInt num_widths
= 0;
153 error
= ta_latin_hints_compute_segments(hints
, (TA_Dimension
)dim
);
158 * We assume that the glyphs selected for the stem width
159 * computation are `featureless' enough so that the linking
160 * algorithm works fine without adjustments of its scoring
163 ta_latin_hints_link_segments(hints
, 0, NULL
, (TA_Dimension
)dim
);
165 seg
= axhints
->segments
;
166 limit
= seg
+ axhints
->num_segments
;
168 for (; seg
< limit
; seg
++)
172 /* we only consider stem segments there! */
180 dist
= seg
->pos
- link
->pos
;
184 if (num_widths
< TA_LATIN_MAX_WIDTHS
)
185 axis
->widths
[num_widths
++].org
= dist
;
189 /* this also replaces multiple almost identical stem widths */
190 /* with a single one (the value 100 is heuristic) */
191 ta_sort_and_quantize_widths(&num_widths
, axis
->widths
,
192 dummy
->units_per_em
/ 100);
193 axis
->width_count
= num_widths
;
197 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
199 FONT
* font
= metrics
->root
.globals
->font
;
200 TA_LatinAxis axis
= &metrics
->axis
[dim
];
204 if (!axis
->width_count
)
206 /* if we have no standard characters, */
207 /* use `fallback-stem-width', if available, */
208 /* or a default width (value 50 is heuristic) */
209 stdw
= (dim
== TA_DIMENSION_VERT
&& font
->fallback_stem_width
)
210 ? (FT_Pos
)font
->fallback_stem_width
211 : TA_LATIN_CONSTANT(metrics
, 50);
213 /* set one width value if we do hinting */
214 if (style_class
->style
!= TA_STYLE_NONE_DFLT
)
217 axis
->widths
[0].org
= stdw
;
221 stdw
= axis
->widths
[0].org
;
223 /* let's try 20% of the smallest width */
224 axis
->edge_distance_threshold
= stdw
/ 5;
225 axis
->standard_width
= stdw
;
226 axis
->extra_light
= 0;
233 TA_LOG_GLOBAL(("%s widths:\n",
234 dim
== TA_DIMENSION_VERT
? "horizontal"
237 TA_LOG_GLOBAL((" %d (standard)", axis
->standard_width
));
238 for (i
= 1; i
< axis
->width_count
; i
++)
239 TA_LOG_GLOBAL((" %d", axis
->widths
[i
].org
));
241 TA_LOG_GLOBAL(("\n"));
247 TA_LOG_GLOBAL(("\n"));
249 ta_glyph_hints_done(hints
);
253 /* find all blue zones; flat segments give the reference points, */
254 /* round segments the overshoot positions */
257 ta_latin_metrics_init_blues(TA_LatinMetrics metrics
,
260 FT_Pos flats
[TA_BLUE_STRING_MAX_LEN
];
261 FT_Pos rounds
[TA_BLUE_STRING_MAX_LEN
];
267 TA_LatinAxis axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
270 TA_StyleClass sc
= metrics
->root
.style_class
;
272 TA_Blue_Stringset bss
= sc
->blue_stringset
;
273 const TA_Blue_StringRec
* bs
= &ta_blue_stringsets
[bss
];
276 /* we walk over the blue character strings as specified in the */
277 /* style's entry in the `ta_blue_stringset' array */
279 TA_LOG_GLOBAL(("latin blue zones computation\n"
280 "============================\n"
283 for (; bs
->string
!= TA_BLUE_STRING_MAX
; bs
++)
285 const char* p
= &ta_blue_strings
[bs
->string
];
292 FT_Bool have_flag
= 0;
295 TA_LOG_GLOBAL(("blue zone %d", axis
->blue_count
));
299 TA_LOG_GLOBAL((" ("));
301 if (TA_LATIN_IS_TOP_BLUE(bs
))
303 TA_LOG_GLOBAL(("top"));
307 if (TA_LATIN_IS_NEUTRAL_BLUE(bs
))
310 TA_LOG_GLOBAL((", "));
311 TA_LOG_GLOBAL(("neutral"));
315 if (TA_LATIN_IS_X_HEIGHT_BLUE(bs
))
318 TA_LOG_GLOBAL((", "));
319 TA_LOG_GLOBAL(("small top"));
323 if (TA_LATIN_IS_LONG_BLUE(bs
))
326 TA_LOG_GLOBAL((", "));
327 TA_LOG_GLOBAL(("long"));
330 TA_LOG_GLOBAL((")"));
333 TA_LOG_GLOBAL((":\n"));
335 #endif /* TA_DEBUG */
343 FT_ULong glyph_index
;
345 FT_Pos best_y
; /* same as points.y */
346 FT_Int best_point
, best_contour_first
, best_contour_last
;
351 GET_UTF8_CHAR(ch
, p
);
353 /* load the character in the face -- skip unknown or empty ones */
354 ta_get_char_index(&metrics
->root
, ch
, &glyph_index
, &y_offset
);
355 if (glyph_index
== 0)
357 TA_LOG_GLOBAL((" U+%04lX unavailable\n", ch
));
361 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_SCALE
);
362 outline
= face
->glyph
->outline
;
363 if (error
|| outline
.n_points
<= 0)
365 TA_LOG_GLOBAL((" U+%04lX contains no outlines\n", ch
));
369 /* now compute min or max point indices and coordinates */
370 points
= outline
.points
;
372 best_y
= 0; /* make compiler happy */
373 best_contour_first
= 0; /* ditto */
374 best_contour_last
= 0; /* ditto */
382 for (nn
= 0; nn
< outline
.n_contours
; first
= last
+ 1, nn
++)
384 FT_Int old_best_point
= best_point
;
388 last
= outline
.contours
[nn
];
390 /* avoid single-point contours since they are never rasterized; */
391 /* in some fonts, they correspond to mark attachment points */
392 /* that are way outside of the glyph's real outline */
396 if (TA_LATIN_IS_TOP_BLUE(bs
))
398 for (pp
= first
; pp
<= last
; pp
++)
400 || points
[pp
].y
> best_y
)
403 best_y
= points
[pp
].y
;
408 for (pp
= first
; pp
<= last
; pp
++)
410 || points
[pp
].y
< best_y
)
413 best_y
= points
[pp
].y
;
417 if (best_point
!= old_best_point
)
419 best_contour_first
= first
;
420 best_contour_last
= last
;
425 /* now check whether the point belongs to a straight or round */
426 /* segment; we first need to find in which contour the extremum */
427 /* lies, then inspect its previous and next points */
430 FT_Pos best_x
= points
[best_point
].x
;
432 FT_Int best_segment_first
, best_segment_last
;
433 FT_Int best_on_point_first
, best_on_point_last
;
437 best_segment_first
= best_point
;
438 best_segment_last
= best_point
;
440 if (FT_CURVE_TAG(outline
.tags
[best_point
]) == FT_CURVE_TAG_ON
)
442 best_on_point_first
= best_point
;
443 best_on_point_last
= best_point
;
447 best_on_point_first
= -1;
448 best_on_point_last
= -1;
451 /* look for the previous and next points on the contour */
452 /* that are not on the same Y coordinate, then threshold */
453 /* the `closeness'... */
459 if (prev
> best_contour_first
)
462 prev
= best_contour_last
;
464 dist
= TA_ABS(points
[prev
].y
- best_y
);
465 /* accept a small distance or a small angle (both values are */
466 /* heuristic; value 20 corresponds to approx. 2.9 degrees) */
468 if (TA_ABS(points
[prev
].x
- best_x
) <= 20 * dist
)
471 best_segment_first
= prev
;
473 if (FT_CURVE_TAG(outline
.tags
[prev
]) == FT_CURVE_TAG_ON
)
475 best_on_point_first
= prev
;
476 if (best_on_point_last
< 0)
477 best_on_point_last
= prev
;
480 } while (prev
!= best_point
);
484 if (next
< best_contour_last
)
487 next
= best_contour_first
;
489 dist
= TA_ABS(points
[next
].y
- best_y
);
491 if (TA_ABS(points
[next
].x
- best_x
) <= 20 * dist
)
494 best_segment_last
= next
;
496 if (FT_CURVE_TAG(outline
.tags
[next
]) == FT_CURVE_TAG_ON
)
498 best_on_point_last
= next
;
499 if (best_on_point_first
< 0)
500 best_on_point_first
= next
;
503 } while (next
!= best_point
);
505 if (TA_LATIN_IS_LONG_BLUE(bs
))
507 /* If this flag is set, we have an additional constraint to */
508 /* get the blue zone distance: Find a segment of the topmost */
509 /* (or bottommost) contour that is longer than a heuristic */
510 /* threshold. This ensures that small bumps in the outline */
511 /* are ignored (for example, the `vertical serifs' found in */
512 /* many Hebrew glyph designs). */
514 /* If this segment is long enough, we are done. Otherwise, */
515 /* search the segment next to the extremum that is long */
516 /* enough, has the same direction, and a not too large */
517 /* vertical distance from the extremum. Note that the */
518 /* algorithm doesn't check whether the found segment is */
519 /* actually the one (vertically) nearest to the extremum. */
521 /* heuristic threshold value */
522 FT_Pos length_threshold
= metrics
->units_per_em
/ 25;
525 dist
= TA_ABS(points
[best_segment_last
].x
-
526 points
[best_segment_first
].x
);
528 if (dist
< length_threshold
529 && best_segment_last
- best_segment_first
+ 2 <=
530 best_contour_last
- best_contour_first
)
532 /* heuristic threshold value */
533 FT_Pos height_threshold
= metrics
->units_per_em
/ 4;
539 /* we intentionally declare these two variables */
540 /* outside of the loop since various compilers emit */
541 /* incorrect warning messages otherwise, talking about */
542 /* `possibly uninitialized variables' */
543 FT_Int p_first
= 0; /* make compiler happy */
549 /* compute direction */
554 if (prev
> best_contour_first
)
557 prev
= best_contour_last
;
559 if (points
[prev
].x
!= best_x
)
561 } while (prev
!= best_point
);
563 /* skip glyph for the degenerate case */
564 if (prev
== best_point
)
567 left2right
= FT_BOOL(points
[prev
].x
< points
[best_point
].x
);
569 first
= best_segment_last
;
581 /* no hit; adjust first point */
584 /* also adjust first and last on point */
585 if (FT_CURVE_TAG(outline
.tags
[first
]) == FT_CURVE_TAG_ON
)
599 if (last
< best_contour_last
)
602 last
= best_contour_first
;
604 if (TA_ABS(best_y
- points
[first
].y
) > height_threshold
)
606 /* vertical distance too large */
611 /* same test as above */
612 dist
= TA_ABS(points
[last
].y
- points
[first
].y
);
614 if (TA_ABS(points
[last
].x
- points
[first
].x
) <= 20 * dist
)
620 if (FT_CURVE_TAG(outline
.tags
[last
]) == FT_CURVE_TAG_ON
)
627 l2r
= FT_BOOL(points
[first
].x
< points
[last
].x
);
628 d
= TA_ABS(points
[last
].x
- points
[first
].x
);
630 if (l2r
== left2right
631 && d
>= length_threshold
)
633 /* all constraints are met; update segment after finding */
637 if (last
< best_contour_last
)
640 last
= best_contour_first
;
642 d
= TA_ABS(points
[last
].y
- points
[first
].y
);
644 if (TA_ABS(points
[next
].x
- points
[first
].x
) <=
647 if (last
> best_contour_first
)
650 last
= best_contour_last
;
656 if (FT_CURVE_TAG(outline
.tags
[last
]) == FT_CURVE_TAG_ON
)
662 } while (last
!= best_segment_first
);
664 best_y
= points
[first
].y
;
666 best_segment_first
= first
;
667 best_segment_last
= last
;
669 best_on_point_first
= p_first
;
670 best_on_point_last
= p_last
;
674 } while (last
!= best_segment_first
);
679 * for computing blue zones, we add the y offset as returned
680 * by the currently used OpenType feature --
681 * for example, superscript glyphs might be identical
682 * to subscript glyphs with a vertical shift
686 TA_LOG_GLOBAL((" U+%04lX: best_y = %5ld", ch
, best_y
));
689 * now set the `round' flag depending on the segment's kind:
691 * - if the horizontal distance between the first and last
692 * `on' point is larger than upem/8 (value 8 is heuristic)
693 * we have a flat segment
694 * - if either the first or the last point of the segment is
695 * an `off' point, the segment is round, otherwise it is
698 if (best_on_point_first
>= 0
699 && best_on_point_last
>= 0
700 && (FT_UInt
)(TA_ABS(points
[best_on_point_last
].x
701 - points
[best_on_point_first
].x
))
702 > metrics
->units_per_em
/ 8)
705 round
= FT_BOOL(FT_CURVE_TAG(outline
.tags
[best_segment_first
])
707 || FT_CURVE_TAG(outline
.tags
[best_segment_last
])
710 if (round
&& TA_LATIN_IS_NEUTRAL_BLUE(bs
))
712 /* only use flat segments for a neutral blue zone */
713 TA_LOG_GLOBAL((" (round, skipped)\n"));
717 TA_LOG_GLOBAL((" (%s)\n", round
? "round" : "flat"));
721 rounds
[num_rounds
++] = best_y
;
723 flats
[num_flats
++] = best_y
;
726 if (num_flats
== 0 && num_rounds
== 0)
728 /* we couldn't find a single glyph to compute this blue zone, */
729 /* we will simply ignore it then */
730 TA_LOG_GLOBAL((" empty\n"));
734 /* we have computed the contents of the `rounds' and `flats' tables, */
735 /* now determine the reference and overshoot position of the blue -- */
736 /* we simply take the median value after a simple sort */
737 ta_sort_pos(num_rounds
, rounds
);
738 ta_sort_pos(num_flats
, flats
);
740 blue
= &axis
->blues
[axis
->blue_count
];
741 blue_ref
= &blue
->ref
.org
;
742 blue_shoot
= &blue
->shoot
.org
;
749 *blue_shoot
= rounds
[num_rounds
/ 2];
751 else if (num_rounds
== 0)
754 *blue_shoot
= flats
[num_flats
/ 2];
758 *blue_ref
= flats
[num_flats
/ 2];
759 *blue_shoot
= rounds
[num_rounds
/ 2];
762 /* there are sometimes problems if the overshoot position of top */
763 /* zones is under its reference position, or the opposite for bottom */
764 /* zones; we must thus check everything there and correct the errors */
765 if (*blue_shoot
!= *blue_ref
)
767 FT_Pos ref
= *blue_ref
;
768 FT_Pos shoot
= *blue_shoot
;
769 FT_Bool over_ref
= FT_BOOL(shoot
> ref
);
772 if (TA_LATIN_IS_TOP_BLUE(bs
) ^ over_ref
)
775 *blue_shoot
= (shoot
+ ref
) / 2;
777 TA_LOG_GLOBAL((" [overshoot smaller than reference,"
778 " taking mean value]\n"));
783 if (TA_LATIN_IS_TOP_BLUE(bs
))
784 blue
->flags
|= TA_LATIN_BLUE_TOP
;
785 if (TA_LATIN_IS_NEUTRAL_BLUE(bs
))
786 blue
->flags
|= TA_LATIN_BLUE_NEUTRAL
;
788 /* the following flag is used later to adjust the y and x scales */
789 /* in order to optimize the pixel grid alignment */
790 /* of the top of small letters */
791 if (TA_LATIN_IS_X_HEIGHT_BLUE(bs
))
792 blue
->flags
|= TA_LATIN_BLUE_ADJUSTMENT
;
794 TA_LOG_GLOBAL((" -> reference = %ld\n"
795 " overshoot = %ld\n",
796 *blue_ref
, *blue_shoot
));
799 /* add two blue zones for usWinAscent and usWinDescent */
800 /* just in case the above algorithm has missed them -- */
801 /* Windows cuts off everything outside of those two values */
806 os2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
810 blue
= &axis
->blues
[axis
->blue_count
];
811 blue
->flags
= TA_LATIN_BLUE_TOP
| TA_LATIN_BLUE_ACTIVE
;
813 blue
->shoot
.org
= os2
->usWinAscent
;
815 TA_LOG_GLOBAL(("artificial blue zone for usWinAscent:\n"
816 " -> reference = %ld\n"
817 " overshoot = %ld\n",
818 blue
->ref
.org
, blue
->shoot
.org
));
820 blue
= &axis
->blues
[axis
->blue_count
+ 1];
821 blue
->flags
= TA_LATIN_BLUE_ACTIVE
;
823 blue
->shoot
.org
= -os2
->usWinDescent
;
825 TA_LOG_GLOBAL(("artificial blue zone for usWinDescent:\n"
826 " -> reference = %ld\n"
827 " overshoot = %ld\n",
828 blue
->ref
.org
, blue
->shoot
.org
));
832 blue
= &axis
->blues
[axis
->blue_count
];
837 blue
= &axis
->blues
[axis
->blue_count
+ 1];
844 TA_LOG_GLOBAL(("\n"));
850 /* check whether all ASCII digits have the same advance width */
853 ta_latin_metrics_check_digits(TA_LatinMetrics metrics
,
857 FT_Bool started
= 0, same_width
= 1;
858 FT_Fixed advance
, old_advance
= 0;
861 /* digit `0' is 0x30 in all supported charmaps */
862 for (i
= 0x30; i
<= 0x39; i
++)
864 FT_ULong glyph_index
;
868 ta_get_char_index(&metrics
->root
, i
, &glyph_index
, &y_offset
);
869 if (glyph_index
== 0)
872 if (FT_Get_Advance(face
, glyph_index
,
875 | FT_LOAD_IGNORE_TRANSFORM
,
881 if (advance
!= old_advance
)
889 old_advance
= advance
;
894 metrics
->root
.digits_have_same_width
= same_width
;
898 /* initialize global metrics */
901 ta_latin_metrics_init(TA_LatinMetrics metrics
,
904 FT_CharMap oldmap
= face
->charmap
;
907 metrics
->units_per_em
= face
->units_per_EM
;
909 if (!FT_Select_Charmap(face
, FT_ENCODING_UNICODE
))
911 ta_latin_metrics_init_widths(metrics
, face
, 1);
912 ta_latin_metrics_init_blues(metrics
, face
);
913 ta_latin_metrics_check_digits(metrics
, face
);
917 /* we only have a symbol font encoding */
918 ta_latin_metrics_init_widths(metrics
, face
, 0);
921 FT_Set_Charmap(face
, oldmap
);
926 /* adjust scaling value, then scale and shift widths */
927 /* and blue zones (if applicable) for given dimension */
930 ta_latin_metrics_scale_dim(TA_LatinMetrics metrics
,
941 ppem
= metrics
->root
.scaler
.face
->size
->metrics
.x_ppem
;
943 if (dim
== TA_DIMENSION_HORZ
)
945 scale
= scaler
->x_scale
;
946 delta
= scaler
->x_delta
;
950 scale
= scaler
->y_scale
;
951 delta
= scaler
->y_delta
;
954 axis
= &metrics
->axis
[dim
];
956 if (axis
->org_scale
== scale
&& axis
->org_delta
== delta
)
959 axis
->org_scale
= scale
;
960 axis
->org_delta
= delta
;
962 /* correct Y scale to optimize the alignment of the top of */
963 /* small letters to the pixel grid */
964 /* (if we do x-height snapping for this ppem value) */
965 if (!number_set_is_element(
966 metrics
->root
.globals
->font
->x_height_snapping_exceptions
,
969 TA_LatinAxis Axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
970 TA_LatinBlue blue
= NULL
;
973 for (nn
= 0; nn
< Axis
->blue_count
; nn
++)
975 if (Axis
->blues
[nn
].flags
& TA_LATIN_BLUE_ADJUSTMENT
)
977 blue
= &Axis
->blues
[nn
];
990 scaled
= FT_MulFix(blue
->shoot
.org
, scaler
->y_scale
);
991 limit
= metrics
->root
.globals
->increase_x_height
;
994 /* if the `increase-x-height' property is active, */
995 /* we round up much more often */
998 && ppem
>= TA_PROP_INCREASE_X_HEIGHT_MIN
)
1001 fitted
= (scaled
+ threshold
) & ~63;
1003 if (scaled
!= fitted
)
1005 if (dim
== TA_DIMENSION_VERT
)
1007 scale
= FT_MulDiv(scale
, fitted
, scaled
);
1010 "ta_latin_metrics_scale_dim:"
1011 " x height alignment (style `%s'):\n"
1013 " vertical scaling changed from %.4f to %.4f (by %d%%)\n"
1015 ta_style_names
[metrics
->root
.style_class
->style
],
1016 axis
->org_scale
/ 65536.0,
1018 (fitted
- scaled
) * 100 / scaled
));
1024 axis
->scale
= scale
;
1025 axis
->delta
= delta
;
1027 if (dim
== TA_DIMENSION_HORZ
)
1029 metrics
->root
.scaler
.x_scale
= scale
;
1030 metrics
->root
.scaler
.x_delta
= delta
;
1034 metrics
->root
.scaler
.y_scale
= scale
;
1035 metrics
->root
.scaler
.y_delta
= delta
;
1038 TA_LOG_GLOBAL(("%s widths (style `%s')\n",
1039 dim
== TA_DIMENSION_HORZ
? "horizontal" : "vertical",
1040 ta_style_names
[metrics
->root
.style_class
->style
]));
1042 /* scale the widths */
1043 for (nn
= 0; nn
< axis
->width_count
; nn
++)
1045 TA_Width width
= axis
->widths
+ nn
;
1048 width
->cur
= FT_MulFix(width
->org
, scale
);
1049 width
->fit
= width
->cur
;
1051 TA_LOG_GLOBAL((" %d scaled to %.2f\n",
1053 width
->cur
/ 64.0));
1056 TA_LOG_GLOBAL(("\n"));
1058 /* an extra-light axis corresponds to a standard width that is */
1059 /* smaller than 5/8 pixels */
1061 (FT_Bool
)(FT_MulFix(axis
->standard_width
, scale
) < 32 + 8);
1064 if (axis
->extra_light
)
1065 TA_LOG_GLOBAL(("`%s' style is extra light (at current resolution)\n"
1067 ta_style_names
[metrics
->root
.style_class
->style
]));
1070 if (dim
== TA_DIMENSION_VERT
)
1072 TA_LOG_GLOBAL(("blue zones (style `%s')\n",
1073 ta_style_names
[metrics
->root
.style_class
->style
]));
1075 /* scale the blue zones */
1076 for (nn
= 0; nn
< axis
->blue_count
; nn
++)
1078 TA_LatinBlue blue
= &axis
->blues
[nn
];
1082 blue
->ref
.cur
= FT_MulFix(blue
->ref
.org
, scale
) + delta
;
1083 blue
->ref
.fit
= blue
->ref
.cur
;
1084 blue
->shoot
.cur
= FT_MulFix(blue
->shoot
.org
, scale
) + delta
;
1085 blue
->shoot
.fit
= blue
->shoot
.cur
;
1086 blue
->flags
&= ~TA_LATIN_BLUE_ACTIVE
;
1088 /* a blue zone is only active if it is less than 3/4 pixels tall */
1089 dist
= FT_MulFix(blue
->ref
.org
- blue
->shoot
.org
, scale
);
1090 if (dist
<= 48 && dist
>= -48)
1098 /* use discrete values for blue zone widths */
1101 /* generic, original code */
1102 delta1
= blue
->shoot
.org
- blue
->ref
.org
;
1107 delta2
= FT_MulFix(delta2
, scale
);
1111 else if (delta2
< 64)
1112 delta2
= 32 + (((delta2
- 32) + 16) & ~31);
1114 delta2
= TA_PIX_ROUND(delta2
);
1119 blue
->ref
.fit
= TA_PIX_ROUND(blue
->ref
.cur
);
1120 blue
->shoot
.fit
= blue
->ref
.fit
+ delta2
;
1122 /* simplified version due to abs(dist) <= 48 */
1129 else if (delta2
< 48)
1137 blue
->ref
.fit
= TA_PIX_ROUND(blue
->ref
.cur
);
1138 blue
->shoot
.fit
= blue
->ref
.fit
- delta2
;
1141 blue
->flags
|= TA_LATIN_BLUE_ACTIVE
;
1143 TA_LOG_GLOBAL((" reference %d: %d scaled to %.2f%s\n"
1144 " overshoot %d: %d scaled to %.2f%s\n",
1147 blue
->ref
.fit
/ 64.0,
1148 blue
->flags
& TA_LATIN_BLUE_ACTIVE
? ""
1152 blue
->shoot
.fit
/ 64.0,
1153 blue
->flags
& TA_LATIN_BLUE_ACTIVE
? ""
1158 /* the last two artificial blue zones are to be scaled */
1159 /* with uncorrected scaling values */
1161 TA_LatinAxis a
= &metrics
->axis
[TA_DIMENSION_VERT
];
1165 b
= &a
->blues
[a
->blue_count
];
1169 b
->shoot
.fit
= FT_MulFix(b
->ref
.org
, a
->org_scale
) + delta
;
1171 TA_LOG_GLOBAL((" reference %d: %d scaled to %.2f (artificial)\n"
1172 " overshoot %d: %d scaled to %.2f (artificial)\n",
1178 b
->shoot
.fit
/ 64.0));
1180 b
= &a
->blues
[a
->blue_count
+ 1];
1184 b
->shoot
.fit
= FT_MulFix(b
->ref
.org
, a
->org_scale
) + delta
;
1186 TA_LOG_GLOBAL((" reference %d: %d scaled to %.2f (artificial)\n"
1187 " overshoot %d: %d scaled to %.2f (artificial)\n",
1193 b
->shoot
.fit
/ 64.0));
1196 TA_LOG_GLOBAL(("\n"));
1201 /* scale global values in both directions */
1204 ta_latin_metrics_scale(TA_LatinMetrics metrics
,
1207 metrics
->root
.scaler
.render_mode
= scaler
->render_mode
;
1208 metrics
->root
.scaler
.face
= scaler
->face
;
1209 metrics
->root
.scaler
.flags
= scaler
->flags
;
1211 ta_latin_metrics_scale_dim(metrics
, scaler
, TA_DIMENSION_HORZ
);
1212 ta_latin_metrics_scale_dim(metrics
, scaler
, TA_DIMENSION_VERT
);
1216 /* walk over all contours and compute its segments */
1219 ta_latin_hints_compute_segments(TA_GlyphHints hints
,
1222 TA_AxisHints axis
= &hints
->axis
[dim
];
1223 FT_Error error
= FT_Err_Ok
;
1225 TA_Segment segment
= NULL
;
1228 TA_Point
* contour
= hints
->contours
;
1229 TA_Point
* contour_limit
= contour
+ hints
->num_contours
;
1230 TA_Direction major_dir
, segment_dir
;
1233 memset(&seg0
, 0, sizeof (TA_SegmentRec
));
1235 seg0
.flags
= TA_EDGE_NORMAL
;
1237 major_dir
= (TA_Direction
)TA_ABS(axis
->major_dir
);
1238 segment_dir
= major_dir
;
1240 axis
->num_segments
= 0;
1242 /* set up (u,v) in each point */
1243 if (dim
== TA_DIMENSION_HORZ
)
1245 TA_Point point
= hints
->points
;
1246 TA_Point limit
= point
+ hints
->num_points
;
1249 for (; point
< limit
; point
++)
1251 point
->u
= point
->fx
;
1252 point
->v
= point
->fy
;
1257 TA_Point point
= hints
->points
;
1258 TA_Point limit
= point
+ hints
->num_points
;
1261 for (; point
< limit
; point
++)
1263 point
->u
= point
->fy
;
1264 point
->v
= point
->fx
;
1268 /* do each contour separately */
1269 for (; contour
< contour_limit
; contour
++)
1271 TA_Point point
= contour
[0];
1272 TA_Point last
= point
->prev
;
1276 FT_Pos min_pos
= 32000; /* minimum segment pos != min_coord */
1277 FT_Pos max_pos
= -32000; /* maximum segment pos != max_coord */
1281 if (point
== last
) /* skip singletons -- just in case */
1284 if (TA_ABS(last
->out_dir
) == major_dir
1285 && TA_ABS(point
->out_dir
) == major_dir
)
1287 /* we are already on an edge, try to locate its start */
1292 point
= point
->prev
;
1293 if (TA_ABS(point
->out_dir
) != major_dir
)
1295 point
= point
->next
;
1319 if (point
->out_dir
!= segment_dir
1322 /* we are just leaving an edge; record a new segment! */
1323 segment
->last
= point
;
1324 segment
->pos
= (FT_Short
)((min_pos
+ max_pos
) >> 1);
1326 /* a segment is round if either its first or last point */
1327 /* is a control point */
1328 if ((segment
->first
->flags
| point
->flags
) & TA_FLAG_CONTROL
)
1329 segment
->flags
|= TA_EDGE_ROUND
;
1331 /* compute segment size */
1332 min_pos
= max_pos
= point
->v
;
1334 v
= segment
->first
->v
;
1340 segment
->min_coord
= (FT_Short
)min_pos
;
1341 segment
->max_coord
= (FT_Short
)max_pos
;
1342 segment
->height
= (FT_Short
)(segment
->max_coord
-
1343 segment
->min_coord
);
1351 /* now exit if we are at the start/end point */
1360 && TA_ABS(point
->out_dir
) == major_dir
)
1362 /* this is the start of a new segment! */
1363 segment_dir
= (TA_Direction
)point
->out_dir
;
1365 error
= ta_axis_hints_new_segment(axis
, &segment
);
1369 /* clear all segment fields */
1372 segment
->dir
= (FT_Char
)segment_dir
;
1373 min_pos
= max_pos
= point
->u
;
1374 segment
->first
= point
;
1375 segment
->last
= point
;
1379 if (point
->out_dir
!= point
->next
->in_dir
)
1381 /* we have a one-point segment */
1382 segment
->pos
= (FT_Short
)min_pos
;
1384 if (point
->flags
& TA_FLAG_CONTROL
)
1385 segment
->flags
|= TA_EDGE_ROUND
;
1387 segment
->min_coord
= (FT_Short
)point
->v
;
1388 segment
->max_coord
= (FT_Short
)point
->v
;
1389 segment
->height
= 0;
1396 point
= point
->next
;
1401 /* now slightly increase the height of segments if this makes sense -- */
1402 /* this is used to better detect and ignore serifs */
1404 TA_Segment segments
= axis
->segments
;
1405 TA_Segment segments_end
= segments
+ axis
->num_segments
;
1408 for (segment
= segments
; segment
< segments_end
; segment
++)
1410 TA_Point first
= segment
->first
;
1411 TA_Point last
= segment
->last
;
1413 FT_Pos first_v
= first
->v
;
1414 FT_Pos last_v
= last
->v
;
1417 if (first_v
< last_v
)
1424 segment
->height
= (FT_Short
)(segment
->height
+
1425 ((first_v
- p
->v
) >> 1));
1429 segment
->height
= (FT_Short
)(segment
->height
+
1430 ((p
->v
- last_v
) >> 1));
1439 segment
->height
= (FT_Short
)(segment
->height
+
1440 ((p
->v
- first_v
) >> 1));
1444 segment
->height
= (FT_Short
)(segment
->height
+
1445 ((last_v
- p
->v
) >> 1));
1455 /* link segments to form stems and serifs; if `width_count' and */
1456 /* `widths' are non-zero, use them to fine-tune the scoring function */
1459 ta_latin_hints_link_segments(TA_GlyphHints hints
,
1460 FT_UInt width_count
,
1461 TA_WidthRec
* widths
,
1464 TA_AxisHints axis
= &hints
->axis
[dim
];
1466 TA_Segment segments
= axis
->segments
;
1467 TA_Segment segment_limit
= segments
+ axis
->num_segments
;
1469 FT_Pos len_threshold
, len_score
, dist_score
, max_width
;
1470 TA_Segment seg1
, seg2
;
1474 max_width
= widths
[width_count
- 1].org
;
1478 /* a heuristic value to set up a minimum value for overlapping */
1479 len_threshold
= TA_LATIN_CONSTANT(hints
->metrics
, 8);
1480 if (len_threshold
== 0)
1483 /* a heuristic value to weight lengths */
1484 len_score
= TA_LATIN_CONSTANT(hints
->metrics
, 6000);
1486 /* a heuristic value to weight distances (no call to */
1487 /* TA_LATIN_CONSTANT needed, since we work on multiples */
1488 /* of the stem width) */
1491 /* now compare each segment to the others */
1492 for (seg1
= segments
; seg1
< segment_limit
; seg1
++)
1494 if (seg1
->dir
!= axis
->major_dir
)
1497 /* search for stems having opposite directions, */
1498 /* with seg1 to the `left' of seg2 */
1499 for (seg2
= segments
; seg2
< segment_limit
; seg2
++)
1501 FT_Pos pos1
= seg1
->pos
;
1502 FT_Pos pos2
= seg2
->pos
;
1505 if (seg1
->dir
+ seg2
->dir
== 0
1508 /* compute distance between the two segments */
1509 FT_Pos min
= seg1
->min_coord
;
1510 FT_Pos max
= seg1
->max_coord
;
1514 if (min
< seg2
->min_coord
)
1515 min
= seg2
->min_coord
;
1516 if (max
> seg2
->max_coord
)
1517 max
= seg2
->max_coord
;
1519 /* compute maximum coordinate difference of the two segments */
1520 /* (this is, how much they overlap) */
1523 /* for one-point segments, `len' is zero if there is an overlap */
1524 /* (and negative otherwise); we have to correct this */
1526 && (seg1
->min_coord
== seg1
->max_coord
1527 || seg2
->min_coord
== seg2
->max_coord
))
1528 len
= len_threshold
;
1530 if (len
>= len_threshold
)
1533 * The score is the sum of two demerits indicating the
1534 * `badness' of a fit, measured along the segments' main axis
1535 * and orthogonal to it, respectively.
1537 * o The less overlapping along the main axis, the worse it
1538 * is, causing a larger demerit.
1540 * o The nearer the orthogonal distance to a stem width, the
1541 * better it is, causing a smaller demerit. For simplicity,
1542 * however, we only increase the demerit for values that
1543 * exceed the largest stem width.
1546 FT_Pos dist
= pos2
- pos1
;
1548 FT_Pos dist_demerit
, score
;
1553 /* distance demerits are based on multiples of `max_width'; */
1554 /* we scale by 1024 for getting more precision */
1555 FT_Pos delta
= (dist
<< 10) / max_width
- (1 << 10);
1559 dist_demerit
= 32000;
1561 dist_demerit
= delta
* delta
/ dist_score
;
1566 dist_demerit
= dist
; /* default if no widths available */
1568 score
= dist_demerit
+ len_score
/ len
;
1570 /* and we search for the smallest score */
1571 if (score
< seg1
->score
)
1573 seg1
->score
= score
;
1577 if (score
< seg2
->score
)
1579 seg2
->score
= score
;
1587 /* now compute the `serif' segments, cf. explanations in `tahints.h' */
1588 for (seg1
= segments
; seg1
< segment_limit
; seg1
++)
1594 if (seg2
->link
!= seg1
)
1597 seg1
->serif
= seg2
->link
;
1604 /* link segments to edges, using feature analysis for selection */
1607 ta_latin_hints_compute_edges(TA_GlyphHints hints
,
1610 TA_AxisHints axis
= &hints
->axis
[dim
];
1611 FT_Error error
= FT_Err_Ok
;
1612 TA_LatinAxis laxis
= &((TA_LatinMetrics
)hints
->metrics
)->axis
[dim
];
1614 TA_Segment segments
= axis
->segments
;
1615 TA_Segment segment_limit
= segments
+ axis
->num_segments
;
1619 TA_Direction up_dir
;
1622 FT_Pos edge_distance_threshold
;
1623 FT_Pos segment_length_threshold
;
1626 axis
->num_edges
= 0;
1628 scale
= (dim
== TA_DIMENSION_HORZ
) ? hints
->x_scale
1632 up_dir
= (dim
== TA_DIMENSION_HORZ
) ? TA_DIR_UP
1636 /* we ignore all segments that are less than 1 pixel in length */
1637 /* to avoid many problems with serif fonts */
1638 /* (the corresponding threshold is computed in font units) */
1639 if (dim
== TA_DIMENSION_HORZ
)
1640 segment_length_threshold
= FT_DivFix(64, hints
->y_scale
);
1642 segment_length_threshold
= 0;
1644 /********************************************************************/
1646 /* We begin by generating a sorted table of edges for the current */
1647 /* direction. To do so, we simply scan each segment and try to find */
1648 /* an edge in our table that corresponds to its position. */
1650 /* If no edge is found, we create and insert a new edge in the */
1651 /* sorted table. Otherwise, we simply add the segment to the edge's */
1652 /* list which gets processed in the second step to compute the */
1653 /* edge's properties. */
1655 /* Note that the table of edges is sorted along the segment/edge */
1658 /********************************************************************/
1660 /* assure that edge distance threshold is at most 0.25px */
1661 edge_distance_threshold
= FT_MulFix(laxis
->edge_distance_threshold
,
1663 if (edge_distance_threshold
> 64 / 4)
1664 edge_distance_threshold
= 64 / 4;
1666 edge_distance_threshold
= FT_DivFix(edge_distance_threshold
,
1669 for (seg
= segments
; seg
< segment_limit
; seg
++)
1671 TA_Edge found
= NULL
;
1675 if (seg
->height
< segment_length_threshold
)
1678 /* a special case for serif edges: */
1679 /* if they are smaller than 1.5 pixels we ignore them */
1681 && 2 * seg
->height
< 3 * segment_length_threshold
)
1684 /* look for an edge corresponding to the segment */
1685 for (ee
= 0; ee
< axis
->num_edges
; ee
++)
1687 TA_Edge edge
= axis
->edges
+ ee
;
1691 dist
= seg
->pos
- edge
->fpos
;
1695 if (dist
< edge_distance_threshold
&& edge
->dir
== seg
->dir
)
1707 /* insert a new edge in the list and sort according to the position */
1708 error
= ta_axis_hints_new_edge(axis
, seg
->pos
,
1709 (TA_Direction
)seg
->dir
,
1714 /* add the segment to the new edge's list */
1715 memset(edge
, 0, sizeof (TA_EdgeRec
));
1718 edge
->dir
= seg
->dir
;
1719 edge
->fpos
= seg
->pos
;
1720 edge
->opos
= FT_MulFix(seg
->pos
, scale
);
1721 edge
->pos
= edge
->opos
;
1722 seg
->edge_next
= seg
;
1726 /* if an edge was found, simply add the segment to the edge's list */
1727 seg
->edge_next
= found
->first
;
1728 found
->last
->edge_next
= seg
;
1733 /*****************************************************************/
1735 /* Good, we now compute each edge's properties according to */
1736 /* the segments found on its position. Basically, these are */
1738 /* - the edge's main direction */
1739 /* - stem edge, serif edge or both (which defaults to stem then) */
1740 /* - rounded edge, straight or both (which defaults to straight) */
1741 /* - link for edge */
1743 /*****************************************************************/
1745 /* first of all, set the `edge' field in each segment -- this is */
1746 /* required in order to compute edge links */
1748 /* note that removing this loop and setting the `edge' field of each */
1749 /* segment directly in the code above slows down execution speed for */
1750 /* some reasons on platforms like the Sun */
1752 TA_Edge edges
= axis
->edges
;
1753 TA_Edge edge_limit
= edges
+ axis
->num_edges
;
1757 for (edge
= edges
; edge
< edge_limit
; edge
++)
1764 seg
= seg
->edge_next
;
1765 } while (seg
!= edge
->first
);
1768 /* now compute each edge properties */
1769 for (edge
= edges
; edge
< edge_limit
; edge
++)
1771 FT_Int is_round
= 0; /* does it contain round segments? */
1772 FT_Int is_straight
= 0; /* does it contain straight segments? */
1774 FT_Pos ups
= 0; /* number of upwards segments */
1775 FT_Pos downs
= 0; /* number of downwards segments */
1786 /* check for roundness of segment */
1787 if (seg
->flags
& TA_EDGE_ROUND
)
1793 /* check for segment direction */
1794 if (seg
->dir
== up_dir
)
1795 ups
+= seg
->max_coord
- seg
->min_coord
;
1797 downs
+= seg
->max_coord
- seg
->min_coord
;
1800 /* check for links -- */
1801 /* if seg->serif is set, then seg->link must be ignored */
1802 is_serif
= (FT_Bool
)(seg
->serif
1804 && seg
->serif
->edge
!= edge
);
1806 if ((seg
->link
&& seg
->link
->edge
!= NULL
)
1819 edge2
= edge
->serif
;
1828 edge_delta
= edge
->fpos
- edge2
->fpos
;
1830 edge_delta
= -edge_delta
;
1832 seg_delta
= seg
->pos
- seg2
->pos
;
1834 seg_delta
= -seg_delta
;
1836 if (seg_delta
< edge_delta
)
1844 edge
->serif
= edge2
;
1845 edge2
->flags
|= TA_EDGE_SERIF
;
1851 seg
= seg
->edge_next
;
1852 } while (seg
!= edge
->first
);
1854 /* set the round/straight flags */
1855 edge
->flags
= TA_EDGE_NORMAL
;
1858 && is_round
>= is_straight
)
1859 edge
->flags
|= TA_EDGE_ROUND
;
1862 /* set the edge's main direction */
1863 edge
->dir
= TA_DIR_NONE
;
1866 edge
->dir
= (FT_Char
)up_dir
;
1868 else if (ups
< downs
)
1869 edge
->dir
= (FT_Char
)-up_dir
;
1871 else if (ups
== downs
)
1872 edge
->dir
= 0; /* both up and down! */
1875 /* get rid of serifs if link is set */
1876 /* XXX: this gets rid of many unpleasant artefacts! */
1877 /* example: the `c' in cour.pfa at size 13 */
1879 if (edge
->serif
&& edge
->link
)
1889 /* detect segments and edges for given dimension */
1892 ta_latin_hints_detect_features(TA_GlyphHints hints
,
1893 FT_UInt width_count
,
1894 TA_WidthRec
* widths
,
1900 error
= ta_latin_hints_compute_segments(hints
, dim
);
1903 ta_latin_hints_link_segments(hints
, width_count
, widths
, dim
);
1905 error
= ta_latin_hints_compute_edges(hints
, dim
);
1912 /* compute all edges which lie within blue zones */
1915 ta_latin_hints_compute_blue_edges(TA_GlyphHints hints
,
1916 TA_LatinMetrics metrics
)
1918 TA_AxisHints axis
= &hints
->axis
[TA_DIMENSION_VERT
];
1920 TA_Edge edge
= axis
->edges
;
1921 TA_Edge edge_limit
= edge
+ axis
->num_edges
;
1923 TA_LatinAxis latin
= &metrics
->axis
[TA_DIMENSION_VERT
];
1924 FT_Fixed scale
= latin
->scale
;
1927 /* compute which blue zones are active, */
1928 /* i.e. have their scaled size < 3/4 pixels */
1930 /* for each horizontal edge search the blue zone which is closest */
1931 for (; edge
< edge_limit
; edge
++)
1934 TA_Width best_blue
= NULL
;
1935 FT_Bool best_blue_is_neutral
= 0;
1936 FT_Pos best_dist
; /* initial threshold */
1938 FT_UInt best_blue_idx
= 0;
1939 FT_Bool best_blue_is_shoot
= 0;
1942 /* compute the initial threshold as a fraction of the EM size */
1943 /* (the value 40 is heuristic) */
1944 best_dist
= FT_MulFix(metrics
->units_per_em
/ 40, scale
);
1946 /* assure a minimum distance of 0.5px */
1947 if (best_dist
> 64 / 2)
1950 /* this loop also handles the two extra blue zones */
1951 /* for usWinAscent and usWinDescent */
1952 /* if option `windows-compatibility' is set */
1954 bb
< latin
->blue_count
1955 + (metrics
->root
.globals
->font
->windows_compatibility
? 2 : 0);
1958 TA_LatinBlue blue
= latin
->blues
+ bb
;
1959 FT_Bool is_top_blue
, is_neutral_blue
, is_major_dir
;
1962 /* skip inactive blue zones (i.e., those that are too large) */
1963 if (!(blue
->flags
& TA_LATIN_BLUE_ACTIVE
))
1966 /* if it is a top zone, check for right edges (against the major */
1967 /* direction); if it is a bottom zone, check for left edges (in */
1968 /* the major direction) */
1969 is_top_blue
= (FT_Byte
)((blue
->flags
& TA_LATIN_BLUE_TOP
) != 0);
1970 is_neutral_blue
= (FT_Byte
)((blue
->flags
& TA_LATIN_BLUE_NEUTRAL
) != 0);
1971 is_major_dir
= FT_BOOL(edge
->dir
== axis
->major_dir
);
1973 /* neutral blue zones are handled for both directions */
1974 if (is_top_blue
^ is_major_dir
|| is_neutral_blue
)
1979 /* first of all, compare it to the reference position */
1980 dist
= edge
->fpos
- blue
->ref
.org
;
1984 dist
= FT_MulFix(dist
, scale
);
1985 if (dist
< best_dist
)
1988 best_blue
= &blue
->ref
;
1989 best_blue_is_neutral
= is_neutral_blue
;
1992 best_blue_is_shoot
= 0;
1995 /* now compare it to the overshoot position and check whether */
1996 /* the edge is rounded, and whether the edge is over the */
1997 /* reference position of a top zone, or under the reference */
1998 /* position of a bottom zone (provided we don't have a */
1999 /* neutral blue zone) */
2000 if (edge
->flags
& TA_EDGE_ROUND
2002 && !is_neutral_blue
)
2004 FT_Bool is_under_ref
= FT_BOOL(edge
->fpos
< blue
->ref
.org
);
2007 if (is_top_blue
^ is_under_ref
)
2009 dist
= edge
->fpos
- blue
->shoot
.org
;
2013 dist
= FT_MulFix(dist
, scale
);
2014 if (dist
< best_dist
)
2017 best_blue
= &blue
->shoot
;
2018 best_blue_is_neutral
= is_neutral_blue
;
2021 best_blue_is_shoot
= 1;
2030 edge
->blue_edge
= best_blue
;
2031 edge
->best_blue_idx
= best_blue_idx
;
2032 edge
->best_blue_is_shoot
= best_blue_is_shoot
;
2033 if (best_blue_is_neutral
)
2034 edge
->flags
|= TA_EDGE_NEUTRAL
;
2040 /* initalize hinting engine */
2043 ta_latin_hints_init(TA_GlyphHints hints
,
2044 TA_LatinMetrics metrics
)
2046 FT_Render_Mode mode
;
2047 FT_UInt32 scaler_flags
, other_flags
;
2048 FT_Face face
= metrics
->root
.scaler
.face
;
2051 ta_glyph_hints_rescale(hints
, (TA_StyleMetrics
)metrics
);
2053 /* correct x_scale and y_scale if needed, since they may have */
2054 /* been modified by `ta_latin_metrics_scale_dim' above */
2055 hints
->x_scale
= metrics
->axis
[TA_DIMENSION_HORZ
].scale
;
2056 hints
->x_delta
= metrics
->axis
[TA_DIMENSION_HORZ
].delta
;
2057 hints
->y_scale
= metrics
->axis
[TA_DIMENSION_VERT
].scale
;
2058 hints
->y_delta
= metrics
->axis
[TA_DIMENSION_VERT
].delta
;
2060 /* compute flags depending on render mode, etc. */
2061 mode
= metrics
->root
.scaler
.render_mode
;
2063 #if 0 /* #ifdef TA_CONFIG_OPTION_USE_WARPER */
2064 if (mode
== FT_RENDER_MODE_LCD
2065 || mode
== FT_RENDER_MODE_LCD_V
)
2066 metrics
->root
.scaler
.render_mode
=
2067 mode
= FT_RENDER_MODE_NORMAL
;
2070 scaler_flags
= hints
->scaler_flags
;
2073 /* we snap the width of vertical stems for the monochrome */
2074 /* and horizontal LCD rendering targets only */
2075 if (mode
== FT_RENDER_MODE_MONO
2076 || mode
== FT_RENDER_MODE_LCD
)
2077 other_flags
|= TA_LATIN_HINTS_HORZ_SNAP
;
2079 /* we snap the width of horizontal stems for the monochrome */
2080 /* and vertical LCD rendering targets only */
2081 if (mode
== FT_RENDER_MODE_MONO
2082 || mode
== FT_RENDER_MODE_LCD_V
)
2083 other_flags
|= TA_LATIN_HINTS_VERT_SNAP
;
2085 /* we adjust stems to full pixels only if we don't use the `light' mode */
2086 if (mode
!= FT_RENDER_MODE_LIGHT
)
2087 other_flags
|= TA_LATIN_HINTS_STEM_ADJUST
;
2089 if (mode
== FT_RENDER_MODE_MONO
)
2090 other_flags
|= TA_LATIN_HINTS_MONO
;
2092 /* in `light' hinting mode we disable horizontal hinting completely; */
2093 /* we also do it if the face is italic */
2094 if (mode
== FT_RENDER_MODE_LIGHT
2095 || (face
->style_flags
& FT_STYLE_FLAG_ITALIC
) != 0)
2096 scaler_flags
|= TA_SCALER_FLAG_NO_HORIZONTAL
;
2098 hints
->scaler_flags
= scaler_flags
;
2099 hints
->other_flags
= other_flags
;
2105 /* snap a given width in scaled coordinates to */
2106 /* one of the current standard widths */
2109 ta_latin_snap_width(TA_Width widths
,
2114 FT_Pos best
= 64 + 32 + 2;
2115 FT_Pos reference
= width
;
2119 for (n
= 0; n
< count
; n
++)
2136 scaled
= TA_PIX_ROUND(reference
);
2138 if (width
>= reference
)
2140 if (width
< scaled
+ 48)
2145 if (width
> scaled
- 48)
2153 /* compute the snapped width of a given stem, ignoring very thin ones */
2155 /* there is a lot of voodoo in this function; changing the hard-coded */
2156 /* parameters influences the whole hinting process */
2159 ta_latin_compute_stem_width(TA_GlyphHints hints
,
2165 TA_LatinMetrics metrics
= (TA_LatinMetrics
) hints
->metrics
;
2166 TA_LatinAxis axis
= &metrics
->axis
[dim
];
2168 FT_Pos dist
= width
;
2170 FT_Int vertical
= (dim
== TA_DIMENSION_VERT
);
2173 if (!TA_LATIN_HINTS_DO_STEM_ADJUST(hints
)
2174 || axis
->extra_light
)
2183 if ((vertical
&& !TA_LATIN_HINTS_DO_VERT_SNAP(hints
))
2184 || (!vertical
&& !TA_LATIN_HINTS_DO_HORZ_SNAP(hints
)))
2186 /* smooth hinting process: very lightly quantize the stem width */
2188 /* leave the widths of serifs alone */
2189 if ((stem_flags
& TA_EDGE_SERIF
)
2193 else if (base_flags
& TA_EDGE_ROUND
)
2201 if (axis
->width_count
> 0)
2206 /* compare to standard width */
2207 delta
= dist
- axis
->widths
[0].cur
;
2214 dist
= axis
->widths
[0].cur
;
2228 else if (delta
< 32)
2230 else if (delta
< 54)
2236 dist
= (dist
+ 32) & ~63;
2241 /* strong hinting process: snap the stem width to integer pixels */
2243 FT_Pos org_dist
= dist
;
2246 dist
= ta_latin_snap_width(axis
->widths
, axis
->width_count
, dist
);
2250 /* in the case of vertical hinting, */
2251 /* always round the stem heights to integer pixels */
2254 dist
= (dist
+ 16) & ~63;
2260 if (TA_LATIN_HINTS_DO_MONO(hints
))
2262 /* monochrome horizontal hinting: */
2263 /* snap widths to integer pixels with a different threshold */
2268 dist
= (dist
+ 32) & ~63;
2272 /* for horizontal anti-aliased hinting, we adopt a more subtle */
2273 /* approach: we strengthen small stems, round stems whose size */
2274 /* is between 1 and 2 pixels to an integer, otherwise nothing */
2277 dist
= (dist
+ 64) >> 1;
2279 else if (dist
< 128)
2281 /* we only round to an integer width if the corresponding */
2282 /* distortion is less than 1/4 pixel -- otherwise, this */
2283 /* makes everything worse since the diagonals, which are */
2284 /* not hinted, appear a lot bolder or thinner than the */
2285 /* vertical stems */
2290 dist
= (dist
+ 22) & ~63;
2291 delta
= dist
- org_dist
;
2299 dist
= (dist
+ 64) >> 1;
2303 /* round otherwise to prevent color fringes in LCD mode */
2304 dist
= (dist
+ 32) & ~63;
2317 /* align one stem edge relative to the previous stem edge */
2320 ta_latin_align_linked_edge(TA_GlyphHints hints
,
2325 FT_Pos dist
= stem_edge
->opos
- base_edge
->opos
;
2327 FT_Pos fitted_width
= ta_latin_compute_stem_width(
2333 stem_edge
->pos
= base_edge
->pos
+ fitted_width
;
2335 TA_LOG((" LINK: edge %d (opos=%.2f) linked to %.2f,"
2336 " dist was %.2f, now %.2f\n",
2337 stem_edge
- hints
->axis
[dim
].edges
, stem_edge
->opos
/ 64.0,
2338 stem_edge
->pos
/ 64.0, dist
/ 64.0, fitted_width
/ 64.0));
2340 if (hints
->recorder
)
2341 hints
->recorder(ta_link
, hints
, dim
,
2342 base_edge
, stem_edge
, NULL
, NULL
, NULL
);
2346 /* shift the coordinates of the `serif' edge by the same amount */
2347 /* as the corresponding `base' edge has been moved already */
2350 ta_latin_align_serif_edge(TA_GlyphHints hints
,
2356 serif
->pos
= base
->pos
+ (serif
->opos
- base
->opos
);
2360 /* the main grid-fitting routine */
2363 ta_latin_hint_edges(TA_GlyphHints hints
,
2366 TA_AxisHints axis
= &hints
->axis
[dim
];
2368 TA_Edge edges
= axis
->edges
;
2369 TA_Edge edge_limit
= edges
+ axis
->num_edges
;
2373 TA_Edge anchor
= NULL
;
2374 FT_Int has_serifs
= 0;
2377 FT_UInt num_actions
= 0;
2380 TA_LOG(("latin %s edge hinting (style `%s')\n",
2381 dim
== TA_DIMENSION_VERT
? "horizontal" : "vertical",
2382 ta_style_names
[hints
->metrics
->style_class
->style
]));
2384 /* we begin by aligning all stems relative to the blue zone if needed -- */
2385 /* that's only for horizontal edges */
2387 if (dim
== TA_DIMENSION_VERT
2388 && TA_HINTS_DO_BLUES(hints
))
2390 for (edge
= edges
; edge
< edge_limit
; edge
++)
2393 TA_Edge edge1
, edge2
; /* these edges form the stem to check */
2396 if (edge
->flags
& TA_EDGE_DONE
)
2403 * If a stem contains both a neutral and a non-neutral blue zone,
2404 * skip the neutral one. Otherwise, outlines with different
2405 * directions might be incorrectly aligned at the same vertical
2408 * If we have two neutral blue zones, skip one of them.
2410 if (edge
->blue_edge
&& edge2
&& edge2
->blue_edge
)
2412 FT_Byte neutral
= edge
->flags
& TA_EDGE_NEUTRAL
;
2413 FT_Byte neutral2
= edge2
->flags
& TA_EDGE_NEUTRAL
;
2416 if ((neutral
&& neutral2
) || neutral2
)
2418 edge2
->blue_edge
= NULL
;
2419 edge2
->flags
&= ~TA_EDGE_NEUTRAL
;
2423 edge
->blue_edge
= NULL
;
2424 edge
->flags
&= ~TA_EDGE_NEUTRAL
;
2428 blue
= edge
->blue_edge
;
2432 /* flip edges if the other edge is aligned to a blue zone */
2433 else if (edge2
&& edge2
->blue_edge
)
2435 blue
= edge2
->blue_edge
;
2445 TA_LOG((" BLUE_ANCHOR: edge %d (opos=%.2f) snapped to %.2f,"
2446 " was %.2f (anchor=edge %d)\n",
2447 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
2448 edge1
->pos
/ 64.0, edge
- edges
));
2450 TA_LOG((" BLUE: edge %d (opos=%.2f) snapped to %.2f, was %.2f\n",
2451 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
2452 edge1
->pos
/ 64.0));
2457 edge1
->pos
= blue
->fit
;
2458 edge1
->flags
|= TA_EDGE_DONE
;
2460 if (hints
->recorder
)
2463 hints
->recorder(ta_blue_anchor
, hints
, dim
,
2464 edge1
, edge
, NULL
, NULL
, NULL
);
2466 hints
->recorder(ta_blue
, hints
, dim
,
2467 edge1
, NULL
, NULL
, NULL
, NULL
);
2470 if (edge2
&& !edge2
->blue_edge
)
2472 ta_latin_align_linked_edge(hints
, dim
, edge1
, edge2
);
2473 edge2
->flags
|= TA_EDGE_DONE
;
2485 /* now we align all other stem edges, */
2486 /* trying to maintain the relative order of stems in the glyph */
2487 for (edge
= edges
; edge
< edge_limit
; edge
++)
2492 if (edge
->flags
& TA_EDGE_DONE
)
2495 /* skip all non-stem edges */
2503 /* now align the stem */
2505 /* this should not happen, but it's better to be safe */
2506 if (edge2
->blue_edge
)
2508 TA_LOG((" ASSERTION FAILED for edge %d\n", edge2
- edges
));
2510 ta_latin_align_linked_edge(hints
, dim
, edge2
, edge
);
2511 edge
->flags
|= TA_EDGE_DONE
;
2521 /* if we reach this if clause, no stem has been aligned yet */
2523 FT_Pos org_len
, org_center
, cur_len
;
2524 FT_Pos cur_pos1
, error1
, error2
, u_off
, d_off
;
2527 org_len
= edge2
->opos
- edge
->opos
;
2528 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
2529 edge
->flags
, edge2
->flags
);
2531 /* some voodoo to specially round edges for small stem widths; */
2532 /* the idea is to align the center of a stem, */
2533 /* then shifting the stem edges to suitable positions */
2542 /* 1px < width < 1.5px */
2549 org_center
= edge
->opos
+ (org_len
>> 1);
2550 cur_pos1
= TA_PIX_ROUND(org_center
);
2552 error1
= org_center
- (cur_pos1
- u_off
);
2556 error2
= org_center
- (cur_pos1
+ d_off
);
2560 if (error1
< error2
)
2565 edge
->pos
= cur_pos1
- cur_len
/ 2;
2566 edge2
->pos
= edge
->pos
+ cur_len
;
2569 edge
->pos
= TA_PIX_ROUND(edge
->opos
);
2572 edge
->flags
|= TA_EDGE_DONE
;
2574 TA_LOG((" ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
2575 " snapped to %.2f and %.2f\n",
2576 edge
- edges
, edge
->opos
/ 64.0,
2577 edge2
- edges
, edge2
->opos
/ 64.0,
2578 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
2580 if (hints
->recorder
)
2581 hints
->recorder(ta_anchor
, hints
, dim
,
2582 edge
, edge2
, NULL
, NULL
, NULL
);
2584 ta_latin_align_linked_edge(hints
, dim
, edge
, edge2
);
2592 FT_Pos org_pos
, org_len
, org_center
, cur_len
;
2593 FT_Pos cur_pos1
, cur_pos2
, delta1
, delta2
;
2596 org_pos
= anchor
->pos
+ (edge
->opos
- anchor
->opos
);
2597 org_len
= edge2
->opos
- edge
->opos
;
2598 org_center
= org_pos
+ (org_len
>> 1);
2600 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
2601 edge
->flags
, edge2
->flags
);
2603 if (edge2
->flags
& TA_EDGE_DONE
)
2605 TA_LOG((" ADJUST: edge %d (pos=%.2f) moved to %.2f\n",
2606 edge
- edges
, edge
->pos
/ 64.0,
2607 (edge2
->pos
- cur_len
) / 64.0));
2609 edge
->pos
= edge2
->pos
- cur_len
;
2611 if (hints
->recorder
)
2613 TA_Edge bound
= NULL
;
2619 hints
->recorder(ta_adjust
, hints
, dim
,
2620 edge
, edge2
, NULL
, bound
, NULL
);
2624 else if (cur_len
< 96)
2626 FT_Pos u_off
, d_off
;
2629 cur_pos1
= TA_PIX_ROUND(org_center
);
2642 delta1
= org_center
- (cur_pos1
- u_off
);
2646 delta2
= org_center
- (cur_pos1
+ d_off
);
2650 if (delta1
< delta2
)
2655 edge
->pos
= cur_pos1
- cur_len
/ 2;
2656 edge2
->pos
= cur_pos1
+ cur_len
/ 2;
2658 TA_LOG((" STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
2659 " snapped to %.2f and %.2f\n",
2660 edge
- edges
, edge
->opos
/ 64.0,
2661 edge2
- edges
, edge2
->opos
/ 64.0,
2662 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
2664 if (hints
->recorder
)
2666 TA_Edge bound
= NULL
;
2672 hints
->recorder(ta_stem
, hints
, dim
,
2673 edge
, edge2
, NULL
, bound
, NULL
);
2679 org_pos
= anchor
->pos
+ (edge
->opos
- anchor
->opos
);
2680 org_len
= edge2
->opos
- edge
->opos
;
2681 org_center
= org_pos
+ (org_len
>> 1);
2683 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
2684 edge
->flags
, edge2
->flags
);
2686 cur_pos1
= TA_PIX_ROUND(org_pos
);
2687 delta1
= cur_pos1
+ (cur_len
>> 1) - org_center
;
2691 cur_pos2
= TA_PIX_ROUND(org_pos
+ org_len
) - cur_len
;
2692 delta2
= cur_pos2
+ (cur_len
>> 1) - org_center
;
2696 edge
->pos
= (delta1
< delta2
) ? cur_pos1
: cur_pos2
;
2697 edge2
->pos
= edge
->pos
+ cur_len
;
2699 TA_LOG((" STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
2700 " snapped to %.2f and %.2f\n",
2701 edge
- edges
, edge
->opos
/ 64.0,
2702 edge2
- edges
, edge2
->opos
/ 64.0,
2703 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
2705 if (hints
->recorder
)
2707 TA_Edge bound
= NULL
;
2713 hints
->recorder(ta_stem
, hints
, dim
,
2714 edge
, edge2
, NULL
, bound
, NULL
);
2722 edge
->flags
|= TA_EDGE_DONE
;
2723 edge2
->flags
|= TA_EDGE_DONE
;
2726 && edge
->pos
< edge
[-1].pos
)
2729 TA_LOG((" 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
;
2737 if (hints
->recorder
)
2738 hints
->recorder(ta_bound
, hints
, dim
,
2739 edge
, &edge
[-1], NULL
, NULL
, NULL
);
2744 /* make sure that lowercase m's maintain their symmetry */
2746 /* In general, lowercase m's have six vertical edges if they are sans */
2747 /* serif, or twelve if they are with serifs. This implementation is */
2748 /* based on that assumption, and seems to work very well with most */
2749 /* faces. However, if for a certain face this assumption is not */
2750 /* true, the m is just rendered like before. In addition, any stem */
2751 /* correction will only be applied to symmetrical glyphs (even if the */
2752 /* glyph is not an m), so the potential for unwanted distortion is */
2753 /* relatively low. */
2755 /* we don't handle horizontal edges since we can't easily assure that */
2756 /* the third (lowest) stem aligns with the base line; it might end up */
2757 /* one pixel higher or lower */
2759 n_edges
= edge_limit
- edges
;
2760 if (dim
== TA_DIMENSION_HORZ
2761 && (n_edges
== 6 || n_edges
== 12))
2763 TA_Edge edge1
, edge2
, edge3
;
2764 FT_Pos dist1
, dist2
, span
, delta
;
2780 dist1
= edge2
->opos
- edge1
->opos
;
2781 dist2
= edge3
->opos
- edge2
->opos
;
2783 span
= dist1
- dist2
;
2789 delta
= edge3
->pos
- (2 * edge2
->pos
- edge1
->pos
);
2790 edge3
->pos
-= delta
;
2792 edge3
->link
->pos
-= delta
;
2794 /* move the serifs along with the stem */
2797 (edges
+ 8)->pos
-= delta
;
2798 (edges
+ 11)->pos
-= delta
;
2801 edge3
->flags
|= TA_EDGE_DONE
;
2803 edge3
->link
->flags
|= TA_EDGE_DONE
;
2807 if (has_serifs
|| !anchor
)
2809 /* now hint the remaining edges (serifs and single) */
2810 /* in order to complete our processing */
2811 for (edge
= edges
; edge
< edge_limit
; edge
++)
2813 TA_Edge lower_bound
= NULL
;
2814 TA_Edge upper_bound
= NULL
;
2819 if (edge
->flags
& TA_EDGE_DONE
)
2826 delta
= edge
->serif
->opos
- edge
->opos
;
2832 lower_bound
= &edge
[-1];
2834 if (edge
+ 1 < edge_limit
2835 && edge
[1].flags
& TA_EDGE_DONE
)
2836 upper_bound
= &edge
[1];
2839 if (delta
< 64 + 16)
2841 ta_latin_align_serif_edge(hints
, edge
->serif
, edge
);
2843 TA_LOG((" SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
2844 " aligned to %.2f\n",
2845 edge
- edges
, edge
->opos
/ 64.0,
2846 edge
->serif
- edges
, edge
->serif
->opos
/ 64.0,
2849 if (hints
->recorder
)
2850 hints
->recorder(ta_serif
, hints
, dim
,
2851 edge
, NULL
, NULL
, lower_bound
, upper_bound
);
2855 edge
->pos
= TA_PIX_ROUND(edge
->opos
);
2858 TA_LOG((" SERIF_ANCHOR: edge %d (opos=%.2f) snapped to %.2f\n",
2859 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0));
2861 if (hints
->recorder
)
2862 hints
->recorder(ta_serif_anchor
, hints
, dim
,
2863 edge
, NULL
, NULL
, lower_bound
, upper_bound
);
2867 TA_Edge before
, after
;
2870 for (before
= edge
- 1; before
>= edges
; before
--)
2871 if (before
->flags
& TA_EDGE_DONE
)
2874 for (after
= edge
+ 1; after
< edge_limit
; after
++)
2875 if (after
->flags
& TA_EDGE_DONE
)
2878 if (before
>= edges
&& before
< edge
2879 && after
< edge_limit
&& after
> edge
)
2881 if (after
->opos
== before
->opos
)
2882 edge
->pos
= before
->pos
;
2884 edge
->pos
= before
->pos
+ FT_MulDiv(edge
->opos
- before
->opos
,
2885 after
->pos
- before
->pos
,
2886 after
->opos
- before
->opos
);
2888 TA_LOG((" SERIF_LINK1: edge %d (opos=%.2f) snapped to %.2f"
2889 " from %d (opos=%.2f)\n",
2890 edge
- edges
, edge
->opos
/ 64.0,
2892 before
- edges
, before
->opos
/ 64.0));
2894 if (hints
->recorder
)
2895 hints
->recorder(ta_serif_link1
, hints
, dim
,
2896 edge
, before
, after
, lower_bound
, upper_bound
);
2900 edge
->pos
= anchor
->pos
+ ((edge
->opos
- anchor
->opos
+ 16) & ~31);
2901 TA_LOG((" SERIF_LINK2: edge %d (opos=%.2f) snapped to %.2f\n",
2902 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0));
2904 if (hints
->recorder
)
2905 hints
->recorder(ta_serif_link2
, hints
, dim
,
2906 edge
, NULL
, NULL
, lower_bound
, upper_bound
);
2913 edge
->flags
|= TA_EDGE_DONE
;
2916 && edge
->pos
< edge
[-1].pos
)
2919 TA_LOG((" BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2920 edge
- edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0));
2924 edge
->pos
= edge
[-1].pos
;
2926 if (hints
->recorder
)
2927 hints
->recorder(ta_bound
, hints
, dim
,
2928 edge
, &edge
[-1], NULL
, NULL
, NULL
);
2931 if (edge
+ 1 < edge_limit
2932 && edge
[1].flags
& TA_EDGE_DONE
2933 && edge
->pos
> edge
[1].pos
)
2936 TA_LOG((" BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2937 edge
- edges
, edge
->pos
/ 64.0, edge
[1].pos
/ 64.0));
2942 edge
->pos
= edge
[1].pos
;
2944 if (hints
->recorder
)
2945 hints
->recorder(ta_bound
, hints
, dim
,
2946 edge
, &edge
[1], NULL
, NULL
, NULL
);
2953 TA_LOG((" (none)\n"));
2959 /* apply the complete hinting algorithm to a latin glyph */
2962 ta_latin_hints_apply(TA_GlyphHints hints
,
2963 FT_Outline
* outline
,
2964 TA_LatinMetrics metrics
)
2972 error
= ta_glyph_hints_reload(hints
, outline
);
2976 /* analyze glyph outline */
2977 #ifdef TA_CONFIG_OPTION_USE_WARPER
2978 if (metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
2979 || TA_HINTS_DO_HORIZONTAL(hints
))
2981 if (TA_HINTS_DO_HORIZONTAL(hints
))
2984 axis
= &metrics
->axis
[TA_DIMENSION_HORZ
];
2985 error
= ta_latin_hints_detect_features(hints
,
2993 if (TA_HINTS_DO_VERTICAL(hints
))
2995 axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
2996 error
= ta_latin_hints_detect_features(hints
,
3003 ta_latin_hints_compute_blue_edges(hints
, metrics
);
3006 /* grid-fit the outline */
3007 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
3009 #ifdef TA_CONFIG_OPTION_USE_WARPER
3010 if (dim
== TA_DIMENSION_HORZ
3011 && metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
)
3013 TA_WarperRec warper
;
3018 ta_warper_compute(&warper
, hints
, (TA_Dimension
)dim
, &scale
, &delta
);
3019 ta_glyph_hints_scale_dim(hints
, (TA_Dimension
)dim
, scale
, delta
);
3025 if ((dim
== TA_DIMENSION_HORZ
&& TA_HINTS_DO_HORIZONTAL(hints
))
3026 || (dim
== TA_DIMENSION_VERT
&& TA_HINTS_DO_VERTICAL(hints
)))
3028 ta_latin_hint_edges(hints
, (TA_Dimension
)dim
);
3029 ta_glyph_hints_align_edge_points(hints
, (TA_Dimension
)dim
);
3030 ta_glyph_hints_align_strong_points(hints
, (TA_Dimension
)dim
);
3031 ta_glyph_hints_align_weak_points(hints
, (TA_Dimension
)dim
);
3035 ta_glyph_hints_save(hints
, outline
);
3042 const TA_WritingSystemClassRec ta_latin_writing_system_class
=
3044 TA_WRITING_SYSTEM_LATIN
,
3046 sizeof (TA_LatinMetricsRec
),
3048 (TA_WritingSystem_InitMetricsFunc
)ta_latin_metrics_init
,
3049 (TA_WritingSystem_ScaleMetricsFunc
)ta_latin_metrics_scale
,
3050 (TA_WritingSystem_DoneMetricsFunc
)NULL
,
3052 (TA_WritingSystem_InitHintsFunc
)ta_latin_hints_init
,
3053 (TA_WritingSystem_ApplyHintsFunc
)ta_latin_hints_apply
3056 /* end of talatin.c */