1 /***************************************************************************/
5 /* Auto-fitter hinting routines for latin script (body). */
7 /* Copyright 2003, 2004, 2005, 2006, 2007 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
28 /*************************************************************************/
29 /*************************************************************************/
31 /***** L A T I N G L O B A L M E T R I C S *****/
33 /*************************************************************************/
34 /*************************************************************************/
37 af_latin_metrics_init_widths( AF_LatinMetrics metrics
,
41 /* scan the array of segments in each direction */
42 AF_GlyphHintsRec hints
[1];
45 af_glyph_hints_init( hints
, face
->memory
);
47 metrics
->axis
[AF_DIMENSION_HORZ
].width_count
= 0;
48 metrics
->axis
[AF_DIMENSION_VERT
].width_count
= 0;
54 AF_LatinMetricsRec dummy
[1];
55 AF_Scaler scaler
= &dummy
->root
.scaler
;
58 glyph_index
= FT_Get_Char_Index( face
, charcode
);
59 if ( glyph_index
== 0 )
62 error
= FT_Load_Glyph( face
, glyph_index
, FT_LOAD_NO_SCALE
);
63 if ( error
|| face
->glyph
->outline
.n_points
<= 0 )
68 dummy
->units_per_em
= metrics
->units_per_em
;
69 scaler
->x_scale
= scaler
->y_scale
= 0x10000L
;
70 scaler
->x_delta
= scaler
->y_delta
= 0;
72 scaler
->render_mode
= FT_RENDER_MODE_NORMAL
;
75 af_glyph_hints_rescale( hints
, (AF_ScriptMetrics
)dummy
);
77 error
= af_glyph_hints_reload( hints
, &face
->glyph
->outline
, 0 );
81 for ( dim
= 0; dim
< AF_DIMENSION_MAX
; dim
++ )
83 AF_LatinAxis axis
= &metrics
->axis
[dim
];
84 AF_AxisHints axhints
= &hints
->axis
[dim
];
85 AF_Segment seg
, limit
, link
;
86 FT_UInt num_widths
= 0;
89 error
= af_latin_hints_compute_segments( hints
,
94 af_latin_hints_link_segments( hints
,
97 seg
= axhints
->segments
;
98 limit
= seg
+ axhints
->num_segments
;
100 for ( ; seg
< limit
; seg
++ )
104 /* we only consider stem segments there! */
105 if ( link
&& link
->link
== seg
&& link
> seg
)
110 dist
= seg
->pos
- link
->pos
;
114 if ( num_widths
< AF_LATIN_MAX_WIDTHS
)
115 axis
->widths
[ num_widths
++ ].org
= dist
;
119 af_sort_widths( num_widths
, axis
->widths
);
120 axis
->width_count
= num_widths
;
124 for ( dim
= 0; dim
< AF_DIMENSION_MAX
; dim
++ )
126 AF_LatinAxis axis
= &metrics
->axis
[dim
];
130 stdw
= ( axis
->width_count
> 0 )
131 ? axis
->widths
[0].org
132 : AF_LATIN_CONSTANT( metrics
, 50 );
134 /* let's try 20% of the smallest width */
135 axis
->edge_distance_threshold
= stdw
/ 5;
136 axis
->standard_width
= stdw
;
137 axis
->extra_light
= 0;
141 af_glyph_hints_done( hints
);
146 #define AF_LATIN_MAX_TEST_CHARACTERS 12
149 static const char* const af_latin_blue_chars
[AF_LATIN_MAX_BLUES
] =
161 af_latin_metrics_init_blues( AF_LatinMetrics metrics
,
164 FT_Pos flats
[AF_LATIN_MAX_TEST_CHARACTERS
];
165 FT_Pos rounds
[AF_LATIN_MAX_TEST_CHARACTERS
];
171 AF_LatinAxis axis
= &metrics
->axis
[AF_DIMENSION_VERT
];
172 FT_GlyphSlot glyph
= face
->glyph
;
175 /* we compute the blues simply by loading each character from the */
176 /* 'af_latin_blue_chars[blues]' string, then compute its top-most or */
177 /* bottom-most points (depending on `AF_IS_TOP_BLUE') */
179 AF_LOG(( "blue zones computation\n" ));
180 AF_LOG(( "------------------------------------------------\n" ));
182 for ( bb
= 0; bb
< AF_LATIN_BLUE_MAX
; bb
++ )
184 const char* p
= af_latin_blue_chars
[bb
];
185 const char* limit
= p
+ AF_LATIN_MAX_TEST_CHARACTERS
;
190 AF_LOG(( "blue %3d: ", bb
));
195 for ( ; p
< limit
&& *p
; p
++ )
198 FT_Int best_point
, best_y
, best_first
, best_last
;
203 AF_LOG(( "'%c'", *p
));
205 /* load the character in the face -- skip unknown or empty ones */
206 glyph_index
= FT_Get_Char_Index( face
, (FT_UInt
)*p
);
207 if ( glyph_index
== 0 )
210 error
= FT_Load_Glyph( face
, glyph_index
, FT_LOAD_NO_SCALE
);
211 if ( error
|| glyph
->outline
.n_points
<= 0 )
214 /* now compute min or max point indices and coordinates */
215 points
= glyph
->outline
.points
;
217 best_y
= 0; /* make compiler happy */
218 best_first
= 0; /* ditto */
219 best_last
= 0; /* ditto */
227 for ( nn
= 0; nn
< glyph
->outline
.n_contours
; first
= last
+1, nn
++ )
229 FT_Int old_best_point
= best_point
;
233 last
= glyph
->outline
.contours
[nn
];
235 /* Avoid single-point contours since they are never rasterized. */
236 /* In some fonts, they correspond to mark attachment points */
237 /* which are way outside of the glyph's real outline. */
241 if ( AF_LATIN_IS_TOP_BLUE( bb
) )
243 for ( pp
= first
; pp
<= last
; pp
++ )
244 if ( best_point
< 0 || points
[pp
].y
> best_y
)
247 best_y
= points
[pp
].y
;
252 for ( pp
= first
; pp
<= last
; pp
++ )
253 if ( best_point
< 0 || points
[pp
].y
< best_y
)
256 best_y
= points
[pp
].y
;
260 if ( best_point
!= old_best_point
)
266 AF_LOG(( "%5d", best_y
));
269 /* now check whether the point belongs to a straight or round */
270 /* segment; we first need to find in which contour the extremum */
271 /* lies, then inspect its previous and next points */
272 if ( best_point
>= 0 )
278 /* now look for the previous and next points that are not on the */
279 /* same Y coordinate. Threshold the `closeness'... */
285 if ( prev
> best_first
)
290 dist
= points
[prev
].y
- best_y
;
291 if ( dist
< -5 || dist
> 5 )
294 } while ( prev
!= best_point
);
298 if ( next
< best_last
)
303 dist
= points
[next
].y
- best_y
;
304 if ( dist
< -5 || dist
> 5 )
307 } while ( next
!= best_point
);
309 /* now, set the `round' flag depending on the segment's kind */
311 FT_CURVE_TAG( glyph
->outline
.tags
[prev
] ) != FT_CURVE_TAG_ON
||
312 FT_CURVE_TAG( glyph
->outline
.tags
[next
] ) != FT_CURVE_TAG_ON
);
314 AF_LOG(( "%c ", round
? 'r' : 'f' ));
318 rounds
[num_rounds
++] = best_y
;
320 flats
[num_flats
++] = best_y
;
325 if ( num_flats
== 0 && num_rounds
== 0 )
328 * we couldn't find a single glyph to compute this blue zone,
329 * we will simply ignore it then
331 AF_LOG(( "empty!\n" ));
335 /* we have computed the contents of the `rounds' and `flats' tables, */
336 /* now determine the reference and overshoot position of the blue -- */
337 /* we simply take the median value after a simple sort */
338 af_sort_pos( num_rounds
, rounds
);
339 af_sort_pos( num_flats
, flats
);
341 blue
= & axis
->blues
[axis
->blue_count
];
342 blue_ref
= & blue
->ref
.org
;
343 blue_shoot
= & blue
->shoot
.org
;
347 if ( num_flats
== 0 )
350 *blue_shoot
= rounds
[num_rounds
/ 2];
352 else if ( num_rounds
== 0 )
355 *blue_shoot
= flats
[num_flats
/ 2];
359 *blue_ref
= flats
[num_flats
/ 2];
360 *blue_shoot
= rounds
[num_rounds
/ 2];
363 /* there are sometimes problems: if the overshoot position of top */
364 /* zones is under its reference position, or the opposite for bottom */
365 /* zones. We must thus check everything there and correct the errors */
366 if ( *blue_shoot
!= *blue_ref
)
368 FT_Pos ref
= *blue_ref
;
369 FT_Pos shoot
= *blue_shoot
;
370 FT_Bool over_ref
= FT_BOOL( shoot
> ref
);
373 if ( AF_LATIN_IS_TOP_BLUE( bb
) ^ over_ref
)
374 *blue_shoot
= *blue_ref
= ( shoot
+ ref
) / 2;
378 if ( AF_LATIN_IS_TOP_BLUE( bb
) )
379 blue
->flags
|= AF_LATIN_BLUE_TOP
;
382 * The following flags is used later to adjust the y and x scales
383 * in order to optimize the pixel grid alignment of the top of small
386 if ( bb
== AF_LATIN_BLUE_SMALL_TOP
)
387 blue
->flags
|= AF_LATIN_BLUE_ADJUSTMENT
;
389 AF_LOG(( "-- ref = %ld, shoot = %ld\n", *blue_ref
, *blue_shoot
));
396 FT_LOCAL_DEF( FT_Error
)
397 af_latin_metrics_init( AF_LatinMetrics metrics
,
400 FT_Error error
= AF_Err_Ok
;
401 FT_CharMap oldmap
= face
->charmap
;
404 static const FT_Encoding latin_encodings
[] =
407 FT_ENCODING_APPLE_ROMAN
,
408 FT_ENCODING_ADOBE_STANDARD
,
409 FT_ENCODING_ADOBE_LATIN_1
,
410 FT_ENCODING_NONE
/* end of list */
414 metrics
->units_per_em
= face
->units_per_EM
;
416 /* do we have a latin charmap in there? */
417 for ( ee
= 0; latin_encodings
[ee
] != FT_ENCODING_NONE
; ee
++ )
419 error
= FT_Select_Charmap( face
, latin_encodings
[ee
] );
426 /* For now, compute the standard width and height from the `o'. */
427 af_latin_metrics_init_widths( metrics
, face
, 'o' );
428 af_latin_metrics_init_blues( metrics
, face
);
431 FT_Set_Charmap( face
, oldmap
);
437 af_latin_metrics_scale_dim( AF_LatinMetrics metrics
,
447 if ( dim
== AF_DIMENSION_HORZ
)
449 scale
= scaler
->x_scale
;
450 delta
= scaler
->x_delta
;
454 scale
= scaler
->y_scale
;
455 delta
= scaler
->y_delta
;
458 axis
= &metrics
->axis
[dim
];
460 if ( axis
->org_scale
== scale
&& axis
->org_delta
== delta
)
463 axis
->org_scale
= scale
;
464 axis
->org_delta
= delta
;
467 * correct X and Y scale to optimize the alignment of the top of small
468 * letters to the pixel grid
471 AF_LatinAxis Axis
= &metrics
->axis
[AF_DIMENSION_VERT
];
472 AF_LatinBlue blue
= NULL
;
475 for ( nn
= 0; nn
< Axis
->blue_count
; nn
++ )
477 if ( Axis
->blues
[nn
].flags
& AF_LATIN_BLUE_ADJUSTMENT
)
479 blue
= &Axis
->blues
[nn
];
486 FT_Pos scaled
= FT_MulFix( blue
->shoot
.org
, scaler
->y_scale
);
487 FT_Pos fitted
= ( scaled
+ 40 ) & ~63;
490 if ( scaled
!= fitted
)
493 if ( dim
== AF_DIMENSION_HORZ
)
495 if ( fitted
< scaled
)
496 scale
-= scale
/ 50; /* scale *= 0.98 */
500 if ( dim
== AF_DIMENSION_VERT
)
502 scale
= FT_MulDiv( scale
, fitted
, scaled
);
511 if ( dim
== AF_DIMENSION_HORZ
)
513 metrics
->root
.scaler
.x_scale
= scale
;
514 metrics
->root
.scaler
.x_delta
= delta
;
518 metrics
->root
.scaler
.y_scale
= scale
;
519 metrics
->root
.scaler
.y_delta
= delta
;
522 /* scale the standard widths */
523 for ( nn
= 0; nn
< axis
->width_count
; nn
++ )
525 AF_Width width
= axis
->widths
+ nn
;
528 width
->cur
= FT_MulFix( width
->org
, scale
);
529 width
->fit
= width
->cur
;
532 /* an extra-light axis corresponds to a standard width that is */
533 /* smaller than 0.75 pixels */
535 (FT_Bool
)( FT_MulFix( axis
->standard_width
, scale
) < 32 + 8 );
537 if ( dim
== AF_DIMENSION_VERT
)
539 /* scale the blue zones */
540 for ( nn
= 0; nn
< axis
->blue_count
; nn
++ )
542 AF_LatinBlue blue
= &axis
->blues
[nn
];
546 blue
->ref
.cur
= FT_MulFix( blue
->ref
.org
, scale
) + delta
;
547 blue
->ref
.fit
= blue
->ref
.cur
;
548 blue
->shoot
.cur
= FT_MulFix( blue
->shoot
.org
, scale
) + delta
;
549 blue
->shoot
.fit
= blue
->shoot
.cur
;
550 blue
->flags
&= ~AF_LATIN_BLUE_ACTIVE
;
552 /* a blue zone is only active if it is less than 3/4 pixels tall */
553 dist
= FT_MulFix( blue
->ref
.org
- blue
->shoot
.org
, scale
);
554 if ( dist
<= 48 && dist
>= -48 )
556 FT_Pos delta1
, delta2
;
559 delta1
= blue
->shoot
.org
- blue
->ref
.org
;
564 delta2
= FT_MulFix( delta2
, scale
);
568 else if ( delta2
< 64 )
569 delta2
= 32 + ( ( ( delta2
- 32 ) + 16 ) & ~31 );
571 delta2
= FT_PIX_ROUND( delta2
);
576 blue
->ref
.fit
= FT_PIX_ROUND( blue
->ref
.cur
);
577 blue
->shoot
.fit
= blue
->ref
.fit
+ delta2
;
579 blue
->flags
|= AF_LATIN_BLUE_ACTIVE
;
587 af_latin_metrics_scale( AF_LatinMetrics metrics
,
590 metrics
->root
.scaler
.render_mode
= scaler
->render_mode
;
591 metrics
->root
.scaler
.face
= scaler
->face
;
593 af_latin_metrics_scale_dim( metrics
, scaler
, AF_DIMENSION_HORZ
);
594 af_latin_metrics_scale_dim( metrics
, scaler
, AF_DIMENSION_VERT
);
598 /*************************************************************************/
599 /*************************************************************************/
601 /***** L A T I N G L Y P H A N A L Y S I S *****/
603 /*************************************************************************/
604 /*************************************************************************/
606 FT_LOCAL_DEF( FT_Error
)
607 af_latin_hints_compute_segments( AF_GlyphHints hints
,
610 AF_AxisHints axis
= &hints
->axis
[dim
];
611 FT_Memory memory
= hints
->memory
;
612 FT_Error error
= AF_Err_Ok
;
613 AF_Segment segment
= NULL
;
615 AF_Point
* contour
= hints
->contours
;
616 AF_Point
* contour_limit
= contour
+ hints
->num_contours
;
617 AF_Direction major_dir
, segment_dir
;
622 seg0
.flags
= AF_EDGE_NORMAL
;
624 major_dir
= (AF_Direction
)FT_ABS( axis
->major_dir
);
625 segment_dir
= major_dir
;
627 axis
->num_segments
= 0;
629 /* set up (u,v) in each point */
630 if ( dim
== AF_DIMENSION_HORZ
)
632 AF_Point point
= hints
->points
;
633 AF_Point limit
= point
+ hints
->num_points
;
636 for ( ; point
< limit
; point
++ )
638 point
->u
= point
->fx
;
639 point
->v
= point
->fy
;
644 AF_Point point
= hints
->points
;
645 AF_Point limit
= point
+ hints
->num_points
;
648 for ( ; point
< limit
; point
++ )
650 point
->u
= point
->fy
;
651 point
->v
= point
->fx
;
655 /* do each contour separately */
656 for ( ; contour
< contour_limit
; contour
++ )
658 AF_Point point
= contour
[0];
659 AF_Point last
= point
->prev
;
661 FT_Pos min_pos
= 32000; /* minimum segment pos != min_coord */
662 FT_Pos max_pos
= -32000; /* maximum segment pos != max_coord */
666 if ( point
== last
) /* skip singletons -- just in case */
669 if ( FT_ABS( last
->out_dir
) == major_dir
&&
670 FT_ABS( point
->out_dir
) == major_dir
)
672 /* we are already on an edge, try to locate its start */
678 if ( FT_ABS( point
->out_dir
) != major_dir
)
704 if ( point
->out_dir
!= segment_dir
|| point
== last
)
706 /* we are just leaving an edge; record a new segment! */
707 segment
->last
= point
;
708 segment
->pos
= (FT_Short
)( ( min_pos
+ max_pos
) >> 1 );
710 /* a segment is round if either its first or last point */
711 /* is a control point */
712 if ( ( segment
->first
->flags
| point
->flags
) &
714 segment
->flags
|= AF_EDGE_ROUND
;
716 /* compute segment size */
717 min_pos
= max_pos
= point
->v
;
719 v
= segment
->first
->v
;
725 segment
->min_coord
= (FT_Short
)min_pos
;
726 segment
->max_coord
= (FT_Short
)max_pos
;
727 segment
->height
= (FT_Short
)( segment
->max_coord
-
728 segment
->min_coord
);
736 /* now exit if we are at the start/end point */
744 if ( !on_edge
&& FT_ABS( point
->out_dir
) == major_dir
)
746 /* this is the start of a new segment! */
747 segment_dir
= (AF_Direction
)point
->out_dir
;
749 /* clear all segment fields */
750 error
= af_axis_hints_new_segment( axis
, memory
, &segment
);
755 segment
->dir
= (FT_Char
)segment_dir
;
756 min_pos
= max_pos
= point
->u
;
757 segment
->first
= point
;
758 segment
->last
= point
;
759 segment
->contour
= contour
;
769 /* now slightly increase the height of segments when this makes */
770 /* sense -- this is used to better detect and ignore serifs */
772 AF_Segment segments
= axis
->segments
;
773 AF_Segment segments_end
= segments
+ axis
->num_segments
;
776 for ( segment
= segments
; segment
< segments_end
; segment
++ )
778 AF_Point first
= segment
->first
;
779 AF_Point last
= segment
->last
;
780 FT_Pos first_v
= first
->v
;
781 FT_Pos last_v
= last
->v
;
787 if ( first_v
< last_v
)
793 if ( p
->v
< first_v
)
794 segment
->height
= (FT_Short
)( segment
->height
+
795 ( ( first_v
- p
->v
) >> 1 ) );
799 segment
->height
= (FT_Short
)( segment
->height
+
800 ( ( p
->v
- last_v
) >> 1 ) );
808 if ( p
->v
> first_v
)
809 segment
->height
= (FT_Short
)( segment
->height
+
810 ( ( p
->v
- first_v
) >> 1 ) );
814 segment
->height
= (FT_Short
)( segment
->height
+
815 ( ( last_v
- p
->v
) >> 1 ) );
826 af_latin_hints_link_segments( AF_GlyphHints hints
,
829 AF_AxisHints axis
= &hints
->axis
[dim
];
830 AF_Segment segments
= axis
->segments
;
831 AF_Segment segment_limit
= segments
+ axis
->num_segments
;
832 FT_Pos len_threshold
, len_score
;
833 AF_Segment seg1
, seg2
;
836 len_threshold
= AF_LATIN_CONSTANT( hints
->metrics
, 8 );
837 if ( len_threshold
== 0 )
840 len_score
= AF_LATIN_CONSTANT( hints
->metrics
, 6000 );
842 /* now compare each segment to the others */
843 for ( seg1
= segments
; seg1
< segment_limit
; seg1
++ )
845 /* the fake segments are introduced to hint the metrics -- */
846 /* we must never link them to anything */
847 if ( seg1
->dir
!= axis
->major_dir
|| seg1
->first
== seg1
->last
)
850 for ( seg2
= segments
; seg2
< segment_limit
; seg2
++ )
851 if ( seg1
->dir
+ seg2
->dir
== 0 && seg2
->pos
> seg1
->pos
)
853 FT_Pos pos1
= seg1
->pos
;
854 FT_Pos pos2
= seg2
->pos
;
855 FT_Pos dist
= pos2
- pos1
;
862 FT_Pos min
= seg1
->min_coord
;
863 FT_Pos max
= seg1
->max_coord
;
867 if ( min
< seg2
->min_coord
)
868 min
= seg2
->min_coord
;
870 if ( max
> seg2
->max_coord
)
871 max
= seg2
->max_coord
;
874 if ( len
>= len_threshold
)
876 score
= dist
+ len_score
/ len
;
878 if ( score
< seg1
->score
)
884 if ( score
< seg2
->score
)
894 /* now, compute the `serif' segments */
895 for ( seg1
= segments
; seg1
< segment_limit
; seg1
++ )
901 if ( seg2
->link
!= seg1
)
904 seg1
->serif
= seg2
->link
;
911 FT_LOCAL_DEF( FT_Error
)
912 af_latin_hints_compute_edges( AF_GlyphHints hints
,
915 AF_AxisHints axis
= &hints
->axis
[dim
];
916 FT_Error error
= AF_Err_Ok
;
917 FT_Memory memory
= hints
->memory
;
918 AF_LatinAxis laxis
= &((AF_LatinMetrics
)hints
->metrics
)->axis
[dim
];
920 AF_Segment segments
= axis
->segments
;
921 AF_Segment segment_limit
= segments
+ axis
->num_segments
;
926 FT_Pos edge_distance_threshold
;
927 FT_Pos segment_length_threshold
;
932 scale
= ( dim
== AF_DIMENSION_HORZ
) ? hints
->x_scale
935 up_dir
= ( dim
== AF_DIMENSION_HORZ
) ? AF_DIR_UP
939 * We ignore all segments that are less than 1 pixels in length,
940 * to avoid many problems with serif fonts. We compute the
941 * corresponding threshold in font units.
943 if ( dim
== AF_DIMENSION_HORZ
)
944 segment_length_threshold
= FT_DivFix( 64, hints
->y_scale
);
946 segment_length_threshold
= 0;
948 /*********************************************************************/
950 /* We will begin by generating a sorted table of edges for the */
951 /* current direction. To do so, we simply scan each segment and try */
952 /* to find an edge in our table that corresponds to its position. */
954 /* If no edge is found, we create and insert a new edge in the */
955 /* sorted table. Otherwise, we simply add the segment to the edge's */
956 /* list which will be processed in the second step to compute the */
957 /* edge's properties. */
959 /* Note that the edges table is sorted along the segment/edge */
962 /*********************************************************************/
964 edge_distance_threshold
= FT_MulFix( laxis
->edge_distance_threshold
,
966 if ( edge_distance_threshold
> 64 / 4 )
967 edge_distance_threshold
= 64 / 4;
969 edge_distance_threshold
= FT_DivFix( edge_distance_threshold
,
972 for ( seg
= segments
; seg
< segment_limit
; seg
++ )
978 if ( seg
->height
< segment_length_threshold
)
981 /* A special case for serif edges: If they are smaller than */
982 /* 1.5 pixels we ignore them. */
984 2 * seg
->height
< 3 * segment_length_threshold
)
987 /* look for an edge corresponding to the segment */
988 for ( ee
= 0; ee
< axis
->num_edges
; ee
++ )
990 AF_Edge edge
= axis
->edges
+ ee
;
994 dist
= seg
->pos
- edge
->fpos
;
998 if ( dist
< edge_distance_threshold
&& edge
->dir
== seg
->dir
)
1010 /* insert a new edge in the list and */
1011 /* sort according to the position */
1012 error
= af_axis_hints_new_edge( axis
, seg
->pos
,
1013 (AF_Direction
)seg
->dir
,
1018 /* add the segment to the new edge's list */
1023 edge
->fpos
= seg
->pos
;
1024 edge
->dir
= seg
->dir
;
1025 edge
->opos
= edge
->pos
= FT_MulFix( seg
->pos
, scale
);
1026 seg
->edge_next
= seg
;
1030 /* if an edge was found, simply add the segment to the edge's */
1032 seg
->edge_next
= found
->first
;
1033 found
->last
->edge_next
= seg
;
1039 /*********************************************************************/
1041 /* Good, we will now compute each edge's properties according to */
1042 /* segments found on its position. Basically, these are: */
1044 /* - edge's main direction */
1045 /* - stem edge, serif edge or both (which defaults to stem then) */
1046 /* - rounded edge, straight or both (which defaults to straight) */
1047 /* - link for edge */
1049 /*********************************************************************/
1051 /* first of all, set the `edge' field in each segment -- this is */
1052 /* required in order to compute edge links */
1055 * Note that removing this loop and setting the `edge' field of each
1056 * segment directly in the code above slows down execution speed for
1057 * some reasons on platforms like the Sun.
1060 AF_Edge edges
= axis
->edges
;
1061 AF_Edge edge_limit
= edges
+ axis
->num_edges
;
1065 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1072 seg
= seg
->edge_next
;
1074 } while ( seg
!= edge
->first
);
1077 /* now, compute each edge properties */
1078 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1080 FT_Int is_round
= 0; /* does it contain round segments? */
1081 FT_Int is_straight
= 0; /* does it contain straight segments? */
1082 FT_Pos ups
= 0; /* number of upwards segments */
1083 FT_Pos downs
= 0; /* number of downwards segments */
1093 /* check for roundness of segment */
1094 if ( seg
->flags
& AF_EDGE_ROUND
)
1099 /* check for segment direction */
1100 if ( seg
->dir
== up_dir
)
1101 ups
+= seg
->max_coord
-seg
->min_coord
;
1103 downs
+= seg
->max_coord
-seg
->min_coord
;
1105 /* check for links -- if seg->serif is set, then seg->link must */
1107 is_serif
= (FT_Bool
)( seg
->serif
&&
1109 seg
->serif
->edge
!= edge
);
1111 if ( ( seg
->link
&& seg
->link
->edge
!= NULL
) || is_serif
)
1123 edge2
= edge
->serif
;
1132 edge_delta
= edge
->fpos
- edge2
->fpos
;
1133 if ( edge_delta
< 0 )
1134 edge_delta
= -edge_delta
;
1136 seg_delta
= seg
->pos
- seg2
->pos
;
1137 if ( seg_delta
< 0 )
1138 seg_delta
= -seg_delta
;
1140 if ( seg_delta
< edge_delta
)
1148 edge
->serif
= edge2
;
1149 edge2
->flags
|= AF_EDGE_SERIF
;
1155 seg
= seg
->edge_next
;
1157 } while ( seg
!= edge
->first
);
1159 /* set the round/straight flags */
1160 edge
->flags
= AF_EDGE_NORMAL
;
1162 if ( is_round
> 0 && is_round
>= is_straight
)
1163 edge
->flags
|= AF_EDGE_ROUND
;
1166 /* set the edge's main direction */
1167 edge
->dir
= AF_DIR_NONE
;
1170 edge
->dir
= (FT_Char
)up_dir
;
1172 else if ( ups
< downs
)
1173 edge
->dir
= (FT_Char
)-up_dir
;
1175 else if ( ups
== downs
)
1176 edge
->dir
= 0; /* both up and down! */
1179 /* gets rid of serifs if link is set */
1180 /* XXX: This gets rid of many unpleasant artefacts! */
1181 /* Example: the `c' in cour.pfa at size 13 */
1183 if ( edge
->serif
&& edge
->link
)
1193 FT_LOCAL_DEF( FT_Error
)
1194 af_latin_hints_detect_features( AF_GlyphHints hints
,
1200 error
= af_latin_hints_compute_segments( hints
, dim
);
1203 af_latin_hints_link_segments( hints
, dim
);
1205 error
= af_latin_hints_compute_edges( hints
, dim
);
1211 FT_LOCAL_DEF( void )
1212 af_latin_hints_compute_blue_edges( AF_GlyphHints hints
,
1213 AF_LatinMetrics metrics
)
1215 AF_AxisHints axis
= &hints
->axis
[ AF_DIMENSION_VERT
];
1216 AF_Edge edge
= axis
->edges
;
1217 AF_Edge edge_limit
= edge
+ axis
->num_edges
;
1218 AF_LatinAxis latin
= &metrics
->axis
[ AF_DIMENSION_VERT
];
1219 FT_Fixed scale
= latin
->scale
;
1222 /* compute which blue zones are active, i.e. have their scaled */
1223 /* size < 3/4 pixels */
1225 /* for each horizontal edge search the blue zone which is closest */
1226 for ( ; edge
< edge_limit
; edge
++ )
1229 AF_Width best_blue
= NULL
;
1230 FT_Pos best_dist
; /* initial threshold */
1233 /* compute the initial threshold as a fraction of the EM size */
1234 best_dist
= FT_MulFix( metrics
->units_per_em
/ 40, scale
);
1236 if ( best_dist
> 64 / 2 )
1239 for ( bb
= 0; bb
< AF_LATIN_BLUE_MAX
; bb
++ )
1241 AF_LatinBlue blue
= latin
->blues
+ bb
;
1242 FT_Bool is_top_blue
, is_major_dir
;
1245 /* skip inactive blue zones (i.e., those that are too small) */
1246 if ( !( blue
->flags
& AF_LATIN_BLUE_ACTIVE
) )
1249 /* if it is a top zone, check for right edges -- if it is a bottom */
1250 /* zone, check for left edges */
1252 /* of course, that's for TrueType */
1253 is_top_blue
= (FT_Byte
)( ( blue
->flags
& AF_LATIN_BLUE_TOP
) != 0 );
1254 is_major_dir
= FT_BOOL( edge
->dir
== axis
->major_dir
);
1256 /* if it is a top zone, the edge must be against the major */
1257 /* direction; if it is a bottom zone, it must be in the major */
1259 if ( is_top_blue
^ is_major_dir
)
1264 /* first of all, compare it to the reference position */
1265 dist
= edge
->fpos
- blue
->ref
.org
;
1269 dist
= FT_MulFix( dist
, scale
);
1270 if ( dist
< best_dist
)
1273 best_blue
= & blue
->ref
;
1276 /* now, compare it to the overshoot position if the edge is */
1277 /* rounded, and if the edge is over the reference position of a */
1278 /* top zone, or under the reference position of a bottom zone */
1279 if ( edge
->flags
& AF_EDGE_ROUND
&& dist
!= 0 )
1281 FT_Bool is_under_ref
= FT_BOOL( edge
->fpos
< blue
->ref
.org
);
1284 if ( is_top_blue
^ is_under_ref
)
1286 blue
= latin
->blues
+ bb
;
1287 dist
= edge
->fpos
- blue
->shoot
.org
;
1291 dist
= FT_MulFix( dist
, scale
);
1292 if ( dist
< best_dist
)
1295 best_blue
= & blue
->shoot
;
1303 edge
->blue_edge
= best_blue
;
1309 af_latin_hints_init( AF_GlyphHints hints
,
1310 AF_LatinMetrics metrics
)
1312 FT_Render_Mode mode
;
1313 FT_UInt32 scaler_flags
, other_flags
;
1314 FT_Face face
= metrics
->root
.scaler
.face
;
1317 af_glyph_hints_rescale( hints
, (AF_ScriptMetrics
)metrics
);
1320 * correct x_scale and y_scale if needed, since they may have
1321 * been modified `af_latin_metrics_scale_dim' above
1323 hints
->x_scale
= metrics
->axis
[AF_DIMENSION_HORZ
].scale
;
1324 hints
->x_delta
= metrics
->axis
[AF_DIMENSION_HORZ
].delta
;
1325 hints
->y_scale
= metrics
->axis
[AF_DIMENSION_VERT
].scale
;
1326 hints
->y_delta
= metrics
->axis
[AF_DIMENSION_VERT
].delta
;
1328 /* compute flags depending on render mode, etc. */
1329 mode
= metrics
->root
.scaler
.render_mode
;
1331 #if 0 /* #ifdef AF_USE_WARPER */
1332 if ( mode
== FT_RENDER_MODE_LCD
|| mode
== FT_RENDER_MODE_LCD_V
)
1334 metrics
->root
.scaler
.render_mode
= mode
= FT_RENDER_MODE_NORMAL
;
1338 scaler_flags
= hints
->scaler_flags
;
1342 * We snap the width of vertical stems for the monochrome and
1343 * horizontal LCD rendering targets only.
1345 if ( mode
== FT_RENDER_MODE_MONO
|| mode
== FT_RENDER_MODE_LCD
)
1346 other_flags
|= AF_LATIN_HINTS_HORZ_SNAP
;
1349 * We snap the width of horizontal stems for the monochrome and
1350 * vertical LCD rendering targets only.
1352 if ( mode
== FT_RENDER_MODE_MONO
|| mode
== FT_RENDER_MODE_LCD_V
)
1353 other_flags
|= AF_LATIN_HINTS_VERT_SNAP
;
1356 * We adjust stems to full pixels only if we don't use the `light' mode.
1358 if ( mode
!= FT_RENDER_MODE_LIGHT
)
1359 other_flags
|= AF_LATIN_HINTS_STEM_ADJUST
;
1361 if ( mode
== FT_RENDER_MODE_MONO
)
1362 other_flags
|= AF_LATIN_HINTS_MONO
;
1365 * In `light' hinting mode we disable horizontal hinting completely.
1366 * We also do it if the face is italic.
1368 if ( mode
== FT_RENDER_MODE_LIGHT
||
1369 (face
->style_flags
& FT_STYLE_FLAG_ITALIC
) != 0 )
1370 scaler_flags
|= AF_SCALER_FLAG_NO_HORIZONTAL
;
1372 hints
->scaler_flags
= scaler_flags
;
1373 hints
->other_flags
= other_flags
;
1379 /*************************************************************************/
1380 /*************************************************************************/
1382 /***** L A T I N G L Y P H G R I D - F I T T I N G *****/
1384 /*************************************************************************/
1385 /*************************************************************************/
1387 /* snap a given width in scaled coordinates to one of the */
1388 /* current standard widths */
1391 af_latin_snap_width( AF_Width widths
,
1396 FT_Pos best
= 64 + 32 + 2;
1397 FT_Pos reference
= width
;
1401 for ( n
= 0; n
< count
; n
++ )
1418 scaled
= FT_PIX_ROUND( reference
);
1420 if ( width
>= reference
)
1422 if ( width
< scaled
+ 48 )
1427 if ( width
> scaled
- 48 )
1435 /* compute the snapped width of a given stem */
1438 af_latin_compute_stem_width( AF_GlyphHints hints
,
1441 AF_Edge_Flags base_flags
,
1442 AF_Edge_Flags stem_flags
)
1444 AF_LatinMetrics metrics
= (AF_LatinMetrics
) hints
->metrics
;
1445 AF_LatinAxis axis
= & metrics
->axis
[dim
];
1446 FT_Pos dist
= width
;
1448 FT_Int vertical
= ( dim
== AF_DIMENSION_VERT
);
1451 if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints
) ||
1461 if ( ( vertical
&& !AF_LATIN_HINTS_DO_VERT_SNAP( hints
) ) ||
1462 ( !vertical
&& !AF_LATIN_HINTS_DO_HORZ_SNAP( hints
) ) )
1464 /* smooth hinting process: very lightly quantize the stem width */
1466 /* leave the widths of serifs alone */
1468 if ( ( stem_flags
& AF_EDGE_SERIF
) && vertical
&& ( dist
< 3 * 64 ) )
1471 else if ( ( base_flags
& AF_EDGE_ROUND
) )
1476 else if ( dist
< 56 )
1479 if ( axis
->width_count
> 0 )
1484 /* compare to standard width */
1485 if ( axis
->width_count
> 0 )
1487 delta
= dist
- axis
->widths
[0].cur
;
1494 dist
= axis
->widths
[0].cur
;
1502 if ( dist
< 3 * 64 )
1510 else if ( delta
< 32 )
1513 else if ( delta
< 54 )
1520 dist
= ( dist
+ 32 ) & ~63;
1525 /* strong hinting process: snap the stem width to integer pixels */
1526 FT_Pos org_dist
= dist
;
1529 dist
= af_latin_snap_width( axis
->widths
, axis
->width_count
, dist
);
1533 /* in the case of vertical hinting, always round */
1534 /* the stem heights to integer pixels */
1537 dist
= ( dist
+ 16 ) & ~63;
1543 if ( AF_LATIN_HINTS_DO_MONO( hints
) )
1545 /* monochrome horizontal hinting: snap widths to integer pixels */
1546 /* with a different threshold */
1551 dist
= ( dist
+ 32 ) & ~63;
1555 /* for horizontal anti-aliased hinting, we adopt a more subtle */
1556 /* approach: we strengthen small stems, round stems whose size */
1557 /* is between 1 and 2 pixels to an integer, otherwise nothing */
1560 dist
= ( dist
+ 64 ) >> 1;
1562 else if ( dist
< 128 )
1564 /* We only round to an integer width if the corresponding */
1565 /* distortion is less than 1/4 pixel. Otherwise this */
1566 /* makes everything worse since the diagonals, which are */
1567 /* not hinted, appear a lot bolder or thinner than the */
1568 /* vertical stems. */
1573 dist
= ( dist
+ 22 ) & ~63;
1574 delta
= dist
- org_dist
;
1582 dist
= ( dist
+ 64 ) >> 1;
1586 /* round otherwise to prevent color fringes in LCD mode */
1587 dist
= ( dist
+ 32 ) & ~63;
1600 /* align one stem edge relative to the previous stem edge */
1603 af_latin_align_linked_edge( AF_GlyphHints hints
,
1608 FT_Pos dist
= stem_edge
->opos
- base_edge
->opos
;
1610 FT_Pos fitted_width
= af_latin_compute_stem_width(
1612 (AF_Edge_Flags
)base_edge
->flags
,
1613 (AF_Edge_Flags
)stem_edge
->flags
);
1616 stem_edge
->pos
= base_edge
->pos
+ fitted_width
;
1618 AF_LOG(( "LINK: edge %d (opos=%.2f) linked to (%.2f), "
1619 "dist was %.2f, now %.2f\n",
1620 stem_edge
-hints
->axis
[dim
].edges
, stem_edge
->opos
/ 64.0,
1621 stem_edge
->pos
/ 64.0, dist
/ 64.0, fitted_width
/ 64.0 ));
1626 af_latin_align_serif_edge( AF_GlyphHints hints
,
1632 serif
->pos
= base
->pos
+ (serif
->opos
- base
->opos
);
1636 /*************************************************************************/
1637 /*************************************************************************/
1638 /*************************************************************************/
1640 /**** E D G E H I N T I N G ****/
1642 /*************************************************************************/
1643 /*************************************************************************/
1644 /*************************************************************************/
1647 FT_LOCAL_DEF( void )
1648 af_latin_hint_edges( AF_GlyphHints hints
,
1651 AF_AxisHints axis
= &hints
->axis
[dim
];
1652 AF_Edge edges
= axis
->edges
;
1653 AF_Edge edge_limit
= edges
+ axis
->num_edges
;
1657 FT_Int has_serifs
= 0;
1660 /* we begin by aligning all stems relative to the blue zone */
1661 /* if needed -- that's only for horizontal edges */
1663 if ( dim
== AF_DIMENSION_VERT
&& AF_HINTS_DO_BLUES( hints
) )
1665 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1668 AF_Edge edge1
, edge2
;
1671 if ( edge
->flags
& AF_EDGE_DONE
)
1674 blue
= edge
->blue_edge
;
1682 else if ( edge2
&& edge2
->blue_edge
)
1684 blue
= edge2
->blue_edge
;
1692 AF_LOG(( "BLUE: edge %d (opos=%.2f) snapped to (%.2f), "
1694 edge1
-edges
, edge1
->opos
/ 64.0, blue
->fit
/ 64.0,
1695 edge1
->pos
/ 64.0 ));
1697 edge1
->pos
= blue
->fit
;
1698 edge1
->flags
|= AF_EDGE_DONE
;
1700 if ( edge2
&& !edge2
->blue_edge
)
1702 af_latin_align_linked_edge( hints
, dim
, edge1
, edge2
);
1703 edge2
->flags
|= AF_EDGE_DONE
;
1711 /* now we will align all stem edges, trying to maintain the */
1712 /* relative order of stems in the glyph */
1713 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1718 if ( edge
->flags
& AF_EDGE_DONE
)
1721 /* skip all non-stem edges */
1729 /* now align the stem */
1731 /* this should not happen, but it's better to be safe */
1732 if ( edge2
->blue_edge
)
1734 AF_LOG(( "ASSERTION FAILED for edge %d\n", edge2
-edges
));
1736 af_latin_align_linked_edge( hints
, dim
, edge2
, edge
);
1737 edge
->flags
|= AF_EDGE_DONE
;
1743 FT_Pos org_len
, org_center
, cur_len
;
1744 FT_Pos cur_pos1
, error1
, error2
, u_off
, d_off
;
1747 org_len
= edge2
->opos
- edge
->opos
;
1748 cur_len
= af_latin_compute_stem_width(
1749 hints
, dim
, org_len
,
1750 (AF_Edge_Flags
)edge
->flags
,
1751 (AF_Edge_Flags
)edge2
->flags
);
1752 if ( cur_len
<= 64 )
1762 org_center
= edge
->opos
+ ( org_len
>> 1 );
1764 cur_pos1
= FT_PIX_ROUND( org_center
);
1766 error1
= org_center
- ( cur_pos1
- u_off
);
1770 error2
= org_center
- ( cur_pos1
+ d_off
);
1774 if ( error1
< error2
)
1779 edge
->pos
= cur_pos1
- cur_len
/ 2;
1780 edge2
->pos
= edge
->pos
+ cur_len
;
1783 edge
->pos
= FT_PIX_ROUND( edge
->opos
);
1785 AF_LOG(( "ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f) "
1786 "snapped to (%.2f) (%.2f)\n",
1787 edge
-edges
, edge
->opos
/ 64.0,
1788 edge2
-edges
, edge2
->opos
/ 64.0,
1789 edge
->pos
/ 64.0, edge2
->pos
/ 64.0 ));
1792 edge
->flags
|= AF_EDGE_DONE
;
1794 af_latin_align_linked_edge( hints
, dim
, edge
, edge2
);
1798 FT_Pos org_pos
, org_len
, org_center
, cur_len
;
1799 FT_Pos cur_pos1
, cur_pos2
, delta1
, delta2
;
1802 org_pos
= anchor
->pos
+ ( edge
->opos
- anchor
->opos
);
1803 org_len
= edge2
->opos
- edge
->opos
;
1804 org_center
= org_pos
+ ( org_len
>> 1 );
1806 cur_len
= af_latin_compute_stem_width(
1807 hints
, dim
, org_len
,
1808 (AF_Edge_Flags
)edge
->flags
,
1809 (AF_Edge_Flags
)edge2
->flags
);
1811 if ( edge2
->flags
& AF_EDGE_DONE
)
1812 edge
->pos
= edge2
->pos
- cur_len
;
1814 else if ( cur_len
< 96 )
1816 FT_Pos u_off
, d_off
;
1819 cur_pos1
= FT_PIX_ROUND( org_center
);
1829 delta1
= org_center
- ( cur_pos1
- u_off
);
1833 delta2
= org_center
- ( cur_pos1
+ d_off
);
1837 if ( delta1
< delta2
)
1842 edge
->pos
= cur_pos1
- cur_len
/ 2;
1843 edge2
->pos
= cur_pos1
+ cur_len
/ 2;
1845 AF_LOG(( "STEM: %d (opos=%.2f) to %d (opos=%.2f) "
1846 "snapped to (%.2f) and (%.2f)\n",
1847 edge
-edges
, edge
->opos
/ 64.0,
1848 edge2
-edges
, edge2
->opos
/ 64.0,
1849 edge
->pos
/ 64.0, edge2
->pos
/ 64.0 ));
1853 org_pos
= anchor
->pos
+ ( edge
->opos
- anchor
->opos
);
1854 org_len
= edge2
->opos
- edge
->opos
;
1855 org_center
= org_pos
+ ( org_len
>> 1 );
1857 cur_len
= af_latin_compute_stem_width(
1858 hints
, dim
, org_len
,
1859 (AF_Edge_Flags
)edge
->flags
,
1860 (AF_Edge_Flags
)edge2
->flags
);
1862 cur_pos1
= FT_PIX_ROUND( org_pos
);
1863 delta1
= cur_pos1
+ ( cur_len
>> 1 ) - org_center
;
1867 cur_pos2
= FT_PIX_ROUND( org_pos
+ org_len
) - cur_len
;
1868 delta2
= cur_pos2
+ ( cur_len
>> 1 ) - org_center
;
1872 edge
->pos
= ( delta1
< delta2
) ? cur_pos1
: cur_pos2
;
1873 edge2
->pos
= edge
->pos
+ cur_len
;
1875 AF_LOG(( "STEM: %d (opos=%.2f) to %d (opos=%.2f) "
1876 "snapped to (%.2f) and (%.2f)\n",
1877 edge
-edges
, edge
->opos
/ 64.0,
1878 edge2
-edges
, edge2
->opos
/ 64.0,
1879 edge
->pos
/ 64.0, edge2
->pos
/ 64.0 ));
1882 edge
->flags
|= AF_EDGE_DONE
;
1883 edge2
->flags
|= AF_EDGE_DONE
;
1885 if ( edge
> edges
&& edge
->pos
< edge
[-1].pos
)
1887 AF_LOG(( "BOUND: %d (pos=%.2f) to (%.2f)\n",
1888 edge
-edges
, edge
->pos
/ 64.0, edge
[-1].pos
/ 64.0 ));
1889 edge
->pos
= edge
[-1].pos
;
1894 /* make sure that lowercase m's maintain their symmetry */
1896 /* In general, lowercase m's have six vertical edges if they are sans */
1897 /* serif, or twelve if they are with serifs. This implementation is */
1898 /* based on that assumption, and seems to work very well with most */
1899 /* faces. However, if for a certain face this assumption is not */
1900 /* true, the m is just rendered like before. In addition, any stem */
1901 /* correction will only be applied to symmetrical glyphs (even if the */
1902 /* glyph is not an m), so the potential for unwanted distortion is */
1903 /* relatively low. */
1905 /* We don't handle horizontal edges since we can't easily assure that */
1906 /* the third (lowest) stem aligns with the base line; it might end up */
1907 /* one pixel higher or lower. */
1909 n_edges
= edge_limit
- edges
;
1910 if ( dim
== AF_DIMENSION_HORZ
&& ( n_edges
== 6 || n_edges
== 12 ) )
1912 AF_Edge edge1
, edge2
, edge3
;
1913 FT_Pos dist1
, dist2
, span
, delta
;
1929 dist1
= edge2
->opos
- edge1
->opos
;
1930 dist2
= edge3
->opos
- edge2
->opos
;
1932 span
= dist1
- dist2
;
1938 delta
= edge3
->pos
- ( 2 * edge2
->pos
- edge1
->pos
);
1939 edge3
->pos
-= delta
;
1941 edge3
->link
->pos
-= delta
;
1943 /* move the serifs along with the stem */
1944 if ( n_edges
== 12 )
1946 ( edges
+ 8 )->pos
-= delta
;
1947 ( edges
+ 11 )->pos
-= delta
;
1950 edge3
->flags
|= AF_EDGE_DONE
;
1952 edge3
->link
->flags
|= AF_EDGE_DONE
;
1956 if ( has_serifs
|| !anchor
)
1959 * now hint the remaining edges (serifs and single) in order
1960 * to complete our processing
1962 for ( edge
= edges
; edge
< edge_limit
; edge
++ )
1967 if ( edge
->flags
& AF_EDGE_DONE
)
1974 delta
= edge
->serif
->opos
- edge
->opos
;
1979 if ( delta
< 64 + 16 )
1981 af_latin_align_serif_edge( hints
, edge
->serif
, edge
);
1982 AF_LOG(( "SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f) "
1983 "aligned to (%.2f)\n",
1984 edge
-edges
, edge
->opos
/ 64.0,
1985 edge
->serif
- edges
, edge
->serif
->opos
/ 64.0,
1986 edge
->pos
/ 64.0 ));
1990 AF_LOG(( "SERIF_ANCHOR: edge %d (opos=%.2f) snapped to (%.2f)\n",
1991 edge
-edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0 ));
1992 edge
->pos
= FT_PIX_ROUND( edge
->opos
);
1997 AF_Edge before
, after
;
2000 for ( before
= edge
- 1; before
>= edges
; before
-- )
2001 if ( before
->flags
& AF_EDGE_DONE
)
2004 for ( after
= edge
+ 1; after
< edge_limit
; after
++ )
2005 if ( after
->flags
& AF_EDGE_DONE
)
2008 if ( before
>= edges
&& before
< edge
&&
2009 after
< edge_limit
&& after
> edge
)
2011 edge
->pos
= before
->pos
+
2012 FT_MulDiv( edge
->opos
- before
->opos
,
2013 after
->pos
- before
->pos
,
2014 after
->opos
- before
->opos
);
2015 AF_LOG(( "SERIF_LINK1: edge %d (opos=%.2f) snapped to (%.2f) "
2016 "from %d (opos=%.2f)\n",
2017 edge
-edges
, edge
->opos
/ 64.0,
2018 edge
->pos
/ 64.0, before
- edges
,
2019 before
->opos
/ 64.0 ));
2023 edge
->pos
= anchor
->pos
+
2024 ( ( edge
->opos
- anchor
->opos
+ 16 ) & ~31 );
2025 AF_LOG(( "SERIF_LINK2: edge %d (opos=%.2f) snapped to (%.2f)\n",
2026 edge
-edges
, edge
->opos
/ 64.0, edge
->pos
/ 64.0 ));
2030 edge
->flags
|= AF_EDGE_DONE
;
2032 if ( edge
> edges
&& edge
->pos
< edge
[-1].pos
)
2033 edge
->pos
= edge
[-1].pos
;
2035 if ( edge
+ 1 < edge_limit
&&
2036 edge
[1].flags
& AF_EDGE_DONE
&&
2037 edge
->pos
> edge
[1].pos
)
2038 edge
->pos
= edge
[1].pos
;
2045 af_latin_hints_apply( AF_GlyphHints hints
,
2046 FT_Outline
* outline
,
2047 AF_LatinMetrics metrics
)
2053 error
= af_glyph_hints_reload( hints
, outline
, 1 );
2057 /* analyze glyph outline */
2058 #ifdef AF_USE_WARPER
2059 if ( metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
||
2060 AF_HINTS_DO_HORIZONTAL( hints
) )
2062 if ( AF_HINTS_DO_HORIZONTAL( hints
) )
2065 error
= af_latin_hints_detect_features( hints
, AF_DIMENSION_HORZ
);
2070 if ( AF_HINTS_DO_VERTICAL( hints
) )
2072 error
= af_latin_hints_detect_features( hints
, AF_DIMENSION_VERT
);
2076 af_latin_hints_compute_blue_edges( hints
, metrics
);
2079 /* grid-fit the outline */
2080 for ( dim
= 0; dim
< AF_DIMENSION_MAX
; dim
++ )
2082 #ifdef AF_USE_WARPER
2083 if ( ( dim
== AF_DIMENSION_HORZ
&&
2084 metrics
->root
.scaler
.render_mode
== FT_RENDER_MODE_LIGHT
) )
2086 AF_WarperRec warper
;
2091 af_warper_compute( &warper
, hints
, dim
, &scale
, &delta
);
2092 af_glyph_hints_scale_dim( hints
, dim
, scale
, delta
);
2097 if ( ( dim
== AF_DIMENSION_HORZ
&& AF_HINTS_DO_HORIZONTAL( hints
) ) ||
2098 ( dim
== AF_DIMENSION_VERT
&& AF_HINTS_DO_VERTICAL( hints
) ) )
2100 af_latin_hint_edges( hints
, (AF_Dimension
)dim
);
2101 af_glyph_hints_align_edge_points( hints
, (AF_Dimension
)dim
);
2102 af_glyph_hints_align_strong_points( hints
, (AF_Dimension
)dim
);
2103 af_glyph_hints_align_weak_points( hints
, (AF_Dimension
)dim
);
2106 af_glyph_hints_save( hints
, outline
);
2113 /*************************************************************************/
2114 /*************************************************************************/
2116 /***** L A T I N S C R I P T C L A S S *****/
2118 /*************************************************************************/
2119 /*************************************************************************/
2122 /* XXX: this should probably fine tuned to differentiate better between */
2125 static const AF_Script_UniRangeRec af_latin_uniranges
[] =
2127 { 0x0020, 0x007F }, /* Basic Latin (no control characters) */
2128 { 0x00A0, 0x00FF }, /* Latin-1 Supplement (no control characters) */
2129 { 0x0100, 0x017F }, /* Latin Extended-A */
2130 { 0x0180, 0x024F }, /* Latin Extended-B */
2131 { 0x0250, 0x02AF }, /* IPA Extensions */
2132 { 0x02B0, 0x02FF }, /* Spacing Modifier Letters */
2133 { 0x0300, 0x036F }, /* Combining Diacritical Marks */
2134 { 0x0370, 0x03FF }, /* Greek and Coptic */
2135 { 0x0400, 0x04FF }, /* Cyrillic */
2136 { 0x0500, 0x052F }, /* Cyrillic Supplement */
2137 { 0x1D00, 0x1D7F }, /* Phonetic Extensions */
2138 { 0x1D80, 0x1DBF }, /* Phonetic Extensions Supplement */
2139 { 0x1DC0, 0x1DFF }, /* Combining Diacritical Marks Supplement */
2140 { 0x1E00, 0x1EFF }, /* Latin Extended Additional */
2141 { 0x1F00, 0x1FFF }, /* Greek Extended */
2142 { 0x2000, 0x206F }, /* General Punctuation */
2143 { 0x2070, 0x209F }, /* Superscripts and Subscripts */
2144 { 0x20A0, 0x20CF }, /* Currency Symbols */
2145 { 0x2150, 0x218F }, /* Number Forms */
2146 { 0x2460, 0x24FF }, /* Enclosed Alphanumerics */
2151 FT_CALLBACK_TABLE_DEF
const AF_ScriptClassRec
2152 af_latin_script_class
=
2157 sizeof( AF_LatinMetricsRec
),
2159 (AF_Script_InitMetricsFunc
) af_latin_metrics_init
,
2160 (AF_Script_ScaleMetricsFunc
)af_latin_metrics_scale
,
2161 (AF_Script_DoneMetricsFunc
) NULL
,
2163 (AF_Script_InitHintsFunc
) af_latin_hints_init
,
2164 (AF_Script_ApplyHintsFunc
) af_latin_hints_apply