📄 aflatin.c
字号:
blue->flags &= ~AF_LATIN_BLUE_ACTIVE; /* a blue zone is only active when it is less than 3/4 pixels tall */ dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale ); if ( dist <= 48 && dist >= -48 ) { FT_Pos delta, delta2; delta = blue->shoot.org - blue->ref.org; delta2 = delta; if ( delta < 0 ) delta2 = -delta2; delta2 = FT_MulFix( delta2, scale ); if ( delta2 < 32 ) delta2 = 0; else if ( delta2 < 64 ) delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 ); else delta2 = FT_PIX_ROUND( delta2 ); if ( delta < 0 ) delta2 = -delta2; blue->ref.fit = FT_PIX_ROUND( blue->ref.cur ); blue->shoot.fit = blue->ref.fit + delta2; blue->flags |= AF_LATIN_BLUE_ACTIVE; } } } } FT_LOCAL_DEF( void ) af_latin_metrics_scale( AF_LatinMetrics metrics, AF_Scaler scaler ) { if ( AF_SCALER_EQUAL_SCALES( scaler, &metrics->root.scaler ) ) return; af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ ); af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT ); } /***************************************************************************/ /***************************************************************************/ /***** *****/ /***** L A T I N G L Y P H A N A L Y S I S *****/ /***** *****/ /***************************************************************************/ /***************************************************************************/ FT_LOCAL_DEF( void ) af_latin_hints_compute_segments( AF_GlyphHints hints, AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; AF_Segment segments = axis->segments; AF_Segment segment = segments; FT_Int num_segments = 0; AF_Point* contour = hints->contours; AF_Point* contour_limit = contour + hints->num_contours; AF_Direction major_dir, segment_dir;#ifdef AF_HINT_METRICS AF_Point min_point = 0; AF_Point max_point = 0; FT_Pos min_coord = 32000; FT_Pos max_coord = -32000;#endif major_dir = FT_ABS( axis->major_dir ); segment_dir = major_dir; /* set up (u,v) in each point */ if ( dim == AF_DIMENSION_HORZ ) { AF_Point point = hints->points; AF_Point limit = point + hints->num_points; for ( ; point < limit; point++ ) { point->u = point->fx; point->v = point->fy; } } else { AF_Point point = hints->points; AF_Point limit = point + hints->num_points; for ( ; point < limit; point++ ) { point->u = point->fy; point->v = point->fx; } } /* do each contour separately */ for ( ; contour < contour_limit; contour++ ) { AF_Point point = contour[0]; AF_Point last = point->prev; int on_edge = 0; FT_Pos min_pos = 32000; /* minimum segment pos != min_coord */ FT_Pos max_pos = -32000; /* maximum segment pos != max_coord */ FT_Bool passed;#ifdef AF_HINT_METRICS if ( point->u < min_coord ) { min_coord = point->u; min_point = point; } if ( point->u > max_coord ) { max_coord = point->u; max_point = point; }#endif if ( point == last ) /* skip singletons -- just in case */ continue; if ( FT_ABS( last->out_dir ) == major_dir && FT_ABS( point->out_dir ) == major_dir ) { /* we are already on an edge, try to locate its start */ last = point; for (;;) { point = point->prev; if ( FT_ABS( point->out_dir ) != major_dir ) { point = point->next; break; } if ( point == last ) break; } } last = point; passed = 0; for (;;) { FT_Pos u, v; if ( on_edge ) { u = point->u; if ( u < min_pos ) min_pos = u; if ( u > max_pos ) max_pos = u; if ( point->out_dir != segment_dir || point == last ) { /* we are just leaving an edge; record a new segment! */ segment->last = point; segment->pos = ( min_pos + max_pos ) >> 1; /* a segment is round if either its first or last point */ /* is a control point */ if ( ( segment->first->flags | point->flags ) & AF_FLAG_CONTROL ) segment->flags |= AF_EDGE_ROUND; /* compute segment size */ min_pos = max_pos = point->v; v = segment->first->v; if ( v < min_pos ) min_pos = v; if ( v > max_pos ) max_pos = v; segment->min_coord = min_pos; segment->max_coord = max_pos; on_edge = 0; num_segments++; segment++; /* fallthrough */ } } /* now exit if we are at the start/end point */ if ( point == last ) { if ( passed ) break; passed = 1; } if ( !on_edge && FT_ABS( point->out_dir ) == major_dir ) { /* this is the start of a new segment! */ segment_dir = point->out_dir; /* clear all segment fields */ FT_ZERO( segment ); segment->dir = segment_dir; segment->flags = AF_EDGE_NORMAL; min_pos = max_pos = point->u; segment->first = point; segment->last = point; segment->contour = contour; segment->score = 32000; segment->link = NULL; on_edge = 1;#ifdef AF_HINT_METRICS if ( point == max_point ) max_point = 0; if ( point == min_point ) min_point = 0;#endif } point = point->next; } } /* contours */#ifdef AF_HINT_METRICS /* we need to ensure that there are edges on the left-most and */ /* right-most points of the glyph in order to hint the metrics; */ /* we do this by inserting fake segments when needed */ if ( dim == AF_DIMENSION_HORZ ) { AF_Point point = hints->points; AF_Point point_limit = point + hints->num_points; FT_Pos min_pos = 32000; FT_Pos max_pos = -32000; min_point = 0; max_point = 0; /* compute minimum and maximum points */ for ( ; point < point_limit; point++ ) { FT_Pos x = point->fx; if ( x < min_pos ) { min_pos = x; min_point = point; } if ( x > max_pos ) { max_pos = x; max_point = point; } } /* insert minimum segment */ if ( min_point ) { /* clear all segment fields */ FT_ZERO( segment ); segment->dir = segment_dir; segment->flags = AF_EDGE_NORMAL; segment->first = min_point; segment->last = min_point; segment->pos = min_pos; segment->score = 32000; segment->link = NULL; num_segments++; segment++; } /* insert maximum segment */ if ( max_point ) { /* clear all segment fields */ FT_ZERO( segment ); segment->dir = segment_dir; segment->flags = AF_EDGE_NORMAL; segment->first = max_point; segment->last = max_point; segment->pos = max_pos; segment->score = 32000; segment->link = NULL; num_segments++; segment++; } }#endif /* AF_HINT_METRICS */ axis->num_segments = num_segments; } FT_LOCAL_DEF( void ) af_latin_hints_link_segments( AF_GlyphHints hints, AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; AF_Segment segments = axis->segments; AF_Segment segment_limit = segments + axis->num_segments; AF_Direction major_dir = axis->major_dir; AF_Segment seg1, seg2; /* now compare each segment to the others */ for ( seg1 = segments; seg1 < segment_limit; seg1++ ) { /* the fake segments are introduced to hint the metrics -- */ /* we must never link them to anything */ if ( seg1->first == seg1->last || seg1->dir != major_dir ) continue; for ( seg2 = segments; seg2 < segment_limit; seg2++ ) if ( seg2 != seg1 && seg1->dir + seg2->dir == 0 ) { FT_Pos pos1 = seg1->pos; FT_Pos pos2 = seg2->pos; FT_Pos dist = pos2 - pos1; if ( dist < 0 ) continue; { FT_Pos min = seg1->min_coord; FT_Pos max = seg1->max_coord; FT_Pos len, score; if ( min < seg2->min_coord ) min = seg2->min_coord; if ( max > seg2->max_coord ) max = seg2->max_coord; len = max - min; if ( len >= 8 ) { score = dist + 3000 / len; if ( score < seg1->score ) { seg1->score = score; seg1->link = seg2; } if ( score < seg2->score ) { seg2->score = score; seg2->link = seg1; } } } } } /* now, compute the `serif' segments */ for ( seg1 = segments; seg1 < segment_limit; seg1++ ) { seg2 = seg1->link; if ( seg2 ) { seg2->num_linked++; if ( seg2->link != seg1 ) { seg1->link = 0; seg1->serif = seg2->link; } } } } FT_LOCAL_DEF( void ) af_latin_hints_compute_edges( AF_GlyphHints hints, AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; AF_LatinAxis laxis = &((AF_LatinMetrics)hints->metrics)->axis[dim]; AF_Edge edges = axis->edges; AF_Edge edge, edge_limit; AF_Segment segments = axis->segments; AF_Segment segment_limit = segments + axis->num_segments; AF_Segment seg; AF_Direction up_dir; FT_Fixed scale; FT_Pos edge_distance_threshold; scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale : hints->y_scale; up_dir = ( dim == AF_DIMENSION_HORZ ) ? AF_DIR_UP : AF_DIR_RIGHT; /*********************************************************************/ /* */ /* We will begin by generating a sorted table of edges for the */ /* current direction. To do so, we simply scan each segment and try */ /* to find an edge in our table that corresponds to its position. */ /* */ /* If no edge is found, we create and insert a new edge in the */ /* sorted table. Otherwise, we simply add the segment to the edge's */ /* list which will be processed in the second step to compute the */ /* edge's properties. */ /* */ /* Note that the edges table is sorted along the segment/edge */ /* position. */ /* */ /*********************************************************************/ edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold, scale ); if ( edge_distance_threshold > 64 / 4 ) edge_distance_threshold = 64 / 4; edge_distance_threshold = FT_DivFix( edge_distance_threshold, scale ); edge_limit = edges; for ( seg = segments; seg < segment_limit; seg++ ) { AF_Edge found = 0; /* look for an edge corresponding to the segment */ for ( edge = edges; edge < edge_limit; edge++ ) { FT_Pos dist; dist = seg->pos - edge->fpos; if ( dist < 0 ) dist = -dist; if ( dist < edge_distance_threshold ) { found = edge; break; } } if ( !found ) { /* insert a new edge in the list and */ /* sort according to the position */ while ( edge > edges && edge[-1].fpos > seg->pos )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -