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.c226
1 files changed, 140 insertions, 86 deletions
diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c
index 88a97d4..37482eb 100644
--- a/src/autofit/afhints.c
+++ b/src/autofit/afhints.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter hinting routines (body). */
/* */
-/* Copyright 2003-2007, 2009-2014 by */
+/* Copyright 2003-2015 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -43,7 +43,15 @@
AF_Segment segment = NULL;
- if ( axis->num_segments >= axis->max_segments )
+ if ( axis->num_segments < AF_SEGMENTS_EMBEDDED )
+ {
+ if ( axis->segments == NULL )
+ {
+ axis->segments = axis->embedded.segments;
+ axis->max_segments = AF_SEGMENTS_EMBEDDED;
+ }
+ }
+ else if ( axis->num_segments >= axis->max_segments )
{
FT_Int old_max = axis->max_segments;
FT_Int new_max = old_max;
@@ -60,8 +68,18 @@
if ( new_max < old_max || new_max > big_max )
new_max = big_max;
- if ( FT_RENEW_ARRAY( axis->segments, old_max, new_max ) )
- goto Exit;
+ if ( axis->segments == axis->embedded.segments )
+ {
+ if ( FT_NEW_ARRAY( axis->segments, new_max ) )
+ goto Exit;
+ ft_memcpy( axis->segments, axis->embedded.segments,
+ sizeof ( axis->embedded.segments ) );
+ }
+ else
+ {
+ if ( FT_RENEW_ARRAY( axis->segments, old_max, new_max ) )
+ goto Exit;
+ }
axis->max_segments = new_max;
}
@@ -74,7 +92,8 @@
}
- /* Get new edge for given axis, direction, and position. */
+ /* Get new edge for given axis, direction, and position, */
+ /* without initializing the edge itself. */
FT_LOCAL( FT_Error )
af_axis_hints_new_edge( AF_AxisHints axis,
@@ -88,7 +107,15 @@
AF_Edge edges;
- if ( axis->num_edges >= axis->max_edges )
+ if ( axis->num_edges < AF_EDGES_EMBEDDED )
+ {
+ if ( axis->edges == NULL )
+ {
+ axis->edges = axis->embedded.edges;
+ axis->max_edges = AF_EDGES_EMBEDDED;
+ }
+ }
+ else if ( axis->num_edges >= axis->max_edges )
{
FT_Int old_max = axis->max_edges;
FT_Int new_max = old_max;
@@ -105,8 +132,18 @@
if ( new_max < old_max || new_max > big_max )
new_max = big_max;
- if ( FT_RENEW_ARRAY( axis->edges, old_max, new_max ) )
- goto Exit;
+ if ( axis->edges == axis->embedded.edges )
+ {
+ if ( FT_NEW_ARRAY( axis->edges, new_max ) )
+ goto Exit;
+ ft_memcpy( axis->edges, axis->embedded.edges,
+ sizeof ( axis->embedded.edges ) );
+ }
+ else
+ {
+ if ( FT_RENEW_ARRAY( axis->edges, old_max, new_max ) )
+ goto Exit;
+ }
axis->max_edges = new_max;
}
@@ -130,10 +167,6 @@
axis->num_edges++;
- FT_ZERO( edge );
- edge->fpos = (FT_Short)fpos;
- edge->dir = (FT_Char)dir;
-
Exit:
*anedge = edge;
return error;
@@ -183,7 +216,7 @@
}
-#define AF_INDEX_NUM( ptr, base ) ( (ptr) ? ( (ptr) - (base) ) : -1 )
+#define AF_INDEX_NUM( ptr, base ) (int)( (ptr) ? ( (ptr) - (base) ) : -1 )
#ifdef __cplusplus
@@ -198,26 +231,25 @@
AF_Point point;
- AF_DUMP(( "Table of points:\n"
- " [ index | xorg | yorg | xscale | yscale"
- " | xfit | yfit | flags ]\n" ));
+ AF_DUMP(( "Table of points:\n" ));
+
+ if ( hints->num_points )
+ AF_DUMP(( " [ index | xorg | yorg | xscale | yscale"
+ " | xfit | yfit | flags ]\n" ));
+ else
+ AF_DUMP(( " (none)\n" ));
for ( point = points; point < limit; point++ )
AF_DUMP(( " [ %5d | %5d | %5d | %6.2f | %6.2f"
- " | %5.2f | %5.2f | %c%c%c%c%c%c ]\n",
- point - points,
+ " | %5.2f | %5.2f | %c ]\n",
+ AF_INDEX_NUM( point, points ),
point->fx,
point->fy,
point->ox / 64.0,
point->oy / 64.0,
point->x / 64.0,
point->y / 64.0,
- ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' ',
- ( point->flags & AF_FLAG_INFLECTION ) ? 'i' : ' ',
- ( point->flags & AF_FLAG_EXTREMA_X ) ? '<' : ' ',
- ( point->flags & AF_FLAG_EXTREMA_Y ) ? 'v' : ' ',
- ( point->flags & AF_FLAG_ROUND_X ) ? '(' : ' ',
- ( point->flags & AF_FLAG_ROUND_Y ) ? 'u' : ' '));
+ ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' '));
AF_DUMP(( "\n" ));
}
#ifdef __cplusplus
@@ -226,7 +258,7 @@
static const char*
- af_edge_flags_to_string( AF_Edge_Flags flags )
+ af_edge_flags_to_string( FT_UInt flags )
{
static char temp[32];
int pos = 0;
@@ -289,7 +321,7 @@
AF_DUMP(( " [ %5d | %5.2g | %5s | %4d"
" | %4d | %4d | %5d | %4d"
" | %6d | %5d | %11s ]\n",
- seg - segments,
+ AF_INDEX_NUM( seg, segments ),
dimension == AF_DIMENSION_HORZ
? (int)seg->first->ox / 64.0
: (int)seg->first->oy / 64.0,
@@ -301,7 +333,7 @@
AF_INDEX_NUM( seg->edge, edges ),
seg->height,
seg->height - ( seg->max_coord - seg->min_coord ),
- af_edge_flags_to_string( (AF_Edge_Flags)seg->flags ) ));
+ af_edge_flags_to_string( seg->flags ) ));
AF_DUMP(( "\n" ));
}
}
@@ -420,7 +452,7 @@
for ( edge = edges; edge < limit; edge++ )
AF_DUMP(( " [ %5d | %5.2g | %5s | %4d"
" | %5d | %c | %5.2f | %5.2f | %11s ]\n",
- edge - edges,
+ AF_INDEX_NUM( edge, edges ),
(int)edge->opos / 64.0,
af_dir_str( (AF_Direction)edge->dir ),
AF_INDEX_NUM( edge->link, edges ),
@@ -428,7 +460,7 @@
edge->blue_edge ? 'y' : 'n',
edge->opos / 64.0,
edge->pos / 64.0,
- af_edge_flags_to_string( (AF_Edge_Flags)edge->flags ) ));
+ af_edge_flags_to_string( edge->flags ) ));
AF_DUMP(( "\n" ));
}
}
@@ -477,15 +509,15 @@
else
{
dir = AF_DIR_DOWN;
- ll = dy;
+ ll = -dy;
ss = dx;
}
}
- /* return no direction if arm lengths differ too much */
+ /* return no direction if arm lengths do not differ enough */
/* (value 14 is heuristic, corresponding to approx. 4.1 degrees) */
- ss *= 14;
- if ( FT_ABS( ll ) <= FT_ABS( ss ) )
+ /* the long arm is never negative */
+ if ( ll <= 14 * FT_ABS( ss ) )
dir = AF_DIR_NONE;
return dir;
@@ -496,7 +528,8 @@
af_glyph_hints_init( AF_GlyphHints hints,
FT_Memory memory )
{
- FT_ZERO( hints );
+ /* no need to initialize the embedded items */
+ FT_MEM_ZERO( hints, sizeof ( *hints ) - sizeof ( hints->embedded ) );
hints->memory = memory;
}
@@ -504,13 +537,15 @@
FT_LOCAL_DEF( void )
af_glyph_hints_done( AF_GlyphHints hints )
{
- FT_Memory memory = hints->memory;
+ FT_Memory memory;
int dim;
if ( !( hints && hints->memory ) )
return;
+ memory = hints->memory;
+
/*
* note that we don't need to free the segment and edge
* buffers since they are really within the hints->points array
@@ -522,20 +557,24 @@
axis->num_segments = 0;
axis->max_segments = 0;
- FT_FREE( axis->segments );
+ if ( axis->segments != axis->embedded.segments )
+ FT_FREE( axis->segments );
axis->num_edges = 0;
axis->max_edges = 0;
- FT_FREE( axis->edges );
+ if ( axis->edges != axis->embedded.edges )
+ FT_FREE( axis->edges );
}
- FT_FREE( hints->contours );
+ if ( hints->contours != hints->embedded.contours )
+ FT_FREE( hints->contours );
hints->max_contours = 0;
hints->num_contours = 0;
- FT_FREE( hints->points );
- hints->num_points = 0;
+ if ( hints->points != hints->embedded.points )
+ FT_FREE( hints->points );
hints->max_points = 0;
+ hints->num_points = 0;
hints->memory = NULL;
}
@@ -579,15 +618,27 @@
/* first of all, reallocate the contours array if necessary */
new_max = (FT_UInt)outline->n_contours;
- old_max = hints->max_contours;
- if ( new_max > old_max )
+ old_max = (FT_UInt)hints->max_contours;
+
+ if ( new_max <= AF_CONTOURS_EMBEDDED )
+ {
+ if ( hints->contours == NULL )
+ {
+ hints->contours = hints->embedded.contours;
+ hints->max_contours = AF_CONTOURS_EMBEDDED;
+ }
+ }
+ else if ( new_max > old_max )
{
- new_max = ( new_max + 3 ) & ~3; /* round up to a multiple of 4 */
+ if ( hints->contours == hints->embedded.contours )
+ hints->contours = NULL;
+
+ new_max = ( new_max + 3 ) & ~3U; /* round up to a multiple of 4 */
if ( FT_RENEW_ARRAY( hints->contours, old_max, new_max ) )
goto Exit;
- hints->max_contours = new_max;
+ hints->max_contours = (FT_Int)new_max;
}
/*
@@ -596,15 +647,27 @@
* hint metrics appropriately
*/
new_max = (FT_UInt)( outline->n_points + 2 );
- old_max = hints->max_points;
- if ( new_max > old_max )
+ old_max = (FT_UInt)hints->max_points;
+
+ if ( new_max <= AF_POINTS_EMBEDDED )
+ {
+ if ( hints->points == NULL )
+ {
+ hints->points = hints->embedded.points;
+ hints->max_points = AF_POINTS_EMBEDDED;
+ }
+ }
+ else if ( new_max > old_max )
{
- new_max = ( new_max + 2 + 7 ) & ~7; /* round up to a multiple of 8 */
+ if ( hints->points == hints->embedded.points )
+ hints->points = NULL;
+
+ new_max = ( new_max + 2 + 7 ) & ~7U; /* round up to a multiple of 8 */
if ( FT_RENEW_ARRAY( hints->points, old_max, new_max ) )
goto Exit;
- hints->max_points = new_max;
+ hints->max_points = (FT_Int)new_max;
}
hints->num_points = outline->n_points;
@@ -729,8 +792,6 @@
FT_Pos out_x, out_y;
- FT_Bool is_first;
-
/* since the first point of a contour could be part of a */
/* series of near points, go backwards to find the first */
@@ -781,17 +842,13 @@
out_x = 0;
out_y = 0;
- is_first = 1;
-
- for ( point = first;
- point != first || is_first;
- point = point->next )
+ next = first;
+ do
{
AF_Direction out_dir;
- is_first = 0;
-
+ point = next;
next = point->next;
out_x += next->fx - point->fx;
@@ -823,7 +880,8 @@
out_x = 0;
out_y = 0;
- }
+
+ } while ( next != first );
}
/*
@@ -1053,7 +1111,7 @@
AF_AxisHints axis = &hints->axis[dim];
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
- AF_Flags touch_flag;
+ FT_UInt touch_flag;
if ( dim == AF_DIMENSION_HORZ )
@@ -1079,8 +1137,7 @@
/* if this point is candidate to weak interpolation, we */
/* interpolate it after all strong points have been processed */
- if ( ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) &&
- !( point->flags & AF_FLAG_INFLECTION ) )
+ if ( ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) )
continue;
if ( dim == AF_DIMENSION_VERT )
@@ -1235,33 +1292,27 @@
AF_Point ref2 )
{
AF_Point p;
- FT_Pos u;
- FT_Pos v1 = ref1->v;
- FT_Pos v2 = ref2->v;
- FT_Pos d1 = ref1->u - v1;
- FT_Pos d2 = ref2->u - v2;
+ FT_Pos u, v1, v2, u1, u2, d1, d2;
if ( p1 > p2 )
return;
- if ( v1 == v2 )
+ if ( ref1->v > ref2->v )
{
- for ( p = p1; p <= p2; p++ )
- {
- u = p->v;
-
- if ( u <= v1 )
- u += d1;
- else
- u += d2;
-
- p->u = u;
- }
- return;
+ p = ref1;
+ ref1 = ref2;
+ ref2 = p;
}
- if ( v1 < v2 )
+ v1 = ref1->v;
+ v2 = ref2->v;
+ u1 = ref1->u;
+ u2 = ref2->u;
+ d1 = u1 - v1;
+ d2 = u2 - v2;
+
+ if ( u1 == u2 || v1 == v2 )
{
for ( p = p1; p <= p2; p++ )
{
@@ -1272,23 +1323,26 @@
else if ( u >= v2 )
u += d2;
else
- u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 );
+ u = u1;
p->u = u;
}
}
else
{
+ FT_Fixed scale = FT_DivFix( u2 - u1, v2 - v1 );
+
+
for ( p = p1; p <= p2; p++ )
{
u = p->v;
- if ( u <= v2 )
- u += d2;
- else if ( u >= v1 )
+ if ( u <= v1 )
u += d1;
+ else if ( u >= v2 )
+ u += d2;
else
- u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 );
+ u = u1 + FT_MulFix( u - v1, scale );
p->u = u;
}
@@ -1307,7 +1361,7 @@
AF_Point point_limit = points + hints->num_points;
AF_Point* contour = hints->contours;
AF_Point* contour_limit = contour + hints->num_contours;
- AF_Flags touch_flag;
+ FT_UInt touch_flag;
AF_Point point;
AF_Point end_point;
AF_Point first_point;