summaryrefslogtreecommitdiffstats
path: root/src/base/ftstroke.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/ftstroke.c')
-rw-r--r--src/base/ftstroke.c125
1 files changed, 87 insertions, 38 deletions
diff --git a/src/base/ftstroke.c b/src/base/ftstroke.c
index ee61cec..842ee30 100644
--- a/src/base/ftstroke.c
+++ b/src/base/ftstroke.c
@@ -4,7 +4,7 @@
/* */
/* FreeType path stroker (body). */
/* */
-/* Copyright 2002-2006, 2008-2011, 2013 by */
+/* Copyright 2002-2015 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -347,7 +347,7 @@
ft_stroke_border_close( FT_StrokeBorder border,
FT_Bool reverse )
{
- FT_UInt start = border->start;
+ FT_UInt start = (FT_UInt)border->start;
FT_UInt count = border->num_points;
@@ -599,7 +599,7 @@
if ( border->start >= 0 )
ft_stroke_border_close( border, FALSE );
- border->start = border->num_points;
+ border->start = (FT_Int)border->num_points;
border->movable = FALSE;
return ft_stroke_border_lineto( border, to, FALSE );
@@ -742,7 +742,7 @@
}
}
- outline->n_points = (short)( outline->n_points + border->num_points );
+ outline->n_points += (short)border->num_points;
FT_ASSERT( FT_Outline_Check( outline ) == 0 );
}
@@ -795,6 +795,9 @@
if ( !library )
+ return FT_THROW( Invalid_Library_Handle );
+
+ if ( !astroker )
return FT_THROW( Invalid_Argument );
memory = library->memory;
@@ -822,14 +825,17 @@
FT_Stroker_LineJoin line_join,
FT_Fixed miter_limit )
{
+ if ( !stroker )
+ return;
+
stroker->radius = radius;
stroker->line_cap = line_cap;
stroker->line_join = line_join;
stroker->miter_limit = miter_limit;
/* ensure miter limit has sensible value */
- if ( stroker->miter_limit < 0x10000 )
- stroker->miter_limit = 0x10000;
+ if ( stroker->miter_limit < 0x10000L )
+ stroker->miter_limit = 0x10000L;
/* save line join style: */
/* line join style can be temporarily changed when stroking curves */
@@ -993,7 +999,9 @@
/* Only intersect borders if between two lineto's and both */
/* lines are long enough (line_length is zero for curves). */
- if ( !border->movable || line_length == 0 )
+ /* Also avoid U-turns of nearly 180 degree. */
+ if ( !border->movable || line_length == 0 ||
+ theta > 0x59C000 || theta < -0x59C000 )
intersect = FALSE;
else
{
@@ -1002,7 +1010,8 @@
FT_Tan( theta ) ) );
- intersect = FT_BOOL( stroker->line_length >= min_length &&
+ intersect = FT_BOOL( min_length &&
+ stroker->line_length >= min_length &&
line_length >= min_length );
}
@@ -1213,11 +1222,8 @@
goto Exit;
/* when we turn to the right, the inside side is 0 */
- inside_side = 0;
-
/* otherwise, the inside side is 1 */
- if ( turn < 0 )
- inside_side = 1;
+ inside_side = ( turn < 0 );
/* process the inside side */
error = ft_stroker_inside( stroker, inside_side, line_length );
@@ -1225,7 +1231,7 @@
goto Exit;
/* process the outside side */
- error = ft_stroker_outside( stroker, 1 - inside_side, line_length );
+ error = ft_stroker_outside( stroker, !inside_side, line_length );
Exit:
return error;
@@ -1287,6 +1293,9 @@
FT_Fixed line_length;
+ if ( !stroker || !to )
+ return FT_THROW( Invalid_Argument );
+
delta.x = to->x - stroker->center.x;
delta.y = to->y - stroker->center.y;
@@ -1360,6 +1369,12 @@
FT_Bool first_arc = TRUE;
+ if ( !stroker || !control || !to )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
/* if all control points are coincident, this is a no-op; */
/* avoid creating a spurious corner */
if ( FT_IS_SMALL( stroker->center.x - control->x ) &&
@@ -1556,6 +1571,12 @@
FT_Bool first_arc = TRUE;
+ if ( !stroker || !control1 || !control2 || !to )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
/* if all control points are coincident, this is a no-op; */
/* avoid creating a spurious corner */
if ( FT_IS_SMALL( stroker->center.x - control1->x ) &&
@@ -1758,6 +1779,9 @@
FT_Vector* to,
FT_Bool open )
{
+ if ( !stroker || !to )
+ return FT_THROW( Invalid_Argument );
+
/* We cannot process the first point, because there is not enough */
/* information regarding its corner/cap. The latter will be processed */
/* in the `FT_Stroker_EndSubPath' routine. */
@@ -1797,7 +1821,7 @@
FT_ASSERT( left->start >= 0 );
- new_points = left->num_points - left->start;
+ new_points = (FT_Int)left->num_points - left->start;
if ( new_points > 0 )
{
error = ft_stroke_border_grow( right, (FT_UInt)new_points );
@@ -1837,8 +1861,8 @@
}
}
- left->num_points = left->start;
- right->num_points += new_points;
+ left->num_points = (FT_UInt)left->start;
+ right->num_points += (FT_UInt)new_points;
right->movable = FALSE;
left->movable = FALSE;
@@ -1858,6 +1882,12 @@
FT_Error error = FT_Err_Ok;
+ if ( !stroker )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
if ( stroker->subpath_open )
{
FT_StrokeBorder right = stroker->borders;
@@ -1910,11 +1940,8 @@
if ( turn != 0 )
{
/* when we turn to the right, the inside side is 0 */
- inside_side = 0;
-
/* otherwise, the inside side is 1 */
- if ( turn < 0 )
- inside_side = 1;
+ inside_side = ( turn < 0 );
error = ft_stroker_inside( stroker,
inside_side,
@@ -1924,7 +1951,7 @@
/* process the outside side */
error = ft_stroker_outside( stroker,
- 1 - inside_side,
+ !inside_side,
stroker->subpath_line_length );
if ( error )
goto Exit;
@@ -1983,6 +2010,12 @@
FT_Error error;
+ if ( !stroker )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
error = ft_stroke_border_get_counts( stroker->borders + 0,
&count1, &count2 );
if ( error )
@@ -1997,8 +2030,12 @@
num_contours = count2 + count4;
Exit:
- *anum_points = num_points;
- *anum_contours = num_contours;
+ if ( anum_points )
+ *anum_points = num_points;
+
+ if ( anum_contours )
+ *anum_contours = num_contours;
+
return error;
}
@@ -2010,6 +2047,9 @@
FT_StrokerBorder border,
FT_Outline* outline )
{
+ if ( !stroker || !outline )
+ return;
+
if ( border == FT_STROKER_BORDER_LEFT ||
border == FT_STROKER_BORDER_RIGHT )
{
@@ -2059,7 +2099,10 @@
FT_Int tag; /* current point's state */
- if ( !outline || !stroker )
+ if ( !outline )
+ return FT_THROW( Invalid_Outline );
+
+ if ( !stroker )
return FT_THROW( Invalid_Argument );
FT_Stroker_Rewind( stroker );
@@ -2071,7 +2114,7 @@
FT_UInt last; /* index of last point in contour */
- last = outline->contours[n];
+ last = (FT_UInt)outline->contours[n];
limit = outline->points + last;
/* skip empty points; we don't stroke these */
@@ -2258,18 +2301,20 @@
FT_Stroker stroker,
FT_Bool destroy )
{
- FT_Error error = FT_ERR( Invalid_Argument );
- FT_Glyph glyph = NULL;
+ FT_Error error = FT_ERR( Invalid_Argument );
+ FT_Glyph glyph = NULL;
+
+ /* for FT_OUTLINE_GLYPH_CLASS_GET (in PIC mode) */
FT_Library library = stroker->library;
FT_UNUSED( library );
- if ( pglyph == NULL )
+ if ( !pglyph )
goto Exit;
glyph = *pglyph;
- if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
+ if ( !glyph || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
goto Exit;
{
@@ -2293,12 +2338,14 @@
if ( error )
goto Fail;
- (void)FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
+ FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
FT_Outline_Done( glyph->library, outline );
error = FT_Outline_New( glyph->library,
- num_points, num_contours, outline );
+ num_points,
+ (FT_Int)num_contours,
+ outline );
if ( error )
goto Fail;
@@ -2334,18 +2381,20 @@
FT_Bool inside,
FT_Bool destroy )
{
- FT_Error error = FT_ERR( Invalid_Argument );
- FT_Glyph glyph = NULL;
+ FT_Error error = FT_ERR( Invalid_Argument );
+ FT_Glyph glyph = NULL;
+
+ /* for FT_OUTLINE_GLYPH_CLASS_GET (in PIC mode) */
FT_Library library = stroker->library;
FT_UNUSED( library );
- if ( pglyph == NULL )
+ if ( !pglyph )
goto Exit;
glyph = *pglyph;
- if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
+ if ( !glyph || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
goto Exit;
{
@@ -2379,14 +2428,14 @@
if ( error )
goto Fail;
- (void)FT_Stroker_GetBorderCounts( stroker, border,
- &num_points, &num_contours );
+ FT_Stroker_GetBorderCounts( stroker, border,
+ &num_points, &num_contours );
FT_Outline_Done( glyph->library, outline );
error = FT_Outline_New( glyph->library,
num_points,
- num_contours,
+ (FT_Int)num_contours,
outline );
if ( error )
goto Fail;