3 /* originally file `aflatin.c' (2011-Mar-28) from FreeType */
5 /* heavily modified 2011 by Werner Lemberg <wl@gnu.org> */
10 #include FT_ADVANCES_H
16 #ifdef TA_CONFIG_OPTION_USE_WARPER
21 /* find segments and links, compute all stem widths, and initialize */
22 /* standard width and height for the glyph with given charcode */
25 ta_latin_metrics_init_widths(TA_LatinMetrics metrics
,
29 /* scan the array of segments in each direction */
30 TA_GlyphHintsRec hints
[1];
33 ta_glyph_hints_init(hints
);
35 metrics
->axis
[TA_DIMENSION_HORZ
].width_count
= 0;
36 metrics
->axis
[TA_DIMENSION_VERT
].width_count
= 0;
42 TA_LatinMetricsRec dummy
[1];
43 TA_Scaler scaler
= &dummy
->root
.scaler
;
46 glyph_index
= FT_Get_Char_Index(face
, charcode
);
50 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_SCALE
);
51 if (error
|| face
->glyph
->outline
.n_points
<= 0)
54 memset(dummy
, 0, sizeof (TA_LatinMetricsRec
));
56 dummy
->units_per_em
= metrics
->units_per_em
;
58 scaler
->x_scale
= 0x10000L
;
59 scaler
->y_scale
= 0x10000L
;
64 scaler
->render_mode
= FT_RENDER_MODE_NORMAL
;
67 ta_glyph_hints_rescale(hints
, (TA_ScriptMetrics
)dummy
);
69 error
= ta_glyph_hints_reload(hints
, &face
->glyph
->outline
);
73 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
75 TA_LatinAxis axis
= &metrics
->axis
[dim
];
76 TA_AxisHints axhints
= &hints
->axis
[dim
];
78 TA_Segment seg
, limit
, link
;
79 FT_UInt num_widths
= 0;
82 error
= ta_latin_hints_compute_segments(hints
, (TA_Dimension
)dim
);
86 ta_latin_hints_link_segments(hints
, (TA_Dimension
)dim
);
88 seg
= axhints
->segments
;
89 limit
= seg
+ axhints
->num_segments
;
91 for (; seg
< limit
; seg
++)
95 /* we only consider stem segments there! */
103 dist
= seg
->pos
- link
->pos
;
107 if (num_widths
< TA_LATIN_MAX_WIDTHS
)
108 axis
->widths
[num_widths
++].org
= dist
;
112 ta_sort_widths(num_widths
, axis
->widths
);
113 axis
->width_count
= num_widths
;
117 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
119 TA_LatinAxis axis
= &metrics
->axis
[dim
];
123 stdw
= (axis
->width_count
> 0) ? axis
->widths
[0].org
124 : TA_LATIN_CONSTANT(metrics
, 50);
126 /* let's try 20% of the smallest width */
127 axis
->edge_distance_threshold
= stdw
/ 5;
128 axis
->standard_width
= stdw
;
129 axis
->extra_light
= 0;
133 ta_glyph_hints_done(hints
);
137 #define TA_LATIN_MAX_TEST_CHARACTERS 12
140 static const char ta_latin_blue_chars
[TA_LATIN_MAX_BLUES
]
141 [TA_LATIN_MAX_TEST_CHARACTERS
+ 1] =
152 /* find all blue zones; flat segments give the reference points, */
153 /* round segments the overshoot positions */
156 ta_latin_metrics_init_blues(TA_LatinMetrics metrics
,
159 FT_Pos flats
[TA_LATIN_MAX_TEST_CHARACTERS
];
160 FT_Pos rounds
[TA_LATIN_MAX_TEST_CHARACTERS
];
167 TA_LatinAxis axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
168 FT_GlyphSlot glyph
= face
->glyph
;
171 /* we compute the blues simply by loading each character from the */
172 /* `ta_latin_blue_chars[blues]' string, then finding its top-most or */
173 /* bottom-most points (depending on `TA_IS_TOP_BLUE') */
175 TA_LOG(("blue zones computation\n"));
176 TA_LOG(("------------------------------------------------\n"));
178 for (bb
= 0; bb
< TA_LATIN_BLUE_MAX
; bb
++)
180 const char* p
= ta_latin_blue_chars
[bb
];
181 const char* limit
= p
+ TA_LATIN_MAX_TEST_CHARACTERS
;
186 TA_LOG(("blue %3d: ", bb
));
191 for (; p
< limit
&& *p
; p
++)
194 FT_Pos best_y
; /* same as points.y */
195 FT_Int best_point
, best_first
, best_last
;
200 TA_LOG(("'%c'", *p
));
202 /* load the character in the face -- skip unknown or empty ones */
203 glyph_index
= FT_Get_Char_Index(face
, (FT_UInt
)*p
);
204 if (glyph_index
== 0)
207 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_SCALE
);
208 if (error
|| glyph
->outline
.n_points
<= 0)
211 /* now compute min or max point indices and coordinates */
212 points
= glyph
->outline
.points
;
214 best_y
= 0; /* make compiler happy */
215 best_first
= 0; /* ditto */
216 best_last
= 0; /* ditto */
224 for (nn
= 0; nn
< glyph
->outline
.n_contours
; first
= last
+ 1, nn
++)
226 FT_Int old_best_point
= best_point
;
230 last
= glyph
->outline
.contours
[nn
];
232 /* avoid single-point contours since they are never rasterized; */
233 /* in some fonts, they correspond to mark attachment points */
234 /* which are way outside of the glyph's real outline */
238 if (TA_LATIN_IS_TOP_BLUE(bb
))
240 for (pp
= first
; pp
<= last
; pp
++)
242 || points
[pp
].y
> best_y
)
245 best_y
= points
[pp
].y
;
250 for (pp
= first
; pp
<= last
; pp
++)
252 || points
[pp
].y
< best_y
)
255 best_y
= points
[pp
].y
;
259 if (best_point
!= old_best_point
)
265 TA_LOG(("%5ld", best_y
));
268 /* now check whether the point belongs to a straight or round */
269 /* segment; we first need to find in which contour the extremum */
270 /* lies, then inspect its previous and next points */
277 /* now look for the previous and next points that are not on the */
278 /* same Y coordinate and threshold the `closeness'... */
284 if (prev
> best_first
)
289 dist
= points
[prev
].y
- best_y
;
290 if (dist
< -5 || dist
> 5)
292 } while (prev
!= best_point
);
296 if (next
< best_last
)
301 dist
= points
[next
].y
- best_y
;
302 if (dist
< -5 || dist
> 5)
304 } while (next
!= best_point
);
306 /* now set the `round' flag depending on the segment's kind */
308 FT_CURVE_TAG(glyph
->outline
.tags
[prev
]) != FT_CURVE_TAG_ON
309 || FT_CURVE_TAG(glyph
->outline
.tags
[next
]) != FT_CURVE_TAG_ON
);
311 TA_LOG(("%c ", round
? 'r' : 'f'));
315 rounds
[num_rounds
++] = best_y
;
317 flats
[num_flats
++] = best_y
;
322 if (num_flats
== 0 && num_rounds
== 0)
324 /* we couldn't find a single glyph to compute this blue zone, */
325 /* we will simply ignore it then */
330 /* we have computed the contents of the `rounds' and `flats' tables, */
331 /* now determine the reference and overshoot position of the blue -- */
332 /* we simply take the median value after a simple sort */
333 ta_sort_pos(num_rounds
, rounds
);
334 ta_sort_pos(num_flats
, flats
);
336 blue
= &axis
->blues
[axis
->blue_count
];
337 blue_ref
= &blue
->ref
.org
;
338 blue_shoot
= &blue
->shoot
.org
;
345 *blue_shoot
= rounds
[num_rounds
/ 2];
347 else if (num_rounds
== 0)
350 *blue_shoot
= flats
[num_flats
/ 2];
354 *blue_ref
= flats
[num_flats
/ 2];
355 *blue_shoot
= rounds
[num_rounds
/ 2];
358 /* there are sometimes problems if the overshoot position of top */
359 /* zones is under its reference position, or the opposite for bottom */
360 /* zones; we must thus check everything there and correct the errors */
361 if (*blue_shoot
!= *blue_ref
)
363 FT_Pos ref
= *blue_ref
;
364 FT_Pos shoot
= *blue_shoot
;
365 FT_Bool over_ref
= FT_BOOL(shoot
> ref
);
368 if (TA_LATIN_IS_TOP_BLUE(bb
) ^ over_ref
)
370 *blue_shoot
= (shoot
+ ref
) / 2;
374 if (TA_LATIN_IS_TOP_BLUE(bb
))
375 blue
->flags
|= TA_LATIN_BLUE_TOP
;
377 /* the following flag is used later to adjust the y and x scales */
378 /* in order to optimize the pixel grid alignment */
379 /* of the top of small letters */
380 if (bb
== TA_LATIN_BLUE_SMALL_TOP
)
381 blue
->flags
|= TA_LATIN_BLUE_ADJUSTMENT
;
383 TA_LOG(("-- ref = %ld, shoot = %ld\n", *blue_ref
, *blue_shoot
));
392 /* check whether all ASCII digits have the same advance width */
395 ta_latin_metrics_check_digits(TA_LatinMetrics metrics
,
399 FT_Bool started
= 0, same_width
= 1;
400 FT_Fixed advance
, old_advance
= 0;
403 /* digit `0' is 0x30 in all supported charmaps */
404 for (i
= 0x30; i
<= 0x39; i
++)
409 glyph_index
= FT_Get_Char_Index(face
, i
);
410 if (glyph_index
== 0)
413 if (FT_Get_Advance(face
, glyph_index
,
416 | FT_LOAD_IGNORE_TRANSFORM
,
422 if (advance
!= old_advance
)
430 old_advance
= advance
;
435 metrics
->root
.digits_have_same_width
= same_width
;
439 /* initialize global metrics */
442 ta_latin_metrics_init(TA_LatinMetrics metrics
,
445 FT_Error error
= FT_Err_Ok
;
446 FT_CharMap oldmap
= face
->charmap
;
449 static const FT_Encoding latin_encodings
[] =
452 FT_ENCODING_APPLE_ROMAN
,
453 FT_ENCODING_ADOBE_STANDARD
,
454 FT_ENCODING_ADOBE_LATIN_1
,
456 FT_ENCODING_NONE
/* end of list */
460 metrics
->units_per_em
= face
->units_per_EM
;
462 /* do we have a latin charmap in there? */
463 for (ee
= 0; latin_encodings
[ee
] != FT_ENCODING_NONE
; ee
++)
465 error
= FT_Select_Charmap(face
, latin_encodings
[ee
]);
472 /* for now, compute the standard width and height from the `o' */
473 ta_latin_metrics_init_widths(metrics
, face
, 'o');
474 ta_latin_metrics_init_blues(metrics
, face
);
475 ta_latin_metrics_check_digits(metrics
, face
);
478 FT_Set_Charmap(face
, oldmap
);
483 /* adjust scaling value, then scale and shift widths */
484 /* and blue zones (if applicable) for given dimension */
487 ta_latin_metrics_scale_dim(TA_LatinMetrics metrics
,
497 if (dim
== TA_DIMENSION_HORZ
)
499 scale
= scaler
->x_scale
;
500 delta
= scaler
->x_delta
;
504 scale
= scaler
->y_scale
;
505 delta
= scaler
->y_delta
;
508 axis
= &metrics
->axis
[dim
];
510 if (axis
->org_scale
== scale
&& axis
->org_delta
== delta
)
513 axis
->org_scale
= scale
;
514 axis
->org_delta
= delta
;
516 /* correct X and Y scale to optimize the alignment of the top of */
517 /* small letters to the pixel grid */
519 TA_LatinAxis Axis
= &metrics
->axis
[TA_DIMENSION_VERT
];
520 TA_LatinBlue blue
= NULL
;
523 for (nn
= 0; nn
< Axis
->blue_count
; nn
++)
525 if (Axis
->blues
[nn
].flags
& TA_LATIN_BLUE_ADJUSTMENT
)
527 blue
= &Axis
->blues
[nn
];
534 FT_Pos scaled
= FT_MulFix(blue
->shoot
.org
, scaler
->y_scale
);
535 FT_Pos fitted
= (scaled
+ 40) & ~63;
538 if (scaled
!= fitted
)
540 if (dim
== TA_DIMENSION_VERT
)
541 scale
= FT_MulDiv(scale
, fitted
, scaled
);
549 if (dim
== TA_DIMENSION_HORZ
)
551 metrics
->root
.scaler
.x_scale
= scale
;
552 metrics
->root
.scaler
.x_delta
= delta
;
556 metrics
->root
.scaler
.y_scale
= scale
;
557 metrics
->root
.scaler
.y_delta
= delta
;
560 /* scale the widths */
561 for (nn
= 0; nn
< axis
->width_count
; nn
++)
563 TA_Width width
= axis
->widths
+ nn
;
566 width
->cur
= FT_MulFix(width
->org
, scale
);
567 width
->fit
= width
->cur
;
570 /* an extra-light axis corresponds to a standard width that is */
571 /* smaller than 5/8 pixels */
573 (FT_Bool
)(FT_MulFix(axis
->standard_width
, scale
) < 32 + 8);
575 if (dim
== TA_DIMENSION_VERT
)
577 /* scale the blue zones */
578 for (nn
= 0; nn
< axis
->blue_count
; nn
++)
580 TA_LatinBlue blue
= &axis
->blues
[nn
];
584 blue
->ref
.cur
= FT_MulFix(blue
->ref
.org
, scale
) + delta
;
585 blue
->ref
.fit
= blue
->ref
.cur
;
586 blue
->shoot
.cur
= FT_MulFix(blue
->shoot
.org
, scale
) + delta
;
587 blue
->shoot
.fit
= blue
->shoot
.cur
;
588 blue
->flags
&= ~TA_LATIN_BLUE_ACTIVE
;
590 /* a blue zone is only active if it is less than 3/4 pixels tall */
591 dist
= FT_MulFix(blue
->ref
.org
- blue
->shoot
.org
, scale
);
592 if (dist
<= 48 && dist
>= -48)
600 /* use discrete values for blue zone widths */
603 /* generic, original code */
604 delta1
= blue
->shoot
.org
- blue
->ref
.org
;
609 delta2
= FT_MulFix(delta2
, scale
);
613 else if (delta2
< 64)
614 delta2
= 32 + (((delta2
- 32) + 16) & ~31);
616 delta2
= TA_PIX_ROUND(delta2
);
621 /* simplified version due to abs(dist) <= 48 */
637 blue
->ref
.fit
= TA_PIX_ROUND(blue
->ref
.cur
);
638 blue
->shoot
.fit
= blue
->ref
.fit
+ delta2
;
640 blue
->flags
|= TA_LATIN_BLUE_ACTIVE
;
647 /* scale global values in both directions */
650 ta_latin_metrics_scale(TA_LatinMetrics metrics
,
653 metrics
->root
.scaler
.render_mode
= scaler
->render_mode
;
654 metrics
->root
.scaler
.face
= scaler
->face
;
656 ta_latin_metrics_scale_dim(metrics
, scaler
, TA_DIMENSION_HORZ
);
657 ta_latin_metrics_scale_dim(metrics
, scaler
, TA_DIMENSION_VERT
);
661 /* walk over all contours and compute its segments */
664 ta_latin_hints_compute_segments(TA_GlyphHints hints
,
667 TA_AxisHints axis
= &hints
->axis
[dim
];
668 FT_Error error
= FT_Err_Ok
;
670 TA_Segment segment
= NULL
;
673 TA_Point
* contour
= hints
->contours
;
674 TA_Point
* contour_limit
= contour
+ hints
->num_contours
;
675 TA_Direction major_dir
, segment_dir
;
678 memset(&seg0
, 0, sizeof (TA_SegmentRec
));
680 seg0
.flags
= TA_EDGE_NORMAL
;
682 major_dir
= (TA_Direction
)TA_ABS(axis
->major_dir
);
683 segment_dir
= major_dir
;
685 axis
->num_segments
= 0;
687 /* set up (u,v) in each point */
688 if (dim
== TA_DIMENSION_HORZ
)
690 TA_Point point
= hints
->points
;
691 TA_Point limit
= point
+ hints
->num_points
;
694 for (; point
< limit
; point
++)
696 point
->u
= point
->fx
;
697 point
->v
= point
->fy
;
702 TA_Point point
= hints
->points
;
703 TA_Point limit
= point
+ hints
->num_points
;
706 for (; point
< limit
; point
++)
708 point
->u
= point
->fy
;
709 point
->v
= point
->fx
;
713 /* do each contour separately */
714 for (; contour
< contour_limit
; contour
++)
716 TA_Point point
= contour
[0];
717 TA_Point last
= point
->prev
;
721 FT_Pos min_pos
= 32000; /* minimum segment pos != min_coord */
722 FT_Pos max_pos
= -32000; /* maximum segment pos != max_coord */
726 if (point
== last
) /* skip singletons -- just in case */
729 if (TA_ABS(last
->out_dir
) == major_dir
730 && TA_ABS(point
->out_dir
) == major_dir
)
732 /* we are already on an edge, try to locate its start */
738 if (TA_ABS(point
->out_dir
) != major_dir
)
764 if (point
->out_dir
!= segment_dir
767 /* we are just leaving an edge; record a new segment! */
768 segment
->last
= point
;
769 segment
->pos
= (FT_Short
)((min_pos
+ max_pos
) >> 1);
771 /* a segment is round if either its first or last point */
772 /* is a control point */
773 if ((segment
->first
->flags
| point
->flags
) & TA_FLAG_CONTROL
)
774 segment
->flags
|= TA_EDGE_ROUND
;
776 /* compute segment size */
777 min_pos
= max_pos
= point
->v
;
779 v
= segment
->first
->v
;
785 segment
->min_coord
= (FT_Short
)min_pos
;
786 segment
->max_coord
= (FT_Short
)max_pos
;
787 segment
->height
= (FT_Short
)(segment
->max_coord
-
796 /* now exit if we are at the start/end point */
805 && TA_ABS(point
->out_dir
) == major_dir
)
807 /* this is the start of a new segment! */
808 segment_dir
= (TA_Direction
)point
->out_dir
;
810 /* clear all segment fields */
811 error
= ta_axis_hints_new_segment(axis
, &segment
);
816 segment
->dir
= (FT_Char
)segment_dir
;
817 min_pos
= max_pos
= point
->u
;
818 segment
->first
= point
;
819 segment
->last
= point
;
820 segment
->contour
= contour
;
829 /* now slightly increase the height of segments if this makes sense -- */
830 /* this is used to better detect and ignore serifs */
832 TA_Segment segments
= axis
->segments
;
833 TA_Segment segments_end
= segments
+ axis
->num_segments
;
836 for (segment
= segments
; segment
< segments_end
; segment
++)
838 TA_Point first
= segment
->first
;
839 TA_Point last
= segment
->last
;
841 FT_Pos first_v
= first
->v
;
842 FT_Pos last_v
= last
->v
;
848 if (first_v
< last_v
)
855 segment
->height
= (FT_Short
)(segment
->height
+
856 ((first_v
- p
->v
) >> 1));
860 segment
->height
= (FT_Short
)(segment
->height
+
861 ((p
->v
- last_v
) >> 1));
870 segment
->height
= (FT_Short
)(segment
->height
+
871 ((p
->v
- first_v
) >> 1));
875 segment
->height
= (FT_Short
)(segment
->height
+
876 ((last_v
- p
->v
) >> 1));
886 /* link segments to form stems and serifs */
889 ta_latin_hints_link_segments(TA_GlyphHints hints
,
892 TA_AxisHints axis
= &hints
->axis
[dim
];
894 TA_Segment segments
= axis
->segments
;
895 TA_Segment segment_limit
= segments
+ axis
->num_segments
;
897 FT_Pos len_threshold
, len_score
;
898 TA_Segment seg1
, seg2
;
901 len_threshold
= TA_LATIN_CONSTANT(hints
->metrics
, 8);
902 if (len_threshold
== 0)
905 len_score
= TA_LATIN_CONSTANT(hints
->metrics
, 6000);
907 /* now compare each segment to the others */
908 for (seg1
= segments
; seg1
< segment_limit
; seg1
++)
910 /* the fake segments are introduced to hint the metrics -- */
911 /* we must never link them to anything */
912 if (seg1
->dir
!= axis
->major_dir
913 || seg1
->first
== seg1
->last
)
916 /* search for stems having opposite directions, */
917 /* with seg1 to the `left' of seg2 */
918 for (seg2
= segments
; seg2
< segment_limit
; seg2
++)
920 FT_Pos pos1
= seg1
->pos
;
921 FT_Pos pos2
= seg2
->pos
;
924 if (seg1
->dir
+ seg2
->dir
== 0
927 /* compute distance between the two segments */
928 FT_Pos dist
= pos2
- pos1
;
929 FT_Pos min
= seg1
->min_coord
;
930 FT_Pos max
= seg1
->max_coord
;
934 if (min
< seg2
->min_coord
)
935 min
= seg2
->min_coord
;
936 if (max
> seg2
->max_coord
)
937 max
= seg2
->max_coord
;
939 /* compute maximum coordinate difference of the two segments */
941 if (len
>= len_threshold
)
943 /* small coordinate differences cause a higher score, and */
944 /* segments with a greater distance cause a higher score also */
945 score
= dist
+ len_score
/ len
;
947 /* and we search for the smallest score */
948 /* of the sum of the two values */
949 if (score
< seg1
->score
)
955 if (score
< seg2
->score
)
965 /* now compute the `serif' segments, cf. explanations in `tahints.h' */
966 for (seg1
= segments
; seg1
< segment_limit
; seg1
++)
972 if (seg2
->link
!= seg1
)
975 seg1
->serif
= seg2
->link
;
982 /* link segments to edges, using feature analysis for selection */
985 ta_latin_hints_compute_edges(TA_GlyphHints hints
,
988 TA_AxisHints axis
= &hints
->axis
[dim
];
989 FT_Error error
= FT_Err_Ok
;
990 TA_LatinAxis laxis
= &((TA_LatinMetrics
)hints
->metrics
)->axis
[dim
];
992 TA_Segment segments
= axis
->segments
;
993 TA_Segment segment_limit
= segments
+ axis
->num_segments
;
1000 FT_Pos edge_distance_threshold
;
1001 FT_Pos segment_length_threshold
;
1004 axis
->num_edges
= 0;
1006 scale
= (dim
== TA_DIMENSION_HORZ
) ? hints
->x_scale
1010 up_dir
= (dim
== TA_DIMENSION_HORZ
) ? TA_DIR_UP
1014 /* we ignore all segments that are less than 1 pixel in length */
1015 /* to avoid many problems with serif fonts */
1016 /* (the corresponding threshold is computed in font units) */
1017 if (dim
== TA_DIMENSION_HORZ
)
1018 segment_length_threshold
= FT_DivFix(64, hints
->y_scale
);
1020 segment_length_threshold
= 0;
1022 /********************************************************************/
1024 /* We begin by generating a sorted table of edges for the current */
1025 /* direction. To do so, we simply scan each segment and try to find */
1026 /* an edge in our table that corresponds to its position. */
1028 /* If no edge is found, we create and insert a new edge in the */
1029 /* sorted table. Otherwise, we simply add the segment to the edge's */
1030 /* list which gets processed in the second step to compute the */
1031 /* edge's properties. */
1033 /* Note that the table of edges is sorted along the segment/edge */
1036 /********************************************************************/
1038 /* assure that edge distance threshold is at most 0.25px */
1039 edge_distance_threshold
= FT_MulFix(laxis
->edge_distance_threshold
,
1041 if (edge_distance_threshold
> 64 / 4)
1042 edge_distance_threshold
= 64 / 4;
1044 edge_distance_threshold
= FT_DivFix(edge_distance_threshold
,
1047 for (seg
= segments
; seg
< segment_limit
; seg
++)
1049 TA_Edge found
= NULL
;
1053 if (seg
->height
< segment_length_threshold
)
1056 /* a special case for serif edges: */
1057 /* if they are smaller than 1.5 pixels we ignore them */
1059 && 2 * seg
->height
< 3 * segment_length_threshold
)
1062 /* look for an edge corresponding to the segment */
1063 for (ee
= 0; ee
< axis
->num_edges
; ee
++)
1065 TA_Edge edge
= axis
->edges
+ ee
;
1069 dist
= seg
->pos
- edge
->fpos
;
1073 if (dist
< edge_distance_threshold
&& edge
->dir
== seg
->dir
)
1085 /* insert a new edge in the list and sort according to the position */
1086 error
= ta_axis_hints_new_edge(axis
, seg
->pos
,
1087 (TA_Direction
)seg
->dir
,
1092 /* add the segment to the new edge's list */
1093 memset(edge
, 0, sizeof (TA_EdgeRec
));
1096 edge
->dir
= seg
->dir
;
1097 edge
->fpos
= seg
->pos
;
1098 edge
->opos
= FT_MulFix(seg
->pos
, scale
);
1099 edge
->pos
= edge
->opos
;
1100 seg
->edge_next
= seg
;
1104 /* if an edge was found, simply add the segment to the edge's list */
1105 seg
->edge_next
= found
->first
;
1106 found
->last
->edge_next
= seg
;
1111 /*****************************************************************/
1113 /* Good, we now compute each edge's properties according to */
1114 /* the segments found on its position. Basically, these are */
1116 /* - the edge's main direction */
1117 /* - stem edge, serif edge or both (which defaults to stem then) */
1118 /* - rounded edge, straight or both (which defaults to straight) */
1119 /* - link for edge */
1121 /*****************************************************************/
1123 /* first of all, set the `edge' field in each segment -- this is */
1124 /* required in order to compute edge links */
1126 /* note that removing this loop and setting the `edge' field of each */
1127 /* segment directly in the code above slows down execution speed for */
1128 /* some reasons on platforms like the Sun */
1130 TA_Edge edges
= axis
->edges
;
1131 TA_Edge edge_limit
= edges
+ axis
->num_edges
;
1135 for (edge
= edges
; edge
< edge_limit
; edge
++)
1142 seg
= seg
->edge_next
;
1143 } while (seg
!= edge
->first
);
1146 /* now compute each edge properties */
1147 for (edge
= edges
; edge
< edge_limit
; edge
++)
1149 FT_Int is_round
= 0; /* does it contain round segments? */
1150 FT_Int is_straight
= 0; /* does it contain straight segments? */
1152 FT_Pos ups
= 0; /* number of upwards segments */
1153 FT_Pos downs
= 0; /* number of downwards segments */
1164 /* check for roundness of segment */
1165 if (seg
->flags
& TA_EDGE_ROUND
)
1171 /* check for segment direction */
1172 if (seg
->dir
== up_dir
)
1173 ups
+= seg
->max_coord
- seg
->min_coord
;
1175 downs
+= seg
->max_coord
- seg
->min_coord
;
1178 /* check for links -- */
1179 /* if seg->serif is set, then seg->link must be ignored */
1180 is_serif
= (FT_Bool
)(seg
->serif
1182 && seg
->serif
->edge
!= edge
);
1184 if ((seg
->link
&& seg
->link
->edge
!= NULL
)
1197 edge2
= edge
->serif
;
1206 edge_delta
= edge
->fpos
- edge2
->fpos
;
1208 edge_delta
= -edge_delta
;
1210 seg_delta
= seg
->pos
- seg2
->pos
;
1212 seg_delta
= -seg_delta
;
1214 if (seg_delta
< edge_delta
)
1222 edge
->serif
= edge2
;
1223 edge2
->flags
|= TA_EDGE_SERIF
;
1229 seg
= seg
->edge_next
;
1230 } while (seg
!= edge
->first
);
1232 /* set the round/straight flags */
1233 edge
->flags
= TA_EDGE_NORMAL
;
1236 && is_round
>= is_straight
)
1237 edge
->flags
|= TA_EDGE_ROUND
;
1240 /* set the edge's main direction */
1241 edge
->dir
= TA_DIR_NONE
;
1244 edge
->dir
= (FT_Char
)up_dir
;
1246 else if (ups
< downs
)
1247 edge
->dir
= (FT_Char
)-up_dir
;
1249 else if (ups
== downs
)
1250 edge
->dir
= 0; /* both up and down! */
1253 /* get rid of serifs if link is set */
1254 /* XXX: this gets rid of many unpleasant artefacts! */
1255 /* example: the `c' in cour.pfa at size 13 */
1257 if (edge
->serif
&& edge
->link
)
1267 /* detect segments and edges for given dimension */
1270 ta_latin_hints_detect_features(TA_GlyphHints hints
,
1276 error
= ta_latin_hints_compute_segments(hints
, dim
);
1279 ta_latin_hints_link_segments(hints
, dim
);
1281 error
= ta_latin_hints_compute_edges(hints
, dim
);
1288 /* compute all edges which lie within blue zones */
1291 ta_latin_hints_compute_blue_edges(TA_GlyphHints hints
,
1292 TA_LatinMetrics metrics
)
1294 TA_AxisHints axis
= &hints
->axis
[TA_DIMENSION_VERT
];
1296 TA_Edge edge
= axis
->edges
;
1297 TA_Edge edge_limit
= edge
+ axis
->num_edges
;
1299 TA_LatinAxis latin
= &metrics
->axis
[TA_DIMENSION_VERT
];
1300 FT_Fixed scale
= latin
->scale
;
1303 /* compute which blue zones are active, */
1304 /* i.e. have their scaled size < 3/4 pixels */
1306 /* for each horizontal edge search the blue zone which is closest */
1307 for (; edge
< edge_limit
; edge
++)
1310 TA_Width best_blue
= NULL
;
1311 FT_Pos best_dist
; /* initial threshold */
1314 /* compute the initial threshold as a fraction of the EM size */
1315 /* (the value 40 is heuristic) */
1316 best_dist
= FT_MulFix(metrics
->units_per_em
/ 40, scale
);
1318 /* assure a minimum distance of 0.5px */
1319 if (best_dist
> 64 / 2)
1322 for (bb
= 0; bb
< TA_LATIN_BLUE_MAX
; bb
++)
1324 TA_LatinBlue blue
= latin
->blues
+ bb
;
1325 FT_Bool is_top_blue
, is_major_dir
;
1328 /* skip inactive blue zones (i.e., those that are too large) */
1329 if (!(blue
->flags
& TA_LATIN_BLUE_ACTIVE
))
1332 /* if it is a top zone, check for right edges -- */
1333 /* if it is a bottom zone, check for left edges */
1334 is_top_blue
= (FT_Byte
)((blue
->flags
& TA_LATIN_BLUE_TOP
) != 0);
1335 is_major_dir
= FT_BOOL(edge
->dir
== axis
->major_dir
);
1337 /* if it is a top zone, the edge must be against the major */
1338 /* direction; if it is a bottom zone, it must be in the major */
1340 if (is_top_blue
^ is_major_dir
)
1345 /* first of all, compare it to the reference position */
1346 dist
= edge
->fpos
- blue
->ref
.org
;
1350 dist
= FT_MulFix(dist
, scale
);
1351 if (dist
< best_dist
)
1354 best_blue
= &blue
->ref
;
1357 /* now compare it to the overshoot position and check whether */
1358 /* the edge is rounded, and whether the edge is over the */
1359 /* reference position of a top zone, or under the reference */
1360 /* position of a bottom zone */
1361 if (edge
->flags
& TA_EDGE_ROUND
1364 FT_Bool is_under_ref
= FT_BOOL(edge
->fpos
< blue
->ref
.org
);
1367 if (is_top_blue
^ is_under_ref
)
1369 dist
= edge
->fpos
- blue
->shoot
.org
;
1373 dist
= FT_MulFix(dist
, scale
);
1374 if (dist
< best_dist
)
1377 best_blue
= &blue
->shoot
;
1385 edge
->blue_edge
= best_blue
;
1390 /* initalize hinting engine */
1393 ta_latin_hints_init(TA_GlyphHints hints
,
1394 TA_LatinMetrics metrics
)
1396 FT_Render_Mode mode
;
1397 FT_UInt32 scaler_flags
, other_flags
;
1398 FT_Face face
= metrics
->root
.scaler
.face
;
1401 ta_glyph_hints_rescale(hints
, (TA_ScriptMetrics
)metrics
);
1403 /* correct x_scale and y_scale if needed, since they may have */
1404 /* been modified by `ta_latin_metrics_scale_dim' above */
1405 hints
->x_scale
= metrics
->axis
[TA_DIMENSION_HORZ
].scale
;
1406 hints
->x_delta
= metrics
->axis
[TA_DIMENSION_HORZ
].delta
;
1407 hints
->y_scale
= metrics
->axis
[TA_DIMENSION_VERT
].scale
;
1408 hints
->y_delta
= metrics
->axis
[TA_DIMENSION_VERT
].delta
;
1410 /* compute flags depending on render mode, etc. */
1411 mode
= metrics
->root
.scaler
.render_mode
;
1413 #if 0 /* #ifdef TA_CONFIG_OPTION_USE_WARPER */
1414 if (mode
== FT_RENDER_MODE_LCD
1415 || mode
== FT_RENDER_MODE_LCD_V
)
1416 metrics
->root
.scaler
.render_mode
=
1417 mode
= FT_RENDER_MODE_NORMAL
;
1420 scaler_flags
= hints
->scaler_flags
;
1423 /* we snap the width of vertical stems for the monochrome */
1424 /* and horizontal LCD rendering targets only */
1425 if (mode
== FT_RENDER_MODE_MONO
1426 || mode
== FT_RENDER_MODE_LCD
)
1427 other_flags
|= TA_LATIN_HINTS_HORZ_SNAP
;
1429 /* we snap the width of horizontal stems for the monochrome */
1430 /* and vertical LCD rendering targets only */
1431 if (mode
== FT_RENDER_MODE_MONO
1432 || mode
== FT_RENDER_MODE_LCD_V
)
1433 other_flags
|= TA_LATIN_HINTS_VERT_SNAP
;
1435 /* we adjust stems to full pixels only if we don't use the `light' mode */
1436 if (mode
!= FT_RENDER_MODE_LIGHT
)
1437 other_flags
|= TA_LATIN_HINTS_STEM_ADJUST
;
1439 if (mode
== FT_RENDER_MODE_MONO
)
1440 other_flags
|= TA_LATIN_HINTS_MONO
;
1442 /* in `light' hinting mode we disable horizontal hinting completely; */
1443 /* we also do it if the face is italic */
1444 if (mode
== FT_RENDER_MODE_LIGHT
1445 || (face
->style_flags
& FT_STYLE_FLAG_ITALIC
) != 0)
1446 scaler_flags
|= TA_SCALER_FLAG_NO_HORIZONTAL
;
1448 hints
->scaler_flags
= scaler_flags
;
1449 hints
->other_flags
= other_flags
;
1455 /* snap a given width in scaled coordinates to */
1456 /* one of the current standard widths */
1459 ta_latin_snap_width(TA_Width widths
,
1464 FT_Pos best
= 64 + 32 + 2;
1465 FT_Pos reference
= width
;
1469 for (n
= 0; n
< count
; n
++)
1486 scaled
= TA_PIX_ROUND(reference
);
1488 if (width
>= reference
)
1490 if (width
< scaled
+ 48)
1495 if (width
> scaled
- 48)
1503 /* compute the snapped width of a given stem, ignoring very thin ones */
1505 /* there is a lot of voodoo in this function; changing the hard-coded */
1506 /* parameters influence the whole hinting process */
1509 ta_latin_compute_stem_width(TA_GlyphHints hints
,
1515 TA_LatinMetrics metrics
= (TA_LatinMetrics
) hints
->metrics
;
1516 TA_LatinAxis axis
= &metrics
->axis
[dim
];
1518 FT_Pos dist
= width
;
1520 FT_Int vertical
= (dim
== TA_DIMENSION_VERT
);
1523 if (!TA_LATIN_HINTS_DO_STEM_ADJUST(hints
)
1524 || axis
->extra_light
)
1533 if ((vertical
&& !TA_LATIN_HINTS_DO_VERT_SNAP(hints
))
1534 || (!vertical
&& !TA_LATIN_HINTS_DO_HORZ_SNAP(hints
)))
1536 /* smooth hinting process: very lightly quantize the stem width */
1538 /* leave the widths of serifs alone */
1539 if ((stem_flags
& TA_EDGE_SERIF
)
1543 else if (base_flags
& TA_EDGE_ROUND
)
1551 if (axis
->width_count
> 0)
1556 /* compare to standard width */
1557 delta
= dist
- axis
->widths
[0].cur
;
1564 dist
= axis
->widths
[0].cur
;
1578 else if (delta
< 32)
1580 else if (delta
< 54)
1586 dist
= (dist
+ 32) & ~63;
1591 /* strong hinting process: snap the stem width to integer pixels */
1593 FT_Pos org_dist
= dist
;
1596 dist
= ta_latin_snap_width(axis
->widths
, axis
->width_count
, dist
);
1600 /* in the case of vertical hinting, */
1601 /* always round the stem heights to integer pixels */
1604 dist
= (dist
+ 16) & ~63;
1610 if (TA_LATIN_HINTS_DO_MONO(hints
))
1612 /* monochrome horizontal hinting: */
1613 /* snap widths to integer pixels with a different threshold */
1618 dist
= (dist
+ 32) & ~63;
1622 /* for horizontal anti-aliased hinting, we adopt a more subtle */
1623 /* approach: we strengthen small stems, round stems whose size */
1624 /* is between 1 and 2 pixels to an integer, otherwise nothing */
1627 dist
= (dist
+ 64) >> 1;
1629 else if (dist
< 128)
1631 /* we only round to an integer width if the corresponding */
1632 /* distortion is less than 1/4 pixel -- otherwise, this */
1633 /* makes everything worse since the diagonals, which are */
1634 /* not hinted, appear a lot bolder or thinner than the */
1635 /* vertical stems */
1640 dist
= (dist
+ 22) & ~63;
1641 delta
= dist
- org_dist
;
1649 dist
= (dist
+ 64) >> 1;
1653 /* round otherwise to prevent color fringes in LCD mode */
1654 dist
= (dist
+ 32) & ~63;
1667 /* align one stem edge relative to the previous stem edge */
1670 ta_latin_align_linked_edge(TA_GlyphHints hints
,
1675 FT_Pos dist
= stem_edge
->opos
- base_edge
->opos
;
1677 FT_Pos fitted_width
= ta_latin_compute_stem_width(
1683 stem_edge
->pos
= base_edge
->pos
+ fitted_width
;
1685 TA_LOG((" LINK: edge %d (opos=%.2f) linked to %.2f,"
1686 " dist was %.2f, now %.2f\n",
1687 stem_edge
- hints
->axis
[dim
].edges
, stem_edge
->opos
/ 64.0,
1688 stem_edge
->pos
/ 64.0, dist
/ 64.0, fitted_width
/ 64.0));
1690 if (hints
->recorder
)
1691 hints
->recorder(ta_link
, hints
, dim
, base_edge
, stem_edge
, NULL
);
1695 /* shift the coordinates of the `serif' edge by the same amount */
1696 /* as the corresponding `base' edge has been moved already */
1699 ta_latin_align_serif_edge(TA_GlyphHints hints
,
1705 serif
->pos
= base
->pos
+ (serif
->opos
- base
->opos
);
1709 /* the main grid-fitting routine */
1712 ta_latin_hint_edges(TA_GlyphHints hints
,
1715 TA_AxisHints axis
= &hints
->axis
[dim
];
1717 TA_Edge edges
= axis
->edges
;
1718 TA_Edge edge_limit
= edges
+ axis
->num_edges
;
1722 TA_Edge anchor
= NULL
;
1723 FT_Int has_serifs
= 0;
1726 TA_LOG(("%s edge hinting\n", dim
== TA_DIMENSION_VERT
? "horizontal"
1729 /* we begin by aligning all stems relative to the blue zone if needed -- */
1730 /* that's only for horizontal edges */
1732 if (dim
== TA_DIMENSION_VERT
1733 && TA_HINTS_DO_BLUES(hints
))
1735 for (edge
= edges
; edge
< edge_limit
; edge
++)
1738 TA_Edge edge1
, edge2
; /* these edges form the stem to check */
1741 if (edge
->flags
& TA_EDGE_DONE
)
1744 blue
= edge
->blue_edge
;
1751 /* flip edges if the other stem is aligned to a blue zone */
1752 else if (edge2
&& edge2
->blue_edge
)
1754 blue
= edge2
->blue_edge
;
1762 TA_LOG((" BLUE: edge %d (opos=%.2f) snapped to %.2f, was %.2f\n",
1763 edge1
- edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
1764 edge1
->pos
/ 64.0));
1766 edge1
->pos
= blue
->fit
;
1767 edge1
->flags
|= TA_EDGE_DONE
;
1769 if (hints
->recorder
)
1770 hints
->recorder(ta_blue
, hints
, dim
, edge1
, NULL
, NULL
);
1772 if (edge2
&& !edge2
->blue_edge
)
1774 ta_latin_align_linked_edge(hints
, dim
, edge1
, edge2
);
1775 edge2
->flags
|= TA_EDGE_DONE
;
1783 /* now we align all other stem edges, */
1784 /* trying to maintain the relative order of stems in the glyph */
1785 for (edge
= edges
; edge
< edge_limit
; edge
++)
1790 if (edge
->flags
& TA_EDGE_DONE
)
1793 /* skip all non-stem edges */
1801 /* now align the stem */
1803 /* this should not happen, but it's better to be safe */
1804 if (edge2
->blue_edge
)
1806 TA_LOG((" ASSERTION FAILED for edge %d\n", edge2
-edges
));
1808 ta_latin_align_linked_edge(hints
, dim
, edge2
, edge
);
1809 edge
->flags
|= TA_EDGE_DONE
;
1815 /* if we reach this if clause, no stem has been aligned yet */
1817 FT_Pos org_len
, org_center
, cur_len
;
1818 FT_Pos cur_pos1
, error1
, error2
, u_off
, d_off
;
1821 org_len
= edge2
->opos
- edge
->opos
;
1822 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
1823 edge
->flags
, edge2
->flags
);
1825 /* some voodoo to specially round edges for small stem widths; */
1826 /* the idea is to align the center of a stem, */
1827 /* then shifting the stem edges to suitable positions */
1836 /* 1px < width < 1.5px */
1843 org_center
= edge
->opos
+ (org_len
>> 1);
1844 cur_pos1
= TA_PIX_ROUND(org_center
);
1846 error1
= org_center
- (cur_pos1
- u_off
);
1850 error2
= org_center
- (cur_pos1
+ d_off
);
1854 if (error1
< error2
)
1859 edge
->pos
= cur_pos1
- cur_len
/ 2;
1860 edge2
->pos
= edge
->pos
+ cur_len
;
1863 edge
->pos
= TA_PIX_ROUND(edge
->opos
);
1866 edge
->flags
|= TA_EDGE_DONE
;
1868 TA_LOG((" ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
1869 " snapped to %.2f and %.2f\n",
1870 edge
- edges
, edge
->opos
/ 64.0,
1871 edge2
- edges
, edge2
->opos
/ 64.0,
1872 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
1874 if (hints
->recorder
)
1875 hints
->recorder(ta_anchor
, hints
, dim
, edge
, edge2
, NULL
);
1877 ta_latin_align_linked_edge(hints
, dim
, edge
, edge2
);
1881 FT_Pos org_pos
, org_len
, org_center
, cur_len
;
1882 FT_Pos cur_pos1
, cur_pos2
, delta1
, delta2
;
1885 org_pos
= anchor
->pos
+ (edge
->opos
- anchor
->opos
);
1886 org_len
= edge2
->opos
- edge
->opos
;
1887 org_center
= org_pos
+ (org_len
>> 1);
1889 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
1890 edge
->flags
, edge2
->flags
);
1892 if (edge2
->flags
& TA_EDGE_DONE
)
1894 TA_LOG((" ADJUST: edge %d (pos=%.2f) moved to %.2f\n",
1895 edge
- edges
, edge
->pos
/ 64.0,
1896 (edge2
->pos
- cur_len
) / 64.0));
1898 edge
->pos
= edge2
->pos
- cur_len
;
1900 if (hints
->recorder
)
1903 hints
->recorder(ta_adjust_bound
, hints
, dim
,
1904 edge
, edge2
, &edge
[-1]);
1906 hints
->recorder(ta_adjust
, hints
, dim
, edge
, edge2
, NULL
);
1910 else if (cur_len
< 96)
1912 FT_Pos u_off
, d_off
;
1915 cur_pos1
= TA_PIX_ROUND(org_center
);
1928 delta1
= org_center
- (cur_pos1
- u_off
);
1932 delta2
= org_center
- (cur_pos1
+ d_off
);
1936 if (delta1
< delta2
)
1941 edge
->pos
= cur_pos1
- cur_len
/ 2;
1942 edge2
->pos
= cur_pos1
+ cur_len
/ 2;
1944 TA_LOG((" STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
1945 " snapped to %.2f and %.2f\n",
1946 edge
- edges
, edge
->opos
/ 64.0,
1947 edge2
- edges
, edge2
->opos
/ 64.0,
1948 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
1950 if (hints
->recorder
)
1953 hints
->recorder(ta_stem_bound
, hints
, dim
,
1954 edge
, edge2
, &edge
[-1]);
1956 hints
->recorder(ta_stem
, hints
, dim
, edge
, edge2
, NULL
);
1962 org_pos
= anchor
->pos
+ (edge
->opos
- anchor
->opos
);
1963 org_len
= edge2
->opos
- edge
->opos
;
1964 org_center
= org_pos
+ (org_len
>> 1);
1966 cur_len
= ta_latin_compute_stem_width(hints
, dim
, org_len
,
1967 edge
->flags
, edge2
->flags
);
1969 cur_pos1
= TA_PIX_ROUND(org_pos
);
1970 delta1
= cur_pos1
+ (cur_len
>> 1) - org_center
;
1974 cur_pos2
= TA_PIX_ROUND(org_pos
+ org_len
) - cur_len
;
1975 delta2
= cur_pos2
+ (cur_len
>> 1) - org_center
;
1979 edge
->pos
= (delta1
< delta2
) ? cur_pos1
: cur_pos2
;
1980 edge2
->pos
= edge
->pos
+ cur_len
;
1982 TA_LOG((" STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
1983 " snapped to %.2f and %.2f\n",
1984 edge
- edges
, edge
->opos
/ 64.0,
1985 edge2
- edges
, edge2
->opos
/ 64.0,
1986 edge
->pos
/ 64.0, edge2
->pos
/ 64.0));
1988 if (hints
->recorder
)
1991 hints
->recorder(ta_stem_bound
, hints
, dim
,
1992 edge
, edge2
, &edge
[-1]);
1994 hints
->recorder(ta_stem
, hints
, dim
, edge
, edge2
, NULL
);
1998 edge
->flags
|= TA_EDGE_DONE
;
1999 edge2
->flags
|= TA_EDGE_DONE
;
2002 && edge
->pos
< edge
[-1].pos
)
2004 TA_LOG((" BOUND: edge %d (pos=%.2f) moved to %.2f\n",
2005 edge
- edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0));
2007 edge
->pos
= edge
[-1].pos
;
2009 if (hints
->recorder
)
2010 hints
->recorder(ta_bound
, hints
, dim
, edge
, &edge
[-1], NULL
);
2015 /* make sure that lowercase m's maintain their symmetry */
2017 /* In general, lowercase m's have six vertical edges if they are sans */
2018 /* serif, or twelve if they are with serifs. This implementation is */
2019 /* based on that assumption, and seems to work very well with most */
2020 /* faces. However, if for a certain face this assumption is not */
2021 /* true, the m is just rendered like before. In addition, any stem */
2022 /* correction will only be applied to symmetrical glyphs (even if the */
2023 /* glyph is not an m), so the potential for unwanted distortion is */
2024 /* relatively low. */
2026 /* we don't handle horizontal edges since we can't easily assure that */
2027 /* the third (lowest) stem aligns with the base line; it might end up */
2028 /* one pixel higher or lower */
2030 n_edges
= edge_limit
- edges
;
2031 if (dim
== TA_DIMENSION_HORZ
2032 && (n_edges
== 6 || n_edges
== 12))
2034 TA_Edge edge1
, edge2
, edge3
;
2035 FT_Pos dist1
, dist2
, span
, delta
;
2051 dist1
= edge2
->opos
- edge1
->opos
;
2052 dist2
= edge3
->opos
- edge2
->opos
;
2054 span
= dist1
- dist2
;
2060 delta
= edge3
->pos
- (2 * edge2
->pos
- edge1
->pos
);
2061 edge3
->pos
-= delta
;
2063 edge3
->link
->pos
-= delta
;
2065 /* move the serifs along with the stem */
2068 (edges
+ 8)->pos
-= delta
;
2069 (edges
+ 11)->pos
-= delta
;
2072 edge3
->flags
|= TA_EDGE_DONE
;
2074 edge3
->link
->flags
|= TA_EDGE_DONE
;
2078 if (has_serifs
|| !anchor
)
2080 /* now hint the remaining edges (serifs and single) */
2081 /* in order to complete our processing */
2082 for (edge
= edges
; edge
< edge_limit
; edge
++)
2087 if (edge
->flags
& TA_EDGE_DONE
)
2094 delta
= edge
->serif
->opos
- edge
->opos
;
2099 if (delta
< 64 + 16)
2101 ta_latin_align_serif_edge(hints
, edge
->serif
, edge
);
2103 TA_LOG((" SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
2104 " aligned to %.2f\n",
2105 edge
- edges
, edge
->opos
/ 64.0,
2106 edge
->serif
- edges
, edge
->serif
->opos
/ 64.0,
2109 if (hints
->recorder
)
2110 hints
->recorder(ta_serif
, hints
, dim
, edge
, NULL
, NULL
);
2114 edge
->pos
= TA_PIX_ROUND(edge
->opos
);
2117 TA_LOG((" SERIF_ANCHOR: edge %d (opos=%.2f) snapped to %.2f\n",
2118 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0));
2120 if (hints
->recorder
)
2121 hints
->recorder(ta_serif_anchor
, hints
, dim
, edge
, NULL
, NULL
);
2125 TA_Edge before
, after
;
2128 for (before
= edge
- 1; before
>= edges
; before
--)
2129 if (before
->flags
& TA_EDGE_DONE
)
2132 for (after
= edge
+ 1; after
< edge_limit
; after
++)
2133 if (after
->flags
& TA_EDGE_DONE
)
2136 if (before
>= edges
&& before
< edge
2137 && after
< edge_limit
&& after
> edge
)
2139 if (after
->opos
== before
->opos
)
2140 edge
->pos
= before
->pos
;
2142 edge
->pos
= before
->pos
+ FT_MulDiv(edge
->opos
- before
->opos
,
2143 after
->pos
- before
->pos
,
2144 after
->opos
- before
->opos
);
2146 TA_LOG((" SERIF_LINK1: edge %d (opos=%.2f) snapped to %.2f"
2147 " from %d (opos=%.2f)\n",
2148 edge
- edges
, edge
->opos
/ 64.0,
2150 before
- edges
, before
->opos
/ 64.0));
2152 if (hints
->recorder
)
2153 hints
->recorder(ta_serif_link1
, hints
, dim
, edge
, NULL
, NULL
);
2157 edge
->pos
= anchor
->pos
+ ((edge
->opos
- anchor
->opos
+ 16) & ~31);
2159 TA_LOG((" SERIF_LINK2: edge %d (opos=%.2f) snapped to %.2f\n",
2160 edge
- edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0));
2162 if (hints
->recorder
)
2163 hints
->recorder(ta_serif_link2
, hints
, dim
, edge
, NULL
, NULL
);
2167 edge
->flags
|= TA_EDGE_DONE
;
2170 && edge
->pos
< edge
[-1].pos
)
2171 edge
->pos
= edge
[-1].pos
;
2173 if (edge
+ 1 < edge_limit
2174 && edge
[1].flags
& TA_EDGE_DONE
2175 && edge
->pos
> edge
[1].pos
)
2176 edge
->pos
= edge
[1].pos
;
2184 /* apply the complete hinting algorithm to a latin glyph */
2187 ta_latin_hints_apply(TA_GlyphHints hints
,
2188 FT_Outline
* outline
,
2189 TA_LatinMetrics metrics
)
2195 error
= ta_glyph_hints_reload(hints
, outline
);
2199 /* analyze glyph outline */
2200 #ifdef TA_CONFIG_OPTION_USE_WARPER
2201 if (metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
2202 || TA_HINTS_DO_HORIZONTAL(hints
))
2204 if (TA_HINTS_DO_HORIZONTAL(hints
))
2207 error
= ta_latin_hints_detect_features(hints
, TA_DIMENSION_HORZ
);
2212 if (TA_HINTS_DO_VERTICAL(hints
))
2214 error
= ta_latin_hints_detect_features(hints
, TA_DIMENSION_VERT
);
2218 ta_latin_hints_compute_blue_edges(hints
, metrics
);
2221 /* grid-fit the outline */
2222 for (dim
= 0; dim
< TA_DIMENSION_MAX
; dim
++)
2224 #ifdef TA_CONFIG_OPTION_USE_WARPER
2225 if (dim
== TA_DIMENSION_HORZ
2226 && metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
)
2228 TA_WarperRec warper
;
2233 ta_warper_compute(&warper
, hints
, (TA_Dimension
)dim
, &scale
, &delta
);
2234 ta_glyph_hints_scale_dim(hints
, (TA_Dimension
)dim
, scale
, delta
);
2240 if ((dim
== TA_DIMENSION_HORZ
&& TA_HINTS_DO_HORIZONTAL(hints
))
2241 || (dim
== TA_DIMENSION_VERT
&& TA_HINTS_DO_VERTICAL(hints
)))
2243 ta_latin_hint_edges(hints
, (TA_Dimension
)dim
);
2244 ta_glyph_hints_align_edge_points(hints
, (TA_Dimension
)dim
);
2245 ta_glyph_hints_align_strong_points(hints
, (TA_Dimension
)dim
);
2246 ta_glyph_hints_align_weak_points(hints
, (TA_Dimension
)dim
);
2249 ta_glyph_hints_save(hints
, outline
);
2256 /* XXX: this should probably fine tuned to differentiate better between */
2259 static const TA_Script_UniRangeRec ta_latin_uniranges
[] =
2261 TA_UNIRANGE_REC(0x0020UL
, 0x007FUL
), /* Basic Latin (no control chars) */
2262 TA_UNIRANGE_REC(0x00A0UL
, 0x00FFUL
), /* Latin-1 Supplement (no control chars) */
2263 TA_UNIRANGE_REC(0x0100UL
, 0x017FUL
), /* Latin Extended-A */
2264 TA_UNIRANGE_REC(0x0180UL
, 0x024FUL
), /* Latin Extended-B */
2265 TA_UNIRANGE_REC(0x0250UL
, 0x02AFUL
), /* IPA Extensions */
2266 TA_UNIRANGE_REC(0x02B0UL
, 0x02FFUL
), /* Spacing Modifier Letters */
2267 TA_UNIRANGE_REC(0x0300UL
, 0x036FUL
), /* Combining Diacritical Marks */
2268 TA_UNIRANGE_REC(0x0370UL
, 0x03FFUL
), /* Greek and Coptic */
2269 TA_UNIRANGE_REC(0x0400UL
, 0x04FFUL
), /* Cyrillic */
2270 TA_UNIRANGE_REC(0x0500UL
, 0x052FUL
), /* Cyrillic Supplement */
2271 TA_UNIRANGE_REC(0x1D00UL
, 0x1D7FUL
), /* Phonetic Extensions */
2272 TA_UNIRANGE_REC(0x1D80UL
, 0x1DBFUL
), /* Phonetic Extensions Supplement */
2273 TA_UNIRANGE_REC(0x1DC0UL
, 0x1DFFUL
), /* Combining Diacritical Marks Supplement */
2274 TA_UNIRANGE_REC(0x1E00UL
, 0x1EFFUL
), /* Latin Extended Additional */
2275 TA_UNIRANGE_REC(0x1F00UL
, 0x1FFFUL
), /* Greek Extended */
2276 TA_UNIRANGE_REC(0x2000UL
, 0x206FUL
), /* General Punctuation */
2277 TA_UNIRANGE_REC(0x2070UL
, 0x209FUL
), /* Superscripts and Subscripts */
2278 TA_UNIRANGE_REC(0x20A0UL
, 0x20CFUL
), /* Currency Symbols */
2279 TA_UNIRANGE_REC(0x2150UL
, 0x218FUL
), /* Number Forms */
2280 TA_UNIRANGE_REC(0x2460UL
, 0x24FFUL
), /* Enclosed Alphanumerics */
2281 TA_UNIRANGE_REC(0x2C60UL
, 0x2C7FUL
), /* Latin Extended-C */
2282 TA_UNIRANGE_REC(0x2DE0UL
, 0x2DFFUL
), /* Cyrillic Extended-A */
2283 TA_UNIRANGE_REC(0xA640UL
, 0xA69FUL
), /* Cyrillic Extended-B */
2284 TA_UNIRANGE_REC(0xA720UL
, 0xA7FFUL
), /* Latin Extended-D */
2285 TA_UNIRANGE_REC(0xFB00UL
, 0xFB06UL
), /* Alphab. Present. Forms (Latin Ligs) */
2286 TA_UNIRANGE_REC(0x1D400UL
, 0x1D7FFUL
), /* Mathematical Alphanumeric Symbols */
2287 TA_UNIRANGE_REC(0UL, 0UL)
2291 const TA_ScriptClassRec ta_latin_script_class
=
2296 sizeof (TA_LatinMetricsRec
),
2298 (TA_Script_InitMetricsFunc
)ta_latin_metrics_init
,
2299 (TA_Script_ScaleMetricsFunc
)ta_latin_metrics_scale
,
2300 (TA_Script_DoneMetricsFunc
)NULL
,
2302 (TA_Script_InitHintsFunc
)ta_latin_hints_init
,
2303 (TA_Script_ApplyHintsFunc
)ta_latin_hints_apply
2306 /* end of talatin.c */