summaryrefslogtreecommitdiffstats
path: root/src/autofit/afhints.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/autofit/afhints.c')
-rw-r--r--src/autofit/afhints.c109
1 files changed, 73 insertions, 36 deletions
diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c
index 56c8220..0f7f6e5 100644
--- a/src/autofit/afhints.c
+++ b/src/autofit/afhints.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter hinting routines (body). */
/* */
-/* Copyright 2003-2015 by */
+/* Copyright 2003-2016 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -99,6 +99,7 @@
af_axis_hints_new_edge( AF_AxisHints axis,
FT_Int fpos,
AF_Direction dir,
+ FT_Bool top_to_bottom_hinting,
FT_Memory memory,
AF_Edge *anedge )
{
@@ -153,7 +154,8 @@
while ( edge > edges )
{
- if ( edge[-1].fpos < fpos )
+ if ( top_to_bottom_hinting ? ( edge[-1].fpos > fpos )
+ : ( edge[-1].fpos < fpos ) )
break;
/* we want the edge with same position and minor direction */
@@ -302,16 +304,18 @@
af_glyph_hints_dump_points( AF_GlyphHints hints,
FT_Bool to_stdout )
{
- AF_Point points = hints->points;
- AF_Point limit = points + hints->num_points;
- AF_Point point;
+ AF_Point points = hints->points;
+ AF_Point limit = points + hints->num_points;
+ AF_Point* contour = hints->contours;
+ AF_Point* climit = contour + hints->num_contours;
+ AF_Point point;
AF_DUMP(( "Table of points:\n" ));
if ( hints->num_points )
- AF_DUMP(( " index hedge hseg vedge vseg flags"
- " xorg yorg xscale yscale xfit yfit\n" ));
+ AF_DUMP(( " index hedge hseg vedge vseg flags "
+ " xorg yorg xscale yscale xfit yfit" ));
else
AF_DUMP(( " (none)\n" ));
@@ -324,7 +328,14 @@
char buf1[16], buf2[16], buf3[16], buf4[16];
- AF_DUMP(( " %5d %5s %5s %5s %5s %s "
+ /* insert extra newline at the beginning of a contour */
+ if ( contour < climit && *contour == point )
+ {
+ AF_DUMP(( "\n" ));
+ contour++;
+ }
+
+ AF_DUMP(( " %5d %5s %5s %5s %5s %s"
" %5d %5d %7.2f %7.2f %7.2f %7.2f\n",
point_idx,
af_print_idx( buf1,
@@ -333,8 +344,11 @@
af_print_idx( buf3,
af_get_edge_index( hints, segment_idx_0, 0 ) ),
af_print_idx( buf4, segment_idx_0 ),
- ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? "weak"
- : " -- ",
+ ( point->flags & AF_FLAG_NEAR )
+ ? " near "
+ : ( point->flags & AF_FLAG_WEAK_INTERPOLATION )
+ ? " weak "
+ : "strong",
point->fx,
point->fy,
@@ -406,20 +420,19 @@
dimension == AF_DIMENSION_HORZ ? "vertical"
: "horizontal" ));
if ( axis->num_segments )
- AF_DUMP(( " index pos dir from to"
- " link serif edge"
+ AF_DUMP(( " index pos delta dir from to "
+ " link serif edge"
" height extra flags\n" ));
else
AF_DUMP(( " (none)\n" ));
for ( seg = segments; seg < limit; seg++ )
- AF_DUMP(( " %5d %5.2g %5s %4d %4d"
+ AF_DUMP(( " %5d %5d %5d %5s %4d %4d"
" %4s %5s %4s"
" %6d %5d %11s\n",
AF_INDEX_NUM( seg, segments ),
- dimension == AF_DIMENSION_HORZ
- ? (int)seg->first->ox / 64.0
- : (int)seg->first->oy / 64.0,
+ seg->pos,
+ seg->delta,
af_dir_str( (AF_Direction)seg->dir ),
AF_INDEX_NUM( seg->first, points ),
AF_INDEX_NUM( seg->last, points ),
@@ -539,18 +552,26 @@
* note: AF_DIMENSION_HORZ corresponds to _vertical_ edges
* since they have a constant X coordinate.
*/
- AF_DUMP(( "Table of %s edges:\n",
- dimension == AF_DIMENSION_HORZ ? "vertical"
- : "horizontal" ));
+ if ( dimension == AF_DIMENSION_HORZ )
+ AF_DUMP(( "Table of %s edges (1px=%.2fu, 10u=%.2fpx):\n",
+ "vertical",
+ 65536.0 * 64.0 / hints->x_scale,
+ 10.0 * hints->x_scale / 65536.0 / 64.0 ));
+ else
+ AF_DUMP(( "Table of %s edges (1px=%.2fu, 10u=%.2fpx):\n",
+ "horizontal",
+ 65536.0 * 64.0 / hints->y_scale,
+ 10.0 * hints->y_scale / 65536.0 / 64.0 ));
+
if ( axis->num_edges )
- AF_DUMP(( " index pos dir link serif"
- " blue opos pos flags\n" ));
+ AF_DUMP(( " index pos dir link serif"
+ " blue opos pos flags\n" ));
else
AF_DUMP(( " (none)\n" ));
for ( edge = edges; edge < limit; edge++ )
- AF_DUMP(( " %5d %5.2g %5s %4s %5s"
- " %c %5.2f %5.2f %11s\n",
+ AF_DUMP(( " %5d %7.2f %5s %4s %5s"
+ " %c %7.2f %7.2f %11s\n",
AF_INDEX_NUM( edge, edges ),
(int)edge->opos / 64.0,
af_dir_str( (AF_Direction)edge->dir ),
@@ -802,18 +823,26 @@
AF_Point point;
AF_Point point_limit = points + hints->num_points;
+ /* value 20 in `near_limit' is heuristic */
+ FT_UInt units_per_em = hints->metrics->scaler.face->units_per_EM;
+ FT_Int near_limit = 20 * units_per_em / 2048;
+
/* compute coordinates & Bezier flags, next and prev */
{
FT_Vector* vec = outline->points;
char* tag = outline->tags;
- AF_Point end = points + outline->contours[0];
+ FT_Short endpoint = outline->contours[0];
+ AF_Point end = points + endpoint;
AF_Point prev = end;
FT_Int contour_index = 0;
for ( point = points; point < point_limit; point++, vec++, tag++ )
{
+ FT_Pos out_x, out_y;
+
+
point->in_dir = (FT_Char)AF_DIR_NONE;
point->out_dir = (FT_Char)AF_DIR_NONE;
@@ -822,6 +851,9 @@
point->ox = point->x = FT_MulFix( vec->x, x_scale ) + x_delta;
point->oy = point->y = FT_MulFix( vec->y, y_scale ) + y_delta;
+ end->fx = (FT_Short)outline->points[endpoint].x;
+ end->fy = (FT_Short)outline->points[endpoint].y;
+
switch ( FT_CURVE_TAG( *tag ) )
{
case FT_CURVE_TAG_CONIC:
@@ -834,6 +866,12 @@
point->flags = AF_FLAG_NONE;
}
+ out_x = point->fx - prev->fx;
+ out_y = point->fy - prev->fy;
+
+ if ( FT_ABS( out_x ) + FT_ABS( out_y ) < near_limit )
+ prev->flags |= AF_FLAG_NEAR;
+
point->prev = prev;
prev->next = point;
prev = point;
@@ -842,8 +880,9 @@
{
if ( ++contour_index < outline->n_contours )
{
- end = points + outline->contours[contour_index];
- prev = end;
+ endpoint = outline->contours[contour_index];
+ end = points + endpoint;
+ prev = end;
}
}
}
@@ -869,17 +908,15 @@
* Compute directions of `in' and `out' vectors.
*
* Note that distances between points that are very near to each
- * other are accumulated. In other words, the auto-hinter
+ * other are accumulated. In other words, the auto-hinter either
* prepends the small vectors between near points to the first
- * non-near vector. All intermediate points are tagged as
- * weak; the directions are adjusted also to be equal to the
- * accumulated one.
+ * non-near vector, or the sum of small vector lengths exceeds a
+ * threshold, thus `grouping' the small vectors. All intermediate
+ * points are tagged as weak; the directions are adjusted also to
+ * be equal to the accumulated one.
*/
- /* value 20 in `near_limit' is heuristic */
- FT_UInt units_per_em = hints->metrics->scaler.face->units_per_EM;
- FT_Int near_limit = 20 * units_per_em / 2048;
- FT_Int near_limit2 = 2 * near_limit - 1;
+ FT_Int near_limit2 = 2 * near_limit - 1;
AF_Point* contour;
AF_Point* contour_limit = hints->contours + hints->num_contours;
@@ -926,7 +963,7 @@
/* now loop over all points of the contour to get */
/* `in' and `out' vector directions */
- curr = first;
+ curr = first;
/*
* We abuse the `u' and `v' fields to store index deltas to the
@@ -949,7 +986,7 @@
point = next;
- next = point->next;
+ next = point->next;
out_x += next->fx - point->fx;
out_y += next->fy - point->fy;