diff options
Diffstat (limited to 'freetype/src/autofit/aflatin2.c')
-rw-r--r-- | freetype/src/autofit/aflatin2.c | 227 |
1 files changed, 128 insertions, 99 deletions
diff --git a/freetype/src/autofit/aflatin2.c b/freetype/src/autofit/aflatin2.c index 6546475a1..23558b879 100644 --- a/freetype/src/autofit/aflatin2.c +++ b/freetype/src/autofit/aflatin2.c @@ -1,10 +1,10 @@ /***************************************************************************/ /* */ -/* aflatin.c */ +/* aflatin2.c */ /* */ /* Auto-fitter hinting routines for latin script (body). */ /* */ -/* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by */ +/* Copyright 2003-2011 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -23,13 +23,24 @@ #include "aferrors.h" -#ifdef AF_USE_WARPER +#ifdef AF_CONFIG_OPTION_USE_WARPER #include "afwarp.h" #endif + + /*************************************************************************/ + /* */ + /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ + /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ + /* messages during execution. */ + /* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_aflatin2 + + FT_LOCAL_DEF( FT_Error ) af_latin2_hints_compute_segments( AF_GlyphHints hints, - AF_Dimension dim ); + AF_Dimension dim ); FT_LOCAL_DEF( void ) af_latin2_hints_link_segments( AF_GlyphHints hints, @@ -45,8 +56,8 @@ FT_LOCAL_DEF( void ) af_latin2_metrics_init_widths( AF_LatinMetrics metrics, - FT_Face face, - FT_ULong charcode ) + FT_Face face, + FT_ULong charcode ) { /* scan the array of segments in each direction */ AF_GlyphHintsRec hints[1]; @@ -156,7 +167,8 @@ #define AF_LATIN_MAX_TEST_CHARACTERS 12 - static const char af_latin2_blue_chars[AF_LATIN_MAX_BLUES][AF_LATIN_MAX_TEST_CHARACTERS+1] = + static const char af_latin2_blue_chars[AF_LATIN_MAX_BLUES] + [AF_LATIN_MAX_TEST_CHARACTERS+1] = { "THEZOCQS", "HEZLOCUS", @@ -169,7 +181,7 @@ static void af_latin2_metrics_init_blues( AF_LatinMetrics metrics, - FT_Face face ) + FT_Face face ) { FT_Pos flats [AF_LATIN_MAX_TEST_CHARACTERS]; FT_Pos rounds[AF_LATIN_MAX_TEST_CHARACTERS]; @@ -182,12 +194,12 @@ FT_GlyphSlot glyph = face->glyph; - /* we compute the blues simply by loading each character from the */ + /* we compute the blues simply by loading each character from the */ /* 'af_latin2_blue_chars[blues]' string, then compute its top-most or */ - /* bottom-most points (depending on `AF_IS_TOP_BLUE') */ + /* bottom-most points (depending on `AF_IS_TOP_BLUE') */ - AF_LOG(( "blue zones computation\n" )); - AF_LOG(( "------------------------------------------------\n" )); + FT_TRACE5(( "blue zones computation\n" )); + FT_TRACE5(( "------------------------------------------------\n" )); for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ ) { @@ -197,7 +209,7 @@ FT_Pos* blue_shoot; - AF_LOG(( "blue %3d: ", bb )); + FT_TRACE5(( "blue %3d: ", bb )); num_flats = 0; num_rounds = 0; @@ -210,7 +222,7 @@ FT_Bool round; - AF_LOG(( "'%c'", *p )); + FT_TRACE5(( "'%c'", *p )); /* load the character in the face -- skip unknown or empty ones */ glyph_index = FT_Get_Char_Index( face, (FT_UInt)*p ); @@ -273,7 +285,7 @@ best_last = last; } } - AF_LOG(( "%5d", best_y )); + FT_TRACE5(( "%5d", best_y )); } /* now check whether the point belongs to a straight or round */ @@ -321,7 +333,7 @@ FT_CURVE_TAG( glyph->outline.tags[start] ) != FT_CURVE_TAG_ON || FT_CURVE_TAG( glyph->outline.tags[ end ] ) != FT_CURVE_TAG_ON ); - AF_LOG(( "%c ", round ? 'r' : 'f' )); + FT_TRACE5(( "%c ", round ? 'r' : 'f' )); } if ( round ) @@ -330,7 +342,7 @@ flats[num_flats++] = best_y; } - AF_LOG(( "\n" )); + FT_TRACE5(( "\n" )); if ( num_flats == 0 && num_rounds == 0 ) { @@ -338,7 +350,7 @@ * we couldn't find a single glyph to compute this blue zone, * we will simply ignore it then */ - AF_LOG(( "empty\n" )); + FT_TRACE5(( "empty\n" )); continue; } @@ -396,7 +408,7 @@ if ( bb == AF_LATIN_BLUE_SMALL_TOP ) blue->flags |= AF_LATIN_BLUE_ADJUSTMENT; - AF_LOG(( "-- ref = %ld, shoot = %ld\n", *blue_ref, *blue_shoot )); + FT_TRACE5(( "-- ref = %ld, shoot = %ld\n", *blue_ref, *blue_shoot )); } return; @@ -451,7 +463,7 @@ FT_LOCAL_DEF( FT_Error ) af_latin2_metrics_init( AF_LatinMetrics metrics, - FT_Face face ) + FT_Face face ) { FT_Error error = AF_Err_Ok; FT_CharMap oldmap = face->charmap; @@ -492,8 +504,8 @@ static void af_latin2_metrics_scale_dim( AF_LatinMetrics metrics, - AF_Scaler scaler, - AF_Dimension dim ) + AF_Scaler scaler, + AF_Dimension dim ) { FT_Fixed scale; FT_Pos delta; @@ -548,7 +560,10 @@ if ( scaled != fitted ) { scale = FT_MulDiv( scale, fitted, scaled ); - AF_LOG(( "== scaled x-top = %.2g fitted = %.2g, scaling = %.4g\n", scaled/64.0, fitted/64.0, (fitted*1.0)/scaled )); + FT_TRACE5(( "== scaled x-top = %.2g" + " fitted = %.2g, scaling = %.4g\n", + scaled / 64.0, fitted / 64.0, + ( fitted * 1.0 ) / scaled )); } #endif } @@ -579,7 +594,7 @@ } /* an extra-light axis corresponds to a standard width that is */ - /* smaller than 0.75 pixels */ + /* smaller than 5/8 pixels */ axis->extra_light = (FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 ); @@ -624,9 +639,11 @@ blue->ref.fit = FT_PIX_ROUND( blue->ref.cur ); blue->shoot.fit = blue->ref.fit + delta2; - AF_LOG(( ">> activating blue zone %d: ref.cur=%.2g ref.fit=%.2g shoot.cur=%.2g shoot.fit=%.2g\n", - nn, blue->ref.cur/64.0, blue->ref.fit/64.0, - blue->shoot.cur/64.0, blue->shoot.fit/64.0 )); + FT_TRACE5(( ">> activating blue zone %d:" + " ref.cur=%.2g ref.fit=%.2g" + " shoot.cur=%.2g shoot.fit=%.2g\n", + nn, blue->ref.cur / 64.0, blue->ref.fit / 64.0, + blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 )); blue->flags |= AF_LATIN_BLUE_ACTIVE; } @@ -637,7 +654,7 @@ FT_LOCAL_DEF( void ) af_latin2_metrics_scale( AF_LatinMetrics metrics, - AF_Scaler scaler ) + AF_Scaler scaler ) { metrics->root.scaler.render_mode = scaler->render_mode; metrics->root.scaler.face = scaler->face; @@ -659,7 +676,7 @@ FT_LOCAL_DEF( FT_Error ) af_latin2_hints_compute_segments( AF_GlyphHints hints, - AF_Dimension dim ) + AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; FT_Memory memory = hints->memory; @@ -779,7 +796,6 @@ segment->dir = first->out_dir; segment->first = first; segment->last = point; - segment->contour = contour; segment->pos = (FT_Short)(( min_u + max_u ) >> 1); segment->min_coord = (FT_Short) min_v; segment->max_coord = (FT_Short) max_v; @@ -917,7 +933,7 @@ FT_LOCAL_DEF( void ) af_latin2_hints_link_segments( AF_GlyphHints hints, - AF_Dimension dim ) + AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; AF_Segment segments = axis->segments; @@ -1017,7 +1033,7 @@ FT_LOCAL_DEF( FT_Error ) af_latin2_hints_compute_edges( AF_GlyphHints hints, - AF_Dimension dim ) + AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; FT_Error error = AF_Err_Ok; @@ -1137,7 +1153,8 @@ /* insert a new edge in the list and */ /* sort according to the position */ - error = af_axis_hints_new_edge( axis, seg->pos, seg->dir, memory, &edge ); + error = af_axis_hints_new_edge( axis, seg->pos, seg->dir, + memory, &edge ); if ( error ) goto Exit; @@ -1205,8 +1222,10 @@ { FT_Int is_round = 0; /* does it contain round segments? */ FT_Int is_straight = 0; /* does it contain straight segments? */ +#if 0 FT_Pos ups = 0; /* number of upwards segments */ FT_Pos downs = 0; /* number of downwards segments */ +#endif seg = edge->first; @@ -1222,11 +1241,13 @@ else is_straight++; +#if 0 /* check for segment direction */ if ( seg->dir == up_dir ) ups += seg->max_coord-seg->min_coord; else downs += seg->max_coord-seg->min_coord; +#endif /* check for links -- if seg->serif is set, then seg->link must */ /* be ignored */ @@ -1318,7 +1339,7 @@ FT_LOCAL_DEF( FT_Error ) af_latin2_hints_detect_features( AF_GlyphHints hints, - AF_Dimension dim ) + AF_Dimension dim ) { FT_Error error; @@ -1336,7 +1357,7 @@ FT_LOCAL_DEF( void ) af_latin2_hints_compute_blue_edges( AF_GlyphHints hints, - AF_LatinMetrics metrics ) + AF_LatinMetrics metrics ) { AF_AxisHints axis = &hints->axis[ AF_DIMENSION_VERT ]; AF_Edge edge = axis->edges; @@ -1442,7 +1463,7 @@ static FT_Error af_latin2_hints_init( AF_GlyphHints hints, - AF_LatinMetrics metrics ) + AF_LatinMetrics metrics ) { FT_Render_Mode mode; FT_UInt32 scaler_flags, other_flags; @@ -1463,7 +1484,7 @@ /* compute flags depending on render mode, etc. */ mode = metrics->root.scaler.render_mode; -#if 0 /* #ifdef AF_USE_WARPER */ +#if 0 /* #ifdef AF_CONFIG_OPTION_USE_WARPER */ if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V ) { metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL; @@ -1524,8 +1545,8 @@ static FT_Pos af_latin2_snap_width( AF_Width widths, - FT_Int count, - FT_Pos width ) + FT_Int count, + FT_Pos width ) { int n; FT_Pos best = 64 + 32 + 2; @@ -1571,10 +1592,10 @@ static FT_Pos af_latin2_compute_stem_width( AF_GlyphHints hints, - AF_Dimension dim, - FT_Pos width, - AF_Edge_Flags base_flags, - AF_Edge_Flags stem_flags ) + AF_Dimension dim, + FT_Pos width, + AF_Edge_Flags base_flags, + AF_Edge_Flags stem_flags ) { AF_LatinMetrics metrics = (AF_LatinMetrics) hints->metrics; AF_LatinAxis axis = & metrics->axis[dim]; @@ -1739,9 +1760,9 @@ static void af_latin2_align_linked_edge( AF_GlyphHints hints, - AF_Dimension dim, - AF_Edge base_edge, - AF_Edge stem_edge ) + AF_Dimension dim, + AF_Edge base_edge, + AF_Edge stem_edge ) { FT_Pos dist = stem_edge->opos - base_edge->opos; @@ -1753,17 +1774,17 @@ stem_edge->pos = base_edge->pos + fitted_width; - AF_LOG(( "LINK: edge %d (opos=%.2f) linked to (%.2f), " - "dist was %.2f, now %.2f\n", - stem_edge-hints->axis[dim].edges, stem_edge->opos / 64.0, - stem_edge->pos / 64.0, dist / 64.0, fitted_width / 64.0 )); + FT_TRACE5(( "LINK: edge %d (opos=%.2f) linked to (%.2f), " + "dist was %.2f, now %.2f\n", + stem_edge-hints->axis[dim].edges, stem_edge->opos / 64.0, + stem_edge->pos / 64.0, dist / 64.0, fitted_width / 64.0 )); } static void af_latin2_align_serif_edge( AF_GlyphHints hints, - AF_Edge base, - AF_Edge serif ) + AF_Edge base, + AF_Edge serif ) { FT_UNUSED( hints ); @@ -1784,7 +1805,7 @@ FT_LOCAL_DEF( void ) af_latin2_hint_edges( AF_GlyphHints hints, - AF_Dimension dim ) + AF_Dimension dim ) { AF_AxisHints axis = &hints->axis[dim]; AF_Edge edges = axis->edges; @@ -1796,7 +1817,8 @@ - AF_LOG(( "==== hinting %s edges =====\n", dim == AF_DIMENSION_HORZ ? "vertical" : "horizontal" )); + FT_TRACE5(( "==== hinting %s edges =====\n", + dim == AF_DIMENSION_HORZ ? "vertical" : "horizontal" )); /* we begin by aligning all stems relative to the blue zone */ /* if needed -- that's only for horizontal edges */ @@ -1830,10 +1852,10 @@ if ( !edge1 ) continue; - AF_LOG(( "BLUE: edge %d (opos=%.2f) snapped to (%.2f), " - "was (%.2f)\n", - edge1-edges, edge1->opos / 64.0, blue->fit / 64.0, - edge1->pos / 64.0 )); + FT_TRACE5(( "BLUE: edge %d (opos=%.2f) snapped to (%.2f), " + "was (%.2f)\n", + edge1-edges, edge1->opos / 64.0, blue->fit / 64.0, + edge1->pos / 64.0 )); edge1->pos = blue->fit; edge1->flags |= AF_EDGE_DONE; @@ -1878,7 +1900,7 @@ /* this should not happen, but it's better to be safe */ if ( edge2->blue_edge ) { - AF_LOG(( "ASSERTION FAILED for edge %d\n", edge2-edges )); + FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges )); af_latin2_align_linked_edge( hints, dim, edge2, edge ); edge->flags |= AF_EDGE_DONE; @@ -1929,11 +1951,11 @@ else edge->pos = FT_PIX_ROUND( edge->opos ); - AF_LOG(( "ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f) " - "snapped to (%.2f) (%.2f)\n", - edge-edges, edge->opos / 64.0, - edge2-edges, edge2->opos / 64.0, - edge->pos / 64.0, edge2->pos / 64.0 )); + FT_TRACE5(( "ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)" + " snapped to (%.2f) (%.2f)\n", + edge-edges, edge->opos / 64.0, + edge2-edges, edge2->opos / 64.0, + edge->pos / 64.0, edge2->pos / 64.0 )); anchor = edge; edge->flags |= AF_EDGE_DONE; @@ -1945,7 +1967,7 @@ anchor_drift = ( (anchor->pos - anchor->opos) + (edge2->pos - edge2->opos)) >> 1; - AF_LOG(( "DRIFT: %.2f\n", anchor_drift/64.0 )); + FT_TRACE5(( "DRIFT: %.2f\n", anchor_drift/64.0 )); } else { @@ -1965,12 +1987,13 @@ org_left = org_pos + ((org_len - cur_len) >> 1); org_right = org_pos + ((org_len + cur_len) >> 1); - AF_LOG(( "ALIGN: left=%.2f right=%.2f ", org_left/64.0, org_right/64.0 )); + FT_TRACE5(( "ALIGN: left=%.2f right=%.2f ", + org_left / 64.0, org_right / 64.0 )); cur_center = org_center; if ( edge2->flags & AF_EDGE_DONE ) { - AF_LOG(( "\n" )); + FT_TRACE5(( "\n" )); edge->pos = edge2->pos - cur_len; } else @@ -1985,14 +2008,14 @@ /* note: don't even try to fit tiny stems */ if ( cur_len < 32 ) { - AF_LOG(( "tiny stem\n" )); + FT_TRACE5(( "tiny stem\n" )); goto AlignStem; } /* if the span is within a single pixel, don't touch it */ if ( FT_PIX_FLOOR(org_left) == FT_PIX_CEIL(org_right) ) { - AF_LOG(( "single pixel stem\n" )); + FT_TRACE5(( "single pixel stem\n" )); goto AlignStem; } @@ -2015,14 +2038,14 @@ delta = FT_ABS(fit - org); displacements[count] = fit - org; scores[count++] = delta; - AF_LOG(( "dispA=%.2f (%d) ", (fit - org)/64.0, delta )); + FT_TRACE5(( "dispA=%.2f (%d) ", (fit - org) / 64.0, delta )); org = frac_right; fit = (org <= 32) ? 16 : 48; delta = FT_ABS(fit - org); displacements[count] = fit - org; scores[count++] = delta; - AF_LOG(( "dispB=%.2f (%d) ", (fit - org)/64.0, delta )); + FT_TRACE5(( "dispB=%.2f (%d) ", (fit - org) / 64.0, delta )); } } @@ -2032,7 +2055,7 @@ delta = FT_ABS(fit - org); displacements[count] = fit - org; scores[count++] = delta; - AF_LOG(( "dispC=%.2f (%d) ", (fit - org)/64.0, delta )); + FT_TRACE5(( "dispC=%.2f (%d) ", (fit - org) / 64.0, delta )); /* snapping the right edge to the grid */ org = org_right; @@ -2040,7 +2063,7 @@ delta = FT_ABS(fit - org); displacements[count] = fit - org; scores[count++] = delta; - AF_LOG(( "dispD=%.2f (%d) ", (fit - org)/64.0, delta )); + FT_TRACE5(( "dispD=%.2f (%d) ", (fit - org) / 64.0, delta )); /* now find the best displacement */ { @@ -2059,27 +2082,28 @@ cur_center = org_center + best_disp; } - AF_LOG(( "\n" )); + FT_TRACE5(( "\n" )); } AlignStem: edge->pos = cur_center - (cur_len >> 1); edge2->pos = edge->pos + cur_len; - AF_LOG(( "STEM1: %d (opos=%.2f) to %d (opos=%.2f) " - "snapped to (%.2f) and (%.2f), org_len = %.2f cur_len=%.2f\n", - edge-edges, edge->opos / 64.0, - edge2-edges, edge2->opos / 64.0, - edge->pos / 64.0, edge2->pos / 64.0, - org_len / 64.0, cur_len / 64.0 )); + FT_TRACE5(( "STEM1: %d (opos=%.2f) to %d (opos=%.2f)" + " snapped to (%.2f) and (%.2f)," + " org_len=%.2f cur_len=%.2f\n", + edge-edges, edge->opos / 64.0, + edge2-edges, edge2->opos / 64.0, + edge->pos / 64.0, edge2->pos / 64.0, + org_len / 64.0, cur_len / 64.0 )); edge->flags |= AF_EDGE_DONE; edge2->flags |= AF_EDGE_DONE; if ( edge > edges && edge->pos < edge[-1].pos ) { - AF_LOG(( "BOUND: %d (pos=%.2f) to (%.2f)\n", - edge-edges, edge->pos / 64.0, edge[-1].pos / 64.0 )); + FT_TRACE5(( "BOUND: %d (pos=%.2f) to (%.2f)\n", + edge-edges, edge->pos / 64.0, edge[-1].pos / 64.0 )); edge->pos = edge[-1].pos; } } @@ -2179,16 +2203,17 @@ if ( delta < 64 + 16 ) { af_latin2_align_serif_edge( hints, edge->serif, edge ); - AF_LOG(( "SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f) " - "aligned to (%.2f)\n", - edge-edges, edge->opos / 64.0, - edge->serif - edges, edge->serif->opos / 64.0, - edge->pos / 64.0 )); + FT_TRACE5(( "SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)" + " aligned to (%.2f)\n", + edge-edges, edge->opos / 64.0, + edge->serif - edges, edge->serif->opos / 64.0, + edge->pos / 64.0 )); } else if ( !anchor ) { - AF_LOG(( "SERIF_ANCHOR: edge %d (opos=%.2f) snapped to (%.2f)\n", - edge-edges, edge->opos / 64.0, edge->pos / 64.0 )); + FT_TRACE5(( "SERIF_ANCHOR: edge %d (opos=%.2f)" + " snapped to (%.2f)\n", + edge-edges, edge->opos / 64.0, edge->pos / 64.0 )); edge->pos = FT_PIX_ROUND( edge->opos ); anchor = edge; } @@ -2215,15 +2240,19 @@ FT_MulDiv( edge->opos - before->opos, after->pos - before->pos, after->opos - before->opos ); - AF_LOG(( "SERIF_LINK1: edge %d (opos=%.2f) snapped to (%.2f) from %d (opos=%.2f)\n", - edge-edges, edge->opos / 64.0, edge->pos / 64.0, before - edges, before->opos / 64.0 )); + FT_TRACE5(( "SERIF_LINK1: edge %d (opos=%.2f) snapped to (%.2f)" + " from %d (opos=%.2f)\n", + edge-edges, edge->opos / 64.0, edge->pos / 64.0, + before - edges, before->opos / 64.0 )); } else { - edge->pos = anchor->pos + (( edge->opos - anchor->opos + 16) & ~31); + edge->pos = anchor->pos + + ( ( edge->opos - anchor->opos + 16 ) & ~31 ); - AF_LOG(( "SERIF_LINK2: edge %d (opos=%.2f) snapped to (%.2f)\n", - edge-edges, edge->opos / 64.0, edge->pos / 64.0 )); + FT_TRACE5(( "SERIF_LINK2: edge %d (opos=%.2f)" + " snapped to (%.2f)\n", + edge-edges, edge->opos / 64.0, edge->pos / 64.0 )); } } @@ -2243,8 +2272,8 @@ static FT_Error af_latin2_hints_apply( AF_GlyphHints hints, - FT_Outline* outline, - AF_LatinMetrics metrics ) + FT_Outline* outline, + AF_LatinMetrics metrics ) { FT_Error error; int dim; @@ -2255,7 +2284,7 @@ goto Exit; /* analyze glyph outline */ -#ifdef AF_USE_WARPER +#ifdef AF_CONFIG_OPTION_USE_WARPER if ( metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT || AF_HINTS_DO_HORIZONTAL( hints ) ) #else @@ -2279,7 +2308,7 @@ /* grid-fit the outline */ for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ ) { -#ifdef AF_USE_WARPER +#ifdef AF_CONFIG_OPTION_USE_WARPER if ( ( dim == AF_DIMENSION_HORZ && metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT ) ) { @@ -2321,7 +2350,7 @@ static const AF_Script_UniRangeRec af_latin2_uniranges[] = { - AF_UNIRANGE_REC( 32UL, 127UL ), /* XXX: TODO: Add new Unicode ranges here! */ + AF_UNIRANGE_REC( 32UL, 127UL ), /* TODO: Add new Unicode ranges here! */ AF_UNIRANGE_REC( 160UL, 255UL ), AF_UNIRANGE_REC( 0UL, 0UL ) }; |