af_warper_compute( AF_Warper warper, AF_GlyphHints hints, AF_Dimension dim, FT_Fixed *a_scale, FT_Pos *a_delta ) { AF_AxisHints axis; AF_Point points; FT_Fixed org_scale; FT_Pos org_delta; FT_UInt nn, num_points, num_segments; FT_Int X1, X2; FT_Int w; AF_WarpScore base_distort; AF_Segment segments; /* get original scaling transformation */ if ( dim == AF_DIMENSION_VERT ) { org_scale = hints->y_scale; org_delta = hints->y_delta; } else { org_scale = hints->x_scale; org_delta = hints->x_delta; } warper->best_scale = org_scale; warper->best_delta = org_delta; warper->best_score = INT_MIN; warper->best_distort = 0; axis = &hints->axis[dim]; segments = axis->segments; num_segments = axis->num_segments; points = hints->points; num_points = hints->num_points; *a_scale = org_scale; *a_delta = org_delta; /* get X1 and X2, minimum and maximum in original coordinates */ if ( num_segments < 1 ) return; #if 1 X1 = X2 = points[0].fx; for ( nn = 1; nn < num_points; nn++ ) { FT_Int X = points[nn].fx; if ( X < X1 ) X1 = X; if ( X > X2 ) X2 = X; } #else X1 = X2 = segments[0].pos; for ( nn = 1; nn < num_segments; nn++ ) { FT_Int X = segments[nn].pos; if ( X < X1 ) X1 = X; if ( X > X2 ) X2 = X; } #endif if ( X1 >= X2 ) return; warper->x1 = FT_MulFix( X1, org_scale ) + org_delta; warper->x2 = FT_MulFix( X2, org_scale ) + org_delta; warper->t1 = AF_WARPER_FLOOR( warper->x1 ); warper->t2 = AF_WARPER_CEIL( warper->x2 ); /* examine a half pixel wide range around the maximum coordinates */ warper->x1min = warper->x1 & ~31; warper->x1max = warper->x1min + 32; warper->x2min = warper->x2 & ~31; warper->x2max = warper->x2min + 32; if ( warper->x1max > warper->x2 ) warper->x1max = warper->x2; if ( warper->x2min < warper->x1 ) warper->x2min = warper->x1; warper->w0 = warper->x2 - warper->x1; if ( warper->w0 <= 64 ) { warper->x1max = warper->x1; warper->x2min = warper->x2; } /* examine (at most) a pixel wide range around the natural width */ warper->wmin = warper->x2min - warper->x1max; warper->wmax = warper->x2max - warper->x1min; #if 1 /* some heuristics to reduce the number of widths to be examined */ { int margin = 16; if ( warper->w0 <= 128 ) { margin = 8; if ( warper->w0 <= 96 ) margin = 4; } if ( warper->wmin < warper->w0 - margin ) warper->wmin = warper->w0 - margin; if ( warper->wmax > warper->w0 + margin ) warper->wmax = warper->w0 + margin; } if ( warper->wmin < warper->w0 * 3 / 4 ) warper->wmin = warper->w0 * 3 / 4; if ( warper->wmax > warper->w0 * 5 / 4 ) warper->wmax = warper->w0 * 5 / 4; #else /* no scaling, just translation */ warper->wmin = warper->wmax = warper->w0; #endif for ( w = warper->wmin; w <= warper->wmax; w++ ) { FT_Fixed new_scale; FT_Pos new_delta; FT_Pos xx1, xx2; /* compute min and max positions for given width, */ /* assuring that they stay within the coordinate ranges */ xx1 = warper->x1; xx2 = warper->x2; if ( w >= warper->w0 ) { xx1 -= w - warper->w0; if ( xx1 < warper->x1min ) { xx2 += warper->x1min - xx1; xx1 = warper->x1min; } } else { xx1 -= w - warper->w0; if ( xx1 > warper->x1max ) { xx2 -= xx1 - warper->x1max; xx1 = warper->x1max; } } if ( xx1 < warper->x1 ) base_distort = warper->x1 - xx1; else base_distort = xx1 - warper->x1; if ( xx2 < warper->x2 ) base_distort += warper->x2 - xx2; else base_distort += xx2 - warper->x2; /* give base distortion a greater weight while scoring */ base_distort *= 10; new_scale = org_scale + FT_DivFix( w - warper->w0, X2 - X1 ); new_delta = xx1 - FT_MulFix( X1, new_scale ); af_warper_compute_line_best( warper, new_scale, new_delta, xx1, xx2, base_distort, segments, num_segments ); } { FT_Fixed best_scale = warper->best_scale; FT_Pos best_delta = warper->best_delta; hints->xmin_delta = FT_MulFix( X1, best_scale - org_scale ) + best_delta; hints->xmax_delta = FT_MulFix( X2, best_scale - org_scale ) + best_delta; *a_scale = best_scale; *a_delta = best_delta; } }
af_warper_compute( AF_Warper warper, AF_GlyphHints hints, AF_Dimension dim, FT_Fixed *a_scale, FT_Pos *a_delta ) { AF_AxisHints axis; AF_Point points; FT_Fixed org_scale; FT_Pos org_delta; FT_UInt nn, num_points, num_segments; FT_Int X1, X2; FT_Int w; AF_WarpScore base_distort; AF_Segment segments; /* get original scaling transformation */ if ( dim == AF_DIMENSION_VERT ) { org_scale = hints->y_scale; org_delta = hints->y_delta; } else { org_scale = hints->x_scale; org_delta = hints->x_delta; } warper->best_scale = org_scale; warper->best_delta = org_delta; warper->best_score = 0; warper->best_distort = 0; axis = &hints->axis[dim]; segments = axis->segments; num_segments = axis->num_segments; points = hints->points; num_points = hints->num_points; *a_scale = org_scale; *a_delta = org_delta; /* get X1 and X2, minimum and maximum in original coordinates */ if ( axis->num_segments < 1 ) return; #if 1 X1 = X2 = points[0].fx; for ( nn = 1; nn < num_points; nn++ ) { FT_Int X = points[nn].fx; if ( X < X1 ) X1 = X; if ( X > X2 ) X2 = X; } #else X1 = X2 = segments[0].pos; for ( nn = 1; nn < num_segments; nn++ ) { FT_Int X = segments[nn].pos; if ( X < X1 ) X1 = X; if ( X > X2 ) X2 = X; } #endif if ( X1 >= X2 ) return; warper->x1 = FT_MulFix( X1, org_scale ) + org_delta; warper->x2 = FT_MulFix( X2, org_scale ) + org_delta; warper->t1 = AF_WARPER_FLOOR( warper->x1 ); warper->t2 = AF_WARPER_CEIL( warper->x2 ); warper->x1min = warper->x1 & ~31; warper->x1max = warper->x1min + 32; warper->x2min = warper->x2 & ~31; warper->x2max = warper->x2min + 32; if ( warper->x1max > warper->x2 ) warper->x1max = warper->x2; if ( warper->x2min < warper->x1 ) warper->x2min = warper->x1; warper->w0 = warper->x2 - warper->x1; if ( warper->w0 <= 64 ) { warper->x1max = warper->x1; warper->x2min = warper->x2; } warper->wmin = warper->x2min - warper->x1max; warper->wmax = warper->x2max - warper->x1min; if ( warper->wmin < warper->w0 - 32 ) warper->wmin = warper->w0 - 32; if ( warper->wmax > warper->w0 + 32 ) warper->wmax = warper->w0 + 32; if ( warper->wmin < warper->w0 * 3 / 4 ) warper->wmin = warper->w0 * 3 / 4; if ( warper->wmax > warper->w0 * 5 / 4 ) warper->wmax = warper->w0 * 5 / 4; /* warper->wmin = warper->wmax = warper->w0; */ for ( w = warper->wmin; w <= warper->wmax; w++ ) { FT_Fixed new_scale; FT_Pos new_delta; FT_Pos xx1, xx2; xx1 = warper->x1; xx2 = warper->x2; if ( w >= warper->w0 ) { xx1 -= w - warper->w0; if ( xx1 < warper->x1min ) { xx2 += warper->x1min - xx1; xx1 = warper->x1min; } } else { xx1 -= w - warper->w0; if ( xx1 > warper->x1max ) { xx2 -= xx1 - warper->x1max; xx1 = warper->x1max; } } if ( xx1 < warper->x1 ) base_distort = warper->x1 - xx1; else base_distort = xx1 - warper->x1; if ( xx2 < warper->x2 ) base_distort += warper->x2 - xx2; else base_distort += xx2 - warper->x2; base_distort *= 10; new_scale = org_scale + FT_DivFix( w - warper->w0, X2 - X1 ); new_delta = xx1 - FT_MulFix( X1, new_scale ); af_warper_compute_line_best( warper, new_scale, new_delta, xx1, xx2, base_distort, segments, num_segments ); } *a_scale = warper->best_scale; *a_delta = warper->best_delta; }