summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/autofit/afhints.c
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2015-11-02 07:10:28 +0400
committerKonstantin Ritt <ritt.ks@gmail.com>2015-11-03 16:21:10 +0000
commitdba44cd4e5754b579f2184a864ffe7b79b0a7e56 (patch)
treec8829051b16c8a78f049fb05bae9322293143c91 /src/3rdparty/freetype/src/autofit/afhints.c
parente056be144a0207699b42a01b6d4cb6f19be474d7 (diff)
Update bundled FreeType to 2.6.1
Change-Id: Ic489f8aa8ad42da3922f542e6c9064afe44f3799 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/3rdparty/freetype/src/autofit/afhints.c')
-rw-r--r--src/3rdparty/freetype/src/autofit/afhints.c199
1 files changed, 131 insertions, 68 deletions
diff --git a/src/3rdparty/freetype/src/autofit/afhints.c b/src/3rdparty/freetype/src/autofit/afhints.c
index f3cc50f202..37482ebd1f 100644
--- a/src/3rdparty/freetype/src/autofit/afhints.c
+++ b/src/3rdparty/freetype/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;
}
@@ -89,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;
@@ -106,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;
}
@@ -195,9 +231,13 @@
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"
@@ -218,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;
@@ -293,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 +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" ));
}
}
@@ -469,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;
@@ -488,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;
}
@@ -496,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
@@ -514,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;
}
@@ -571,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;
}
/*
@@ -588,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;
@@ -721,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 */
@@ -773,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;
@@ -815,7 +880,8 @@
out_x = 0;
out_y = 0;
- }
+
+ } while ( next != first );
}
/*
@@ -1045,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 )
@@ -1226,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++ )
{
@@ -1263,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;
}
@@ -1298,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;