4 * Copyright (C) 2011-2015 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 /* needed for computation of round vs. flat segments */
39 #define FLAT_THRESHOLD(x) (x / 14)
42 /* find segments and links, compute all stem widths, and initialize */
43 /* standard width and height for the glyph with given charcode */
46 ta_latin_metrics_init_widths(TA_LatinMetrics metrics
,
50 /* scan the array of segments in each direction */
51 TA_GlyphHintsRec hints
[1];
55 "latin standard widths computation (style `%s')\n"
56 "=====================================================\n"
58 ta_style_names
[metrics
->root
.style_class
->style
]));
60 ta_glyph_hints_init(hints
);
62 metrics
->axis
[TA_DIMENSION_HORZ
].width_count
= 0;
63 metrics
->axis
[TA_DIMENSION_VERT
].width_count
= 0;
70 TA_LatinMetricsRec dummy
[1];
71 TA_Scaler scaler
= &dummy
->root
.scaler
;
73 TA_StyleClass style_class
= metrics
->root
.style_class
;
74 TA_ScriptClass script_class
= ta_script_classes
[style_class
->script
];
76 FT_UInt32 standard_char
;
83 * We check more than a single standard character to catch features
84 * like `c2sc' (small caps from caps) that don't contain lowercase
85 * letters by definition, or other features that mainly operate on
88 standard_char
= script_class
->standard_char1
;
89 ta_get_char_index(&metrics
->root
,
95 if (script_class
->standard_char2
)
97 standard_char
= script_class
->standard_char2
;
98 ta_get_char_index(&metrics
->root
,
104 if (script_class
->standard_char3
)
106 standard_char
= script_class
->standard_char3
;
107 ta_get_char_index(&metrics
->root
,
122 TA_LOG_GLOBAL(("standard character: U+%04lX (glyph index %d)\n",
123 standard_char
, glyph_index
));
125 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_SCALE
);
126 if (error
|| face
->glyph
->outline
.n_points
<= 0)
129 memset(dummy
, 0, sizeof (TA_LatinMetricsRec
));
131 dummy
->units_per_em
= metrics
->units_per_em
;
133 scaler
->x_scale
= 0x10000L
;
134 scaler
->y_scale
= 0x10000L
;
139 scaler
->render_mode
= FT_RENDER_MODE_NORMAL
;
142 ta_glyph_hints_rescale(hints
, (TA_StyleMetrics
)dummy
);
144 error
= ta_glyph_hints_reload(hints
, &face
->glyph
->outline
);
148 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
150 TA_LatinAxis axis
= &metrics
->axis
[dim
];
151 TA_AxisHints axhints
= &hints
->axis
[dim
];
153 TA_Segment seg
, limit
, link
;
154 FT_UInt num_widths
= 0;
157 error
= ta_latin_hints_compute_segments(hints
, (TA_Dimension
)dim
);
162 * We assume that the glyphs selected for the stem width
163 * computation are `featureless' enough so that the linking
164 * algorithm works fine without adjustments of its scoring
167 ta_latin_hints_link_segments(hints
, 0, NULL
, (TA_Dimension
)dim
);
169 seg
= axhints
->segments
;
170 limit
= seg
+ axhints
->num_segments
;
172 for (; seg
< limit
; seg
++)
176 /* we only consider stem segments there! */
184 dist
= seg
->pos
- link
->pos
;
188 if (num_widths
< TA_LATIN_MAX_WIDTHS
)
189 axis
->widths
[num_widths
++].org
= dist
;
193 /* this also replaces multiple almost identical stem widths */
194 /* with a single one (the value 100 is heuristic) */
195 ta_sort_and_quantize_widths(&num_widths
, axis
->widths
,
196 dummy
->units_per_em
/ 100);
197 axis
->width_count
= num_widths
;
201 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
203 FONT
* font
= metrics
->root
.globals
->font
;
204 TA_LatinAxis axis
= &metrics
->axis
[dim
];
208 if (!axis
->width_count
)
210 /* if we have no standard characters, */
211 /* use `fallback-stem-width', if available, */
212 /* or a default width (value 50 is heuristic) */
213 stdw
= (dim
== TA_DIMENSION_VERT
&& font
->fallback_stem_width
)
214 ? (FT_Pos
)font
->fallback_stem_width
215 : TA_LATIN_CONSTANT(metrics
, 50);
217 /* set one width value if we do hinting */
218 if (style_class
->style
!= TA_STYLE_NONE_DFLT
)
221 axis
->widths
[0].org
= stdw
;
225 stdw
= axis
->widths
[0].org
;
227 /* let's try 20% of the smallest width */
228 axis
->edge_distance_threshold
= stdw
/ 5;
229 axis
->standard_width
= stdw
;
230 axis
->extra_light
= 0;
237 TA_LOG_GLOBAL(("%s widths:\n",
238 dim
== TA_DIMENSION_VERT
? "horizontal"
241 TA_LOG_GLOBAL((" %d (standard)", axis
->standard_width
));
242 for (i
= 1; i
< axis
->width_count
; i
++)
243 TA_LOG_GLOBAL((" %d", axis
->widths
[i
].org
));
245 TA_LOG_GLOBAL(("\n"));
251 TA_LOG_GLOBAL(("\n"));
253 ta_glyph_hints_done(hints
);
257 /* find all blue zones; flat segments give the reference points, */
258 /* round segments the overshoot positions */
261 ta_latin_metrics_init_blues(TA_LatinMetrics metrics
,
264 FT_Pos flats
[TA_BLUE_STRING_MAX_LEN
];
265 FT_Pos rounds
[TA_BLUE_STRING_MAX_LEN
];
271 TA_LatinAxis axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
274 TA_StyleClass sc
= metrics
->root
.style_class
;
276 TA_Blue_Stringset bss
= sc
->blue_stringset
;
277 const TA_Blue_StringRec
* bs
= &ta_blue_stringsets
[bss
];
279 FT_Pos flat_threshold
= FLAT_THRESHOLD(metrics
->units_per_em
);
282 /* we walk over the blue character strings as specified in the */
283 /* style's entry in the `ta_blue_stringset' array */
285 TA_LOG_GLOBAL(("latin blue zones computation\n"
286 "============================\n"
289 for (; bs
->string
!= TA_BLUE_STRING_MAX
; bs
++)
291 const char* p
= &ta_blue_strings
[bs
->string
];
298 FT_Bool have_flag
= 0;
301 TA_LOG_GLOBAL(("blue zone %d", axis
->blue_count
));
305 TA_LOG_GLOBAL((" ("));
307 if (TA_LATIN_IS_TOP_BLUE(bs
))
309 TA_LOG_GLOBAL(("top"));
313 if (TA_LATIN_IS_NEUTRAL_BLUE(bs
))
316 TA_LOG_GLOBAL((", "));
317 TA_LOG_GLOBAL(("neutral"));
321 if (TA_LATIN_IS_X_HEIGHT_BLUE(bs
))
324 TA_LOG_GLOBAL((", "));
325 TA_LOG_GLOBAL(("small top"));
329 if (TA_LATIN_IS_LONG_BLUE(bs
))
332 TA_LOG_GLOBAL((", "));
333 TA_LOG_GLOBAL(("long"));
336 TA_LOG_GLOBAL((")"));
339 TA_LOG_GLOBAL((":\n"));
341 #endif /* TA_DEBUG */
349 FT_ULong glyph_index
;
351 FT_Pos best_y
; /* same as points.y */
352 FT_Int best_point
, best_contour_first
, best_contour_last
;
357 GET_UTF8_CHAR(ch
, p
);
359 /* load the character in the face -- skip unknown or empty ones */
360 ta_get_char_index(&metrics
->root
, ch
, &glyph_index
, &y_offset
);
361 if (glyph_index
== 0)
363 TA_LOG_GLOBAL((" U+%04lX unavailable\n", ch
));
367 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_SCALE
);
368 outline
= face
->glyph
->outline
;
369 /* reject glyphs that don't produce any rendering */
370 if (error
|| outline
.n_points
<= 2)
372 TA_LOG_GLOBAL((" U+%04lX contains no (usable) outlines\n", ch
));
376 /* now compute min or max point indices and coordinates */
377 points
= outline
.points
;
379 best_y
= 0; /* make compiler happy */
380 best_contour_first
= 0; /* ditto */
381 best_contour_last
= 0; /* ditto */
389 for (nn
= 0; nn
< outline
.n_contours
; first
= last
+ 1, nn
++)
391 FT_Int old_best_point
= best_point
;
395 last
= outline
.contours
[nn
];
397 /* avoid single-point contours since they are never rasterized; */
398 /* in some fonts, they correspond to mark attachment points */
399 /* that are way outside of the glyph's real outline */
403 if (TA_LATIN_IS_TOP_BLUE(bs
))
405 for (pp
= first
; pp
<= last
; pp
++)
407 || points
[pp
].y
> best_y
)
410 best_y
= points
[pp
].y
;
415 for (pp
= first
; pp
<= last
; pp
++)
417 || points
[pp
].y
< best_y
)
420 best_y
= points
[pp
].y
;
424 if (best_point
!= old_best_point
)
426 best_contour_first
= first
;
427 best_contour_last
= last
;
432 /* now check whether the point belongs to a straight or round */
433 /* segment; we first need to find in which contour the extremum */
434 /* lies, then inspect its previous and next points */
437 FT_Pos best_x
= points
[best_point
].x
;
439 FT_Int best_segment_first
, best_segment_last
;
440 FT_Int best_on_point_first
, best_on_point_last
;
444 best_segment_first
= best_point
;
445 best_segment_last
= best_point
;
447 if (FT_CURVE_TAG(outline
.tags
[best_point
]) == FT_CURVE_TAG_ON
)
449 best_on_point_first
= best_point
;
450 best_on_point_last
= best_point
;
454 best_on_point_first
= -1;
455 best_on_point_last
= -1;
458 /* look for the previous and next points on the contour */
459 /* that are not on the same Y coordinate, then threshold */
460 /* the `closeness'... */
466 if (prev
> best_contour_first
)
469 prev
= best_contour_last
;
471 dist
= TA_ABS(points
[prev
].y
- best_y
);
472 /* accept a small distance or a small angle (both values are */
473 /* heuristic; value 20 corresponds to approx. 2.9 degrees) */
475 if (TA_ABS(points
[prev
].x
- best_x
) <= 20 * dist
)
478 best_segment_first
= prev
;
480 if (FT_CURVE_TAG(outline
.tags
[prev
]) == FT_CURVE_TAG_ON
)
482 best_on_point_first
= prev
;
483 if (best_on_point_last
< 0)
484 best_on_point_last
= prev
;
487 } while (prev
!= best_point
);
491 if (next
< best_contour_last
)
494 next
= best_contour_first
;
496 dist
= TA_ABS(points
[next
].y
- best_y
);
498 if (TA_ABS(points
[next
].x
- best_x
) <= 20 * dist
)
501 best_segment_last
= next
;
503 if (FT_CURVE_TAG(outline
.tags
[next
]) == FT_CURVE_TAG_ON
)
505 best_on_point_last
= next
;
506 if (best_on_point_first
< 0)
507 best_on_point_first
= next
;
510 } while (next
!= best_point
);
512 if (TA_LATIN_IS_LONG_BLUE(bs
))
514 /* If this flag is set, we have an additional constraint to */
515 /* get the blue zone distance: Find a segment of the topmost */
516 /* (or bottommost) contour that is longer than a heuristic */
517 /* threshold. This ensures that small bumps in the outline */
518 /* are ignored (for example, the `vertical serifs' found in */
519 /* many Hebrew glyph designs). */
521 /* If this segment is long enough, we are done. Otherwise, */
522 /* search the segment next to the extremum that is long */
523 /* enough, has the same direction, and a not too large */
524 /* vertical distance from the extremum. Note that the */
525 /* algorithm doesn't check whether the found segment is */
526 /* actually the one (vertically) nearest to the extremum. */
528 /* heuristic threshold value */
529 FT_Pos length_threshold
= metrics
->units_per_em
/ 25;
532 dist
= TA_ABS(points
[best_segment_last
].x
-
533 points
[best_segment_first
].x
);
535 if (dist
< length_threshold
536 && best_segment_last
- best_segment_first
+ 2 <=
537 best_contour_last
- best_contour_first
)
539 /* heuristic threshold value */
540 FT_Pos height_threshold
= metrics
->units_per_em
/ 4;
546 /* we intentionally declare these two variables */
547 /* outside of the loop since various compilers emit */
548 /* incorrect warning messages otherwise, talking about */
549 /* `possibly uninitialized variables' */
550 FT_Int p_first
= 0; /* make compiler happy */
556 /* compute direction */
561 if (prev
> best_contour_first
)
564 prev
= best_contour_last
;
566 if (points
[prev
].x
!= best_x
)
568 } while (prev
!= best_point
);
570 /* skip glyph for the degenerate case */
571 if (prev
== best_point
)
574 left2right
= FT_BOOL(points
[prev
].x
< points
[best_point
].x
);
576 first
= best_segment_last
;
588 /* no hit; adjust first point */
591 /* also adjust first and last on point */
592 if (FT_CURVE_TAG(outline
.tags
[first
]) == FT_CURVE_TAG_ON
)
606 if (last
< best_contour_last
)
609 last
= best_contour_first
;
611 if (TA_ABS(best_y
- points
[first
].y
) > height_threshold
)
613 /* vertical distance too large */
618 /* same test as above */
619 dist
= TA_ABS(points
[last
].y
- points
[first
].y
);
621 if (TA_ABS(points
[last
].x
- points
[first
].x
) <= 20 * dist
)
627 if (FT_CURVE_TAG(outline
.tags
[last
]) == FT_CURVE_TAG_ON
)
634 l2r
= FT_BOOL(points
[first
].x
< points
[last
].x
);
635 d
= TA_ABS(points
[last
].x
- points
[first
].x
);
637 if (l2r
== left2right
638 && d
>= length_threshold
)
640 /* all constraints are met; update segment after finding */
644 if (last
< best_contour_last
)
647 last
= best_contour_first
;
649 d
= TA_ABS(points
[last
].y
- points
[first
].y
);
651 if (TA_ABS(points
[next
].x
- points
[first
].x
) <=
654 if (last
> best_contour_first
)
657 last
= best_contour_last
;
663 if (FT_CURVE_TAG(outline
.tags
[last
]) == FT_CURVE_TAG_ON
)
669 } while (last
!= best_segment_first
);
671 best_y
= points
[first
].y
;
673 best_segment_first
= first
;
674 best_segment_last
= last
;
676 best_on_point_first
= p_first
;
677 best_on_point_last
= p_last
;
681 } while (last
!= best_segment_first
);
686 * for computing blue zones, we add the y offset as returned
687 * by the currently used OpenType feature --
688 * for example, superscript glyphs might be identical
689 * to subscript glyphs with a vertical shift
693 TA_LOG_GLOBAL((" U+%04lX: best_y = %5ld", ch
, best_y
));
696 * now set the `round' flag depending on the segment's kind:
698 * - if the horizontal distance between the first and last
699 * `on' point is larger than a heuristic threshold
700 * we have a flat segment
701 * - if either the first or the last point of the segment is
702 * an `off' point, the segment is round, otherwise it is
705 if (best_on_point_first
>= 0
706 && best_on_point_last
>= 0
707 && (TA_ABS(points
[best_on_point_last
].x
708 - points
[best_on_point_first
].x
))
712 round
= FT_BOOL(FT_CURVE_TAG(outline
.tags
[best_segment_first
])
714 || FT_CURVE_TAG(outline
.tags
[best_segment_last
])
717 if (round
&& TA_LATIN_IS_NEUTRAL_BLUE(bs
))
719 /* only use flat segments for a neutral blue zone */
720 TA_LOG_GLOBAL((" (round, skipped)\n"));
724 TA_LOG_GLOBAL((" (%s)\n", round
? "round" : "flat"));
728 rounds
[num_rounds
++] = best_y
;
730 flats
[num_flats
++] = best_y
;
733 if (num_flats
== 0 && num_rounds
== 0)
735 /* we couldn't find a single glyph to compute this blue zone, */
736 /* we will simply ignore it then */
737 TA_LOG_GLOBAL((" empty\n"));
741 /* we have computed the contents of the `rounds' and `flats' tables, */
742 /* now determine the reference and overshoot position of the blue -- */
743 /* we simply take the median value after a simple sort */
744 ta_sort_pos(num_rounds
, rounds
);
745 ta_sort_pos(num_flats
, flats
);
747 blue
= &axis
->blues
[axis
->blue_count
];
748 blue_ref
= &blue
->ref
.org
;
749 blue_shoot
= &blue
->shoot
.org
;
756 *blue_shoot
= rounds
[num_rounds
/ 2];
758 else if (num_rounds
== 0)
761 *blue_shoot
= flats
[num_flats
/ 2];
765 *blue_ref
= flats
[num_flats
/ 2];
766 *blue_shoot
= rounds
[num_rounds
/ 2];
769 /* there are sometimes problems if the overshoot position of top */
770 /* zones is under its reference position, or the opposite for bottom */
771 /* zones; we must thus check everything there and correct the errors */
772 if (*blue_shoot
!= *blue_ref
)
774 FT_Pos ref
= *blue_ref
;
775 FT_Pos shoot
= *blue_shoot
;
776 FT_Bool over_ref
= FT_BOOL(shoot
> ref
);
779 if (TA_LATIN_IS_TOP_BLUE(bs
) ^ over_ref
)
782 *blue_shoot
= (shoot
+ ref
) / 2;
784 TA_LOG_GLOBAL((" [overshoot smaller than reference,"
785 " taking mean value]\n"));
790 if (TA_LATIN_IS_TOP_BLUE(bs
))
791 blue
->flags
|= TA_LATIN_BLUE_TOP
;
792 if (TA_LATIN_IS_NEUTRAL_BLUE(bs
))
793 blue
->flags
|= TA_LATIN_BLUE_NEUTRAL
;
795 /* the following flag is used later to adjust the y and x scales */
796 /* in order to optimize the pixel grid alignment */
797 /* of the top of small letters */
798 if (TA_LATIN_IS_X_HEIGHT_BLUE(bs
))
799 blue
->flags
|= TA_LATIN_BLUE_ADJUSTMENT
;
801 TA_LOG_GLOBAL((" -> reference = %ld\n"
802 " overshoot = %ld\n",
803 *blue_ref
, *blue_shoot
));
806 /* add two blue zones for usWinAscent and usWinDescent */
807 /* just in case the above algorithm has missed them -- */
808 /* Windows cuts off everything outside of those two values */
813 os2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
817 blue
= &axis
->blues
[axis
->blue_count
];
818 blue
->flags
= TA_LATIN_BLUE_TOP
| TA_LATIN_BLUE_ACTIVE
;
820 blue
->shoot
.org
= os2
->usWinAscent
;
822 TA_LOG_GLOBAL(("artificial blue zone for usWinAscent:\n"
823 " -> reference = %ld\n"
824 " overshoot = %ld\n",
825 blue
->ref
.org
, blue
->shoot
.org
));
827 blue
= &axis
->blues
[axis
->blue_count
+ 1];
828 blue
->flags
= TA_LATIN_BLUE_ACTIVE
;
830 blue
->shoot
.org
= -os2
->usWinDescent
;
832 TA_LOG_GLOBAL(("artificial blue zone for usWinDescent:\n"
833 " -> reference = %ld\n"
834 " overshoot = %ld\n",
835 blue
->ref
.org
, blue
->shoot
.org
));
839 blue
= &axis
->blues
[axis
->blue_count
];
844 blue
= &axis
->blues
[axis
->blue_count
+ 1];
851 TA_LOG_GLOBAL(("\n"));
857 /* check whether all ASCII digits have the same advance width */
860 ta_latin_metrics_check_digits(TA_LatinMetrics metrics
,
864 FT_Bool started
= 0, same_width
= 1;
865 FT_Fixed advance
, old_advance
= 0;
868 /* digit `0' is 0x30 in all supported charmaps */
869 for (i
= 0x30; i
<= 0x39; i
++)
871 FT_ULong glyph_index
;
875 ta_get_char_index(&metrics
->root
, i
, &glyph_index
, &y_offset
);
876 if (glyph_index
== 0)
879 if (FT_Get_Advance(face
, glyph_index
,
882 | FT_LOAD_IGNORE_TRANSFORM
,
888 if (advance
!= old_advance
)
896 old_advance
= advance
;
901 metrics
->root
.digits_have_same_width
= same_width
;
905 /* initialize global metrics */
908 ta_latin_metrics_init(TA_LatinMetrics metrics
,
911 FT_CharMap oldmap
= face
->charmap
;
914 metrics
->units_per_em
= face
->units_per_EM
;
916 if (!FT_Select_Charmap(face
, FT_ENCODING_UNICODE
))
918 ta_latin_metrics_init_widths(metrics
, face
, 1);
919 ta_latin_metrics_init_blues(metrics
, face
);
920 ta_latin_metrics_check_digits(metrics
, face
);
924 /* we only have a symbol font encoding */
925 ta_latin_metrics_init_widths(metrics
, face
, 0);
928 FT_Set_Charmap(face
, oldmap
);
933 /* adjust scaling value, then scale and shift widths */
934 /* and blue zones (if applicable) for given dimension */
937 ta_latin_metrics_scale_dim(TA_LatinMetrics metrics
,
948 ppem
= metrics
->root
.scaler
.face
->size
->metrics
.x_ppem
;
950 if (dim
== TA_DIMENSION_HORZ
)
952 scale
= scaler
->x_scale
;
953 delta
= scaler
->x_delta
;
957 scale
= scaler
->y_scale
;
958 delta
= scaler
->y_delta
;
961 axis
= &metrics
->axis
[dim
];
963 if (axis
->org_scale
== scale
&& axis
->org_delta
== delta
)
966 axis
->org_scale
= scale
;
967 axis
->org_delta
= delta
;
969 /* correct Y scale to optimize the alignment of the top of */
970 /* small letters to the pixel grid */
971 /* (if we do x-height snapping for this ppem value) */
972 if (!number_set_is_element(
973 metrics
->root
.globals
->font
->x_height_snapping_exceptions
,
976 TA_LatinAxis Axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
977 TA_LatinBlue blue
= NULL
;
980 for (nn
= 0; nn
< Axis
->blue_count
; nn
++)
982 if (Axis
->blues
[nn
].flags
& TA_LATIN_BLUE_ADJUSTMENT
)
984 blue
= &Axis
->blues
[nn
];
997 scaled
= FT_MulFix(blue
->shoot
.org
, scaler
->y_scale
);
998 limit
= metrics
->root
.globals
->increase_x_height
;
1001 /* if the `increase-x-height' property is active, */
1002 /* we round up much more often */
1005 && ppem
>= TA_PROP_INCREASE_X_HEIGHT_MIN
)
1008 fitted
= (scaled
+ threshold
) & ~63;
1010 if (scaled
!= fitted
)
1012 if (dim
== TA_DIMENSION_VERT
)
1014 scale
= FT_MulDiv(scale
, fitted
, scaled
);
1017 "ta_latin_metrics_scale_dim:"
1018 " x height alignment (style `%s'):\n"
1020 " vertical scaling changed from %.4f to %.4f (by %d%%)\n"
1022 ta_style_names
[metrics
->root
.style_class
->style
],
1023 axis
->org_scale
/ 65536.0,
1025 (fitted
- scaled
) * 100 / scaled
));
1031 axis
->scale
= scale
;
1032 axis
->delta
= delta
;
1034 if (dim
== TA_DIMENSION_HORZ
)
1036 metrics
->root
.scaler
.x_scale
= scale
;
1037 metrics
->root
.scaler
.x_delta
= delta
;
1041 metrics
->root
.scaler
.y_scale
= scale
;
1042 metrics
->root
.scaler
.y_delta
= delta
;
1045 TA_LOG_GLOBAL(("%s widths (style `%s')\n",
1046 dim
== TA_DIMENSION_HORZ
? "horizontal" : "vertical",
1047 ta_style_names
[metrics
->root
.style_class
->style
]));
1049 /* scale the widths */
1050 for (nn
= 0; nn
< axis
->width_count
; nn
++)
1052 TA_Width width
= axis
->widths
+ nn
;
1055 width
->cur
= FT_MulFix(width
->org
, scale
);
1056 width
->fit
= width
->cur
;
1058 TA_LOG_GLOBAL((" %d scaled to %.2f\n",
1060 width
->cur
/ 64.0));
1063 TA_LOG_GLOBAL(("\n"));
1065 /* an extra-light axis corresponds to a standard width that is */
1066 /* smaller than 5/8 pixels */
1068 (FT_Bool
)(FT_MulFix(axis
->standard_width
, scale
) < 32 + 8);
1071 if (axis
->extra_light
)
1072 TA_LOG_GLOBAL(("`%s' style is extra light (at current resolution)\n"
1074 ta_style_names
[metrics
->root
.style_class
->style
]));
1077 if (dim
== TA_DIMENSION_VERT
)
1079 TA_LOG_GLOBAL(("blue zones (style `%s')\n",
1080 ta_style_names
[metrics
->root
.style_class
->style
]));
1082 /* scale the blue zones */
1083 for (nn
= 0; nn
< axis
->blue_count
; nn
++)
1085 TA_LatinBlue blue
= &axis
->blues
[nn
];
1089 blue
->ref
.cur
= FT_MulFix(blue
->ref
.org
, scale
) + delta
;
1090 blue
->ref
.fit
= blue
->ref
.cur
;
1091 blue
->shoot
.cur
= FT_MulFix(blue
->shoot
.org
, scale
) + delta
;
1092 blue
->shoot
.fit
= blue
->shoot
.cur
;
1093 blue
->flags
&= ~TA_LATIN_BLUE_ACTIVE
;
1095 /* a blue zone is only active if it is less than 3/4 pixels tall */
1096 dist
= FT_MulFix(blue
->ref
.org
- blue
->shoot
.org
, scale
);
1097 if (dist
<= 48 && dist
>= -48)
1105 /* use discrete values for blue zone widths */
1108 /* generic, original code */
1109 delta1
= blue
->shoot
.org
- blue
->ref
.org
;
1114 delta2
= FT_MulFix(delta2
, scale
);
1118 else if (delta2
< 64)
1119 delta2
= 32 + (((delta2
- 32) + 16) & ~31);
1121 delta2
= TA_PIX_ROUND(delta2
);
1126 blue
->ref
.fit
= TA_PIX_ROUND(blue
->ref
.cur
);
1127 blue
->shoot
.fit
= blue
->ref
.fit
+ delta2
;
1129 /* simplified version due to abs(dist) <= 48 */
1136 else if (delta2
< 48)
1144 blue
->ref
.fit
= TA_PIX_ROUND(blue
->ref
.cur
);
1145 blue
->shoot
.fit
= blue
->ref
.fit
- delta2
;
1148 blue
->flags
|= TA_LATIN_BLUE_ACTIVE
;
1150 TA_LOG_GLOBAL((" reference %d: %d scaled to %.2f%s\n"
1151 " overshoot %d: %d scaled to %.2f%s\n",
1154 blue
->ref
.fit
/ 64.0,
1155 blue
->flags
& TA_LATIN_BLUE_ACTIVE
? ""
1159 blue
->shoot
.fit
/ 64.0,
1160 blue
->flags
& TA_LATIN_BLUE_ACTIVE
? ""
1165 /* the last two artificial blue zones are to be scaled */
1166 /* with uncorrected scaling values */
1168 TA_LatinAxis a
= &metrics
->axis
[TA_DIMENSION_VERT
];
1172 b
= &a
->blues
[a
->blue_count
];
1176 b
->shoot
.fit
= FT_MulFix(b
->ref
.org
, a
->org_scale
) + delta
;
1178 TA_LOG_GLOBAL((" reference %d: %d scaled to %.2f (artificial)\n"
1179 " overshoot %d: %d scaled to %.2f (artificial)\n",
1185 b
->shoot
.fit
/ 64.0));
1187 b
= &a
->blues
[a
->blue_count
+ 1];
1191 b
->shoot
.fit
= FT_MulFix(b
->ref
.org
, a
->org_scale
) + delta
;
1193 TA_LOG_GLOBAL((" reference %d: %d scaled to %.2f (artificial)\n"
1194 " overshoot %d: %d scaled to %.2f (artificial)\n",
1200 b
->shoot
.fit
/ 64.0));
1203 TA_LOG_GLOBAL(("\n"));
1208 /* scale global values in both directions */
1211 ta_latin_metrics_scale(TA_LatinMetrics metrics
,
1214 metrics
->root
.scaler
.render_mode
= scaler
->render_mode
;
1215 metrics
->root
.scaler
.face
= scaler
->face
;
1216 metrics
->root
.scaler
.flags
= scaler
->flags
;
1218 ta_latin_metrics_scale_dim(metrics
, scaler
, TA_DIMENSION_HORZ
);
1219 ta_latin_metrics_scale_dim(metrics
, scaler
, TA_DIMENSION_VERT
);
1223 /* walk over all contours and compute its segments */
1226 ta_latin_hints_compute_segments(TA_GlyphHints hints
,
1229 TA_LatinMetrics metrics
= (TA_LatinMetrics
)hints
->metrics
;
1230 TA_AxisHints axis
= &hints
->axis
[dim
];
1231 FT_Error error
= FT_Err_Ok
;
1233 TA_Segment segment
= NULL
;
1236 TA_Point
* contour
= hints
->contours
;
1237 TA_Point
* contour_limit
= contour
+ hints
->num_contours
;
1238 TA_Direction major_dir
, segment_dir
;
1240 FT_Pos flat_threshold
= FLAT_THRESHOLD(metrics
->units_per_em
);
1243 memset(&seg0
, 0, sizeof (TA_SegmentRec
));
1245 seg0
.flags
= TA_EDGE_NORMAL
;
1247 major_dir
= (TA_Direction
)TA_ABS(axis
->major_dir
);
1248 segment_dir
= major_dir
;
1250 axis
->num_segments
= 0;
1252 /* set up (u,v) in each point */
1253 if (dim
== TA_DIMENSION_HORZ
)
1255 TA_Point point
= hints
->points
;
1256 TA_Point limit
= point
+ hints
->num_points
;
1259 for (; point
< limit
; point
++)
1261 point
->u
= point
->fx
;
1262 point
->v
= point
->fy
;
1267 TA_Point point
= hints
->points
;
1268 TA_Point limit
= point
+ hints
->num_points
;
1271 for (; point
< limit
; point
++)
1273 point
->u
= point
->fy
;
1274 point
->v
= point
->fx
;
1278 /* do each contour separately */
1279 for (; contour
< contour_limit
; contour
++)
1281 TA_Point point
= contour
[0];
1282 TA_Point last
= point
->prev
;
1286 FT_Pos min_pos
= 32000; /* minimum segment pos != min_coord */
1287 FT_Pos max_pos
= -32000; /* maximum segment pos != max_coord */
1288 FT_Pos min_on_pos
= 32000;
1289 FT_Pos max_on_pos
= -32000;
1293 if (point
== last
) /* skip singletons -- just in case */
1296 if (TA_ABS(last
->out_dir
) == major_dir
1297 && TA_ABS(point
->out_dir
) == major_dir
)
1299 /* we are already on an edge, try to locate its start */
1304 point
= point
->prev
;
1305 if (TA_ABS(point
->out_dir
) != major_dir
)
1307 point
= point
->next
;
1331 /* get minimum and maximum coordinate of on points */
1332 if (!(point
->flags
& TA_FLAG_CONTROL
))
1341 if (point
->out_dir
!= segment_dir
1344 /* we are just leaving an edge; record a new segment! */
1345 segment
->last
= point
;
1346 segment
->pos
= (FT_Short
)((min_pos
+ max_pos
) >> 1);
1348 /* a segment is round if either its first or last point */
1349 /* is a control point, and the length of the on points */
1350 /* inbetween doesn't exceed a heuristic limit */
1351 if ((segment
->first
->flags
| point
->flags
) & TA_FLAG_CONTROL
1352 && (max_on_pos
- min_on_pos
) < flat_threshold
)
1353 segment
->flags
|= TA_EDGE_ROUND
;
1355 /* compute segment size */
1356 min_pos
= max_pos
= point
->v
;
1358 v
= segment
->first
->v
;
1364 segment
->min_coord
= (FT_Short
)min_pos
;
1365 segment
->max_coord
= (FT_Short
)max_pos
;
1366 segment
->height
= (FT_Short
)(segment
->max_coord
-
1367 segment
->min_coord
);
1375 /* now exit if we are at the start/end point */
1384 && TA_ABS(point
->out_dir
) == major_dir
)
1386 /* this is the start of a new segment! */
1387 segment_dir
= (TA_Direction
)point
->out_dir
;
1389 error
= ta_axis_hints_new_segment(axis
, &segment
);
1393 /* clear all segment fields */
1396 segment
->dir
= (FT_Char
)segment_dir
;
1397 segment
->first
= point
;
1398 segment
->last
= point
;
1400 min_pos
= max_pos
= point
->u
;
1402 if (point
->flags
& TA_FLAG_CONTROL
)
1405 max_on_pos
= -32000;
1408 min_on_pos
= max_on_pos
= point
->v
;
1412 if (point
->out_dir
!= point
->next
->in_dir
)
1414 /* we have a one-point segment */
1415 segment
->pos
= (FT_Short
)min_pos
;
1417 if (point
->flags
& TA_FLAG_CONTROL
)
1418 segment
->flags
|= TA_EDGE_ROUND
;
1420 /* artificially extend the horizontal size if requested */
1421 segment
->min_coord
= (FT_Short
)point
->v
+ point
->left_offset
;
1422 segment
->max_coord
= (FT_Short
)point
->v
+ point
->right_offset
;
1423 segment
->height
= 0;
1430 point
= point
->next
;
1435 /* now slightly increase the height of segments if this makes sense -- */
1436 /* this is used to better detect and ignore serifs */
1438 TA_Segment segments
= axis
->segments
;
1439 TA_Segment segments_end
= segments
+ axis
->num_segments
;
1442 for (segment
= segments
; segment
< segments_end
; segment
++)
1444 TA_Point first
= segment
->first
;
1445 TA_Point last
= segment
->last
;
1447 FT_Pos first_v
= first
->v
;
1448 FT_Pos last_v
= last
->v
;
1451 if (first_v
< last_v
)
1458 segment
->height
= (FT_Short
)(segment
->height
+
1459 ((first_v
- p
->v
) >> 1));
1463 segment
->height
= (FT_Short
)(segment
->height
+
1464 ((p
->v
- last_v
) >> 1));
1473 segment
->height
= (FT_Short
)(segment
->height
+
1474 ((p
->v
- first_v
) >> 1));
1478 segment
->height
= (FT_Short
)(segment
->height
+
1479 ((last_v
- p
->v
) >> 1));
1489 /* link segments to form stems and serifs; if `width_count' and */
1490 /* `widths' are non-zero, use them to fine-tune the scoring function */
1493 ta_latin_hints_link_segments(TA_GlyphHints hints
,
1494 FT_UInt width_count
,
1495 TA_WidthRec
* widths
,
1498 TA_AxisHints axis
= &hints
->axis
[dim
];
1500 TA_Segment segments
= axis
->segments
;
1501 TA_Segment segment_limit
= segments
+ axis
->num_segments
;
1503 FT_Pos len_threshold
, len_score
, dist_score
, max_width
;
1504 TA_Segment seg1
, seg2
;
1508 max_width
= widths
[width_count
- 1].org
;
1512 /* a heuristic value to set up a minimum value for overlapping */
1513 len_threshold
= TA_LATIN_CONSTANT(hints
->metrics
, 8);
1514 if (len_threshold
== 0)
1517 /* a heuristic value to weight lengths */
1518 len_score
= TA_LATIN_CONSTANT(hints
->metrics
, 6000);
1520 /* a heuristic value to weight distances (no call to */
1521 /* TA_LATIN_CONSTANT needed, since we work on multiples */
1522 /* of the stem width) */
1525 /* now compare each segment to the others */
1526 for (seg1
= segments
; seg1
< segment_limit
; seg1
++)
1528 if (seg1
->dir
!= axis
->major_dir
)
1531 /* search for stems having opposite directions, */
1532 /* with seg1 to the `left' of seg2 */
1533 for (seg2
= segments
; seg2
< segment_limit
; seg2
++)
1535 FT_Pos pos1
= seg1
->pos
;
1536 FT_Pos pos2
= seg2
->pos
;
1539 if (seg1
->dir
+ seg2
->dir
== 0
1542 /* compute distance between the two segments */
1543 FT_Pos min
= seg1
->min_coord
;
1544 FT_Pos max
= seg1
->max_coord
;
1548 if (min
< seg2
->min_coord
)
1549 min
= seg2
->min_coord
;
1550 if (max
> seg2
->max_coord
)
1551 max
= seg2
->max_coord
;
1553 /* compute maximum coordinate difference of the two segments */
1554 /* (this is, how much they overlap) */
1557 /* for one-point segments, `len' is zero if there is an overlap */
1558 /* (and negative otherwise); we have to correct this */
1560 && (seg1
->min_coord
== seg1
->max_coord
1561 || seg2
->min_coord
== seg2
->max_coord
))
1562 len
= len_threshold
;
1564 if (len
>= len_threshold
)
1567 * The score is the sum of two demerits indicating the
1568 * `badness' of a fit, measured along the segments' main axis
1569 * and orthogonal to it, respectively.
1571 * o The less overlapping along the main axis, the worse it
1572 * is, causing a larger demerit.
1574 * o The nearer the orthogonal distance to a stem width, the
1575 * better it is, causing a smaller demerit. For simplicity,
1576 * however, we only increase the demerit for values that
1577 * exceed the largest stem width.
1580 FT_Pos dist
= pos2
- pos1
;
1582 FT_Pos dist_demerit
, score
;
1587 /* distance demerits are based on multiples of `max_width'; */
1588 /* we scale by 1024 for getting more precision */
1589 FT_Pos delta
= (dist
<< 10) / max_width
- (1 << 10);
1593 dist_demerit
= 32000;
1595 dist_demerit
= delta
* delta
/ dist_score
;
1600 dist_demerit
= dist
; /* default if no widths available */
1602 score
= dist_demerit
+ len_score
/ len
;
1604 /* and we search for the smallest score */
1605 if (score
< seg1
->score
)
1607 seg1
->score
= score
;
1611 if (score
< seg2
->score
)
1613 seg2
->score
= score
;
1621 /* now compute the `serif' segments, cf. explanations in `tahints.h' */
1622 for (seg1
= segments
; seg1
< segment_limit
; seg1
++)
1628 if (seg2
->link
!= seg1
)
1631 seg1
->serif
= seg2
->link
;
1638 /* link segments to edges, using feature analysis for selection */
1641 ta_latin_hints_compute_edges(TA_GlyphHints hints
,
1644 TA_AxisHints axis
= &hints
->axis
[dim
];
1645 FT_Error error
= FT_Err_Ok
;
1646 TA_LatinAxis laxis
= &((TA_LatinMetrics
)hints
->metrics
)->axis
[dim
];
1648 TA_Segment segments
= axis
->segments
;
1649 TA_Segment segment_limit
= segments
+ axis
->num_segments
;
1653 TA_Direction up_dir
;
1656 FT_Pos edge_distance_threshold
;
1657 FT_Pos segment_length_threshold
;
1660 axis
->num_edges
= 0;
1662 scale
= (dim
== TA_DIMENSION_HORZ
) ? hints
->x_scale
1666 up_dir
= (dim
== TA_DIMENSION_HORZ
) ? TA_DIR_UP
1670 /* we ignore all segments that are less than 1 pixel in length */
1671 /* to avoid many problems with serif fonts */
1672 /* (the corresponding threshold is computed in font units) */
1673 if (dim
== TA_DIMENSION_HORZ
)
1674 segment_length_threshold
= FT_DivFix(64, hints
->y_scale
);
1676 segment_length_threshold
= 0;
1678 /********************************************************************/
1680 /* We begin by generating a sorted table of edges for the current */
1681 /* direction. To do so, we simply scan each segment and try to find */
1682 /* an edge in our table that corresponds to its position. */
1684 /* If no edge is found, we create and insert a new edge in the */
1685 /* sorted table. Otherwise, we simply add the segment to the edge's */
1686 /* list which gets processed in the second step to compute the */
1687 /* edge's properties. */
1689 /* Note that the table of edges is sorted along the segment/edge */
1692 /********************************************************************/
1694 /* assure that edge distance threshold is at most 0.25px */
1695 edge_distance_threshold
= FT_MulFix(laxis
->edge_distance_threshold
,
1697 if (edge_distance_threshold
> 64 / 4)
1698 edge_distance_threshold
= 64 / 4;
1700 edge_distance_threshold
= FT_DivFix(edge_distance_threshold
,
1703 for (seg
= segments
; seg
< segment_limit
; seg
++)
1705 TA_Edge found
= NULL
;
1709 if (seg
->height
< segment_length_threshold
)
1712 /* a special case for serif edges: */
1713 /* if they are smaller than 1.5 pixels we ignore them */
1715 && 2 * seg
->height
< 3 * segment_length_threshold
)
1718 /* look for an edge corresponding to the segment */
1719 for (ee
= 0; ee
< axis
->num_edges
; ee
++)
1721 TA_Edge edge
= axis
->edges
+ ee
;
1725 dist
= seg
->pos
- edge
->fpos
;
1729 if (dist
< edge_distance_threshold
&& edge
->dir
== seg
->dir
)
1741 /* insert a new edge in the list and sort according to the position */
1742 error
= ta_axis_hints_new_edge(axis
, seg
->pos
,
1743 (TA_Direction
)seg
->dir
,
1748 /* add the segment to the new edge's list */
1749 memset(edge
, 0, sizeof (TA_EdgeRec
));
1752 edge
->dir
= seg
->dir
;
1753 edge
->fpos
= seg
->pos
;
1754 edge
->opos
= FT_MulFix(seg
->pos
, scale
);
1755 edge
->pos
= edge
->opos
;
1756 seg
->edge_next
= seg
;
1760 /* if an edge was found, simply add the segment to the edge's list */
1761 seg
->edge_next
= found
->first
;
1762 found
->last
->edge_next
= seg
;
1767 /*****************************************************************/
1769 /* Good, we now compute each edge's properties according to */
1770 /* the segments found on its position. Basically, these are */
1772 /* - the edge's main direction */
1773 /* - stem edge, serif edge or both (which defaults to stem then) */
1774 /* - rounded edge, straight or both (which defaults to straight) */
1775 /* - link for edge */
1777 /*****************************************************************/
1779 /* first of all, set the `edge' field in each segment -- this is */
1780 /* required in order to compute edge links */
1782 /* note that removing this loop and setting the `edge' field of each */
1783 /* segment directly in the code above slows down execution speed for */
1784 /* some reasons on platforms like the Sun */
1786 TA_Edge edges
= axis
->edges
;
1787 TA_Edge edge_limit
= edges
+ axis
->num_edges
;
1791 for (edge
= edges
; edge
< edge_limit
; edge
++)
1798 seg
= seg
->edge_next
;
1799 } while (seg
!= edge
->first
);
1802 /* now compute each edge properties */
1803 for (edge
= edges
; edge
< edge_limit
; edge
++)
1805 FT_Int is_round
= 0; /* does it contain round segments? */
1806 FT_Int is_straight
= 0; /* does it contain straight segments? */
1808 FT_Pos ups
= 0; /* number of upwards segments */
1809 FT_Pos downs
= 0; /* number of downwards segments */
1820 /* check for roundness of segment */
1821 if (seg
->flags
& TA_EDGE_ROUND
)
1827 /* check for segment direction */
1828 if (seg
->dir
== up_dir
)
1829 ups
+= seg
->max_coord
- seg
->min_coord
;
1831 downs
+= seg
->max_coord
- seg
->min_coord
;
1834 /* check for links -- */
1835 /* if seg->serif is set, then seg->link must be ignored */
1836 is_serif
= (FT_Bool
)(seg
->serif
1838 && seg
->serif
->edge
!= edge
);
1840 if ((seg
->link
&& seg
->link
->edge
!= NULL
)
1853 edge2
= edge
->serif
;
1862 edge_delta
= edge
->fpos
- edge2
->fpos
;
1864 edge_delta
= -edge_delta
;
1866 seg_delta
= seg
->pos
- seg2
->pos
;
1868 seg_delta
= -seg_delta
;
1870 if (seg_delta
< edge_delta
)
1878 edge
->serif
= edge2
;
1879 edge2
->flags
|= TA_EDGE_SERIF
;
1885 seg
= seg
->edge_next
;
1886 } while (seg
!= edge
->first
);
1888 /* set the round/straight flags */
1889 edge
->flags
= TA_EDGE_NORMAL
;
1892 && is_round
>= is_straight
)
1893 edge
->flags
|= TA_EDGE_ROUND
;
1896 /* set the edge's main direction */
1897 edge
->dir
= TA_DIR_NONE
;
1900 edge
->dir
= (FT_Char
)up_dir
;
1902 else if (ups
< downs
)
1903 edge
->dir
= (FT_Char
)-up_dir
;
1905 else if (ups
== downs
)
1906 edge
->dir
= 0; /* both up and down! */
1909 /* get rid of serifs if link is set */
1910 /* XXX: this gets rid of many unpleasant artefacts! */
1911 /* example: the `c' in cour.pfa at size 13 */
1913 if (edge
->serif
&& edge
->link
)
1923 /* detect segments and edges for given dimension */
1926 ta_latin_hints_detect_features(TA_GlyphHints hints
,
1927 FT_UInt width_count
,
1928 TA_WidthRec
* widths
,
1934 error
= ta_latin_hints_compute_segments(hints
, dim
);
1937 ta_latin_hints_link_segments(hints
, width_count
, widths
, dim
);
1939 error
= ta_latin_hints_compute_edges(hints
, dim
);
1946 /* compute all edges which lie within blue zones */
1949 ta_latin_hints_compute_blue_edges(TA_GlyphHints hints
,
1950 TA_LatinMetrics metrics
)
1952 TA_AxisHints axis
= &hints
->axis
[TA_DIMENSION_VERT
];
1954 TA_Edge edge
= axis
->edges
;
1955 TA_Edge edge_limit
= edge
+ axis
->num_edges
;
1957 TA_LatinAxis latin
= &metrics
->axis
[TA_DIMENSION_VERT
];
1958 FT_Fixed scale
= latin
->scale
;
1961 /* compute which blue zones are active, */
1962 /* i.e. have their scaled size < 3/4 pixels */
1964 /* for each horizontal edge search the blue zone which is closest */
1965 for (; edge
< edge_limit
; edge
++)
1968 TA_Width best_blue
= NULL
;
1969 FT_Bool best_blue_is_neutral
= 0;
1970 FT_Pos best_dist
; /* initial threshold */
1972 FT_UInt best_blue_idx
= 0;
1973 FT_Bool best_blue_is_shoot
= 0;
1976 /* compute the initial threshold as a fraction of the EM size */
1977 /* (the value 40 is heuristic) */
1978 best_dist
= FT_MulFix(metrics
->units_per_em
/ 40, scale
);
1980 /* assure a minimum distance of 0.5px */
1981 if (best_dist
> 64 / 2)
1984 /* this loop also handles the two extra blue zones */
1985 /* for usWinAscent and usWinDescent */
1986 /* if option `windows-compatibility' is set */
1988 bb
< latin
->blue_count
1989 + (metrics
->root
.globals
->font
->windows_compatibility
? 2 : 0);
1992 TA_LatinBlue blue
= latin
->blues
+ bb
;
1993 FT_Bool is_top_blue
, is_neutral_blue
, is_major_dir
;
1996 /* skip inactive blue zones (i.e., those that are too large) */
1997 if (!(blue
->flags
& TA_LATIN_BLUE_ACTIVE
))
2000 /* if it is a top zone, check for right edges (against the major */
2001 /* direction); if it is a bottom zone, check for left edges (in */
2002 /* the major direction) */
2003 is_top_blue
= (FT_Byte
)((blue
->flags
& TA_LATIN_BLUE_TOP
) != 0);
2004 is_neutral_blue
= (FT_Byte
)((blue
->flags
& TA_LATIN_BLUE_NEUTRAL
) != 0);
2005 is_major_dir
= FT_BOOL(edge
->dir
== axis
->major_dir
);
2007 /* neutral blue zones are handled for both directions */
2008 if (is_top_blue
^ is_major_dir
|| is_neutral_blue
)
2013 /* first of all, compare it to the reference position */
2014 dist
= edge
->fpos
- blue
->ref
.org
;
2018 dist
= FT_MulFix(dist
, scale
);
2019 if (dist
< best_dist
)
2022 best_blue
= &blue
->ref
;
2023 best_blue_is_neutral
= is_neutral_blue
;
2026 best_blue_is_shoot
= 0;
2029 /* now compare it to the overshoot position and check whether */
2030 /* the edge is rounded, and whether the edge is over the */
2031 /* reference position of a top zone, or under the reference */
2032 /* position of a bottom zone (provided we don't have a */
2033 /* neutral blue zone) */
2034 if (edge
->flags
& TA_EDGE_ROUND
2036 && !is_neutral_blue
)
2038 FT_Bool is_under_ref
= FT_BOOL(edge
->fpos
< blue
->ref
.org
);
2041 if (is_top_blue
^ is_under_ref
)
2043 dist
= edge
->fpos
- blue
->shoot
.org
;
2047 dist
= FT_MulFix(dist
, scale
);
2048 if (dist
< best_dist
)
2051 best_blue
= &blue
->shoot
;
2052 best_blue_is_neutral
= is_neutral_blue
;
2055 best_blue_is_shoot
= 1;
2064 edge
->blue_edge
= best_blue
;
2065 edge
->best_blue_idx
= best_blue_idx
;
2066 edge
->best_blue_is_shoot
= best_blue_is_shoot
;
2067 if (best_blue_is_neutral
)
2068 edge
->flags
|= TA_EDGE_NEUTRAL
;
2074 /* initalize hinting engine */
2077 ta_latin_hints_init(TA_GlyphHints hints
,
2078 TA_LatinMetrics metrics
)
2080 FT_Render_Mode mode
;
2081 FT_UInt32 scaler_flags
, other_flags
;
2082 FT_Face face
= metrics
->root
.scaler
.face
;
2085 ta_glyph_hints_rescale(hints
, (TA_StyleMetrics
)metrics
);
2087 /* correct x_scale and y_scale if needed, since they may have */
2088 /* been modified by `ta_latin_metrics_scale_dim' above */
2089 hints
->x_scale
= metrics
->axis
[TA_DIMENSION_HORZ
].scale
;
2090 hints
->x_delta
= metrics
->axis
[TA_DIMENSION_HORZ
].delta
;
2091 hints
->y_scale
= metrics
->axis
[TA_DIMENSION_VERT
].scale
;
2092 hints
->y_delta
= metrics
->axis
[TA_DIMENSION_VERT
].delta
;
2094 /* compute flags depending on render mode, etc. */
2095 mode
= metrics
->root
.scaler
.render_mode
;
2097 #if 0 /* #ifdef TA_CONFIG_OPTION_USE_WARPER */
2098 if (mode
== FT_RENDER_MODE_LCD
2099 || mode
== FT_RENDER_MODE_LCD_V
)
2100 metrics
->root
.scaler
.render_mode
=
2101 mode
= FT_RENDER_MODE_NORMAL
;
2104 scaler_flags
= hints
->scaler_flags
;
2107 /* we snap the width of vertical stems for the monochrome */
2108 /* and horizontal LCD rendering targets only */
2109 if (mode
== FT_RENDER_MODE_MONO
2110 || mode
== FT_RENDER_MODE_LCD
)
2111 other_flags
|= TA_LATIN_HINTS_HORZ_SNAP
;
2113 /* we snap the width of horizontal stems for the monochrome */
2114 /* and vertical LCD rendering targets only */
2115 if (mode
== FT_RENDER_MODE_MONO
2116 || mode
== FT_RENDER_MODE_LCD_V
)
2117 other_flags
|= TA_LATIN_HINTS_VERT_SNAP
;
2119 /* we adjust stems to full pixels only if we don't use the `light' mode */
2120 if (mode
!= FT_RENDER_MODE_LIGHT
)
2121 other_flags
|= TA_LATIN_HINTS_STEM_ADJUST
;
2123 if (mode
== FT_RENDER_MODE_MONO
)
2124 other_flags
|= TA_LATIN_HINTS_MONO
;
2126 /* in `light' hinting mode we disable horizontal hinting completely; */
2127 /* we also do it if the face is italic -- */
2128 /* however, if warping is enabled (which only works in `light' hinting */
2129 /* mode), advance widths get adjusted, too */
2130 if (mode
== FT_RENDER_MODE_LIGHT
2131 || (face
->style_flags
& FT_STYLE_FLAG_ITALIC
) != 0)
2132 scaler_flags
|= TA_SCALER_FLAG_NO_HORIZONTAL
;
2134 #ifdef TA_CONFIG_OPTION_USE_WARPER
2135 /* get (global) warper flag */
2136 if (!metrics
->root
.globals
->module
->warping
)
2137 scaler_flags
|= TA_SCALER_FLAG_NO_WARPER
;
2140 hints
->scaler_flags
= scaler_flags
;
2141 hints
->other_flags
= other_flags
;
2147 /* snap a given width in scaled coordinates to */
2148 /* one of the current standard widths */
2151 ta_latin_snap_width(TA_Width widths
,
2156 FT_Pos best
= 64 + 32 + 2;
2157 FT_Pos reference
= width
;
2161 for (n
= 0; n
< count
; n
++)
2178 scaled
= TA_PIX_ROUND(reference
);
2180 if (width
>= reference
)
2182 if (width
< scaled
+ 48)
2187 if (width
> scaled
- 48)
2195 /* compute the snapped width of a given stem, ignoring very thin ones */
2197 /* there is a lot of voodoo in this function; changing the hard-coded */
2198 /* parameters influences the whole hinting process */
2201 ta_latin_compute_stem_width(TA_GlyphHints hints
,
2207 TA_LatinMetrics metrics
= (TA_LatinMetrics
) hints
->metrics
;
2208 TA_LatinAxis axis
= &metrics
->axis
[dim
];
2210 FT_Pos dist
= width
;
2212 FT_Int vertical
= (dim
== TA_DIMENSION_VERT
);
2215 if (!TA_LATIN_HINTS_DO_STEM_ADJUST(hints
)
2216 || axis
->extra_light
)
2225 if ((vertical
&& !TA_LATIN_HINTS_DO_VERT_SNAP(hints
))
2226 || (!vertical
&& !TA_LATIN_HINTS_DO_HORZ_SNAP(hints
)))
2228 /* smooth hinting process: very lightly quantize the stem width */
2230 /* leave the widths of serifs alone */
2231 if ((stem_flags
& TA_EDGE_SERIF
)
2235 else if (base_flags
& TA_EDGE_ROUND
)
2243 if (axis
->width_count
> 0)
2248 /* compare to standard width */
2249 delta
= dist
- axis
->widths
[0].cur
;
2256 dist
= axis
->widths
[0].cur
;
2270 else if (delta
< 32)
2272 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
= ta_latin_snap_width(axis
->widths
, axis
->width_count
, dist
);
2292 /* in the case of vertical hinting, */
2293 /* always round the stem heights to integer pixels */
2296 dist
= (dist
+ 16) & ~63;
2302 if (TA_LATIN_HINTS_DO_MONO(hints
))
2304 /* monochrome horizontal hinting: */
2305 /* snap widths to integer pixels 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 ta_latin_align_linked_edge(TA_GlyphHints hints
,
2367 FT_Pos dist
= stem_edge
->opos
- base_edge
->opos
;
2369 FT_Pos fitted_width
= ta_latin_compute_stem_width(
2375 stem_edge
->pos
= base_edge
->pos
+ fitted_width
;
2377 TA_LOG((" LINK: edge %d (opos=%.2f) linked to %.2f,"
2378 " dist was %.2f, now %.2f\n",
2379 stem_edge
- hints
->axis
[dim
].edges
, stem_edge
->opos
/ 64.0,
2380 stem_edge
->pos
/ 64.0, dist
/ 64.0, fitted_width
/ 64.0));
2382 if (hints
->recorder
)
2383 hints
->recorder(ta_link
, hints
, dim
,
2384 base_edge
, stem_edge
, NULL
, NULL
, NULL
);
2388 /* shift the coordinates of the `serif' edge by the same amount */
2389 /* as the corresponding `base' edge has been moved already */
2392 ta_latin_align_serif_edge(TA_GlyphHints hints
,
2398 serif
->pos
= base
->pos
+ (serif
->opos
- base
->opos
);
2402 /* the main grid-fitting routine */
2405 ta_latin_hint_edges(TA_GlyphHints hints
,
2408 TA_AxisHints axis
= &hints
->axis
[dim
];
2410 TA_Edge edges
= axis
->edges
;
2411 TA_Edge edge_limit
= edges
+ axis
->num_edges
;
2415 TA_Edge anchor
= NULL
;
2416 FT_Int has_serifs
= 0;
2419 FT_UInt num_actions
= 0;
2422 TA_LOG(("latin %s edge hinting (style `%s')\n",
2423 dim
== TA_DIMENSION_VERT
? "horizontal" : "vertical",
2424 ta_style_names
[hints
->metrics
->style_class
->style
]));
2426 /* we begin by aligning all stems relative to the blue zone if needed -- */
2427 /* that's only for horizontal edges */
2429 if (dim
== TA_DIMENSION_VERT
2430 && TA_HINTS_DO_BLUES(hints
))
2432 for (edge
= edges
; edge
< edge_limit
; edge
++)
2435 TA_Edge edge1
, edge2
; /* these edges form the stem to check */
2438 if (edge
->flags
& TA_EDGE_DONE
)
2445 * If a stem contains both a neutral and a non-neutral blue zone,
2446 * skip the neutral one. Otherwise, outlines with different
2447 * directions might be incorrectly aligned at the same vertical
2450 * If we have two neutral blue zones, skip one of them.
2452 if (edge
->blue_edge
&& edge2
&& edge2
->blue_edge
)
2454 FT_Byte neutral
= edge
->flags
& TA_EDGE_NEUTRAL
;
2455 FT_Byte neutral2
= edge2
->flags
& TA_EDGE_NEUTRAL
;
2460 edge2
->blue_edge
= NULL
;
2461 edge2
->flags
&= ~TA_EDGE_NEUTRAL
;
2465 edge
->blue_edge
= NULL
;
2466 edge
->flags
&= ~TA_EDGE_NEUTRAL
;
2470 blue
= edge
->blue_edge
;
2474 /* flip edges if the other edge is aligned to a blue zone */
2475 else if (edge2
&& edge2
->blue_edge
)
2477 blue
= edge2
->blue_edge
;
2487 TA_LOG((" BLUE_ANCHOR: edge %d (opos=%.2f) snapped to %.2f,"
2488 " was %.2f (anchor=edge %d)\n",
2489 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
2490 edge1
->pos
/ 64.0, edge
- edges
));
2492 TA_LOG((" BLUE: edge %d (opos=%.2f) snapped to %.2f, was %.2f\n",
2493 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
2494 edge1
->pos
/ 64.0));
2499 edge1
->pos
= blue
->fit
;
2500 edge1
->flags
|= TA_EDGE_DONE
;
2502 if (hints
->recorder
)
2505 hints
->recorder(ta_blue_anchor
, hints
, dim
,
2506 edge1
, edge
, NULL
, NULL
, NULL
);
2508 hints
->recorder(ta_blue
, hints
, dim
,
2509 edge1
, NULL
, NULL
, NULL
, NULL
);
2512 if (edge2
&& !edge2
->blue_edge
)
2514 ta_latin_align_linked_edge(hints
, dim
, edge1
, edge2
);
2515 edge2
->flags
|= TA_EDGE_DONE
;
2527 /* now we align all other stem edges, */
2528 /* trying to maintain the relative order of stems in the glyph */
2529 for (edge
= edges
; edge
< edge_limit
; edge
++)
2534 if (edge
->flags
& TA_EDGE_DONE
)
2537 /* skip all non-stem edges */
2545 /* now align the stem */
2547 /* this should not happen, but it's better to be safe */
2548 if (edge2
->blue_edge
)
2550 TA_LOG((" ASSERTION FAILED for edge %d\n", edge2
- edges
));
2552 ta_latin_align_linked_edge(hints
, dim
, edge2
, edge
);
2553 edge
->flags
|= TA_EDGE_DONE
;
2563 /* if we reach this if clause, no stem has been aligned yet */
2565 FT_Pos org_len
, org_center
, cur_len
;
2566 FT_Pos cur_pos1
, error1
, error2
, u_off
, d_off
;
2569 org_len
= edge2
->opos
- edge
->opos
;
2570 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
2571 edge
->flags
, edge2
->flags
);
2573 /* some voodoo to specially round edges for small stem widths; */
2574 /* the idea is to align the center of a stem, */
2575 /* then shifting the stem edges to suitable positions */
2584 /* 1px < width < 1.5px */
2591 org_center
= edge
->opos
+ (org_len
>> 1);
2592 cur_pos1
= TA_PIX_ROUND(org_center
);
2594 error1
= org_center
- (cur_pos1
- u_off
);
2598 error2
= org_center
- (cur_pos1
+ d_off
);
2602 if (error1
< error2
)
2607 edge
->pos
= cur_pos1
- cur_len
/ 2;
2608 edge2
->pos
= edge
->pos
+ cur_len
;
2611 edge
->pos
= TA_PIX_ROUND(edge
->opos
);
2614 edge
->flags
|= TA_EDGE_DONE
;
2616 TA_LOG((" ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
2617 " snapped to %.2f and %.2f\n",
2618 edge
- edges
, edge
->opos
/ 64.0,
2619 edge2
- edges
, edge2
->opos
/ 64.0,
2620 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
2622 if (hints
->recorder
)
2623 hints
->recorder(ta_anchor
, hints
, dim
,
2624 edge
, edge2
, NULL
, NULL
, NULL
);
2626 ta_latin_align_linked_edge(hints
, dim
, edge
, edge2
);
2634 FT_Pos org_pos
, org_len
, org_center
, cur_len
;
2635 FT_Pos cur_pos1
, cur_pos2
, delta1
, delta2
;
2638 org_pos
= anchor
->pos
+ (edge
->opos
- anchor
->opos
);
2639 org_len
= edge2
->opos
- edge
->opos
;
2640 org_center
= org_pos
+ (org_len
>> 1);
2642 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
2643 edge
->flags
, edge2
->flags
);
2645 if (edge2
->flags
& TA_EDGE_DONE
)
2647 TA_LOG((" ADJUST: edge %d (pos=%.2f) moved to %.2f\n",
2648 edge
- edges
, edge
->pos
/ 64.0,
2649 (edge2
->pos
- cur_len
) / 64.0));
2651 edge
->pos
= edge2
->pos
- cur_len
;
2653 if (hints
->recorder
)
2655 TA_Edge bound
= NULL
;
2661 hints
->recorder(ta_adjust
, hints
, dim
,
2662 edge
, edge2
, NULL
, bound
, NULL
);
2666 else if (cur_len
< 96)
2668 FT_Pos u_off
, d_off
;
2671 cur_pos1
= TA_PIX_ROUND(org_center
);
2684 delta1
= org_center
- (cur_pos1
- u_off
);
2688 delta2
= org_center
- (cur_pos1
+ d_off
);
2692 if (delta1
< delta2
)
2697 edge
->pos
= cur_pos1
- cur_len
/ 2;
2698 edge2
->pos
= cur_pos1
+ cur_len
/ 2;
2700 TA_LOG((" STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
2701 " snapped to %.2f and %.2f\n",
2702 edge
- edges
, edge
->opos
/ 64.0,
2703 edge2
- edges
, edge2
->opos
/ 64.0,
2704 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
2706 if (hints
->recorder
)
2708 TA_Edge bound
= NULL
;
2714 hints
->recorder(ta_stem
, hints
, dim
,
2715 edge
, edge2
, NULL
, bound
, NULL
);
2721 org_pos
= anchor
->pos
+ (edge
->opos
- anchor
->opos
);
2722 org_len
= edge2
->opos
- edge
->opos
;
2723 org_center
= org_pos
+ (org_len
>> 1);
2725 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
2726 edge
->flags
, edge2
->flags
);
2728 cur_pos1
= TA_PIX_ROUND(org_pos
);
2729 delta1
= cur_pos1
+ (cur_len
>> 1) - org_center
;
2733 cur_pos2
= TA_PIX_ROUND(org_pos
+ org_len
) - cur_len
;
2734 delta2
= cur_pos2
+ (cur_len
>> 1) - org_center
;
2738 edge
->pos
= (delta1
< delta2
) ? cur_pos1
: cur_pos2
;
2739 edge2
->pos
= edge
->pos
+ cur_len
;
2741 TA_LOG((" STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
2742 " snapped to %.2f and %.2f\n",
2743 edge
- edges
, edge
->opos
/ 64.0,
2744 edge2
- edges
, edge2
->opos
/ 64.0,
2745 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
2747 if (hints
->recorder
)
2749 TA_Edge bound
= NULL
;
2755 hints
->recorder(ta_stem
, hints
, dim
,
2756 edge
, edge2
, NULL
, bound
, NULL
);
2764 edge
->flags
|= TA_EDGE_DONE
;
2765 edge2
->flags
|= TA_EDGE_DONE
;
2768 && edge
->pos
< edge
[-1].pos
)
2771 TA_LOG((" BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2772 edge
- edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0));
2777 edge
->pos
= edge
[-1].pos
;
2779 if (hints
->recorder
)
2780 hints
->recorder(ta_bound
, hints
, dim
,
2781 edge
, &edge
[-1], NULL
, NULL
, NULL
);
2786 /* make sure that lowercase m's maintain their symmetry */
2788 /* In general, lowercase m's have six vertical edges if they are sans */
2789 /* serif, or twelve if they are with serifs. This implementation is */
2790 /* based on that assumption, and seems to work very well with most */
2791 /* faces. However, if for a certain face this assumption is not */
2792 /* true, the m is just rendered like before. In addition, any stem */
2793 /* correction will only be applied to symmetrical glyphs (even if the */
2794 /* glyph is not an m), so the potential for unwanted distortion is */
2795 /* relatively low. */
2797 /* we don't handle horizontal edges since we can't easily assure that */
2798 /* the third (lowest) stem aligns with the base line; it might end up */
2799 /* one pixel higher or lower */
2801 n_edges
= edge_limit
- edges
;
2802 if (dim
== TA_DIMENSION_HORZ
2803 && (n_edges
== 6 || n_edges
== 12))
2805 TA_Edge edge1
, edge2
, edge3
;
2806 FT_Pos dist1
, dist2
, span
, delta
;
2822 dist1
= edge2
->opos
- edge1
->opos
;
2823 dist2
= edge3
->opos
- edge2
->opos
;
2825 span
= dist1
- dist2
;
2831 delta
= edge3
->pos
- (2 * edge2
->pos
- edge1
->pos
);
2832 edge3
->pos
-= delta
;
2834 edge3
->link
->pos
-= delta
;
2836 /* move the serifs along with the stem */
2839 (edges
+ 8)->pos
-= delta
;
2840 (edges
+ 11)->pos
-= delta
;
2843 edge3
->flags
|= TA_EDGE_DONE
;
2845 edge3
->link
->flags
|= TA_EDGE_DONE
;
2849 if (has_serifs
|| !anchor
)
2851 /* now hint the remaining edges (serifs and single) */
2852 /* in order to complete our processing */
2853 for (edge
= edges
; edge
< edge_limit
; edge
++)
2855 TA_Edge lower_bound
= NULL
;
2856 TA_Edge upper_bound
= NULL
;
2861 if (edge
->flags
& TA_EDGE_DONE
)
2868 delta
= edge
->serif
->opos
- edge
->opos
;
2874 lower_bound
= &edge
[-1];
2876 if (edge
+ 1 < edge_limit
2877 && edge
[1].flags
& TA_EDGE_DONE
)
2878 upper_bound
= &edge
[1];
2881 if (delta
< 64 + 16)
2883 ta_latin_align_serif_edge(hints
, edge
->serif
, edge
);
2885 TA_LOG((" SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
2886 " aligned to %.2f\n",
2887 edge
- edges
, edge
->opos
/ 64.0,
2888 edge
->serif
- edges
, edge
->serif
->opos
/ 64.0,
2891 if (hints
->recorder
)
2892 hints
->recorder(ta_serif
, hints
, dim
,
2893 edge
, NULL
, NULL
, lower_bound
, upper_bound
);
2897 edge
->pos
= TA_PIX_ROUND(edge
->opos
);
2900 TA_LOG((" SERIF_ANCHOR: edge %d (opos=%.2f) snapped to %.2f\n",
2901 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0));
2903 if (hints
->recorder
)
2904 hints
->recorder(ta_serif_anchor
, hints
, dim
,
2905 edge
, NULL
, NULL
, lower_bound
, upper_bound
);
2909 TA_Edge before
, after
;
2912 for (before
= edge
- 1; before
>= edges
; before
--)
2913 if (before
->flags
& TA_EDGE_DONE
)
2916 for (after
= edge
+ 1; after
< edge_limit
; after
++)
2917 if (after
->flags
& TA_EDGE_DONE
)
2920 if (before
>= edges
&& before
< edge
2921 && after
< edge_limit
&& after
> edge
)
2923 if (after
->opos
== before
->opos
)
2924 edge
->pos
= before
->pos
;
2926 edge
->pos
= before
->pos
+ FT_MulDiv(edge
->opos
- before
->opos
,
2927 after
->pos
- before
->pos
,
2928 after
->opos
- before
->opos
);
2930 TA_LOG((" SERIF_LINK1: edge %d (opos=%.2f) snapped to %.2f"
2931 " from %d (opos=%.2f)\n",
2932 edge
- edges
, edge
->opos
/ 64.0,
2934 before
- edges
, before
->opos
/ 64.0));
2936 if (hints
->recorder
)
2937 hints
->recorder(ta_serif_link1
, hints
, dim
,
2938 edge
, before
, after
, lower_bound
, upper_bound
);
2942 edge
->pos
= anchor
->pos
+ ((edge
->opos
- anchor
->opos
+ 16) & ~31);
2943 TA_LOG((" SERIF_LINK2: edge %d (opos=%.2f) snapped to %.2f\n",
2944 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0));
2946 if (hints
->recorder
)
2947 hints
->recorder(ta_serif_link2
, hints
, dim
,
2948 edge
, NULL
, NULL
, lower_bound
, upper_bound
);
2955 edge
->flags
|= TA_EDGE_DONE
;
2958 && edge
->pos
< edge
[-1].pos
)
2961 TA_LOG((" BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2962 edge
- edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0));
2966 edge
->pos
= edge
[-1].pos
;
2968 if (hints
->recorder
)
2969 hints
->recorder(ta_bound
, hints
, dim
,
2970 edge
, &edge
[-1], NULL
, NULL
, NULL
);
2973 if (edge
+ 1 < edge_limit
2974 && edge
[1].flags
& TA_EDGE_DONE
2975 && edge
->pos
> edge
[1].pos
)
2978 TA_LOG((" BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2979 edge
- edges
, edge
->pos
/ 64.0, edge
[1].pos
/ 64.0));
2984 edge
->pos
= edge
[1].pos
;
2986 if (hints
->recorder
)
2987 hints
->recorder(ta_bound
, hints
, dim
,
2988 edge
, &edge
[1], NULL
, NULL
, NULL
);
2995 TA_LOG((" (none)\n"));
3001 /* apply the complete hinting algorithm to a latin glyph */
3004 ta_latin_hints_apply(TA_GlyphHints hints
,
3005 FT_Outline
* outline
,
3006 TA_LatinMetrics metrics
)
3014 error
= ta_glyph_hints_reload(hints
, outline
);
3018 /* analyze glyph outline */
3019 #ifdef TA_CONFIG_OPTION_USE_WARPER
3020 if ((metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
3021 && TA_HINTS_DO_WARP(hints
))
3022 || TA_HINTS_DO_HORIZONTAL(hints
))
3024 if (TA_HINTS_DO_HORIZONTAL(hints
))
3027 axis
= &metrics
->axis
[TA_DIMENSION_HORZ
];
3028 error
= ta_latin_hints_detect_features(hints
,
3036 if (TA_HINTS_DO_VERTICAL(hints
))
3038 axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
3039 error
= ta_latin_hints_detect_features(hints
,
3046 ta_latin_hints_compute_blue_edges(hints
, metrics
);
3049 /* grid-fit the outline */
3050 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
3052 #ifdef TA_CONFIG_OPTION_USE_WARPER
3053 if (dim
== TA_DIMENSION_HORZ
3054 && metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
3055 && TA_HINTS_DO_WARP(hints
))
3057 TA_WarperRec warper
;
3062 ta_warper_compute(&warper
, hints
, (TA_Dimension
)dim
, &scale
, &delta
);
3063 ta_glyph_hints_scale_dim(hints
, (TA_Dimension
)dim
, scale
, delta
);
3067 #endif /* TA_CONFIG_OPTION_USE_WARPER */
3069 if ((dim
== TA_DIMENSION_HORZ
&& TA_HINTS_DO_HORIZONTAL(hints
))
3070 || (dim
== TA_DIMENSION_VERT
&& TA_HINTS_DO_VERTICAL(hints
)))
3072 ta_latin_hint_edges(hints
, (TA_Dimension
)dim
);
3073 ta_glyph_hints_align_edge_points(hints
, (TA_Dimension
)dim
);
3074 ta_glyph_hints_align_strong_points(hints
, (TA_Dimension
)dim
);
3075 ta_glyph_hints_align_weak_points(hints
, (TA_Dimension
)dim
);
3079 ta_glyph_hints_save(hints
, outline
);
3086 const TA_WritingSystemClassRec ta_latin_writing_system_class
=
3088 TA_WRITING_SYSTEM_LATIN
,
3090 sizeof (TA_LatinMetricsRec
),
3092 (TA_WritingSystem_InitMetricsFunc
)ta_latin_metrics_init
,
3093 (TA_WritingSystem_ScaleMetricsFunc
)ta_latin_metrics_scale
,
3094 (TA_WritingSystem_DoneMetricsFunc
)NULL
,
3096 (TA_WritingSystem_InitHintsFunc
)ta_latin_hints_init
,
3097 (TA_WritingSystem_ApplyHintsFunc
)ta_latin_hints_apply
3100 /* end of talatin.c */