static MagickBooleanType
DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *,
ExceptionInfo *),
- RenderMVGContent(Image *,const DrawInfo *,const size_t,ExceptionInfo *);
-
-static PrimitiveInfo
- *TraceStrokePolygon(const Image *,const DrawInfo *,const PrimitiveInfo *);
-
-static size_t
- TracePath(MVGInfo *,const char *,ExceptionInfo *);
-
-static void
+ RenderMVGContent(Image *,const DrawInfo *,const size_t,ExceptionInfo *),
TraceArc(MVGInfo *,const PointInfo,const PointInfo,const PointInfo),
TraceArcPath(MVGInfo *,const PointInfo,const PointInfo,const PointInfo,
const double,const MagickBooleanType,const MagickBooleanType),
TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo),
TraceRoundRectangle(MVGInfo *,const PointInfo,const PointInfo,PointInfo),
TraceSquareLinecap(PrimitiveInfo *,const size_t,const double);
+
+static PrimitiveInfo
+ *TraceStrokePolygon(const Image *,const DrawInfo *,const PrimitiveInfo *);
+
+static size_t
+ TracePath(MVGInfo *,const char *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
primitive_info[0].primitive=RectanglePrimitive;
- TraceRectangle(primitive_info,start,end);
+ status&=TraceRectangle(primitive_info,start,end);
primitive_info[0].method=ReplaceMethod;
coordinates=(ssize_t) primitive_info[0].coordinates;
primitive_info[coordinates].primitive=UndefinedPrimitive;
end.x=(double) (bounds.x2+mid);
end.y=(double) (bounds.y2+mid);
primitive_info[0].primitive=RectanglePrimitive;
- TraceRectangle(primitive_info,start,end);
+ status&=TraceRectangle(primitive_info,start,end);
primitive_info[0].method=ReplaceMethod;
coordinates=(ssize_t) primitive_info[0].coordinates;
primitive_info[coordinates].primitive=UndefinedPrimitive;
/*
Check if there is enough storage for drawing pimitives.
*/
- extent=(size_t) mvg_info->offset+pad+4096;
- if (extent <= *mvg_info->extent)
- return(MagickTrue);
- *mvg_info->primitive_info=ResizeQuantumMemory(*mvg_info->primitive_info,
- extent,sizeof(**mvg_info->primitive_info));
- if (*mvg_info->primitive_info != (PrimitiveInfo *) NULL)
+ extent=(size_t) mvg_info->offset;
+ if ((HeapOverflowSanityCheck(extent,pad) != MagickFalse) &&
+ (HeapOverflowSanityCheck(extent+pad,4096) != MagickFalse))
{
- *mvg_info->extent=extent;
- return(MagickTrue);
+ extent+=pad+4096;
+ if (extent <= *mvg_info->extent)
+ return(MagickTrue);
+ *mvg_info->primitive_info=ResizeQuantumMemory(*mvg_info->primitive_info,
+ extent,sizeof(**mvg_info->primitive_info));
+ if (*mvg_info->primitive_info != (PrimitiveInfo *) NULL)
+ {
+ *mvg_info->extent=extent;
+ return(MagickTrue);
+ }
}
/*
Reallocation failed, allocate a primitive to facilitate unwinding.
value;
value=StringToDouble(point,&p);
- return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse : MagickTrue);
+ return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
+ MagickTrue);
}
-static inline void TracePoint(PrimitiveInfo *primitive_info,
+static inline MagickBooleanType TracePoint(PrimitiveInfo *primitive_info,
const PointInfo point)
{
primitive_info->coordinates=1;
primitive_info->closed_subpath=MagickFalse;
primitive_info->point=point;
+ return(MagickTrue);
}
static MagickBooleanType RenderMVGContent(Image *image,
status=MagickFalse;
break;
}
- TracePoint(primitive_info+j,primitive_info[j].point);
+ status&=TracePoint(primitive_info+j,primitive_info[j].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
}
status=MagickFalse;
break;
}
- TraceLine(primitive_info+j,primitive_info[j].point,
+ status&=TraceLine(primitive_info+j,primitive_info[j].point,
primitive_info[j+1].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
status=MagickFalse;
break;
}
- TraceRectangle(primitive_info+j,primitive_info[j].point,
+ status&=TraceRectangle(primitive_info+j,primitive_info[j].point,
primitive_info[j+1].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
status=MagickFalse;
break;
}
- TraceRoundRectangle(&mvg_info,primitive_info[j].point,
+ status&=TraceRoundRectangle(&mvg_info,primitive_info[j].point,
primitive_info[j+1].point,primitive_info[j+2].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
primitive_type=UndefinedPrimitive;
break;
}
- TraceArc(&mvg_info,primitive_info[j].point,primitive_info[j+1].point,
- primitive_info[j+2].point);
+ status&=TraceArc(&mvg_info,primitive_info[j].point,
+ primitive_info[j+1].point,primitive_info[j+2].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
}
status=MagickFalse;
break;
}
- TraceEllipse(&mvg_info,primitive_info[j].point,
+ status&=TraceEllipse(&mvg_info,primitive_info[j].point,
primitive_info[j+1].point,primitive_info[j+2].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
status=MagickFalse;
break;
}
- TraceCircle(&mvg_info,primitive_info[j].point,
+ status&=TraceCircle(&mvg_info,primitive_info[j].point,
primitive_info[j+1].point);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
status=MagickFalse;
break;
}
- TraceBezier(&mvg_info,primitive_info[j].coordinates);
+ status&=TraceBezier(&mvg_info,primitive_info[j].coordinates);
i=(ssize_t) (j+primitive_info[j].coordinates);
break;
}
%
*/
-static void TraceArc(MVGInfo *mvg_info,const PointInfo start,
+static MagickBooleanType TraceArc(MVGInfo *mvg_info,const PointInfo start,
const PointInfo end,const PointInfo degrees)
{
PointInfo
center.y=0.5*(end.y+start.y);
radius.x=fabs(center.x-start.x);
radius.y=fabs(center.y-start.y);
- TraceEllipse(mvg_info,center,radius,degrees);
+ return(TraceEllipse(mvg_info,center,radius,degrees));
}
-static void TraceArcPath(MVGInfo *mvg_info,const PointInfo start,
+static MagickBooleanType TraceArcPath(MVGInfo *mvg_info,const PointInfo start,
const PointInfo end,const PointInfo arc,const double angle,
const MagickBooleanType large_arc,const MagickBooleanType sweep)
{
gamma,
theta;
+ MagickBooleanType
+ status;
+
PointInfo
center,
points[3],
primitive_info->coordinates=0;
if ((fabs(start.x-end.x) < MagickEpsilon) &&
(fabs(start.y-end.y) < MagickEpsilon))
- {
- TracePoint(primitive_info,end);
- return;
- }
+ return(TracePoint(primitive_info,end));
radii.x=fabs(arc.x);
radii.y=fabs(arc.y);
if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
- {
- TraceLine(primitive_info,start,end);
- return;
- }
+ return(TraceLine(primitive_info,start,end));
cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
(radii.y*radii.y);
if (delta < MagickEpsilon)
- {
- TraceLine(primitive_info,start,end);
- return;
- }
+ return(TraceLine(primitive_info,start,end));
if (delta > 1.0)
{
radii.x*=sqrt((double) delta);
else
if ((theta > 0.0) && (sweep == MagickFalse))
theta-=2.0*MagickPI;
- arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+MagickEpsilon))));
+ arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+
+ MagickEpsilon))));
+ status=MagickTrue;
p=primitive_info;
for (i=0; i < (ssize_t) arc_segments; i++)
{
points[2].y);
if (i == (ssize_t) (arc_segments-1))
(p+3)->point=end;
- TraceBezier(mvg_info,4);
+ status&=TraceBezier(mvg_info,4);
p=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=p->coordinates;
p+=p->coordinates;
p->primitive=primitive_info->primitive;
p--;
}
+ return(status);
}
-static void TraceBezier(MVGInfo *mvg_info,const size_t number_coordinates)
+static MagickBooleanType TraceBezier(MVGInfo *mvg_info,
+ const size_t number_coordinates)
{
double
alpha,
(double) BezierQuantum);
control_points=quantum*number_coordinates;
if (CheckPrimitiveExtent(mvg_info,control_points+1) == MagickFalse)
- return;
+ return(MagickFalse);
primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
coefficients=(double *) AcquireQuantumMemory((size_t)
number_coordinates,sizeof(*coefficients));
p=primitive_info;
for (i=0; i < (ssize_t) control_points; i++)
{
- TracePoint(p,points[i]);
+ if (TracePoint(p,points[i]) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
}
- TracePoint(p,end);
+ if (TracePoint(p,end) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
primitive_info->coordinates=(size_t) (p-primitive_info);
primitive_info->closed_subpath=MagickFalse;
}
points=(PointInfo *) RelinquishMagickMemory(points);
coefficients=(double *) RelinquishMagickMemory(coefficients);
+ return(MagickTrue);
}
-static void TraceCircle(MVGInfo *mvg_info,const PointInfo start,
+static MagickBooleanType TraceCircle(MVGInfo *mvg_info,const PointInfo start,
const PointInfo end)
{
double
offset.y=(double) radius;
degrees.x=0.0;
degrees.y=360.0;
- TraceEllipse(mvg_info,start,offset,degrees);
+ return(TraceEllipse(mvg_info,start,offset,degrees));
}
-static void TraceEllipse(MVGInfo *mvg_info,const PointInfo center,
+static MagickBooleanType TraceEllipse(MVGInfo *mvg_info,const PointInfo center,
const PointInfo radii,const PointInfo arc)
{
double
primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
primitive_info->coordinates=0;
if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
- return;
+ return(MagickTrue);
delta=2.0*PerceptibleReciprocal(MagickMax(radii.x,radii.y));
step=MagickPI/8.0;
if ((delta >= 0.0) && (delta < (MagickPI/8.0)))
angle.y=DegreesToRadians(y);
extent=(size_t) ceil((angle.y-angle.x)/step)+1;
if (CheckPrimitiveExtent(mvg_info,extent) == MagickFalse)
- return;
+ return(MagickFalse);
primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
for (p=primitive_info; angle.x < angle.y; angle.x+=step)
{
point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
- TracePoint(p,point);
+ if (TracePoint(p,point) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
}
point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
- TracePoint(p,point);
+ if (TracePoint(p,point) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
primitive_info->coordinates=(size_t) (p-primitive_info);
primitive_info->closed_subpath=MagickFalse;
p->primitive=primitive_info->primitive;
p--;
}
+ return(MagickTrue);
}
-static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
- const PointInfo end)
+static MagickBooleanType TraceLine(PrimitiveInfo *primitive_info,
+ const PointInfo start,const PointInfo end)
{
- TracePoint(primitive_info,start);
+ if (TracePoint(primitive_info,start) == MagickFalse)
+ return(MagickFalse);
if ((fabs(start.x-end.x) < MagickEpsilon) &&
(fabs(start.y-end.y) < MagickEpsilon))
{
primitive_info->primitive=PointPrimitive;
primitive_info->coordinates=1;
- return;
+ return(MagickTrue);
}
- TracePoint(primitive_info+1,end);
+ if (TracePoint(primitive_info+1,end) == MagickFalse)
+ return(MagickFalse);
(primitive_info+1)->primitive=primitive_info->primitive;
primitive_info->coordinates=2;
primitive_info->closed_subpath=MagickFalse;
+ return(MagickTrue);
}
static size_t TracePath(MVGInfo *mvg_info,const char *path,
ThrowPointExpectedException(token,exception);
end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
- TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep);
+ if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
+ return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
}
for (i=0; i < 4; i++)
(q+i)->point=points[i];
- TraceBezier(mvg_info,4);
+ if (TraceBezier(mvg_info,4) == MagickFalse)
+ return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
if (CheckPrimitiveExtent(mvg_info,4096) == MagickFalse)
return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
- TracePoint(q,point);
+ if (TracePoint(q,point) == MagickFalse)
+ return(0);
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
while (isspace((int) ((unsigned char) *p)) != 0)
if (CheckPrimitiveExtent(mvg_info,4096) == MagickFalse)
return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
- TracePoint(q,point);
+ if (TracePoint(q,point) == MagickFalse)
+ return(0);
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
while (isspace((int) ((unsigned char) *p)) != 0)
if (CheckPrimitiveExtent(mvg_info,4096) == MagickFalse)
return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
- TracePoint(q,point);
+ if (TracePoint(q,point) == MagickFalse)
+ return(0);
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
while (isspace((int) ((unsigned char) *p)) != 0)
}
for (i=0; i < 3; i++)
(q+i)->point=points[i];
- TraceBezier(mvg_info,3);
+ if (TraceBezier(mvg_info,3) == MagickFalse)
+ return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
}
for (i=0; i < 4; i++)
(q+i)->point=points[i];
- TraceBezier(mvg_info,4);
+ if (TraceBezier(mvg_info,4) == MagickFalse)
+ return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
}
for (i=0; i < 3; i++)
(q+i)->point=points[i];
- TraceBezier(mvg_info,3);
+ if (TraceBezier(mvg_info,3) == MagickFalse)
+ return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
if (CheckPrimitiveExtent(mvg_info,4096) == MagickFalse)
return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
- TracePoint(q,point);
+ if (TracePoint(q,point) == MagickFalse)
+ return(0);
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
while (isspace((int) ((unsigned char) *p)) != 0)
if (CheckPrimitiveExtent(mvg_info,4096) == MagickFalse)
return(0);
q=(*mvg_info->primitive_info)+mvg_info->offset;
- TracePoint(q,point);
+ if (TracePoint(q,point) == MagickFalse)
+ return(0);
mvg_info->offset+=q->coordinates;
q+=q->coordinates;
primitive_info=(*mvg_info->primitive_info)+subpath_offset;
return(number_coordinates);
}
-static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
- const PointInfo end)
+static MagickBooleanType TraceRectangle(PrimitiveInfo *primitive_info,
+ const PointInfo start,const PointInfo end)
{
PointInfo
point;
(fabs(start.y-end.y) < MagickEpsilon))
{
primitive_info->coordinates=0;
- return;
+ return(MagickTrue);
}
p=primitive_info;
- TracePoint(p,start);
+ if (TracePoint(p,start) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
point.x=start.x;
point.y=end.y;
- TracePoint(p,point);
+ if (TracePoint(p,point) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
- TracePoint(p,end);
+ if (TracePoint(p,end) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
point.x=end.x;
point.y=start.y;
- TracePoint(p,point);
+ if (TracePoint(p,point) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
- TracePoint(p,start);
+ if (TracePoint(p,start) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
primitive_info->coordinates=(size_t) (p-primitive_info);
primitive_info->closed_subpath=MagickTrue;
p->primitive=primitive_info->primitive;
p--;
}
+ return(MagickTrue);
}
-static void TraceRoundRectangle(MVGInfo *mvg_info,const PointInfo start,
- const PointInfo end,PointInfo arc)
+static MagickBooleanType TraceRoundRectangle(MVGInfo *mvg_info,
+ const PointInfo start,const PointInfo end,PointInfo arc)
{
PointInfo
degrees,
if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
{
(*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
- return;
+ return(MagickTrue);
}
if (arc.x > (0.5*segment.x))
arc.x=0.5*segment.x;
point.y=start.y+arc.y;
degrees.x=270.0;
degrees.y=360.0;
- TraceEllipse(mvg_info,point,arc,degrees);
+ if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
+ return(MagickFalse);
p=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=p->coordinates;
point.x=start.x+segment.x-arc.x;
point.y=start.y+segment.y-arc.y;
degrees.x=0.0;
degrees.y=90.0;
- TraceEllipse(mvg_info,point,arc,degrees);
+ if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
+ return(MagickFalse);
p=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=p->coordinates;
point.x=start.x+arc.x;
point.y=start.y+segment.y-arc.y;
degrees.x=90.0;
degrees.y=180.0;
- TraceEllipse(mvg_info,point,arc,degrees);
+ if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
+ return(MagickFalse);
p=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=p->coordinates;
point.x=start.x+arc.x;
point.y=start.y+arc.y;
degrees.x=180.0;
degrees.y=270.0;
- TraceEllipse(mvg_info,point,arc,degrees);
+ if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
+ return(MagickFalse);
p=(*mvg_info->primitive_info)+mvg_info->offset;
mvg_info->offset+=p->coordinates;
if (CheckPrimitiveExtent(mvg_info,4096) == MagickFalse)
- return;
+ return(MagickFalse);
p=(*mvg_info->primitive_info)+mvg_info->offset;
- TracePoint(p,(*mvg_info->primitive_info+offset)->point);
+ if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
+ return(MagickFalse);
p+=p->coordinates;
mvg_info->offset=offset;
primitive_info=(*mvg_info->primitive_info)+offset;
p->primitive=primitive_info->primitive;
p--;
}
+ return(MagickTrue);
}
-static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
+static MagickBooleanType TraceSquareLinecap(PrimitiveInfo *primitive_info,
const size_t number_vertices,const double offset)
{
double
dx*(distance+offset)/distance);
primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
dy*(distance+offset)/distance);
+ return(MagickTrue);
}
static PrimitiveInfo *TraceStrokePolygon(const Image *image,
mid=ExpandAffine(&draw_info->affine)*SaneStrokeWidth(image,draw_info)/2.0;
miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
- TraceSquareLinecap(polygon_primitive,number_vertices,mid);
+ (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
offset.y=(double) (offset.x*inverse_slope.p);
if ((dy.p*offset.x-dx.p*offset.y) > 0.0)