48#include "MagickCore/studio.h"
49#include "MagickCore/annotate.h"
50#include "MagickCore/artifact.h"
51#include "MagickCore/blob.h"
52#include "MagickCore/cache.h"
53#include "MagickCore/cache-private.h"
54#include "MagickCore/cache-view.h"
55#include "MagickCore/channel.h"
56#include "MagickCore/color.h"
57#include "MagickCore/colorspace-private.h"
58#include "MagickCore/composite.h"
59#include "MagickCore/composite-private.h"
60#include "MagickCore/constitute.h"
61#include "MagickCore/constitute-private.h"
62#include "MagickCore/draw.h"
63#include "MagickCore/draw-private.h"
64#include "MagickCore/enhance.h"
65#include "MagickCore/exception.h"
66#include "MagickCore/exception-private.h"
67#include "MagickCore/gem.h"
68#include "MagickCore/geometry.h"
69#include "MagickCore/image-private.h"
70#include "MagickCore/list.h"
71#include "MagickCore/log.h"
72#include "MagickCore/magick.h"
73#include "MagickCore/memory-private.h"
74#include "MagickCore/monitor.h"
75#include "MagickCore/monitor-private.h"
76#include "MagickCore/option.h"
77#include "MagickCore/paint.h"
78#include "MagickCore/pixel-accessor.h"
79#include "MagickCore/property.h"
80#include "MagickCore/resample.h"
81#include "MagickCore/resample-private.h"
82#include "MagickCore/resource_.h"
83#include "MagickCore/splay-tree.h"
84#include "MagickCore/string_.h"
85#include "MagickCore/string-private.h"
86#include "MagickCore/thread-private.h"
87#include "MagickCore/token.h"
88#include "MagickCore/transform-private.h"
89#include "MagickCore/utility.h"
94#define AntialiasThreshold (1.0/3.0)
95#define BezierQuantum 200
96#define MaxVectorRecursionDepth 400
97#define PrimitiveExtentPad 4296.0
98#define MaxBezierCoordinates 67108864
99#define MacroExpansionLimit 262144
100#define ThrowPointExpectedException(token,exception) \
102 (void) ThrowMagickException(exception,GetMagickModule(),DrawError, \
103 "NonconformingDrawingPrimitiveDefinition","`%s'",token); \
104 status=MagickFalse; \
194 *DrawClippingMask(Image *,
const DrawInfo *,
const char *,
const char *,
195 const size_t,ExceptionInfo *);
197static MagickBooleanType
198 DrawStrokePolygon(Image *,
const DrawInfo *,
const PrimitiveInfo *,
200 RenderMVGContent(Image *,
const DrawInfo *,
const size_t,ExceptionInfo *),
201 TraceArc(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo),
202 TraceArcPath(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo,
203 const double,
const MagickBooleanType,
const MagickBooleanType),
204 TraceBezier(MVGInfo *,
const size_t),
205 TraceCircle(MVGInfo *,
const PointInfo,
const PointInfo),
206 TraceEllipse(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo),
207 TraceLine(PrimitiveInfo *,
const PointInfo,
const PointInfo),
208 TraceRectangle(PrimitiveInfo *,
const PointInfo,
const PointInfo),
209 TraceRoundRectangle(MVGInfo *,
const PointInfo,
const PointInfo,PointInfo),
210 TraceSquareLinecap(PrimitiveInfo *,
const size_t,
const double);
213 *TraceStrokePolygon(
const DrawInfo *,
const PrimitiveInfo *,ExceptionInfo *);
216 TracePath(MVGInfo *,
const char *,ExceptionInfo *);
236MagickExport DrawInfo *AcquireDrawInfo(
void)
241 draw_info=(DrawInfo *) AcquireCriticalMemory(
sizeof(*draw_info));
242 GetDrawInfo((ImageInfo *) NULL,draw_info);
273MagickExport DrawInfo *CloneDrawInfo(
const ImageInfo *image_info,
274 const DrawInfo *draw_info)
282 clone_info=(DrawInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
283 GetDrawInfo(image_info,clone_info);
284 if (draw_info == (DrawInfo *) NULL)
286 exception=AcquireExceptionInfo();
287 if (draw_info->id != (
char *) NULL)
288 (void) CloneString(&clone_info->id,draw_info->id);
289 if (draw_info->primitive != (
char *) NULL)
290 (void) CloneString(&clone_info->primitive,draw_info->primitive);
291 if (draw_info->geometry != (
char *) NULL)
292 (void) CloneString(&clone_info->geometry,draw_info->geometry);
293 clone_info->compliance=draw_info->compliance;
294 clone_info->viewbox=draw_info->viewbox;
295 clone_info->affine=draw_info->affine;
296 clone_info->gravity=draw_info->gravity;
297 clone_info->fill=draw_info->fill;
298 clone_info->stroke=draw_info->stroke;
299 clone_info->stroke_width=draw_info->stroke_width;
300 if (draw_info->fill_pattern != (Image *) NULL)
301 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
303 if (draw_info->stroke_pattern != (Image *) NULL)
304 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
305 MagickTrue,exception);
306 clone_info->stroke_antialias=draw_info->stroke_antialias;
307 clone_info->text_antialias=draw_info->text_antialias;
308 clone_info->fill_rule=draw_info->fill_rule;
309 clone_info->linecap=draw_info->linecap;
310 clone_info->linejoin=draw_info->linejoin;
311 clone_info->miterlimit=draw_info->miterlimit;
312 clone_info->dash_offset=draw_info->dash_offset;
313 clone_info->decorate=draw_info->decorate;
314 clone_info->compose=draw_info->compose;
315 if (draw_info->text != (
char *) NULL)
316 (void) CloneString(&clone_info->text,draw_info->text);
317 if (draw_info->font != (
char *) NULL)
318 (void) CloneString(&clone_info->font,draw_info->font);
319 if (draw_info->metrics != (
char *) NULL)
320 (void) CloneString(&clone_info->metrics,draw_info->metrics);
321 if (draw_info->family != (
char *) NULL)
322 (void) CloneString(&clone_info->family,draw_info->family);
323 clone_info->style=draw_info->style;
324 clone_info->stretch=draw_info->stretch;
325 clone_info->weight=draw_info->weight;
326 if (draw_info->encoding != (
char *) NULL)
327 (void) CloneString(&clone_info->encoding,draw_info->encoding);
328 clone_info->pointsize=draw_info->pointsize;
329 clone_info->kerning=draw_info->kerning;
330 clone_info->interline_spacing=draw_info->interline_spacing;
331 clone_info->interword_spacing=draw_info->interword_spacing;
332 clone_info->direction=draw_info->direction;
333 clone_info->word_break=draw_info->word_break;
334 if (draw_info->density != (
char *) NULL)
335 (void) CloneString(&clone_info->density,draw_info->density);
336 clone_info->align=draw_info->align;
337 clone_info->undercolor=draw_info->undercolor;
338 clone_info->border_color=draw_info->border_color;
339 if (draw_info->server_name != (
char *) NULL)
340 (void) CloneString(&clone_info->server_name,draw_info->server_name);
341 if (draw_info->dash_pattern != (
double *) NULL)
346 for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
347 clone_info->dash_pattern=(
double *) AcquireQuantumMemory((
size_t) (x+1),
348 sizeof(*clone_info->dash_pattern));
349 if (clone_info->dash_pattern == (
double *) NULL)
350 ThrowFatalException(ResourceLimitFatalError,
351 "UnableToAllocateDashPattern");
352 (void) memset(clone_info->dash_pattern,0,(
size_t) (x+1)*
353 sizeof(*clone_info->dash_pattern));
354 (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(
size_t)
355 x*
sizeof(*clone_info->dash_pattern));
357 clone_info->gradient=draw_info->gradient;
358 if (draw_info->gradient.stops != (StopInfo *) NULL)
363 number_stops=clone_info->gradient.number_stops;
364 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((
size_t)
365 number_stops,
sizeof(*clone_info->gradient.stops));
366 if (clone_info->gradient.stops == (StopInfo *) NULL)
367 ThrowFatalException(ResourceLimitFatalError,
368 "UnableToAllocateDashPattern");
369 (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
370 (
size_t) number_stops*
sizeof(*clone_info->gradient.stops));
372 clone_info->bounds=draw_info->bounds;
373 clone_info->fill_alpha=draw_info->fill_alpha;
374 clone_info->stroke_alpha=draw_info->stroke_alpha;
375 clone_info->element_reference=draw_info->element_reference;
376 clone_info->clip_path=draw_info->clip_path;
377 clone_info->clip_units=draw_info->clip_units;
378 if (draw_info->clip_mask != (
char *) NULL)
379 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
380 if (draw_info->clipping_mask != (Image *) NULL)
381 clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
382 MagickTrue,exception);
383 if (draw_info->composite_mask != (Image *) NULL)
384 clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
385 MagickTrue,exception);
386 clone_info->render=draw_info->render;
387 clone_info->debug=draw_info->debug;
388 clone_info->macro_expansion=draw_info->macro_expansion;
389 exception=DestroyExceptionInfo(exception);
424static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
429 if (polygon_info->edges != (EdgeInfo *) NULL)
431 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
432 if (polygon_info->edges[i].points != (PointInfo *) NULL)
433 polygon_info->edges[i].points=(PointInfo *)
434 RelinquishMagickMemory(polygon_info->edges[i].points);
435 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(
436 polygon_info->edges);
438 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
440#if defined(__cplusplus) || defined(c_plusplus)
444static int DrawCompareEdges(
const void *p_edge,
const void *q_edge)
446#define DrawCompareEdge(p,q) \
448 if (((p)-(q)) < 0.0) \
450 if (((p)-(q)) > 0.0) \
461 p=((
const EdgeInfo *) p_edge)->points;
462 q=((
const EdgeInfo *) q_edge)->points;
463 DrawCompareEdge(p[0].y,q[0].y);
464 DrawCompareEdge(p[0].x,q[0].x);
465 DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
467 DrawCompareEdge(p[1].y,q[1].y);
468 DrawCompareEdge(p[1].x,q[1].x);
472#if defined(__cplusplus) || defined(c_plusplus)
476static void LogPolygonInfo(
const PolygonInfo *polygon_info)
485 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin active-edge");
486 p=polygon_info->edges;
487 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
489 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" edge %.17g:",
491 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" direction: %s",
492 p->direction != MagickFalse ?
"down" :
"up");
493 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" ghostline: %s",
494 p->ghostline != MagickFalse ?
"transparent" :
"opaque");
495 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
496 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
497 p->bounds.x2,p->bounds.y2);
498 for (j=0; j < (ssize_t) p->number_points; j++)
499 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %g,%g",
500 p->points[j].x,p->points[j].y);
503 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end active-edge");
506static void ReversePoints(PointInfo *points,
const size_t number_points)
514 for (i=0; i < (number_points >> 1); i++)
517 points[i]=points[number_points-(i+1)];
518 points[number_points-(i+1)]=point;
522static PolygonInfo *ConvertPathToPolygon(
const PathInfo *path_info,
523 ExceptionInfo *exception)
554 polygon_info=(PolygonInfo *) AcquireMagickMemory(
sizeof(*polygon_info));
555 if (polygon_info == (PolygonInfo *) NULL)
557 (void) ThrowMagickException(exception,GetMagickModule(),
558 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
559 return((PolygonInfo *) NULL);
562 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory(number_edges,
563 sizeof(*polygon_info->edges));
564 if (polygon_info->edges == (EdgeInfo *) NULL)
566 (void) ThrowMagickException(exception,GetMagickModule(),
567 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
568 return(DestroyPolygonInfo(polygon_info));
570 (void) memset(polygon_info->edges,0,number_edges*
571 sizeof(*polygon_info->edges));
574 ghostline=MagickFalse;
577 points=(PointInfo *) NULL;
578 (void) memset(&point,0,
sizeof(point));
579 (void) memset(&bounds,0,
sizeof(bounds));
580 polygon_info->edges[edge].number_points=(size_t) n;
581 polygon_info->edges[edge].scanline=0.0;
582 polygon_info->edges[edge].highwater=0;
583 polygon_info->edges[edge].ghostline=ghostline;
584 polygon_info->edges[edge].direction=(ssize_t) direction;
585 polygon_info->edges[edge].points=points;
586 polygon_info->edges[edge].bounds=bounds;
587 polygon_info->number_edges=0;
588 for (i=0; path_info[i].code != EndCode; i++)
590 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
591 (path_info[i].code == GhostlineCode))
596 if ((points != (PointInfo *) NULL) && (n >= 2))
598 if (edge == number_edges)
601 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
602 polygon_info->edges,(
size_t) number_edges,
603 sizeof(*polygon_info->edges));
604 if (polygon_info->edges == (EdgeInfo *) NULL)
606 (void) ThrowMagickException(exception,GetMagickModule(),
607 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
608 points=(PointInfo *) RelinquishMagickMemory(points);
609 return(DestroyPolygonInfo(polygon_info));
612 polygon_info->edges[edge].number_points=(size_t) n;
613 polygon_info->edges[edge].scanline=(-1.0);
614 polygon_info->edges[edge].highwater=0;
615 polygon_info->edges[edge].ghostline=ghostline;
616 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
618 ReversePoints(points,(
size_t) n);
619 polygon_info->edges[edge].points=points;
620 polygon_info->edges[edge].bounds=bounds;
621 polygon_info->edges[edge].bounds.y1=points[0].y;
622 polygon_info->edges[edge].bounds.y2=points[n-1].y;
623 points=(PointInfo *) NULL;
624 ghostline=MagickFalse;
626 polygon_info->number_edges=edge;
628 if (points == (PointInfo *) NULL)
631 points=(PointInfo *) AcquireQuantumMemory((
size_t) number_points,
633 if (points == (PointInfo *) NULL)
635 (void) ThrowMagickException(exception,GetMagickModule(),
636 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
637 return(DestroyPolygonInfo(polygon_info));
640 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
641 point=path_info[i].point;
652 next_direction=((path_info[i].point.y > point.y) ||
653 ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
654 (path_info[i].point.x > point.x))) ? 1 : -1;
655 if ((points != (PointInfo *) NULL) && (direction != 0) &&
656 (direction != next_direction))
662 if (edge == number_edges)
665 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
666 polygon_info->edges,(
size_t) number_edges,
667 sizeof(*polygon_info->edges));
668 if (polygon_info->edges == (EdgeInfo *) NULL)
670 (void) ThrowMagickException(exception,GetMagickModule(),
671 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
672 points=(PointInfo *) RelinquishMagickMemory(points);
673 return(DestroyPolygonInfo(polygon_info));
676 polygon_info->edges[edge].number_points=(size_t) n;
677 polygon_info->edges[edge].scanline=(-1.0);
678 polygon_info->edges[edge].highwater=0;
679 polygon_info->edges[edge].ghostline=ghostline;
680 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
682 ReversePoints(points,(
size_t) n);
683 polygon_info->edges[edge].points=points;
684 polygon_info->edges[edge].bounds=bounds;
685 polygon_info->edges[edge].bounds.y1=points[0].y;
686 polygon_info->edges[edge].bounds.y2=points[n-1].y;
687 polygon_info->number_edges=edge+1;
688 points=(PointInfo *) NULL;
690 points=(PointInfo *) AcquireQuantumMemory((
size_t) number_points,
692 if (points == (PointInfo *) NULL)
694 (void) ThrowMagickException(exception,GetMagickModule(),
695 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
696 return(DestroyPolygonInfo(polygon_info));
699 ghostline=MagickFalse;
705 direction=next_direction;
706 if (points == (PointInfo *) NULL)
708 if (n == (ssize_t) number_points)
711 points=(PointInfo *) ResizeQuantumMemory(points,(
size_t) number_points,
713 if (points == (PointInfo *) NULL)
715 (void) ThrowMagickException(exception,GetMagickModule(),
716 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
717 return(DestroyPolygonInfo(polygon_info));
720 point=path_info[i].point;
722 if (point.x < bounds.x1)
724 if (point.x > bounds.x2)
728 if (points != (PointInfo *) NULL)
731 points=(PointInfo *) RelinquishMagickMemory(points);
734 if (edge == number_edges)
737 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
738 polygon_info->edges,(
size_t) number_edges,
739 sizeof(*polygon_info->edges));
740 if (polygon_info->edges == (EdgeInfo *) NULL)
742 (void) ThrowMagickException(exception,GetMagickModule(),
743 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
744 return(DestroyPolygonInfo(polygon_info));
747 polygon_info->edges[edge].number_points=(size_t) n;
748 polygon_info->edges[edge].scanline=(-1.0);
749 polygon_info->edges[edge].highwater=0;
750 polygon_info->edges[edge].ghostline=ghostline;
751 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
753 ReversePoints(points,(
size_t) n);
754 polygon_info->edges[edge].points=points;
755 polygon_info->edges[edge].bounds=bounds;
756 polygon_info->edges[edge].bounds.y1=points[0].y;
757 polygon_info->edges[edge].bounds.y2=points[n-1].y;
758 points=(PointInfo *) NULL;
759 ghostline=MagickFalse;
761 polygon_info->number_edges=edge;
764 polygon_info->number_edges=edge;
765 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(polygon_info->edges,
766 polygon_info->number_edges,
sizeof(*polygon_info->edges));
767 if (polygon_info->edges == (EdgeInfo *) NULL)
769 (void) ThrowMagickException(exception,GetMagickModule(),
770 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
771 return(DestroyPolygonInfo(polygon_info));
773 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
778 edge_info=polygon_info->edges+i;
779 edge_info->points=(PointInfo *) ResizeQuantumMemory(edge_info->points,
780 edge_info->number_points,
sizeof(*edge_info->points));
781 if (edge_info->points == (PointInfo *) NULL)
783 (void) ThrowMagickException(exception,GetMagickModule(),
784 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
785 return(DestroyPolygonInfo(polygon_info));
788 qsort(polygon_info->edges,(
size_t) polygon_info->number_edges,
789 sizeof(*polygon_info->edges),DrawCompareEdges);
790 if ((GetLogEventMask() & DrawEvent) != 0)
791 LogPolygonInfo(polygon_info);
792 return(polygon_info);
825static void LogPathInfo(
const PathInfo *path_info)
830 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin vector-path");
831 for (p=path_info; p->code != EndCode; p++)
832 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
833 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
834 "moveto ghostline" : p->code == OpenCode ?
"moveto open" :
835 p->code == MoveToCode ?
"moveto" : p->code == LineToCode ?
"lineto" :
837 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end vector-path");
840static PathInfo *ConvertPrimitiveToPath(
const PrimitiveInfo *primitive_info,
841 ExceptionInfo *exception)
867 switch (primitive_info->primitive)
874 return((PathInfo *) NULL);
878 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
879 path_info=(PathInfo *) AcquireQuantumMemory((
size_t) (3UL*i+1UL),
881 if (path_info == (PathInfo *) NULL)
883 (void) ThrowMagickException(exception,GetMagickModule(),
884 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
885 return((PathInfo *) NULL);
888 closed_subpath=MagickFalse;
895 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
898 if (coordinates <= 0)
903 coordinates=primitive_info[i].coordinates;
904 p=primitive_info[i].point;
907 closed_subpath=primitive_info[i].closed_subpath;
910 if ((code == MoveToCode) || (coordinates <= 0) ||
911 (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
912 (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
917 path_info[n].code=code;
918 path_info[n].point=primitive_info[i].point;
919 q=primitive_info[i].point;
924 if (closed_subpath != MagickFalse)
926 closed_subpath=MagickFalse;
932 path_info[start].code=OpenCode;
933 path_info[n].code=GhostlineCode;
934 path_info[n].point=primitive_info[i].point;
936 path_info[n].code=LineToCode;
937 path_info[n].point=p;
940 path_info[n].code=EndCode;
941 path_info[n].point.x=0.0;
942 path_info[n].point.y=0.0;
943 if (IsEventLogging() != MagickFalse)
944 LogPathInfo(path_info);
945 path_info=(PathInfo *) ResizeQuantumMemory(path_info,(
size_t) (n+1),
972MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
974 assert(draw_info != (DrawInfo *) NULL);
975 assert(draw_info->signature == MagickCoreSignature);
976 if (IsEventLogging() != MagickFalse)
977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
978 if (draw_info->id != (
char *) NULL)
979 draw_info->id=DestroyString(draw_info->id);
980 if (draw_info->primitive != (
char *) NULL)
981 draw_info->primitive=DestroyString(draw_info->primitive);
982 if (draw_info->text != (
char *) NULL)
983 draw_info->text=DestroyString(draw_info->text);
984 if (draw_info->geometry != (
char *) NULL)
985 draw_info->geometry=DestroyString(draw_info->geometry);
986 if (draw_info->fill_pattern != (Image *) NULL)
987 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
988 if (draw_info->stroke_pattern != (Image *) NULL)
989 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
990 if (draw_info->font != (
char *) NULL)
991 draw_info->font=DestroyString(draw_info->font);
992 if (draw_info->metrics != (
char *) NULL)
993 draw_info->metrics=DestroyString(draw_info->metrics);
994 if (draw_info->family != (
char *) NULL)
995 draw_info->family=DestroyString(draw_info->family);
996 if (draw_info->encoding != (
char *) NULL)
997 draw_info->encoding=DestroyString(draw_info->encoding);
998 if (draw_info->density != (
char *) NULL)
999 draw_info->density=DestroyString(draw_info->density);
1000 if (draw_info->server_name != (
char *) NULL)
1001 draw_info->server_name=(
char *)
1002 RelinquishMagickMemory(draw_info->server_name);
1003 if (draw_info->dash_pattern != (
double *) NULL)
1004 draw_info->dash_pattern=(
double *) RelinquishMagickMemory(
1005 draw_info->dash_pattern);
1006 if (draw_info->gradient.stops != (StopInfo *) NULL)
1007 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
1008 draw_info->gradient.stops);
1009 if (draw_info->clip_mask != (
char *) NULL)
1010 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
1011 if (draw_info->clipping_mask != (Image *) NULL)
1012 draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
1013 if (draw_info->composite_mask != (Image *) NULL)
1014 draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
1015 if (draw_info->image_info != (ImageInfo *) NULL)
1016 draw_info->image_info=DestroyImageInfo(draw_info->image_info);
1017 draw_info->signature=(~MagickCoreSignature);
1018 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
1053static SegmentInfo AffineEdge(
const Image *image,
const AffineMatrix *affine,
1054 const double y,
const SegmentInfo *edge)
1069 inverse_edge.x1=edge->x1;
1070 inverse_edge.y1=edge->y1;
1071 inverse_edge.x2=edge->x2;
1072 inverse_edge.y2=edge->y2;
1073 z=affine->ry*y+affine->tx;
1074 if (affine->sx >= MagickEpsilon)
1076 intercept=(-z/affine->sx);
1078 if (x > inverse_edge.x1)
1080 intercept=(-z+(double) image->columns)/affine->sx;
1082 if (x < inverse_edge.x2)
1086 if (affine->sx < -MagickEpsilon)
1088 intercept=(-z+(double) image->columns)/affine->sx;
1090 if (x > inverse_edge.x1)
1092 intercept=(-z/affine->sx);
1094 if (x < inverse_edge.x2)
1098 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->columns))
1100 inverse_edge.x2=edge->x1;
1101 return(inverse_edge);
1106 z=affine->sy*y+affine->ty;
1107 if (affine->rx >= MagickEpsilon)
1109 intercept=(-z/affine->rx);
1111 if (x > inverse_edge.x1)
1113 intercept=(-z+(double) image->rows)/affine->rx;
1115 if (x < inverse_edge.x2)
1119 if (affine->rx < -MagickEpsilon)
1121 intercept=(-z+(double) image->rows)/affine->rx;
1123 if (x > inverse_edge.x1)
1125 intercept=(-z/affine->rx);
1127 if (x < inverse_edge.x2)
1131 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->rows))
1133 inverse_edge.x2=edge->x2;
1134 return(inverse_edge);
1136 return(inverse_edge);
1139static AffineMatrix InverseAffineMatrix(
const AffineMatrix *affine)
1147 determinant=MagickSafeReciprocal(affine->sx*affine->sy-affine->rx*
1149 inverse_affine.sx=determinant*affine->sy;
1150 inverse_affine.rx=determinant*(-affine->rx);
1151 inverse_affine.ry=determinant*(-affine->ry);
1152 inverse_affine.sy=determinant*affine->sx;
1153 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1155 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1157 return(inverse_affine);
1160MagickExport MagickBooleanType DrawAffineImage(Image *image,
1161 const Image *source,
const AffineMatrix *affine,ExceptionInfo *exception)
1195 assert(image != (Image *) NULL);
1196 assert(image->signature == MagickCoreSignature);
1197 if (IsEventLogging() != MagickFalse)
1198 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1199 assert(source != (
const Image *) NULL);
1200 assert(source->signature == MagickCoreSignature);
1201 assert(affine != (AffineMatrix *) NULL);
1204 extent[1].x=(double) source->columns;
1206 extent[2].x=(double) source->columns;
1207 extent[2].y=(double) source->rows;
1209 extent[3].y=(double) source->rows;
1210 for (i=0; i < 4; i++)
1216 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1217 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1221 for (i=1; i < 4; i++)
1223 if (min.x > extent[i].x)
1225 if (min.y > extent[i].y)
1227 if (max.x < extent[i].x)
1229 if (max.y < extent[i].y)
1235 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1236 return(MagickFalse);
1242 inverse_affine=InverseAffineMatrix(affine);
1245 if (edge.y2 > ((
double) image->rows-1.0))
1246 edge.y2=(double) image->rows-1.0;
1247 GetPixelInfo(image,&zero);
1248 start=CastDoubleToSsizeT(ceil(edge.y1-0.5));
1249 stop=CastDoubleToSsizeT(floor(edge.y2+0.5));
1250 source_view=AcquireVirtualCacheView(source,exception);
1251 image_view=AcquireAuthenticCacheView(image,exception);
1252#if defined(MAGICKCORE_OPENMP_SUPPORT)
1253 #pragma omp parallel for schedule(static) shared(status) \
1254 magick_number_threads(source,image,(size_t) (stop-start),2)
1256 for (y=start; y <= stop; y++)
1274 if (status == MagickFalse)
1276 inverse_edge=AffineEdge(source,&inverse_affine,(
double) y,&edge);
1277 if (inverse_edge.x2 < inverse_edge.x1)
1279 if (inverse_edge.x1 < 0.0)
1280 inverse_edge.x1=0.0;
1281 if (inverse_edge.x2 > ((
double) image->columns-1.0))
1282 inverse_edge.x2=(double) image->columns-1.0;
1283 q=GetCacheViewAuthenticPixels(image_view,CastDoubleToSsizeT(
1284 ceil(inverse_edge.x1-0.5)),y,(
size_t) CastDoubleToSsizeT(floor(
1285 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
1286 if (q == (Quantum *) NULL)
1290 for (x=CastDoubleToSsizeT(ceil(inverse_edge.x1-0.5));
1291 x <= CastDoubleToSsizeT(floor(inverse_edge.x2+0.5)); x++)
1293 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1295 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1297 status=InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
1298 point.x,point.y,&pixel,exception);
1299 if (status == MagickFalse)
1301 GetPixelInfoPixel(image,q,&composite);
1302 CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
1304 SetPixelViaPixelInfo(image,&composite,q);
1305 q+=(ptrdiff_t) GetPixelChannels(image);
1307 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1310 source_view=DestroyCacheView(source_view);
1311 image_view=DestroyCacheView(image_view);
1347static MagickBooleanType DrawBoundingRectangles(Image *image,
1348 const DrawInfo *draw_info,
const PolygonInfo *polygon_info,
1349 ExceptionInfo *exception)
1377 (void) memset(primitive_info,0,
sizeof(primitive_info));
1378 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1379 status=QueryColorCompliance(
"#000F",AllCompliance,&clone_info->fill,
1381 if (status == MagickFalse)
1383 clone_info=DestroyDrawInfo(clone_info);
1384 return(MagickFalse);
1388 if (clone_info->density != (
char *) NULL)
1396 flags=ParseGeometry(clone_info->density,&geometry_info);
1397 if ((flags & RhoValue) != 0)
1398 resolution.x=geometry_info.rho;
1399 resolution.y=resolution.x;
1400 if ((flags & SigmaValue) != 0)
1401 resolution.y=geometry_info.sigma;
1403 mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
1404 clone_info->stroke_width/2.0;
1409 if (polygon_info != (PolygonInfo *) NULL)
1411 bounds=polygon_info->edges[0].bounds;
1412 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1414 if (polygon_info->edges[i].bounds.x1 < (
double) bounds.x1)
1415 bounds.x1=polygon_info->edges[i].bounds.x1;
1416 if (polygon_info->edges[i].bounds.y1 < (
double) bounds.y1)
1417 bounds.y1=polygon_info->edges[i].bounds.y1;
1418 if (polygon_info->edges[i].bounds.x2 > (
double) bounds.x2)
1419 bounds.x2=polygon_info->edges[i].bounds.x2;
1420 if (polygon_info->edges[i].bounds.y2 > (
double) bounds.y2)
1421 bounds.y2=polygon_info->edges[i].bounds.y2;
1424 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1425 image->columns ? (
double) image->columns-1 : bounds.x1;
1427 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1428 image->rows ? (
double) image->rows-1 : bounds.y1;
1430 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1431 image->columns ? (
double) image->columns-1 : bounds.x2;
1433 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1434 image->rows ? (
double) image->rows-1 : bounds.y2;
1435 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1437 if (polygon_info->edges[i].direction != 0)
1438 status=QueryColorCompliance(
"#f00",AllCompliance,&clone_info->stroke,
1441 status=QueryColorCompliance(
"#0f0",AllCompliance,&clone_info->stroke,
1443 if (status == MagickFalse)
1445 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1446 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1447 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1448 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1449 primitive_info[0].primitive=RectanglePrimitive;
1450 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1451 primitive_info[0].method=ReplaceMethod;
1452 coordinates=(ssize_t) primitive_info[0].coordinates;
1453 primitive_info[coordinates].primitive=UndefinedPrimitive;
1454 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1455 if (status == MagickFalse)
1458 if (i < (ssize_t) polygon_info->number_edges)
1460 clone_info=DestroyDrawInfo(clone_info);
1461 return(status == 0 ? MagickFalse : MagickTrue);
1464 status=QueryColorCompliance(
"#00f",AllCompliance,&clone_info->stroke,
1466 if (status == MagickFalse)
1468 clone_info=DestroyDrawInfo(clone_info);
1469 return(MagickFalse);
1471 start.x=(double) (bounds.x1-mid);
1472 start.y=(double) (bounds.y1-mid);
1473 end.x=(double) (bounds.x2+mid);
1474 end.y=(double) (bounds.y2+mid);
1475 primitive_info[0].primitive=RectanglePrimitive;
1476 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1477 primitive_info[0].method=ReplaceMethod;
1478 coordinates=(ssize_t) primitive_info[0].coordinates;
1479 primitive_info[coordinates].primitive=UndefinedPrimitive;
1480 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1481 clone_info=DestroyDrawInfo(clone_info);
1482 return(status == 0 ? MagickFalse : MagickTrue);
1515static MagickBooleanType DrawClipPath_(Image *image,
1516 const DrawInfo *draw_info,
const char *
id,
const size_t depth,
1517 ExceptionInfo *exception)
1528 clip_path=GetImageArtifact(image,
id);
1529 if (clip_path == (
const char *) NULL)
1530 return(MagickFalse);
1531 clipping_mask=DrawClippingMask(image,draw_info,draw_info->clip_mask,clip_path,
1533 if (clipping_mask == (Image *) NULL)
1534 return(MagickFalse);
1535 status=SetImageMask(image,WritePixelMask,clipping_mask,exception);
1536 clipping_mask=DestroyImage(clipping_mask);
1540MagickExport MagickBooleanType DrawClipPath(Image *image,
1541 const DrawInfo *draw_info,
const char *
id,ExceptionInfo *exception)
1543 return(DrawClipPath_(image,draw_info,
id,0,exception));
1581static Image *DrawClippingMask(Image *image,
const DrawInfo *draw_info,
1582 const char *
id,
const char *clip_path,
const size_t depth,
1583 ExceptionInfo *exception)
1598 assert(image != (Image *) NULL);
1599 assert(image->signature == MagickCoreSignature);
1600 assert(draw_info != (
const DrawInfo *) NULL);
1601 if (IsEventLogging() != MagickFalse)
1602 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1603 clip_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1604 status=SetImageExtent(clip_mask,image->columns,image->rows,exception);
1605 if (status == MagickFalse)
1606 return(DestroyImage(clip_mask));
1607 status=SetImageMask(clip_mask,WritePixelMask,(Image *) NULL,exception);
1608 status=QueryColorCompliance(
"#0000",AllCompliance,
1609 &clip_mask->background_color,exception);
1610 clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1611 clip_mask->background_color.alpha_trait=BlendPixelTrait;
1612 status=SetImageBackgroundColor(clip_mask,exception);
1613 if (draw_info->debug != MagickFalse)
1614 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin clip-path %s",
1616 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1617 (void) CloneString(&clone_info->primitive,clip_path);
1618 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1620 if (clone_info->clip_mask != (
char *) NULL)
1621 clone_info->clip_mask=DestroyString(clone_info->clip_mask);
1622 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1624 clone_info->stroke_width=0.0;
1625 clone_info->alpha=OpaqueAlpha;
1626 clone_info->clip_path=MagickTrue;
1627 status=RenderMVGContent(clip_mask,clone_info,depth+1,exception);
1628 clone_info=DestroyDrawInfo(clone_info);
1629 separate_mask=SeparateImage(clip_mask,AlphaChannel,exception);
1630 if (separate_mask == (Image *) NULL)
1634 clip_mask=DestroyImage(clip_mask);
1635 clip_mask=separate_mask;
1636 status&=(MagickStatusType) NegateImage(clip_mask,MagickFalse,exception);
1638 if (status == MagickFalse)
1639 clip_mask=DestroyImage(clip_mask);
1640 if (draw_info->debug != MagickFalse)
1641 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end clip-path");
1679static Image *DrawCompositeMask(Image *image,
const DrawInfo *draw_info,
1680 const char *
id,
const char *mask_path,
const size_t depth,
1681 ExceptionInfo *exception)
1696 assert(image != (Image *) NULL);
1697 assert(image->signature == MagickCoreSignature);
1698 assert(draw_info != (
const DrawInfo *) NULL);
1699 if (IsEventLogging() != MagickFalse)
1700 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1701 composite_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1702 status=SetImageExtent(composite_mask,image->columns,image->rows,exception);
1703 if (status == MagickFalse)
1704 return(DestroyImage(composite_mask));
1705 status=SetImageMask(composite_mask,CompositePixelMask,(Image *) NULL,
1707 status=QueryColorCompliance(
"#0000",AllCompliance,
1708 &composite_mask->background_color,exception);
1709 composite_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1710 composite_mask->background_color.alpha_trait=BlendPixelTrait;
1711 (void) SetImageBackgroundColor(composite_mask,exception);
1712 if (draw_info->debug != MagickFalse)
1713 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin mask-path %s",
1715 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1716 (void) CloneString(&clone_info->primitive,mask_path);
1717 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1719 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1721 clone_info->stroke_width=0.0;
1722 clone_info->alpha=OpaqueAlpha;
1723 status=RenderMVGContent(composite_mask,clone_info,depth+1,exception);
1724 clone_info=DestroyDrawInfo(clone_info);
1725 separate_mask=SeparateImage(composite_mask,AlphaChannel,exception);
1726 if (separate_mask != (Image *) NULL)
1728 composite_mask=DestroyImage(composite_mask);
1729 composite_mask=separate_mask;
1730 status=NegateImage(composite_mask,MagickFalse,exception);
1731 if (status == MagickFalse)
1732 composite_mask=DestroyImage(composite_mask);
1734 if (status == MagickFalse)
1735 composite_mask=DestroyImage(composite_mask);
1736 if (draw_info->debug != MagickFalse)
1737 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end mask-path");
1738 return(composite_mask);
1772static MagickBooleanType DrawDashPolygon(
const DrawInfo *draw_info,
1773 const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception)
1803 assert(draw_info != (
const DrawInfo *) NULL);
1804 if (draw_info->debug != MagickFalse)
1805 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-dash");
1806 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1807 number_vertices=(size_t) i;
1808 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
1809 (2UL*number_vertices+32UL),
sizeof(*dash_polygon));
1810 if (dash_polygon == (PrimitiveInfo *) NULL)
1812 (void) ThrowMagickException(exception,GetMagickModule(),
1813 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1814 return(MagickFalse);
1816 (void) memset(dash_polygon,0,(2UL*number_vertices+32UL)*
1817 sizeof(*dash_polygon));
1818 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1819 clone_info->miterlimit=0;
1820 dash_polygon[0]=primitive_info[0];
1821 dash_polygon[0].closed_subpath=MagickFalse;
1822 scale=ExpandAffine(&draw_info->affine);
1823 length=scale*draw_info->dash_pattern[0];
1824 offset=fabs(draw_info->dash_offset) >= MagickEpsilon ?
1825 scale*draw_info->dash_offset : 0.0;
1827 for (n=0; offset > 0.0; j=0)
1829 if (draw_info->dash_pattern[n] <= 0.0)
1831 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1832 if (offset > length)
1836 length=scale*draw_info->dash_pattern[n];
1839 if (offset < length)
1851 for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
1853 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1854 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1855 maximum_length=hypot(dx,dy);
1856 if (maximum_length > (
double) (MaxBezierCoordinates >> 2))
1858 if (fabs(length) < MagickEpsilon)
1860 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1862 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1864 length=scale*draw_info->dash_pattern[n];
1866 for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); )
1868 total_length+=length;
1869 if ((n & 0x01) != 0)
1871 dash_polygon[0]=primitive_info[0];
1872 dash_polygon[0].closed_subpath=MagickFalse;
1873 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1874 total_length*MagickSafeReciprocal(maximum_length));
1875 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1876 total_length*MagickSafeReciprocal(maximum_length));
1881 if ((j+1) > (ssize_t) number_vertices)
1883 dash_polygon[j]=primitive_info[i-1];
1884 dash_polygon[j].closed_subpath=MagickFalse;
1885 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1886 total_length*MagickSafeReciprocal(maximum_length));
1887 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1888 total_length*MagickSafeReciprocal(maximum_length));
1889 dash_polygon[j].coordinates=1;
1891 dash_polygon[0].coordinates=(size_t) j;
1892 dash_polygon[j].primitive=UndefinedPrimitive;
1893 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1894 dash_polygon,exception);
1895 if (status == MagickFalse)
1898 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1900 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1902 length=scale*draw_info->dash_pattern[n];
1904 length-=(maximum_length-total_length);
1905 if ((n & 0x01) != 0)
1907 dash_polygon[j]=primitive_info[i];
1908 dash_polygon[j].coordinates=1;
1911 if ((status != MagickFalse) && (total_length < maximum_length) &&
1912 ((n & 0x01) == 0) && (j > 1))
1914 dash_polygon[j]=primitive_info[i-1];
1915 dash_polygon[j].closed_subpath=MagickFalse;
1916 dash_polygon[j].point.x+=MagickEpsilon;
1917 dash_polygon[j].point.y+=MagickEpsilon;
1918 dash_polygon[j].coordinates=1;
1920 dash_polygon[0].coordinates=(size_t) j;
1921 dash_polygon[j].primitive=UndefinedPrimitive;
1922 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1923 dash_polygon,exception);
1925 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1926 clone_info=DestroyDrawInfo(clone_info);
1927 if (draw_info->debug != MagickFalse)
1928 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-dash");
1929 return(status != 0 ? MagickTrue : MagickFalse);
1960static inline double GetStopColorOffset(
const GradientInfo *gradient,
1961 const ssize_t x,
const ssize_t y)
1963 switch (gradient->type)
1965 case UndefinedGradient:
1966 case LinearGradient:
1981 gradient_vector=(&gradient->gradient_vector);
1982 p.x=gradient_vector->x2-gradient_vector->x1;
1983 p.y=gradient_vector->y2-gradient_vector->y1;
1984 q.x=(double) x-gradient_vector->x1;
1985 q.y=(double) y-gradient_vector->y1;
1986 length=sqrt(q.x*q.x+q.y*q.y);
1987 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
1988 gamma=MagickSafeReciprocal(gamma);
1989 scale=p.x*q.x+p.y*q.y;
1990 offset=gamma*scale*length;
1993 case RadialGradient:
1998 if (gradient->spread == RepeatSpread)
2000 v.x=(double) x-gradient->center.x;
2001 v.y=(double) y-gradient->center.y;
2002 return(sqrt(v.x*v.x+v.y*v.y));
2004 v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians(
2005 gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians(
2006 gradient->angle))))*MagickSafeReciprocal(gradient->radii.x);
2007 v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians(
2008 gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians(
2009 gradient->angle))))*MagickSafeReciprocal(gradient->radii.y);
2010 return(sqrt(v.x*v.x+v.y*v.y));
2016static int StopInfoCompare(
const void *x,
const void *y)
2022 stop_1=(StopInfo *) x;
2023 stop_2=(StopInfo *) y;
2024 if (stop_1->offset > stop_2->offset)
2026 if (fabs(stop_1->offset-stop_2->offset) <= MagickEpsilon)
2031MagickExport MagickBooleanType DrawGradientImage(Image *image,
2032 const DrawInfo *draw_info,ExceptionInfo *exception)
2067 assert(image != (Image *) NULL);
2068 assert(image->signature == MagickCoreSignature);
2069 assert(draw_info != (
const DrawInfo *) NULL);
2070 if (IsEventLogging() != MagickFalse)
2071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2072 gradient=(&draw_info->gradient);
2073 qsort(gradient->stops,gradient->number_stops,
sizeof(StopInfo),
2075 gradient_vector=(&gradient->gradient_vector);
2076 point.x=gradient_vector->x2-gradient_vector->x1;
2077 point.y=gradient_vector->y2-gradient_vector->y1;
2078 length=sqrt(point.x*point.x+point.y*point.y);
2079 bounding_box=gradient->bounding_box;
2081 GetPixelInfo(image,&zero);
2082 image_view=AcquireAuthenticCacheView(image,exception);
2083 height=(size_t) (bounding_box.y+(ssize_t) bounding_box.height);
2084#if defined(MAGICKCORE_OPENMP_SUPPORT)
2085 #pragma omp parallel for schedule(static) shared(status) \
2086 magick_number_threads(image,image,height,1)
2088 for (y=bounding_box.y; y < (ssize_t) height; y++)
2109 if (status == MagickFalse)
2111 q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,y,(
size_t)
2112 bounding_box.width,1,exception);
2113 if (q == (Quantum *) NULL)
2120 offset=GetStopColorOffset(gradient,0,y);
2121 if (gradient->type != RadialGradient)
2122 offset*=MagickSafeReciprocal(length);
2123 width=(size_t) (bounding_box.x+(ssize_t) bounding_box.width);
2124 for (x=bounding_box.x; x < (ssize_t) width; x++)
2126 GetPixelInfoPixel(image,q,&pixel);
2127 switch (gradient->spread)
2129 case UndefinedSpread:
2132 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2133 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2135 offset=GetStopColorOffset(gradient,x,y);
2136 if (gradient->type != RadialGradient)
2137 offset*=MagickSafeReciprocal(length);
2139 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2140 if (offset < gradient->stops[i].offset)
2142 if ((offset < 0.0) || (i == 0))
2143 composite=gradient->stops[0].color;
2145 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
2146 composite=gradient->stops[gradient->number_stops-1].color;
2151 alpha=(offset-gradient->stops[i].offset)/
2152 (gradient->stops[j].offset-gradient->stops[i].offset);
2153 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2154 &gradient->stops[j].color,alpha,&composite);
2160 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2161 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2163 offset=GetStopColorOffset(gradient,x,y);
2164 if (gradient->type != RadialGradient)
2165 offset*=MagickSafeReciprocal(length);
2169 if ((ssize_t) fmod(offset,2.0) == 0)
2170 offset=fmod(offset,1.0);
2172 offset=1.0-fmod(offset,1.0);
2173 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2174 if (offset < gradient->stops[i].offset)
2177 composite=gradient->stops[0].color;
2179 if (i == (ssize_t) gradient->number_stops)
2180 composite=gradient->stops[gradient->number_stops-1].color;
2185 alpha=(offset-gradient->stops[i].offset)/
2186 (gradient->stops[j].offset-gradient->stops[i].offset);
2187 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2188 &gradient->stops[j].color,alpha,&composite);
2200 antialias=MagickFalse;
2202 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2203 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2205 offset=GetStopColorOffset(gradient,x,y);
2206 if (gradient->type == LinearGradient)
2208 repeat=fmod(offset,length);
2210 repeat=length-fmod(-repeat,length);
2212 repeat=fmod(offset,length);
2213 antialias=(repeat < length) && ((repeat+1.0) > length) ?
2214 MagickTrue : MagickFalse;
2215 offset=MagickSafeReciprocal(length)*repeat;
2219 repeat=fmod(offset,gradient->radius);
2221 repeat=gradient->radius-fmod(-repeat,gradient->radius);
2223 repeat=fmod(offset,gradient->radius);
2224 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
2226 offset=repeat*MagickSafeReciprocal(gradient->radius);
2229 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2230 if (offset < gradient->stops[i].offset)
2233 composite=gradient->stops[0].color;
2235 if (i == (ssize_t) gradient->number_stops)
2236 composite=gradient->stops[gradient->number_stops-1].color;
2241 alpha=(offset-gradient->stops[i].offset)/
2242 (gradient->stops[j].offset-gradient->stops[i].offset);
2243 if (antialias != MagickFalse)
2245 if (gradient->type == LinearGradient)
2246 alpha=length-repeat;
2248 alpha=gradient->radius-repeat;
2250 j=(ssize_t) gradient->number_stops-1L;
2252 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2253 &gradient->stops[j].color,alpha,&composite);
2258 CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha,
2260 SetPixelViaPixelInfo(image,&pixel,q);
2261 q+=(ptrdiff_t) GetPixelChannels(image);
2263 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2266 image_view=DestroyCacheView(image_view);
2302static inline MagickBooleanType CheckPrimitiveExtent(MVGInfo *mvg_info,
2317 if ((mvg_info == (MVGInfo *) NULL) ||
2318 (mvg_info->primitive_info == (PrimitiveInfo **) NULL) ||
2319 (*mvg_info->primitive_info == (PrimitiveInfo *) NULL) ||
2320 (mvg_info->extent == (
size_t *) NULL))
2321 return(MagickFalse);
2322 proposed_extent=mvg_info->offset+pad+PrimitiveExtentPad+1.0;
2323 if ((proposed_extent <= 0.0) || (proposed_extent > (
double) MAGICK_SIZE_MAX))
2324 return(MagickFalse);
2325 extent=CastDoubleToSizeT(ceil(proposed_extent));
2326 if (extent <= *mvg_info->extent)
2328 if (extent > (GetMaxMemoryRequest()/
sizeof(PrimitiveInfo)))
2329 return(MagickFalse);
2330 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(
2331 *mvg_info->primitive_info,extent+1,
sizeof(PrimitiveInfo));
2332 if (primitive_info == (PrimitiveInfo *) NULL)
2337 extent=(size_t) PrimitiveExtentPad;
2338 primitive_info=(PrimitiveInfo *) AcquireCriticalMemory(extent*
2339 sizeof(*primitive_info));
2340 (void) memset(primitive_info,0,extent*
sizeof(*primitive_info));
2341 *mvg_info->primitive_info=primitive_info;
2342 *mvg_info->extent=extent;
2344 ThrowMagickException(mvg_info->exception,GetMagickModule(),
2345 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2346 return(MagickFalse);
2348 primitive_info[extent].primitive=UndefinedPrimitive;
2349 primitive_info[extent].text=(
char *) NULL;
2353 for (i=(ssize_t) *mvg_info->extent; i < (ssize_t) extent; i++)
2355 primitive_info[i].primitive=UndefinedPrimitive;
2356 primitive_info[i].text=(
char *) NULL;
2358 *mvg_info->primitive_info=primitive_info;
2359 *mvg_info->extent=extent;
2363static inline double GetDrawValue(
const char *magick_restrict
string,
2364 char **magick_restrict sentinel)
2367 **magick_restrict q;
2373 value=InterpretLocaleValue(
string,q);
2378static int MVGMacroCompare(
const void *target,
const void *source)
2384 p=(
const char *) target;
2385 q=(
const char *) source;
2386 return(strcmp(p,q));
2389static SplayTreeInfo *GetMVGMacros(
const char *primitive,
2390 ExceptionInfo *exception)
2408 if (primitive == (
const char *) NULL)
2409 return((SplayTreeInfo *) NULL);
2410 macros=NewSplayTree(MVGMacroCompare,RelinquishMagickMemory,
2411 RelinquishMagickMemory);
2412 macro=AcquireString(primitive);
2413 token=AcquireString(primitive);
2414 extent=strlen(token)+MagickPathExtent;
2415 for (q=primitive; *q !=
'\0'; )
2417 if (GetNextToken(q,&q,extent,token) < 1)
2421 if (LocaleCompare(
"push",token) == 0)
2427 (void) GetNextToken(q,&q,extent,token);
2431 name[MagickPathExtent];
2442 (void) GetNextToken(q,&q,extent,token);
2445 (void) CopyMagickString(name,token,MagickPathExtent);
2447 for (p=q; *p !=
'\0'; )
2449 if (GetNextToken(p,&p,extent,token) < 1)
2453 if (LocaleCompare(token,
"pop") == 0)
2455 end=p-strlen(token)-1;
2458 if (LocaleCompare(token,
"push") == 0)
2460 if (n++ >= MaxVectorRecursionDepth)
2462 (void) ThrowMagickException(exception,GetMagickModule(),
2463 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2467 if ((n == 0) && (end >= start))
2470 length=(size_t) (end-start);
2475 (void) GetNextToken(p,&p,extent,token);
2478 (void) CopyMagickString(macro,start,length);
2479 (void) AddValueToSplayTree(macros,ConstantString(name),
2480 ConstantString(macro));
2488 token=DestroyString(token);
2489 macro=DestroyString(macro);
2493static inline MagickBooleanType IsValidListChar(
int c)
2495 if ((c >=
'0') && (c <=
'9'))
2509 return(MagickFalse);
2514static inline MagickBooleanType IsValidPoint(
const char *point)
2522 value=GetDrawValue(point,&p);
2523 return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
2527static inline MagickBooleanType TracePoint(PrimitiveInfo *primitive_info,
2528 const PointInfo point)
2530 primitive_info->point=point;
2531 primitive_info->coordinates=1;
2532 primitive_info->closed_subpath=MagickFalse;
2533 primitive_info->text=(
char *) NULL;
2537static MagickBooleanType RenderMVGContent(Image *image,
2538 const DrawInfo *draw_info,
const size_t depth,ExceptionInfo *exception)
2540#define RenderImageTag "Render/Image"
2547 keyword[MagickPathExtent],
2548 geometry[MagickPathExtent],
2550 pattern[MagickPathExtent],
2614 assert(image != (Image *) NULL);
2615 assert(image->signature == MagickCoreSignature);
2616 assert(draw_info != (DrawInfo *) NULL);
2617 assert(draw_info->signature == MagickCoreSignature);
2618 if (IsEventLogging() != MagickFalse)
2619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2620 if (depth >= MaxVectorRecursionDepth)
2621 ThrowBinaryException(DrawError,
"VectorGraphicsNestedTooDeeply",
2623 if ((draw_info->primitive == (
char *) NULL) ||
2624 (*draw_info->primitive ==
'\0'))
2625 return(MagickFalse);
2626 if (draw_info->debug != MagickFalse)
2627 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"begin draw-image");
2628 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2629 return(MagickFalse);
2630 if ((image->alpha_trait & BlendPixelTrait) == 0)
2632 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2633 if (status == MagickFalse)
2634 return(MagickFalse);
2636 if ((*draw_info->primitive ==
'@') && (strlen(draw_info->primitive) > 1) &&
2637 (*(draw_info->primitive+1) !=
'-') && (depth == 0))
2638 primitive=FileToString(draw_info->primitive,~0UL,exception);
2640 primitive=AcquireString(draw_info->primitive);
2641 if (primitive == (
char *) NULL)
2642 return(MagickFalse);
2643 primitive_extent=(double) strlen(primitive);
2644 (void) SetImageArtifact(image,
"mvg:vector-graphics",primitive);
2647 stops=(StopInfo *) NULL;
2651 graphic_context=(DrawInfo **) AcquireMagickMemory(
sizeof(*graphic_context));
2652 if (graphic_context == (DrawInfo **) NULL)
2654 primitive=DestroyString(primitive);
2655 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2658 number_points=(size_t) PrimitiveExtentPad;
2659 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
2660 (number_points+1),
sizeof(*primitive_info));
2661 if (primitive_info == (PrimitiveInfo *) NULL)
2663 primitive=DestroyString(primitive);
2664 for ( ; n >= 0; n--)
2665 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2666 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
2667 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2670 (void) memset(primitive_info,0,(
size_t) (number_points+1)*
2671 sizeof(*primitive_info));
2672 (void) memset(&mvg_info,0,
sizeof(mvg_info));
2673 mvg_info.primitive_info=(&primitive_info);
2674 mvg_info.extent=(&number_points);
2675 mvg_info.exception=exception;
2676 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
2677 if (graphic_context[n]->primitive != (
char *) NULL)
2678 graphic_context[n]->primitive=DestroyString(graphic_context[n]->primitive);
2679 graphic_context[n]->viewbox=image->page;
2680 if ((image->page.width == 0) || (image->page.height == 0))
2682 graphic_context[n]->viewbox.width=image->columns;
2683 graphic_context[n]->viewbox.height=image->rows;
2685 token=AcquireString(primitive);
2686 extent=strlen(token)+MagickPathExtent;
2690 macros=GetMVGMacros(primitive,exception);
2692 for (q=primitive; *q !=
'\0'; )
2697 if (GetNextToken(q,&q,MagickPathExtent,keyword) < 1)
2699 if (*keyword ==
'\0')
2701 if (*keyword ==
'#')
2706 while ((*q !=
'\n') && (*q !=
'\0'))
2710 p=q-strlen(keyword)-1;
2711 primitive_type=UndefinedPrimitive;
2712 current=graphic_context[n]->affine;
2713 GetAffineMatrix(&affine);
2722 if (LocaleCompare(
"affine",keyword) == 0)
2724 (void) GetNextToken(q,&q,extent,token);
2725 affine.sx=GetDrawValue(token,&next_token);
2726 if (token == next_token)
2727 ThrowPointExpectedException(token,exception);
2728 (void) GetNextToken(q,&q,extent,token);
2729 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2730 ThrowPointExpectedException(token,exception);
2732 (void) GetNextToken(q,&q,extent,token);
2733 affine.ry=GetDrawValue(token,&next_token);
2734 if (token == next_token)
2735 ThrowPointExpectedException(token,exception);
2736 (void) GetNextToken(q,&q,extent,token);
2737 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2738 ThrowPointExpectedException(token,exception);
2740 (void) GetNextToken(q,&q,extent,token);
2741 affine.rx=GetDrawValue(token,&next_token);
2742 if (token == next_token)
2743 ThrowPointExpectedException(token,exception);
2744 (void) GetNextToken(q,&q,extent,token);
2745 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2746 ThrowPointExpectedException(token,exception);
2748 (void) GetNextToken(q,&q,extent,token);
2749 affine.sy=GetDrawValue(token,&next_token);
2750 if (token == next_token)
2751 ThrowPointExpectedException(token,exception);
2752 (void) GetNextToken(q,&q,extent,token);
2753 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2754 ThrowPointExpectedException(token,exception);
2756 (void) GetNextToken(q,&q,extent,token);
2757 affine.tx=GetDrawValue(token,&next_token);
2758 if (token == next_token)
2759 ThrowPointExpectedException(token,exception);
2760 (void) GetNextToken(q,&q,extent,token);
2761 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2762 ThrowPointExpectedException(token,exception);
2764 (void) GetNextToken(q,&q,extent,token);
2765 affine.ty=GetDrawValue(token,&next_token);
2766 if (token == next_token)
2767 ThrowPointExpectedException(token,exception);
2770 if (LocaleCompare(
"alpha",keyword) == 0)
2772 primitive_type=AlphaPrimitive;
2775 if (LocaleCompare(
"arc",keyword) == 0)
2777 primitive_type=ArcPrimitive;
2786 if (LocaleCompare(
"bezier",keyword) == 0)
2788 primitive_type=BezierPrimitive;
2791 if (LocaleCompare(
"border-color",keyword) == 0)
2793 (void) GetNextToken(q,&q,extent,token);
2794 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2795 &graphic_context[n]->border_color,exception);
2804 if (LocaleCompare(
"class",keyword) == 0)
2809 (void) GetNextToken(q,&q,extent,token);
2810 if ((*token ==
'\0') || (*token ==
';'))
2818 for (i=0; i <= n; i++)
2819 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2823 if (classDepth++ >= MaxVectorRecursionDepth)
2825 (void) ThrowMagickException(exception,GetMagickModule(),
2826 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2830 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2831 if ((graphic_context[n]->render != MagickFalse) &&
2832 (mvg_class != (
const char *) NULL) && (p > primitive))
2843 (void) CloneString(&graphic_context[n]->
id,token);
2844 offset=(ssize_t) (p-primitive);
2845 elements=AcquireString(primitive);
2846 elements[offset]=
'\0';
2847 (void) ConcatenateString(&elements,mvg_class);
2848 (void) ConcatenateString(&elements,
"\n");
2849 (void) ConcatenateString(&elements,q);
2850 primitive=DestroyString(primitive);
2856 if (LocaleCompare(
"clip-path",keyword) == 0)
2864 (void) GetNextToken(q,&q,extent,token);
2870 (void) CloneString(&graphic_context[n]->clip_mask,token);
2871 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2872 if (clip_path != (
const char *) NULL)
2874 if (graphic_context[n]->clipping_mask != (Image *) NULL)
2875 graphic_context[n]->clipping_mask=
2876 DestroyImage(graphic_context[n]->clipping_mask);
2877 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2878 graphic_context[n],token,clip_path,depth+1,exception);
2879 if (graphic_context[n]->compliance != SVGCompliance)
2881 clip_path=(
const char *) GetValueFromSplayTree(macros,
2882 graphic_context[n]->clip_mask);
2883 if (clip_path != (
const char *) NULL)
2884 (void) SetImageArtifact(image,
2885 graphic_context[n]->clip_mask,clip_path);
2886 status&=(MagickStatusType) DrawClipPath_(image,
2887 graphic_context[n],graphic_context[n]->clip_mask,
2893 if (LocaleCompare(
"clip-rule",keyword) == 0)
2898 (void) GetNextToken(q,&q,extent,token);
2899 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2901 if (fill_rule == -1)
2906 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2909 if (LocaleCompare(
"clip-units",keyword) == 0)
2914 (void) GetNextToken(q,&q,extent,token);
2915 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2917 if (clip_units == -1)
2922 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2923 if (clip_units == ObjectBoundingBox)
2925 GetAffineMatrix(¤t);
2926 affine.sx=draw_info->bounds.x2;
2927 affine.sy=draw_info->bounds.y2;
2928 affine.tx=draw_info->bounds.x1;
2929 affine.ty=draw_info->bounds.y1;
2934 if (LocaleCompare(
"circle",keyword) == 0)
2936 primitive_type=CirclePrimitive;
2939 if (LocaleCompare(
"color",keyword) == 0)
2941 primitive_type=ColorPrimitive;
2944 if (LocaleCompare(
"compliance",keyword) == 0)
2950 (void) GetNextToken(q,&q,extent,token);
2951 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2952 MagickComplianceOptions,MagickFalse,token);
2955 if (LocaleCompare(
"currentColor",keyword) == 0)
2957 (void) GetNextToken(q,&q,extent,token);
2966 if (LocaleCompare(
"decorate",keyword) == 0)
2971 (void) GetNextToken(q,&q,extent,token);
2972 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2979 graphic_context[n]->decorate=(DecorationType) decorate;
2982 if (LocaleCompare(
"density",keyword) == 0)
2984 (void) GetNextToken(q,&q,extent,token);
2985 (void) CloneString(&graphic_context[n]->density,token);
2988 if (LocaleCompare(
"direction",keyword) == 0)
2993 (void) GetNextToken(q,&q,extent,token);
2994 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2996 if (direction == -1)
2999 graphic_context[n]->direction=(DirectionType) direction;
3008 if (LocaleCompare(
"ellipse",keyword) == 0)
3010 primitive_type=EllipsePrimitive;
3013 if (LocaleCompare(
"encoding",keyword) == 0)
3015 (void) GetNextToken(q,&q,extent,token);
3016 (void) CloneString(&graphic_context[n]->encoding,token);
3025 if (LocaleCompare(
"fill",keyword) == 0)
3030 (void) GetNextToken(q,&q,extent,token);
3031 if (graphic_context[n]->clip_path != MagickFalse)
3033 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3034 if (mvg_class != (
const char *) NULL)
3036 (void) DrawPatternPath(image,draw_info,mvg_class,
3037 &graphic_context[n]->fill_pattern,exception);
3040 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3041 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3043 (void) DrawPatternPath(image,draw_info,token,
3044 &graphic_context[n]->fill_pattern,exception);
3047 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3048 &graphic_context[n]->fill,exception);
3049 if ((graphic_context[n]->fill_alpha != (
double) OpaqueAlpha) &&
3050 ((graphic_context[n]->compliance != SVGCompliance) ||
3051 (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)))
3052 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3055 if (LocaleCompare(
"fill-opacity",keyword) == 0)
3060 (void) GetNextToken(q,&q,extent,token);
3061 if (graphic_context[n]->clip_path != MagickFalse)
3063 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3064 opacity=MagickMin(MagickMax(factor*
3065 GetDrawValue(token,&next_token),0.0),1.0);
3066 if (token == next_token)
3067 ThrowPointExpectedException(token,exception);
3068 if (graphic_context[n]->compliance == SVGCompliance)
3069 graphic_context[n]->fill_alpha*=opacity;
3071 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3072 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3073 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3075 if (graphic_context[n]->compliance != SVGCompliance)
3076 graphic_context[n]->fill.alpha=(MagickRealType)
3077 ClampToQuantum((
double) QuantumRange*opacity);
3078 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3081 if (LocaleCompare(
"fill-rule",keyword) == 0)
3086 (void) GetNextToken(q,&q,extent,token);
3087 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3089 if (fill_rule == -1)
3094 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3097 if (LocaleCompare(
"font",keyword) == 0)
3099 (void) GetNextToken(q,&q,extent,token);
3100 (void) CloneString(&graphic_context[n]->font,token);
3101 if (LocaleCompare(
"none",token) == 0)
3102 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3103 graphic_context[n]->font);
3106 if (LocaleCompare(
"font-family",keyword) == 0)
3108 (void) GetNextToken(q,&q,extent,token);
3109 (void) CloneString(&graphic_context[n]->family,token);
3112 if (LocaleCompare(
"font-size",keyword) == 0)
3114 (void) GetNextToken(q,&q,extent,token);
3115 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3116 if (token == next_token)
3117 ThrowPointExpectedException(token,exception);
3120 if (LocaleCompare(
"font-stretch",keyword) == 0)
3125 (void) GetNextToken(q,&q,extent,token);
3126 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3132 graphic_context[n]->stretch=(StretchType) stretch;
3135 if (LocaleCompare(
"font-style",keyword) == 0)
3140 (void) GetNextToken(q,&q,extent,token);
3141 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3147 graphic_context[n]->style=(StyleType) style;
3150 if (LocaleCompare(
"font-weight",keyword) == 0)
3155 (void) GetNextToken(q,&q,extent,token);
3156 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3158 weight=(ssize_t) StringToUnsignedLong(token);
3159 graphic_context[n]->weight=(size_t) weight;
3168 if (LocaleCompare(
"gradient-units",keyword) == 0)
3170 (void) GetNextToken(q,&q,extent,token);
3173 if (LocaleCompare(
"gravity",keyword) == 0)
3178 (void) GetNextToken(q,&q,extent,token);
3179 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3185 graphic_context[n]->gravity=(GravityType) gravity;
3194 if (LocaleCompare(
"image",keyword) == 0)
3199 primitive_type=ImagePrimitive;
3200 (void) GetNextToken(q,&q,extent,token);
3201 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3207 graphic_context[n]->compose=(CompositeOperator) compose;
3210 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3212 (void) GetNextToken(q,&q,extent,token);
3213 graphic_context[n]->interline_spacing=GetDrawValue(token,
3215 if (token == next_token)
3216 ThrowPointExpectedException(token,exception);
3219 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3221 (void) GetNextToken(q,&q,extent,token);
3222 graphic_context[n]->interword_spacing=GetDrawValue(token,
3224 if (token == next_token)
3225 ThrowPointExpectedException(token,exception);
3234 if (LocaleCompare(
"kerning",keyword) == 0)
3236 (void) GetNextToken(q,&q,extent,token);
3237 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3238 if (token == next_token)
3239 ThrowPointExpectedException(token,exception);
3248 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3250 (void) GetNextToken(q,&q,extent,token);
3251 if (IsValidPoint(token) == MagickFalse)
3253 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
3254 clone_info->text=AcquireString(
" ");
3255 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,&metrics,
3257 graphic_context[n]->kerning=metrics.width*
3258 GetDrawValue(token,&next_token);
3259 clone_info=DestroyDrawInfo(clone_info);
3260 if (token == next_token)
3261 ThrowPointExpectedException(token,exception);
3264 if (LocaleCompare(
"line",keyword) == 0)
3266 primitive_type=LinePrimitive;
3275 if (LocaleCompare(
"mask",keyword) == 0)
3283 (void) GetNextToken(q,&q,extent,token);
3284 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3285 if (mask_path != (
const char *) NULL)
3287 if (graphic_context[n]->composite_mask != (Image *) NULL)
3288 graphic_context[n]->composite_mask=
3289 DestroyImage(graphic_context[n]->composite_mask);
3290 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3291 graphic_context[n],token,mask_path,depth+1,exception);
3292 if (graphic_context[n]->compliance != SVGCompliance)
3293 status=SetImageMask(image,CompositePixelMask,
3294 graphic_context[n]->composite_mask,exception);
3304 if (LocaleCompare(
"offset",keyword) == 0)
3306 (void) GetNextToken(q,&q,extent,token);
3309 if (LocaleCompare(
"opacity",keyword) == 0)
3314 (void) GetNextToken(q,&q,extent,token);
3315 if (graphic_context[n]->clip_path != MagickFalse)
3317 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3318 opacity=MagickMin(MagickMax(factor*
3319 GetDrawValue(token,&next_token),0.0),1.0);
3320 if (token == next_token)
3321 ThrowPointExpectedException(token,exception);
3322 if (graphic_context[n]->compliance == SVGCompliance)
3324 graphic_context[n]->fill_alpha*=opacity;
3325 graphic_context[n]->stroke_alpha*=opacity;
3329 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3330 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3332 if (graphic_context[n]->compliance == SVGCompliance)
3334 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3335 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3336 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3337 graphic_context[n]->stroke.alpha=
3338 graphic_context[n]->stroke_alpha;
3340 else if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3342 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3343 graphic_context[n]->stroke.alpha=
3344 graphic_context[n]->stroke_alpha;
3348 graphic_context[n]->fill.alpha=(MagickRealType)
3349 ClampToQuantum((
double) QuantumRange*opacity);
3350 graphic_context[n]->stroke.alpha=(MagickRealType)
3351 ClampToQuantum((
double) QuantumRange*opacity);
3353 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3354 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3363 if (LocaleCompare(
"path",keyword) == 0)
3365 primitive_type=PathPrimitive;
3368 if (LocaleCompare(
"point",keyword) == 0)
3370 primitive_type=PointPrimitive;
3373 if (LocaleCompare(
"polyline",keyword) == 0)
3375 primitive_type=PolylinePrimitive;
3378 if (LocaleCompare(
"polygon",keyword) == 0)
3380 primitive_type=PolygonPrimitive;
3383 if (LocaleCompare(
"pop",keyword) == 0)
3385 if (GetNextToken(q,&q,extent,token) < 1)
3387 if (LocaleCompare(
"class",token) == 0)
3389 if (LocaleCompare(
"clip-path",token) == 0)
3391 if (LocaleCompare(
"defs",token) == 0)
3394 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3398 if (LocaleCompare(
"gradient",token) == 0)
3400 if (LocaleCompare(
"graphic-context",token) == 0)
3404 (void) ThrowMagickException(exception,GetMagickModule(),
3405 DrawError,
"UnbalancedGraphicContextPushPop",
"`%s'",token);
3410 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3411 (graphic_context[n]->compliance != SVGCompliance))
3412 if (LocaleCompare(graphic_context[n]->clip_mask,
3413 graphic_context[n-1]->clip_mask) != 0)
3414 status=SetImageMask(image,WritePixelMask,(Image *) NULL,
3416 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3420 if (LocaleCompare(
"mask",token) == 0)
3422 if (LocaleCompare(
"pattern",token) == 0)
3424 if (LocaleCompare(
"symbol",token) == 0)
3427 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3434 if (LocaleCompare(
"push",keyword) == 0)
3436 if (GetNextToken(q,&q,extent,token) < 1)
3438 if (LocaleCompare(
"class",token) == 0)
3443 for (p=q; *q !=
'\0'; )
3445 if (GetNextToken(q,&q,extent,token) < 1)
3447 if (LocaleCompare(token,
"pop") != 0)
3449 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3450 if (LocaleCompare(token,
"class") != 0)
3454 (void) GetNextToken(q,&q,extent,token);
3457 if (LocaleCompare(
"clip-path",token) == 0)
3459 (void) GetNextToken(q,&q,extent,token);
3460 for (p=q; *q !=
'\0'; )
3462 if (GetNextToken(q,&q,extent,token) < 1)
3464 if (LocaleCompare(token,
"pop") != 0)
3466 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3467 if (LocaleCompare(token,
"clip-path") != 0)
3471 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3476 (void) GetNextToken(q,&q,extent,token);
3479 if (LocaleCompare(
"defs",token) == 0)
3482 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3486 if (LocaleCompare(
"gradient",token) == 0)
3489 key[2*MagickPathExtent],
3490 name[MagickPathExtent],
3491 type[MagickPathExtent];
3496 (void) GetNextToken(q,&q,extent,token);
3497 (void) CopyMagickString(name,token,MagickPathExtent);
3498 (void) GetNextToken(q,&q,extent,token);
3499 (void) CopyMagickString(type,token,MagickPathExtent);
3500 (void) GetNextToken(q,&q,extent,token);
3501 segment.x1=GetDrawValue(token,&next_token);
3502 if (token == next_token)
3503 ThrowPointExpectedException(token,exception);
3504 (void) GetNextToken(q,&q,extent,token);
3505 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3506 ThrowPointExpectedException(token,exception);
3508 (void) GetNextToken(q,&q,extent,token);
3509 segment.y1=GetDrawValue(token,&next_token);
3510 if (token == next_token)
3511 ThrowPointExpectedException(token,exception);
3512 (void) GetNextToken(q,&q,extent,token);
3513 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3514 ThrowPointExpectedException(token,exception);
3516 (void) GetNextToken(q,&q,extent,token);
3517 segment.x2=GetDrawValue(token,&next_token);
3518 if (token == next_token)
3519 ThrowPointExpectedException(token,exception);
3520 (void) GetNextToken(q,&q,extent,token);
3521 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3522 ThrowPointExpectedException(token,exception);
3524 (void) GetNextToken(q,&q,extent,token);
3525 segment.y2=GetDrawValue(token,&next_token);
3526 if (token == next_token)
3527 ThrowPointExpectedException(token,exception);
3528 if (LocaleCompare(type,
"radial") == 0)
3530 (void) GetNextToken(q,&q,extent,token);
3531 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3532 ThrowPointExpectedException(token,exception);
3534 (void) GetNextToken(q,&q,extent,token);
3536 for (p=q; *q !=
'\0'; )
3538 if (GetNextToken(q,&q,extent,token) < 1)
3540 if (LocaleCompare(token,
"pop") != 0)
3542 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3543 if (LocaleCompare(token,
"gradient") != 0)
3547 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3548 (p == (
char *) NULL) || ((q-4) < p) ||
3549 ((
size_t) (q-p+4+1) > extent))
3554 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3555 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3556 graphic_context[n]->affine.ry*segment.y1+
3557 graphic_context[n]->affine.tx;
3558 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3559 graphic_context[n]->affine.sy*segment.y1+
3560 graphic_context[n]->affine.ty;
3561 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3562 graphic_context[n]->affine.ry*segment.y2+
3563 graphic_context[n]->affine.tx;
3564 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3565 graphic_context[n]->affine.sy*segment.y2+
3566 graphic_context[n]->affine.ty;
3567 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3568 (void) SetImageArtifact(image,key,token);
3569 (void) FormatLocaleString(key,MagickPathExtent,
"%s-type",name);
3570 (void) SetImageArtifact(image,key,type);
3571 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3573 (void) FormatLocaleString(geometry,MagickPathExtent,
3574 "%gx%g%+.15g%+.15g",
3575 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3576 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3577 bounds.x1,bounds.y1);
3578 (void) SetImageArtifact(image,key,geometry);
3579 (void) GetNextToken(q,&q,extent,token);
3582 if (LocaleCompare(
"graphic-context",token) == 0)
3585 graphic_context=(DrawInfo **) ResizeQuantumMemory(
3586 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3587 if (graphic_context == (DrawInfo **) NULL)
3589 (void) ThrowMagickException(exception,GetMagickModule(),
3590 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3595 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
3596 graphic_context[n-1]);
3599 (void) GetNextToken(q,&q,extent,token);
3600 (void) CloneString(&graphic_context[n]->
id,token);
3602 if (n >= MaxVectorRecursionDepth)
3604 (void) ThrowMagickException(exception,GetMagickModule(),
3605 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",
3611 if (LocaleCompare(
"mask",token) == 0)
3613 (void) GetNextToken(q,&q,extent,token);
3616 if (LocaleCompare(
"pattern",token) == 0)
3619 key[2*MagickPathExtent],
3620 name[MagickPathExtent];
3625 (void) GetNextToken(q,&q,extent,token);
3626 (void) CopyMagickString(name,token,MagickPathExtent);
3627 (void) GetNextToken(q,&q,extent,token);
3628 region.x=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3630 if (token == next_token)
3631 ThrowPointExpectedException(token,exception);
3632 (void) GetNextToken(q,&q,extent,token);
3633 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3634 ThrowPointExpectedException(token,exception);
3636 (void) GetNextToken(q,&q,extent,token);
3637 region.y=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3639 if (token == next_token)
3640 ThrowPointExpectedException(token,exception);
3641 (void) GetNextToken(q,&q,extent,token);
3642 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3643 ThrowPointExpectedException(token,exception);
3645 (void) GetNextToken(q,&q,extent,token);
3646 region.width=CastDoubleToSizeT(floor(GetDrawValue(token,
3648 if (token == next_token)
3649 ThrowPointExpectedException(token,exception);
3650 (void) GetNextToken(q,&q,extent,token);
3651 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3652 ThrowPointExpectedException(token,exception);
3654 (void) GetNextToken(q,&q,extent,token);
3655 region.height=CastDoubleToSizeT(GetDrawValue(token,
3657 if (token == next_token)
3658 ThrowPointExpectedException(token,exception);
3659 for (p=q; *q !=
'\0'; )
3661 if (GetNextToken(q,&q,extent,token) < 1)
3663 if (LocaleCompare(token,
"pop") != 0)
3665 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3666 if (LocaleCompare(token,
"pattern") != 0)
3670 if ((q == (
char *) NULL) || (p == (
char *) NULL) ||
3671 ((q-4) < p) || ((
size_t) (q-p+4+1) > extent))
3676 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3677 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3678 (void) SetImageArtifact(image,key,token);
3679 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3681 (void) FormatLocaleString(geometry,MagickPathExtent,
3682 "%.17gx%.17g%+.20g%+.20g",(
double) region.width,(
double)
3683 region.height,(
double) region.x,(
double) region.y);
3684 (void) SetImageArtifact(image,key,geometry);
3685 (void) GetNextToken(q,&q,extent,token);
3688 if (LocaleCompare(
"symbol",token) == 0)
3691 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3704 if (LocaleCompare(
"rectangle",keyword) == 0)
3706 primitive_type=RectanglePrimitive;
3709 if (LocaleCompare(
"rotate",keyword) == 0)
3711 (void) GetNextToken(q,&q,extent,token);
3712 angle=GetDrawValue(token,&next_token);
3713 if (token == next_token)
3714 ThrowPointExpectedException(token,exception);
3715 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3716 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3717 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3718 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3721 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3723 primitive_type=RoundRectanglePrimitive;
3732 if (LocaleCompare(
"scale",keyword) == 0)
3734 (void) GetNextToken(q,&q,extent,token);
3735 affine.sx=GetDrawValue(token,&next_token);
3736 if (token == next_token)
3737 ThrowPointExpectedException(token,exception);
3738 (void) GetNextToken(q,&q,extent,token);
3739 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3740 ThrowPointExpectedException(token,exception);
3742 (void) GetNextToken(q,&q,extent,token);
3743 affine.sy=GetDrawValue(token,&next_token);
3744 if (token == next_token)
3745 ThrowPointExpectedException(token,exception);
3748 if (LocaleCompare(
"skewX",keyword) == 0)
3750 (void) GetNextToken(q,&q,extent,token);
3751 angle=GetDrawValue(token,&next_token);
3752 if (token == next_token)
3753 ThrowPointExpectedException(token,exception);
3754 affine.ry=sin(DegreesToRadians(angle));
3757 if (LocaleCompare(
"skewY",keyword) == 0)
3759 (void) GetNextToken(q,&q,extent,token);
3760 angle=GetDrawValue(token,&next_token);
3761 if (token == next_token)
3762 ThrowPointExpectedException(token,exception);
3763 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3766 if (LocaleCompare(
"stop-color",keyword) == 0)
3772 if (number_stops == 1)
3773 stops=(StopInfo *) AcquireQuantumMemory(2,
sizeof(*stops));
3775 if (number_stops > 2)
3776 stops=(StopInfo *) ResizeQuantumMemory(stops,number_stops,
3778 if (stops == (StopInfo *) NULL)
3780 (void) ThrowMagickException(exception,GetMagickModule(),
3781 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3786 (void) GetNextToken(q,&q,extent,token);
3787 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3788 &stop_color,exception);
3789 stops[number_stops-1].color=stop_color;
3790 (void) GetNextToken(q,&q,extent,token);
3791 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3792 stops[number_stops-1].offset=factor*GetDrawValue(token,
3794 if (token == next_token)
3795 ThrowPointExpectedException(token,exception);
3798 if (LocaleCompare(
"stroke",keyword) == 0)
3803 (void) GetNextToken(q,&q,extent,token);
3804 if (graphic_context[n]->clip_path != MagickFalse)
3806 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3807 if (mvg_class != (
const char *) NULL)
3809 (void) DrawPatternPath(image,draw_info,mvg_class,
3810 &graphic_context[n]->stroke_pattern,exception);
3813 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3814 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3816 (void) DrawPatternPath(image,draw_info,token,
3817 &graphic_context[n]->stroke_pattern,exception);
3820 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3821 &graphic_context[n]->stroke,exception);
3822 if ((graphic_context[n]->stroke_alpha != (
double) OpaqueAlpha) &&
3823 ((graphic_context[n]->compliance != SVGCompliance) ||
3824 (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)))
3825 graphic_context[n]->stroke.alpha=
3826 graphic_context[n]->stroke_alpha;
3829 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3831 (void) GetNextToken(q,&q,extent,token);
3832 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3833 MagickTrue : MagickFalse;
3836 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3838 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3839 graphic_context[n]->dash_pattern=(
double *)
3840 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3841 if (IsValidPoint(q) != MagickFalse)
3847 (void) GetNextToken(r,&r,extent,token);
3848 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3849 ThrowPointExpectedException(token,exception);
3851 (void) GetNextToken(r,&r,extent,token);
3852 for (x=0; IsValidPoint(token) != MagickFalse; x++)
3854 (void) GetNextToken(r,&r,extent,token);
3856 (void) GetNextToken(r,&r,extent,token);
3858 graphic_context[n]->dash_pattern=(
double *)
3859 AcquireQuantumMemory((
size_t) (2*x+2),
3860 sizeof(*graphic_context[n]->dash_pattern));
3861 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3863 (void) ThrowMagickException(exception,GetMagickModule(),
3864 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3869 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3870 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3871 for (j=0; j < x; j++)
3873 (void) GetNextToken(q,&q,extent,token);
3874 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3875 ThrowPointExpectedException(token,exception);
3877 (void) GetNextToken(q,&q,extent,token);
3878 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3880 if (token == next_token)
3881 ThrowPointExpectedException(token,exception);
3882 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3885 if (((x & 0x01) != 0) && (j == x))
3886 for ( ; j < (2*x); j++)
3887 graphic_context[n]->dash_pattern[j]=
3888 graphic_context[n]->dash_pattern[j-x];
3889 graphic_context[n]->dash_pattern[j]=0.0;
3892 (void) GetNextToken(q,&q,extent,token);
3895 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3897 (void) GetNextToken(q,&q,extent,token);
3898 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3899 if (token == next_token)
3900 ThrowPointExpectedException(token,exception);
3903 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3908 (void) GetNextToken(q,&q,extent,token);
3909 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3915 graphic_context[n]->linecap=(LineCap) linecap;
3918 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3923 (void) GetNextToken(q,&q,extent,token);
3924 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3931 graphic_context[n]->linejoin=(LineJoin) linejoin;
3934 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3936 (void) GetNextToken(q,&q,extent,token);
3937 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3940 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3945 (void) GetNextToken(q,&q,extent,token);
3946 if (graphic_context[n]->clip_path != MagickFalse)
3948 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3949 opacity=MagickMin(MagickMax(factor*GetDrawValue(token,&next_token),
3951 if (token == next_token)
3952 ThrowPointExpectedException(token,exception);
3953 if (graphic_context[n]->compliance == SVGCompliance)
3954 graphic_context[n]->stroke_alpha*=opacity;
3956 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3957 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3958 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3960 if (graphic_context[n]->compliance != SVGCompliance)
3961 graphic_context[n]->stroke.alpha=(MagickRealType)
3962 ClampToQuantum((
double) QuantumRange*opacity);
3963 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3966 if (LocaleCompare(
"stroke-width",keyword) == 0)
3968 (void) GetNextToken(q,&q,extent,token);
3969 if (graphic_context[n]->clip_path != MagickFalse)
3971 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3972 if ((token == next_token) ||
3973 (graphic_context[n]->stroke_width < 0.0))
3974 ThrowPointExpectedException(token,exception);
3983 if (LocaleCompare(
"text",keyword) == 0)
3985 primitive_type=TextPrimitive;
3989 if (LocaleCompare(
"text-align",keyword) == 0)
3994 (void) GetNextToken(q,&q,extent,token);
3995 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
4001 graphic_context[n]->align=(AlignType) align;
4004 if (LocaleCompare(
"text-anchor",keyword) == 0)
4009 (void) GetNextToken(q,&q,extent,token);
4010 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
4016 graphic_context[n]->align=(AlignType) align;
4019 if (LocaleCompare(
"text-antialias",keyword) == 0)
4021 (void) GetNextToken(q,&q,extent,token);
4022 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
4023 MagickTrue : MagickFalse;
4026 if (LocaleCompare(
"text-undercolor",keyword) == 0)
4028 (void) GetNextToken(q,&q,extent,token);
4029 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
4030 &graphic_context[n]->undercolor,exception);
4033 if (LocaleCompare(
"translate",keyword) == 0)
4035 (void) GetNextToken(q,&q,extent,token);
4036 affine.tx=GetDrawValue(token,&next_token);
4037 if (token == next_token)
4038 ThrowPointExpectedException(token,exception);
4039 (void) GetNextToken(q,&q,extent,token);
4040 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4041 ThrowPointExpectedException(token,exception);
4043 (void) GetNextToken(q,&q,extent,token);
4044 affine.ty=GetDrawValue(token,&next_token);
4045 if (token == next_token)
4046 ThrowPointExpectedException(token,exception);
4056 if (LocaleCompare(
"use",keyword) == 0)
4064 (void) GetNextToken(q,&q,extent,token);
4065 use=(
const char *) GetValueFromSplayTree(macros,token);
4066 if (use != (
const char *) NULL)
4068 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4069 if (draw_info->macro_expansion != (
size_t *) NULL)
4071 if (*draw_info->macro_expansion >= MacroExpansionLimit)
4073 (void) ThrowMagickException(exception,GetMagickModule(),
4074 DrawError,
"NonconformingDrawingPrimitiveDefinition",
4076 clone_info=DestroyDrawInfo(clone_info);
4077 return(MagickFalse);
4079 (*draw_info->macro_expansion)++;
4081 (void) CloneString(&clone_info->primitive,use);
4082 status=RenderMVGContent(image,clone_info,depth+1,exception);
4083 clone_info=DestroyDrawInfo(clone_info);
4093 if (LocaleCompare(
"viewbox",keyword) == 0)
4095 (void) GetNextToken(q,&q,extent,token);
4096 graphic_context[n]->viewbox.x=CastDoubleToSsizeT(ceil(
4097 GetDrawValue(token,&next_token)-0.5));
4098 if (token == next_token)
4099 ThrowPointExpectedException(token,exception);
4100 (void) GetNextToken(q,&q,extent,token);
4101 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4102 ThrowPointExpectedException(token,exception);
4104 (void) GetNextToken(q,&q,extent,token);
4105 graphic_context[n]->viewbox.y=CastDoubleToSsizeT(
4106 ceil(GetDrawValue(token,&next_token)-0.5));
4107 if (token == next_token)
4108 ThrowPointExpectedException(token,exception);
4109 (void) GetNextToken(q,&q,extent,token);
4110 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4111 ThrowPointExpectedException(token,exception);
4113 (void) GetNextToken(q,&q,extent,token);
4114 graphic_context[n]->viewbox.width=CastDoubleToSizeT(floor(
4115 GetDrawValue(token,&next_token)+0.5));
4116 if (token == next_token)
4117 ThrowPointExpectedException(token,exception);
4118 (void) GetNextToken(q,&q,extent,token);
4119 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4120 ThrowPointExpectedException(token,exception);
4122 (void) GetNextToken(q,&q,extent,token);
4123 graphic_context[n]->viewbox.height=CastDoubleToSizeT(floor(
4124 GetDrawValue(token,&next_token)+0.5));
4125 if (token == next_token)
4126 ThrowPointExpectedException(token,exception);
4135 if (LocaleCompare(
"word-spacing",keyword) == 0)
4137 (void) GetNextToken(q,&q,extent,token);
4138 graphic_context[n]->interword_spacing=GetDrawValue(token,
4140 if (token == next_token)
4141 ThrowPointExpectedException(token,exception);
4153 if (status == MagickFalse)
4155 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4156 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4157 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4158 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4160 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4161 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4162 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4163 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4164 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4166 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4169 if (primitive_type == UndefinedPrimitive)
4173 if (number_stops > 1)
4178 type=LinearGradient;
4179 if (draw_info->gradient.type == RadialGradient)
4180 type=RadialGradient;
4181 (void) GradientImage(image,type,PadSpread,stops,number_stops,
4184 if (number_stops > 0)
4185 stops=(StopInfo *) RelinquishMagickMemory(stops);
4187 if ((draw_info->debug != MagickFalse) && (q > p))
4188 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int)
4195 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4196 if (primitive_info[i].text != (
char *) NULL)
4197 primitive_info[i].text=DestroyString(primitive_info[i].text);
4201 primitive_info[0].primitive=primitive_type;
4202 primitive_info[0].point.x=0.0;
4203 primitive_info[0].point.y=0.0;
4204 primitive_info[0].coordinates=0;
4205 primitive_info[0].method=FloodfillMethod;
4206 primitive_info[0].closed_subpath=MagickFalse;
4207 for (x=0; *q !=
'\0'; x++)
4212 if (IsValidPoint(q) == MagickFalse)
4214 (void) GetNextToken(q,&q,extent,token);
4215 point.x=GetDrawValue(token,&next_token);
4216 if (token == next_token)
4217 ThrowPointExpectedException(token,exception);
4218 (void) GetNextToken(q,&q,extent,token);
4219 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4220 ThrowPointExpectedException(token,exception);
4222 (void) GetNextToken(q,&q,extent,token);
4223 point.y=GetDrawValue(token,&next_token);
4224 if (token == next_token)
4225 ThrowPointExpectedException(token,exception);
4226 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4228 (void) GetNextToken(q,&q,extent,token);
4229 primitive_info[i].primitive=primitive_type;
4230 primitive_info[i].point=point;
4231 primitive_info[i].coordinates=0;
4232 primitive_info[i].method=FloodfillMethod;
4233 primitive_info[i].closed_subpath=MagickFalse;
4236 if (i < (ssize_t) number_points)
4238 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4240 primitive_info=(*mvg_info.primitive_info);
4241 if (status == MagickFalse)
4244 if (status == MagickFalse)
4246 if (primitive_info[j].text != (
char *) NULL)
4247 primitive_info[j].text=DestroyString(primitive_info[j].text);
4248 primitive_info[j].primitive=primitive_type;
4249 primitive_info[j].coordinates=(size_t) x;
4250 primitive_info[j].method=FloodfillMethod;
4251 primitive_info[j].closed_subpath=MagickFalse;
4255 bounds.x1=primitive_info[j].point.x;
4256 bounds.y1=primitive_info[j].point.y;
4257 bounds.x2=primitive_info[j].point.x;
4258 bounds.y2=primitive_info[j].point.y;
4259 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4261 point=primitive_info[j+k].point;
4262 if (point.x < bounds.x1)
4264 if (point.y < bounds.y1)
4266 if (point.x > bounds.x2)
4268 if (point.y > bounds.y2)
4274 coordinates=(double) primitive_info[j].coordinates;
4275 switch (primitive_type)
4277 case RectanglePrimitive:
4282 case RoundRectanglePrimitive:
4289 alpha=bounds.x2-bounds.x1;
4290 beta=bounds.y2-bounds.y1;
4291 radius=hypot(alpha,beta);
4293 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4294 BezierQuantum+360.0;
4297 case BezierPrimitive:
4299 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4308 (void) GetNextToken(q,&q,extent,token);
4311 for (s=token; *s !=
'\0'; s=t)
4316 value=GetDrawValue(s,&t);
4325 for (s=token; *s !=
'\0'; s++)
4326 if (strspn(s,
"AaCcQqSsTt") != 0)
4327 coordinates+=(20.0*BezierQuantum)+360.0;
4333 if (status == MagickFalse)
4335 if (((
size_t) (i+coordinates)) >= number_points)
4340 number_points+=(size_t) coordinates+1;
4341 if (number_points < (
size_t) coordinates)
4343 (void) ThrowMagickException(exception,GetMagickModule(),
4344 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4350 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points+
4351 (
double) coordinates+1.0);
4352 primitive_info=(*mvg_info.primitive_info);
4353 if (status == MagickFalse)
4356 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,
4357 PrimitiveExtentPad);
4358 primitive_info=(*mvg_info.primitive_info);
4359 if (status == MagickFalse)
4362 switch (primitive_type)
4364 case PointPrimitive:
4367 if (primitive_info[j].coordinates != 1)
4372 status&=(MagickStatusType) TracePoint(primitive_info+j,
4373 primitive_info[j].point);
4374 primitive_info=(*mvg_info.primitive_info);
4375 if (status == MagickFalse)
4377 i=j+(ssize_t) primitive_info[j].coordinates;
4382 if (primitive_info[j].coordinates != 2)
4387 status&=(MagickStatusType) TraceLine(primitive_info+j,
4388 primitive_info[j].point,primitive_info[j+1].point);
4389 primitive_info=(*mvg_info.primitive_info);
4390 if (status == MagickFalse)
4392 i=j+(ssize_t) primitive_info[j].coordinates;
4395 case RectanglePrimitive:
4397 if (primitive_info[j].coordinates != 2)
4402 status&=(MagickStatusType) TraceRectangle(primitive_info+j,
4403 primitive_info[j].point,primitive_info[j+1].point);
4404 primitive_info=(*mvg_info.primitive_info);
4405 if (status == MagickFalse)
4407 i=j+(ssize_t) primitive_info[j].coordinates;
4410 case RoundRectanglePrimitive:
4412 if (primitive_info[j].coordinates != 3)
4417 if ((primitive_info[j+2].point.x < 0.0) ||
4418 (primitive_info[j+2].point.y < 0.0))
4423 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4428 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4433 status&=(MagickStatusType) TraceRoundRectangle(&mvg_info,
4434 primitive_info[j].point,primitive_info[j+1].point,
4435 primitive_info[j+2].point);
4436 primitive_info=(*mvg_info.primitive_info);
4437 if (status == MagickFalse)
4439 i=j+(ssize_t) primitive_info[j].coordinates;
4444 if (primitive_info[j].coordinates != 3)
4449 status&=(MagickStatusType) TraceArc(&mvg_info,primitive_info[j].point,
4450 primitive_info[j+1].point,primitive_info[j+2].point);
4451 primitive_info=(*mvg_info.primitive_info);
4452 if (status == MagickFalse)
4454 i=j+(ssize_t) primitive_info[j].coordinates;
4457 case EllipsePrimitive:
4459 if (primitive_info[j].coordinates != 3)
4464 if ((primitive_info[j+1].point.x < 0.0) ||
4465 (primitive_info[j+1].point.y < 0.0))
4470 status&=(MagickStatusType) TraceEllipse(&mvg_info,
4471 primitive_info[j].point,primitive_info[j+1].point,
4472 primitive_info[j+2].point);
4473 primitive_info=(*mvg_info.primitive_info);
4474 if (status == MagickFalse)
4476 i=j+(ssize_t) primitive_info[j].coordinates;
4479 case CirclePrimitive:
4481 if (primitive_info[j].coordinates != 2)
4486 status&=(MagickStatusType) TraceCircle(&mvg_info,
4487 primitive_info[j].point,primitive_info[j+1].point);
4488 primitive_info=(*mvg_info.primitive_info);
4489 if (status == MagickFalse)
4491 i=j+(ssize_t) primitive_info[j].coordinates;
4494 case PolylinePrimitive:
4496 if (primitive_info[j].coordinates < 1)
4503 case PolygonPrimitive:
4505 if (primitive_info[j].coordinates < 3)
4510 primitive_info[i]=primitive_info[j];
4511 primitive_info[i].coordinates=0;
4512 primitive_info[j].coordinates++;
4513 primitive_info[j].closed_subpath=MagickTrue;
4517 case BezierPrimitive:
4519 if (primitive_info[j].coordinates < 3)
4524 status&=(MagickStatusType) TraceBezier(&mvg_info,
4525 primitive_info[j].coordinates);
4526 primitive_info=(*mvg_info.primitive_info);
4527 if (status == MagickFalse)
4529 i=j+(ssize_t) primitive_info[j].coordinates;
4534 coordinates=(double) TracePath(&mvg_info,token,exception);
4535 primitive_info=(*mvg_info.primitive_info);
4536 if (status == MagickFalse)
4538 if (coordinates < 0.0)
4543 i=(ssize_t) (j+coordinates);
4546 case AlphaPrimitive:
4547 case ColorPrimitive:
4552 if (primitive_info[j].coordinates != 1)
4557 (void) GetNextToken(q,&q,extent,token);
4558 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4564 primitive_info[j].method=(PaintMethod) method;
4569 if (primitive_info[j].coordinates != 1)
4575 (void) GetNextToken(q,&q,extent,token);
4576 (void) CloneString(&primitive_info[j].text,token);
4580 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4581 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4582 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4584 mvg_info.point=primitive_info->point;
4585 primitive_info->point.x+=cursor;
4589 mvg_info.point=primitive_info->point;
4592 clone_info->render=MagickFalse;
4593 clone_info->text=AcquireString(token);
4594 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,
4595 &metrics,exception);
4596 clone_info=DestroyDrawInfo(clone_info);
4597 cursor+=metrics.width;
4598 if (graphic_context[n]->compliance != SVGCompliance)
4602 case ImagePrimitive:
4604 if (primitive_info[j].coordinates != 2)
4609 (void) GetNextToken(q,&q,extent,token);
4610 (void) CloneString(&primitive_info[j].text,token);
4617 primitive_info[i].primitive=UndefinedPrimitive;
4618 if ((draw_info->debug != MagickFalse) && (q > p))
4619 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int) (q-p),p);
4623 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4624 &graphic_context[n]->affine));
4625 primitive_info=(*mvg_info.primitive_info);
4628 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4629 graphic_context[n]->stroke_width);
4630 primitive_info=(*mvg_info.primitive_info);
4638 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4640 point=primitive_info[i].point;
4641 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4642 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4643 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4644 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4645 point=primitive_info[i].point;
4646 if (point.x < graphic_context[n]->bounds.x1)
4647 graphic_context[n]->bounds.x1=point.x;
4648 if (point.y < graphic_context[n]->bounds.y1)
4649 graphic_context[n]->bounds.y1=point.y;
4650 if (point.x > graphic_context[n]->bounds.x2)
4651 graphic_context[n]->bounds.x2=point.x;
4652 if (point.y > graphic_context[n]->bounds.y2)
4653 graphic_context[n]->bounds.y2=point.y;
4654 if (primitive_info[i].primitive == ImagePrimitive)
4656 if (i >= (ssize_t) number_points)
4657 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4659 if (graphic_context[n]->render != MagickFalse)
4661 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4662 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4663 (LocaleCompare(graphic_context[n]->clip_mask,
4664 graphic_context[n-1]->clip_mask) != 0))
4669 clip_path=(
const char *) GetValueFromSplayTree(macros,
4670 graphic_context[n]->clip_mask);
4671 if (clip_path != (
const char *) NULL)
4672 (void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4674 status&=(MagickStatusType) DrawClipPath_(image,graphic_context[n],
4675 graphic_context[n]->clip_mask,depth+1,exception);
4677 status&=(MagickStatusType) DrawPrimitive(image,graphic_context[n],
4678 primitive_info,exception);
4680 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4682 if (proceed == MagickFalse)
4687 if (draw_info->debug != MagickFalse)
4688 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4692 macros=DestroySplayTree(macros);
4693 token=DestroyString(token);
4694 if (primitive_info != (PrimitiveInfo *) NULL)
4696 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4697 if (primitive_info[i].text != (
char *) NULL)
4698 primitive_info[i].text=DestroyString(primitive_info[i].text);
4699 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4701 primitive=DestroyString(primitive);
4702 if (stops != (StopInfo *) NULL)
4703 stops=(StopInfo *) RelinquishMagickMemory(stops);
4704 for ( ; n >= 0; n--)
4705 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4706 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
4707 if ((status == MagickFalse) && (exception->severity < ErrorException))
4708 ThrowBinaryException(DrawError,
"NonconformingDrawingPrimitiveDefinition",
4710 return(status != 0 ? MagickTrue : MagickFalse);
4713MagickExport MagickBooleanType DrawImage(Image *image,
const DrawInfo *draw_info,
4714 ExceptionInfo *exception)
4720 macro_expansion = 0;
4722 ((DrawInfo *) draw_info)->macro_expansion=(¯o_expansion);
4723 status=RenderMVGContent(image,draw_info,0,exception);
4724 ((DrawInfo *) draw_info)->macro_expansion=(
size_t *) NULL;
4759MagickExport MagickBooleanType DrawPatternPath(Image *image,
4760 const DrawInfo *draw_info,
const char *name,Image **pattern,
4761 ExceptionInfo *exception)
4764 property[MagickPathExtent];
4780 assert(image != (Image *) NULL);
4781 assert(image->signature == MagickCoreSignature);
4782 assert(draw_info != (
const DrawInfo *) NULL);
4783 assert(name != (
const char *) NULL);
4784 if (IsEventLogging() != MagickFalse)
4785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4786 (void) FormatLocaleString(property,MagickPathExtent,
"%s",name);
4787 path=GetImageArtifact(image,property);
4788 if (path == (
const char *) NULL)
4789 return(MagickFalse);
4790 (void) FormatLocaleString(property,MagickPathExtent,
"%s-geometry",name);
4791 geometry=GetImageArtifact(image,property);
4792 if (geometry == (
const char *) NULL)
4793 return(MagickFalse);
4794 if ((*pattern) != (Image *) NULL)
4795 *pattern=DestroyImage(*pattern);
4796 image_info=AcquireImageInfo();
4797 image_info->size=AcquireString(geometry);
4798 *pattern=AcquireImage(image_info,exception);
4799 image_info=DestroyImageInfo(image_info);
4800 (void) QueryColorCompliance(
"#00000000",AllCompliance,
4801 &(*pattern)->background_color,exception);
4802 (void) SetImageBackgroundColor(*pattern,exception);
4803 if (draw_info->debug != MagickFalse)
4804 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4805 "begin pattern-path %s %s",name,geometry);
4806 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4807 if (clone_info->fill_pattern != (Image *) NULL)
4808 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4809 if (clone_info->stroke_pattern != (Image *) NULL)
4810 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4811 (void) FormatLocaleString(property,MagickPathExtent,
"%s-type",name);
4812 type=GetImageArtifact(image,property);
4813 if (type != (
const char *) NULL)
4814 clone_info->gradient.type=(GradientType) ParseCommandOption(
4815 MagickGradientOptions,MagickFalse,type);
4816 (void) CloneString(&clone_info->primitive,path);
4817 status=RenderMVGContent(*pattern,clone_info,0,exception);
4818 clone_info=DestroyDrawInfo(clone_info);
4819 if (draw_info->debug != MagickFalse)
4820 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4855static PolygonInfo **DestroyPolygonTLS(PolygonInfo **polygon_info)
4860 assert(polygon_info != (PolygonInfo **) NULL);
4861 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4862 if (polygon_info[i] != (PolygonInfo *) NULL)
4863 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4864 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
4865 return(polygon_info);
4868static PolygonInfo **AcquirePolygonTLS(
const PrimitiveInfo *primitive_info,
4869 ExceptionInfo *exception)
4872 *magick_restrict path_info;
4880 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4881 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
4882 sizeof(*polygon_info));
4883 if (polygon_info == (PolygonInfo **) NULL)
4885 (void) ThrowMagickException(exception,GetMagickModule(),
4886 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4887 return((PolygonInfo **) NULL);
4889 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4890 path_info=ConvertPrimitiveToPath(primitive_info,exception);
4891 if (path_info == (PathInfo *) NULL)
4892 return(DestroyPolygonTLS(polygon_info));
4893 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4894 if (polygon_info[0] == (PolygonInfo *) NULL)
4896 (void) ThrowMagickException(exception,GetMagickModule(),
4897 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4898 return(DestroyPolygonTLS(polygon_info));
4900 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
4901 return(polygon_info);
4904static MagickBooleanType ClonePolygonEdgesTLS(PolygonInfo **polygon_info,
4905 const size_t number_threads,ExceptionInfo *exception)
4910 for (i=1; i < (ssize_t) number_threads; i++)
4918 polygon_info[i]=(PolygonInfo *) AcquireMagickMemory(
4919 sizeof(*polygon_info[i]));
4920 if (polygon_info[i] == (PolygonInfo *) NULL)
4922 (void) ThrowMagickException(exception,GetMagickModule(),
4923 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4924 return(MagickFalse);
4926 polygon_info[i]->number_edges=0;
4927 edge_info=polygon_info[0]->edges;
4928 polygon_info[i]->edges=(EdgeInfo *) AcquireQuantumMemory(
4929 polygon_info[0]->number_edges,
sizeof(*edge_info));
4930 if (polygon_info[i]->edges == (EdgeInfo *) NULL)
4932 (void) ThrowMagickException(exception,GetMagickModule(),
4933 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4934 return(MagickFalse);
4936 (void) memcpy(polygon_info[i]->edges,edge_info,
4937 polygon_info[0]->number_edges*
sizeof(*edge_info));
4938 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4939 polygon_info[i]->edges[j].points=(PointInfo *) NULL;
4940 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4941 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4943 edge_info=polygon_info[0]->edges+j;
4944 polygon_info[i]->edges[j].points=(PointInfo *) AcquireQuantumMemory(
4945 edge_info->number_points,
sizeof(*edge_info));
4946 if (polygon_info[i]->edges[j].points == (PointInfo *) NULL)
4948 (void) ThrowMagickException(exception,GetMagickModule(),
4949 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4950 return(MagickFalse);
4952 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4953 edge_info->number_points*
sizeof(*edge_info->points));
4959static size_t DestroyEdge(PolygonInfo *polygon_info,
const ssize_t edge)
4961 assert(edge < (ssize_t) polygon_info->number_edges);
4962 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
4963 polygon_info->edges[edge].points);
4964 polygon_info->number_edges--;
4965 if (edge < (ssize_t) polygon_info->number_edges)
4966 (void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4967 (polygon_info->number_edges-(
size_t) edge)*
sizeof(*polygon_info->edges));
4968 return(polygon_info->number_edges);
4971static double GetFillAlpha(PolygonInfo *polygon_info,
const double mid,
4972 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4973 const ssize_t y,
double *stroke_alpha)
5000 p=polygon_info->edges;
5001 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
5003 if ((
double) y <= (p->bounds.y1-mid-0.5))
5005 if ((
double) y > (p->bounds.y2+mid+0.5))
5008 (void) DestroyEdge(polygon_info,j--);
5011 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
5012 ((
double) x > (p->bounds.x2+mid+0.5)))
5014 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5015 for ( ; i < (ssize_t) p->number_points; i++)
5017 if ((
double) y <= (p->points[i-1].y-mid-0.5))
5019 if ((
double) y > (p->points[i].y+mid+0.5))
5021 if (p->scanline != (
double) y)
5023 p->scanline=(double) y;
5024 p->highwater=(size_t) i;
5030 delta.x=(q+1)->x-q->x;
5031 delta.y=(q+1)->y-q->y;
5032 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
5038 delta.x=(double) x-q->x;
5039 delta.y=(double) y-q->y;
5040 distance=delta.x*delta.x+delta.y*delta.y;
5044 alpha=delta.x*delta.x+delta.y*delta.y;
5050 delta.x=(double) x-(q+1)->x;
5051 delta.y=(double) y-(q+1)->y;
5052 distance=delta.x*delta.x+delta.y*delta.y;
5059 alpha=MagickSafeReciprocal(alpha);
5060 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
5061 distance=alpha*beta*beta;
5068 if (p->ghostline == MagickFalse)
5071 if ((*stroke_alpha < 1.0) &&
5072 (distance <= ((alpha+0.25)*(alpha+0.25))))
5075 if (distance <= ((alpha+0.25)*(alpha+0.25)))
5080 if (fabs(distance-1.0) >= MagickEpsilon)
5081 beta=sqrt((
double) distance);
5083 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
5084 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
5088 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
5090 if (distance <= 0.0)
5097 if (fabs(beta) < MagickEpsilon)
5100 if (fabs(distance-1.0) >= MagickEpsilon)
5101 beta=sqrt(distance);
5104 if (subpath_alpha < (alpha*alpha))
5105 subpath_alpha=alpha*alpha;
5111 if (fill == MagickFalse)
5113 if (subpath_alpha >= 1.0)
5119 p=polygon_info->edges;
5120 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
5122 if ((
double) y <= p->bounds.y1)
5124 if (((
double) y > p->bounds.y2) || ((
double) x <= p->bounds.x1))
5126 if ((
double) x > p->bounds.x2)
5128 winding_number+=p->direction != 0 ? 1 : -1;
5131 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5132 for ( ; i < (ssize_t) (p->number_points-1); i++)
5133 if ((
double) y <= p->points[i].y)
5136 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
5137 winding_number+=p->direction != 0 ? 1 : -1;
5139 if (fill_rule != NonZeroRule)
5141 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
5145 if (MagickAbsoluteValue(winding_number) != 0)
5147 return(subpath_alpha);
5150static MagickBooleanType DrawPolygonPrimitive(Image *image,
5151 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5152 ExceptionInfo *exception)
5154 typedef struct _ExtentInfo
5183 **magick_restrict polygon_info;
5195 assert(image != (Image *) NULL);
5196 assert(image->signature == MagickCoreSignature);
5197 assert(draw_info != (DrawInfo *) NULL);
5198 assert(draw_info->signature == MagickCoreSignature);
5199 assert(primitive_info != (PrimitiveInfo *) NULL);
5200 if (IsEventLogging() != MagickFalse)
5201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5202 if (primitive_info->coordinates <= 1)
5207 polygon_info=AcquirePolygonTLS(primitive_info,exception);
5208 if (polygon_info == (PolygonInfo **) NULL)
5209 return(MagickFalse);
5210 if (draw_info->debug != MagickFalse)
5211 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5212 fill=(primitive_info->method == FillToBorderMethod) ||
5213 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5214 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5215 bounds=polygon_info[0]->edges[0].bounds;
5216 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5217 if (IsStringTrue(artifact) != MagickFalse)
5218 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
5219 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5221 p=polygon_info[0]->edges+i;
5222 if (p->bounds.x1 < bounds.x1)
5223 bounds.x1=p->bounds.x1;
5224 if (p->bounds.y1 < bounds.y1)
5225 bounds.y1=p->bounds.y1;
5226 if (p->bounds.x2 > bounds.x2)
5227 bounds.x2=p->bounds.x2;
5228 if (p->bounds.y2 > bounds.y2)
5229 bounds.y2=p->bounds.y2;
5231 bounds.x1-=(mid+1.0);
5232 bounds.y1-=(mid+1.0);
5233 bounds.x2+=(mid+1.0);
5234 bounds.y2+=(mid+1.0);
5235 if ((bounds.x1 >= (
double) image->columns) ||
5236 (bounds.y1 >= (
double) image->rows) ||
5237 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5239 polygon_info=DestroyPolygonTLS(polygon_info);
5242 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5243 (
double) image->columns-1.0 : bounds.x1;
5244 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5245 (
double) image->rows-1.0 : bounds.y1;
5246 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5247 (
double) image->columns-1.0 : bounds.x2;
5248 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5249 (
double) image->rows-1.0 : bounds.y2;
5250 poly_extent.x1=CastDoubleToSsizeT(ceil(bounds.x1-0.5));
5251 poly_extent.y1=CastDoubleToSsizeT(ceil(bounds.y1-0.5));
5252 poly_extent.x2=CastDoubleToSsizeT(floor(bounds.x2+0.5));
5253 poly_extent.y2=CastDoubleToSsizeT(floor(bounds.y2+0.5));
5254 number_threads=(size_t) GetMagickNumberThreads(image,image,(
size_t)
5255 (poly_extent.y2-poly_extent.y1+1),1);
5256 status=ClonePolygonEdgesTLS(polygon_info,number_threads,exception);
5257 if (status == MagickFalse)
5259 polygon_info=DestroyPolygonTLS(polygon_info);
5262 image_view=AcquireAuthenticCacheView(image,exception);
5263 if ((primitive_info->coordinates == 1) ||
5264 (polygon_info[0]->number_edges == 0))
5269#if defined(MAGICKCORE_OPENMP_SUPPORT)
5270 #pragma omp parallel for schedule(static) shared(status) \
5271 num_threads((int) number_threads)
5273 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5284 if (status == MagickFalse)
5287 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5289 if (q == (Quantum *) NULL)
5294 GetPixelInfo(image,&pixel);
5295 for ( ; x <= poly_extent.x2; x++)
5297 if ((x == CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5))) &&
5298 (y == CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5))))
5300 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&pixel,
5302 SetPixelViaPixelInfo(image,&pixel,q);
5304 q+=(ptrdiff_t) GetPixelChannels(image);
5306 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5309 image_view=DestroyCacheView(image_view);
5310 polygon_info=DestroyPolygonTLS(polygon_info);
5311 if (draw_info->debug != MagickFalse)
5312 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5313 " end draw-polygon");
5319#if defined(MAGICKCORE_OPENMP_SUPPORT)
5320 #pragma omp parallel for schedule(static) shared(status) \
5321 num_threads((int) number_threads)
5323 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5326 id = GetOpenMPThreadId();
5334 if (status == MagickFalse)
5336 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5337 (poly_extent.x2-poly_extent.x1+1),1,exception);
5338 if (q == (Quantum *) NULL)
5343 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5356 fill_alpha=GetFillAlpha(polygon_info[
id],mid,fill,draw_info->fill_rule,
5358 if (draw_info->stroke_antialias == MagickFalse)
5360 fill_alpha=fill_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5361 stroke_alpha=stroke_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5363 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&fill_color,
5365 CompositePixelOver(image,&fill_color,fill_alpha*fill_color.alpha,q,
5366 (
double) GetPixelAlpha(image,q),q);
5367 GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&stroke_color,
5369 CompositePixelOver(image,&stroke_color,stroke_alpha*stroke_color.alpha,q,
5370 (
double) GetPixelAlpha(image,q),q);
5371 q+=(ptrdiff_t) GetPixelChannels(image);
5373 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5376 image_view=DestroyCacheView(image_view);
5377 polygon_info=DestroyPolygonTLS(polygon_info);
5378 if (draw_info->debug != MagickFalse)
5379 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5412static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5438 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5439 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5440 switch (primitive_info->primitive)
5442 case AlphaPrimitive:
5444 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5445 "AlphaPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5446 methods[primitive_info->method]);
5449 case ColorPrimitive:
5451 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5452 "ColorPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5453 methods[primitive_info->method]);
5456 case ImagePrimitive:
5458 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5459 "ImagePrimitive %.17g,%.17g",(
double) x,(
double) y);
5462 case PointPrimitive:
5464 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5465 "PointPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5466 methods[primitive_info->method]);
5471 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5472 "TextPrimitive %.17g,%.17g",(
double) x,(
double) y);
5479 p=primitive_info[0].point;
5482 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5484 point=primitive_info[i].point;
5485 if (coordinates <= 0)
5487 coordinates=(ssize_t) primitive_info[i].coordinates;
5488 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5489 " begin open (%.17g)",(
double) coordinates);
5492 point=primitive_info[i].point;
5493 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5494 (fabs(q.y-point.y) >= MagickEpsilon))
5495 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5496 " %.17g: %.18g,%.18g",(
double) coordinates,point.x,point.y);
5498 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5499 " %.17g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5502 if (coordinates > 0)
5504 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5505 (fabs(p.y-point.y) >= MagickEpsilon))
5506 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.17g)",
5507 (
double) coordinates);
5509 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.17g)",
5510 (
double) coordinates);
5514MagickExport MagickBooleanType DrawPrimitive(Image *image,
5515 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5516 ExceptionInfo *exception)
5531 if (draw_info->debug != MagickFalse)
5533 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5534 " begin draw-primitive");
5535 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5536 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5537 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5538 draw_info->affine.tx,draw_info->affine.ty);
5541 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5542 ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
5543 (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
5544 status&=(MagickStatusType) SetImageColorspace(image,sRGBColorspace,
5546 if (draw_info->compliance == SVGCompliance)
5548 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5549 draw_info->clipping_mask,exception);
5550 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5551 draw_info->composite_mask,exception);
5553 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5554 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5555 image_view=AcquireAuthenticCacheView(image,exception);
5556 switch (primitive_info->primitive)
5558 case AlphaPrimitive:
5560 if ((image->alpha_trait & BlendPixelTrait) == 0)
5561 status&=(MagickStatusType) SetImageAlphaChannel(image,
5562 OpaqueAlphaChannel,exception);
5563 switch (primitive_info->method)
5574 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5575 if (q == (Quantum *) NULL)
5577 GetFillColor(draw_info,x,y,&pixel,exception);
5578 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5579 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5589 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5590 x,y,&target,exception);
5591 GetPixelInfo(image,&pixel);
5592 for (y=0; y < (ssize_t) image->rows; y++)
5597 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5599 if (q == (Quantum *) NULL)
5601 for (x=0; x < (ssize_t) image->columns; x++)
5603 GetPixelInfoPixel(image,q,&pixel);
5604 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5606 q+=(ptrdiff_t) GetPixelChannels(image);
5609 GetFillColor(draw_info,x,y,&pixel,exception);
5610 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5611 q+=(ptrdiff_t) GetPixelChannels(image);
5613 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5615 if (status == MagickFalse)
5620 case FloodfillMethod:
5621 case FillToBorderMethod:
5629 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5630 TileVirtualPixelMethod,x,y,&target,exception);
5631 if (primitive_info->method == FillToBorderMethod)
5633 target.red=(double) draw_info->border_color.red;
5634 target.green=(double) draw_info->border_color.green;
5635 target.blue=(double) draw_info->border_color.blue;
5637 channel_mask=SetImageChannelMask(image,AlphaChannel);
5638 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5639 &target,x,y,primitive_info->method == FloodfillMethod ?
5640 MagickFalse : MagickTrue,exception);
5641 (void) SetImageChannelMask(image,channel_mask);
5649 for (y=0; y < (ssize_t) image->rows; y++)
5654 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5656 if (q == (Quantum *) NULL)
5658 for (x=0; x < (ssize_t) image->columns; x++)
5660 GetFillColor(draw_info,x,y,&pixel,exception);
5661 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5662 q+=(ptrdiff_t) GetPixelChannels(image);
5664 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5666 if (status == MagickFalse)
5674 case ColorPrimitive:
5676 switch (primitive_info->method)
5687 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5688 if (q == (Quantum *) NULL)
5690 GetPixelInfo(image,&pixel);
5691 GetFillColor(draw_info,x,y,&pixel,exception);
5692 SetPixelViaPixelInfo(image,&pixel,q);
5693 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5703 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5704 x,y,&target,exception);
5705 for (y=0; y < (ssize_t) image->rows; y++)
5710 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5712 if (q == (Quantum *) NULL)
5714 for (x=0; x < (ssize_t) image->columns; x++)
5716 GetPixelInfoPixel(image,q,&pixel);
5717 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5719 q+=(ptrdiff_t) GetPixelChannels(image);
5722 GetFillColor(draw_info,x,y,&pixel,exception);
5723 SetPixelViaPixelInfo(image,&pixel,q);
5724 q+=(ptrdiff_t) GetPixelChannels(image);
5726 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5728 if (status == MagickFalse)
5733 case FloodfillMethod:
5734 case FillToBorderMethod:
5739 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5740 TileVirtualPixelMethod,x,y,&target,exception);
5741 if (primitive_info->method == FillToBorderMethod)
5743 target.red=(double) draw_info->border_color.red;
5744 target.green=(double) draw_info->border_color.green;
5745 target.blue=(double) draw_info->border_color.blue;
5747 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5748 &target,x,y,primitive_info->method == FloodfillMethod ?
5749 MagickFalse : MagickTrue,exception);
5757 GetPixelInfo(image,&pixel);
5758 for (y=0; y < (ssize_t) image->rows; y++)
5763 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5765 if (q == (Quantum *) NULL)
5767 for (x=0; x < (ssize_t) image->columns; x++)
5769 GetFillColor(draw_info,x,y,&pixel,exception);
5770 SetPixelViaPixelInfo(image,&pixel,q);
5771 q+=(ptrdiff_t) GetPixelChannels(image);
5773 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5775 if (status == MagickFalse)
5783 case ImagePrimitive:
5789 composite_geometry[MagickPathExtent];
5805 if (primitive_info->text == (
char *) NULL)
5807 clone_info=AcquireImageInfo();
5808 composite_images=(Image *) NULL;
5809 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5810 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5813 if (*primitive_info->text !=
'\0')
5818 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5820 (void) SetImageInfo(clone_info,1,exception);
5821 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5823 if (clone_info->size != (
char *) NULL)
5824 clone_info->size=DestroyString(clone_info->size);
5825 if (clone_info->extract != (
char *) NULL)
5826 clone_info->extract=DestroyString(clone_info->extract);
5827 clone_info->coder_depth=draw_info->image_info->coder_depth;
5828 composite_images=StrictReadImage(clone_info,exception);
5829 draw_info->image_info->coder_depth=clone_info->coder_depth;
5831 clone_info=DestroyImageInfo(clone_info);
5832 if (composite_images == (Image *) NULL)
5837 composite_image=RemoveFirstImageFromList(&composite_images);
5838 composite_images=DestroyImageList(composite_images);
5839 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5840 NULL,(
void *) NULL);
5841 x1=CastDoubleToSsizeT(ceil(primitive_info[1].point.x-0.5));
5842 y1=CastDoubleToSsizeT(ceil(primitive_info[1].point.y-0.5));
5843 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5844 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5849 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5850 "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y);
5851 composite_image->filter=image->filter;
5852 status&=(MagickStatusType) TransformImage(&composite_image,
5853 (
char *) NULL,composite_geometry,exception);
5855 if (composite_image->alpha_trait == UndefinedPixelTrait)
5856 status&=(MagickStatusType) SetImageAlphaChannel(composite_image,
5857 OpaqueAlphaChannel,exception);
5858 if (draw_info->alpha != OpaqueAlpha)
5859 status&=(MagickStatusType) SetImageAlpha(composite_image,
5860 draw_info->alpha,exception);
5861 SetGeometry(image,&geometry);
5862 image->gravity=draw_info->gravity;
5865 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5866 "%.17gx%.17g%+.20g%+.20g",(
double) composite_image->columns,(
double)
5867 composite_image->rows,(
double) geometry.x,(
double) geometry.y);
5868 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
5869 affine=draw_info->affine;
5870 affine.tx=(double) geometry.x;
5871 affine.ty=(double) geometry.y;
5872 composite_image->interpolate=image->interpolate;
5873 if ((draw_info->compose == OverCompositeOp) ||
5874 (draw_info->compose == SrcOverCompositeOp))
5875 status&=(MagickStatusType) DrawAffineImage(image,composite_image,
5878 status&=(MagickStatusType) CompositeImage(image,composite_image,
5879 draw_info->compose,MagickTrue,geometry.x,geometry.y,exception);
5880 composite_image=DestroyImage(composite_image);
5883 case PointPrimitive:
5891 if ((y < 0) || (y >= (ssize_t) image->rows))
5893 if ((x < 0) || (x >= (ssize_t) image->columns))
5895 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5896 if (q == (Quantum *) NULL)
5898 GetFillColor(draw_info,x,y,&fill_color,exception);
5899 CompositePixelOver(image,&fill_color,(
double) fill_color.alpha,q,(
double)
5900 GetPixelAlpha(image,q),q);
5901 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5908 geometry[MagickPathExtent];
5913 if (primitive_info->text == (
char *) NULL)
5915 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5916 (void) CloneString(&clone_info->text,primitive_info->text);
5917 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
5918 primitive_info->point.x,primitive_info->point.y);
5919 (void) CloneString(&clone_info->geometry,geometry);
5920 status&=(MagickStatusType) AnnotateImage(image,clone_info,exception);
5921 clone_info=DestroyDrawInfo(clone_info);
5933 if (IsEventLogging() != MagickFalse)
5934 LogPrimitiveInfo(primitive_info);
5935 scale=ExpandAffine(&draw_info->affine);
5936 if ((draw_info->dash_pattern != (
double *) NULL) &&
5937 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5938 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5939 (draw_info->stroke.alpha != (
double) TransparentAlpha))
5944 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5945 clone_info->stroke_width=0.0;
5946 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5947 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5948 primitive_info,exception);
5949 clone_info=DestroyDrawInfo(clone_info);
5950 if (status != MagickFalse)
5951 status&=(MagickStatusType) DrawDashPolygon(draw_info,primitive_info,
5955 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5957 ((draw_info->stroke.alpha != (
double) TransparentAlpha) ||
5958 (draw_info->stroke_pattern != (Image *) NULL)))
5970 closed_path=primitive_info[0].closed_subpath;
5971 i=(ssize_t) primitive_info[0].coordinates;
5972 point_x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5973 point_y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5974 if ((point_x < MagickEpsilon) && (point_y < MagickEpsilon))
5975 closed_path=MagickTrue;
5976 if ((((draw_info->linecap == RoundCap) ||
5977 (closed_path != MagickFalse)) &&
5978 (draw_info->linejoin == RoundJoin)) ||
5979 (primitive_info[i].primitive != UndefinedPrimitive))
5981 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5982 primitive_info,exception);
5985 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5986 clone_info->stroke_width=0.0;
5987 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5988 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5989 primitive_info,exception);
5990 clone_info=DestroyDrawInfo(clone_info);
5991 if (status != MagickFalse)
5992 status&=(MagickStatusType) DrawStrokePolygon(image,draw_info,
5993 primitive_info,exception);
5996 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5997 primitive_info,exception);
6001 image_view=DestroyCacheView(image_view);
6002 if (draw_info->compliance == SVGCompliance)
6004 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
6005 (Image *) NULL,exception);
6006 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
6007 (Image *) NULL,exception);
6009 if (draw_info->debug != MagickFalse)
6010 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
6011 return(status != 0 ? MagickTrue : MagickFalse);
6044static MagickBooleanType DrawRoundLinecap(Image *image,
6045 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6046 ExceptionInfo *exception)
6054 if (primitive_info->coordinates < 1)
6055 return(MagickFalse);
6056 for (i=0; i < 4; i++)
6057 linecap[i]=(*primitive_info);
6058 linecap[0].coordinates=4;
6059 linecap[1].point.x+=2.0*MagickEpsilon;
6060 linecap[2].point.x+=2.0*MagickEpsilon;
6061 linecap[2].point.y+=2.0*MagickEpsilon;
6062 linecap[3].point.y+=2.0*MagickEpsilon;
6063 linecap[4].primitive=UndefinedPrimitive;
6064 return(DrawPolygonPrimitive(image,draw_info,linecap,exception));
6067static MagickBooleanType DrawStrokePolygon(Image *image,
6068 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6069 ExceptionInfo *exception)
6090 if (draw_info->debug != MagickFalse)
6091 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6092 " begin draw-stroke-polygon");
6093 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
6094 clone_info->fill=draw_info->stroke;
6095 if (clone_info->fill_pattern != (Image *) NULL)
6096 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
6097 if (clone_info->stroke_pattern != (Image *) NULL)
6098 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
6099 MagickTrue,exception);
6100 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
6101 clone_info->stroke_width=0.0;
6102 clone_info->fill_rule=NonZeroRule;
6104 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ptrdiff_t) p->coordinates)
6106 if (p->coordinates == 1)
6108 stroke_polygon=TraceStrokePolygon(draw_info,p,exception);
6109 if (stroke_polygon == (PrimitiveInfo *) NULL)
6114 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
6115 stroke_polygon,exception);
6116 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
6119 q=p+p->coordinates-1;
6120 closed_path=p->closed_subpath;
6121 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
6123 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,p,
6125 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,q,
6129 clone_info=DestroyDrawInfo(clone_info);
6130 if (draw_info->debug != MagickFalse)
6131 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6132 " end draw-stroke-polygon");
6133 return(status != 0 ? MagickTrue : MagickFalse);
6159MagickExport
void GetAffineMatrix(AffineMatrix *affine_matrix)
6161 if (IsEventLogging() != MagickFalse)
6162 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6163 assert(affine_matrix != (AffineMatrix *) NULL);
6164 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
6165 affine_matrix->sx=1.0;
6166 affine_matrix->sy=1.0;
6193MagickExport
void GetDrawInfo(
const ImageInfo *image_info,DrawInfo *draw_info)
6207 assert(draw_info != (DrawInfo *) NULL);
6208 if (IsEventLogging() != MagickFalse)
6209 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6210 (void) memset(draw_info,0,
sizeof(*draw_info));
6211 draw_info->image_info=CloneImageInfo(image_info);
6212 GetAffineMatrix(&draw_info->affine);
6213 exception=AcquireExceptionInfo();
6214 (void) QueryColorCompliance(
"#000F",AllCompliance,&draw_info->fill,
6216 (void) QueryColorCompliance(
"#FFF0",AllCompliance,&draw_info->stroke,
6218 draw_info->stroke_antialias=draw_info->image_info->antialias;
6219 draw_info->stroke_width=1.0;
6220 draw_info->fill_rule=EvenOddRule;
6221 draw_info->alpha=OpaqueAlpha;
6222 draw_info->fill_alpha=OpaqueAlpha;
6223 draw_info->stroke_alpha=OpaqueAlpha;
6224 draw_info->linecap=ButtCap;
6225 draw_info->linejoin=MiterJoin;
6226 draw_info->miterlimit=10;
6227 draw_info->decorate=NoDecoration;
6228 draw_info->pointsize=12.0;
6229 draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
6230 draw_info->compose=OverCompositeOp;
6231 draw_info->render=MagickTrue;
6232 draw_info->clip_path=MagickFalse;
6233 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6234 MagickTrue : MagickFalse;
6235 draw_info->macro_expansion=(
size_t *) NULL;
6236 if (draw_info->image_info->font != (
char *) NULL)
6237 draw_info->font=AcquireString(draw_info->image_info->font);
6238 if (draw_info->image_info->density != (
char *) NULL)
6239 draw_info->density=AcquireString(draw_info->image_info->density);
6240 draw_info->text_antialias=draw_info->image_info->antialias;
6241 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6242 draw_info->pointsize=draw_info->image_info->pointsize;
6243 draw_info->border_color=draw_info->image_info->border_color;
6244 if (draw_info->image_info->server_name != (
char *) NULL)
6245 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6246 option=GetImageOption(draw_info->image_info,
"direction");
6247 if (option != (
const char *) NULL)
6248 draw_info->direction=(DirectionType) ParseCommandOption(
6249 MagickDirectionOptions,MagickFalse,option);
6251 draw_info->direction=UndefinedDirection;
6252 option=GetImageOption(draw_info->image_info,
"encoding");
6253 if (option != (
const char *) NULL)
6254 (void) CloneString(&draw_info->encoding,option);
6255 option=GetImageOption(draw_info->image_info,
"family");
6256 if (option != (
const char *) NULL)
6257 (void) CloneString(&draw_info->family,option);
6258 option=GetImageOption(draw_info->image_info,
"fill");
6259 if (option != (
const char *) NULL)
6260 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
6262 option=GetImageOption(draw_info->image_info,
"gravity");
6263 if (option != (
const char *) NULL)
6264 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6265 MagickFalse,option);
6266 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6267 if (option != (
const char *) NULL)
6268 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6269 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6270 if (option != (
const char *) NULL)
6271 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6272 option=GetImageOption(draw_info->image_info,
"kerning");
6273 if (option != (
const char *) NULL)
6274 draw_info->kerning=GetDrawValue(option,&next_token);
6275 option=GetImageOption(draw_info->image_info,
"stroke");
6276 if (option != (
const char *) NULL)
6277 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
6279 option=GetImageOption(draw_info->image_info,
"strokewidth");
6280 if (option != (
const char *) NULL)
6281 draw_info->stroke_width=GetDrawValue(option,&next_token);
6282 option=GetImageOption(draw_info->image_info,
"style");
6283 if (option != (
const char *) NULL)
6284 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6285 MagickFalse,option);
6286 option=GetImageOption(draw_info->image_info,
"undercolor");
6287 if (option != (
const char *) NULL)
6288 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
6290 option=GetImageOption(draw_info->image_info,
"weight");
6291 if (option != (
const char *) NULL)
6296 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6298 weight=(ssize_t) StringToUnsignedLong(option);
6299 draw_info->weight=(size_t) weight;
6301 option=GetImageOption(draw_info->image_info,
"word-break");
6302 if (option != (
const char *) NULL)
6303 draw_info->word_break=(WordBreakType) ParseCommandOption(
6304 MagickWordBreakOptions,MagickFalse,option);
6305 exception=DestroyExceptionInfo(exception);
6306 draw_info->signature=MagickCoreSignature;
6334static inline double Permutate(
const ssize_t n,
const ssize_t k)
6343 for (i=k+1; i <= n; i++)
6345 for (i=1; i <= (n-k); i++)
6366static MagickBooleanType TraceArc(MVGInfo *mvg_info,
const PointInfo start,
6367 const PointInfo end,
const PointInfo degrees)
6373 center.x=0.5*(end.x+start.x);
6374 center.y=0.5*(end.y+start.y);
6375 radius.x=fabs(center.x-start.x);
6376 radius.y=fabs(center.y-start.y);
6377 return(TraceEllipse(mvg_info,center,radius,degrees));
6380static MagickBooleanType TraceArcPath(MVGInfo *mvg_info,
const PointInfo start,
6381 const PointInfo end,
const PointInfo arc,
const double angle,
6382 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6419 offset=mvg_info->offset;
6420 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6421 primitive_info->coordinates=0;
6422 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6423 (fabs(start.y-end.y) < MagickEpsilon))
6424 return(TracePoint(primitive_info,end));
6425 radii.x=fabs(arc.x);
6426 radii.y=fabs(arc.y);
6427 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6428 return(TraceLine(primitive_info,start,end));
6429 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6430 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6431 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6432 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6433 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6435 if (delta < MagickEpsilon)
6436 return(TraceLine(primitive_info,start,end));
6439 radii.x*=sqrt((
double) delta);
6440 radii.y*=sqrt((
double) delta);
6442 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6443 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6444 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6445 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6446 alpha=points[1].x-points[0].x;
6447 beta=points[1].y-points[0].y;
6448 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6449 return(TraceLine(primitive_info,start,end));
6450 factor=MagickSafeReciprocal(alpha*alpha+beta*beta)-0.25;
6455 factor=sqrt((
double) factor);
6456 if (sweep == large_arc)
6459 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6460 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6461 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6462 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6463 if ((theta < 0.0) && (sweep != MagickFalse))
6464 theta+=2.0*MagickPI;
6466 if ((theta > 0.0) && (sweep == MagickFalse))
6467 theta-=2.0*MagickPI;
6468 arc_segments=(size_t) CastDoubleToSsizeT(ceil(fabs((
double) (theta/(0.5*
6469 MagickPI+MagickEpsilon)))));
6472 for (i=0; i < (ssize_t) arc_segments; i++)
6474 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6475 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6476 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6477 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6478 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6479 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6480 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6481 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6482 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6483 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6484 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) (i+1)*
6485 theta/arc_segments),DegreesToRadians(360.0))));
6486 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) (i+1)*
6487 theta/arc_segments),DegreesToRadians(360.0))));
6488 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(
double)
6489 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6490 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(
double)
6491 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6492 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6493 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6494 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
6496 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
6498 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
6500 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
6502 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
6504 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
6506 if (i == (ssize_t) (arc_segments-1))
6508 status&=(MagickStatusType) TraceBezier(mvg_info,4);
6511 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
6512 mvg_info->offset+=(ssize_t) p->coordinates;
6513 p+=(ptrdiff_t) p->coordinates;
6516 return(MagickFalse);
6517 mvg_info->offset=offset;
6518 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6519 primitive_info->coordinates=(size_t) (p-primitive_info);
6520 primitive_info->closed_subpath=MagickFalse;
6521 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6523 p->primitive=primitive_info->primitive;
6529static MagickBooleanType TraceBezier(MVGInfo *mvg_info,
6530 const size_t number_coordinates)
6559 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6560 quantum=number_coordinates;
6561 for (i=0; i < (ssize_t) number_coordinates; i++)
6563 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6565 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6566 if (alpha > (
double) GetMaxMemoryRequest())
6568 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6569 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6570 return(MagickFalse);
6572 if (alpha > (
double) quantum)
6573 quantum=(size_t) alpha;
6574 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6575 if (alpha > (
double) quantum)
6576 quantum=(size_t) alpha;
6579 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6580 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6581 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6582 sizeof(*coefficients));
6583 points=(PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6585 if ((coefficients == (
double *) NULL) || (points == (PointInfo *) NULL))
6587 if (points != (PointInfo *) NULL)
6588 points=(PointInfo *) RelinquishMagickMemory(points);
6589 if (coefficients != (
double *) NULL)
6590 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6591 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6592 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6593 return(MagickFalse);
6595 control_points=quantum*number_coordinates;
6596 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6598 points=(PointInfo *) RelinquishMagickMemory(points);
6599 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6600 return(MagickFalse);
6602 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6606 end=primitive_info[number_coordinates-1].point;
6607 for (i=0; i < (ssize_t) number_coordinates; i++)
6608 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6610 for (i=0; i < (ssize_t) control_points; i++)
6615 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6616 for (j=0; j < (ssize_t) number_coordinates; j++)
6618 point.x+=alpha*coefficients[j]*p->point.x;
6619 point.y+=alpha*coefficients[j]*p->point.y;
6620 alpha*=weight/(1.0-weight);
6624 weight+=1.0/control_points;
6630 for (i=0; i < (ssize_t) control_points; i++)
6632 if (TracePoint(p,points[i]) == MagickFalse)
6634 points=(PointInfo *) RelinquishMagickMemory(points);
6635 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6636 return(MagickFalse);
6638 p+=(ptrdiff_t) p->coordinates;
6640 if (TracePoint(p,end) == MagickFalse)
6642 points=(PointInfo *) RelinquishMagickMemory(points);
6643 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6644 return(MagickFalse);
6646 p+=(ptrdiff_t) p->coordinates;
6647 primitive_info->coordinates=(size_t) (p-primitive_info);
6648 primitive_info->closed_subpath=MagickFalse;
6649 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6651 p->primitive=primitive_info->primitive;
6654 points=(PointInfo *) RelinquishMagickMemory(points);
6655 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6659static MagickBooleanType TraceCircle(MVGInfo *mvg_info,
const PointInfo start,
6660 const PointInfo end)
6671 alpha=end.x-start.x;
6673 radius=hypot((
double) alpha,(
double) beta);
6674 offset.x=(double) radius;
6675 offset.y=(double) radius;
6678 return(TraceEllipse(mvg_info,start,offset,degrees));
6681static MagickBooleanType TraceEllipse(MVGInfo *mvg_info,
const PointInfo center,
6682 const PointInfo radii,
const PointInfo arc)
6707 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6708 primitive_info->coordinates=0;
6709 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6711 delta=MagickSafeReciprocal(MagickMax(radii.x,radii.y));
6712 step=MagickPI/(MagickPI*MagickSafeReciprocal(delta))/8.0;
6713 angle.x=DegreesToRadians(arc.x);
6717 angle.y=DegreesToRadians(y);
6718 coordinates=ceil((angle.y-angle.x)/step+1.0);
6719 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6720 return(MagickFalse);
6722 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6723 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6725 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6726 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6727 if (i++ >= (ssize_t) coordinates)
6729 if (TracePoint(p,point) == MagickFalse)
6730 return(MagickFalse);
6731 p+=(ptrdiff_t) p->coordinates;
6733 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6734 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6735 if (TracePoint(p,point) == MagickFalse)
6736 return(MagickFalse);
6737 p+=(ptrdiff_t) p->coordinates;
6738 primitive_info->coordinates=(size_t) (p-primitive_info);
6739 primitive_info->closed_subpath=MagickFalse;
6740 x=fabs(primitive_info[0].point.x-
6741 primitive_info[primitive_info->coordinates-1].point.x);
6742 y=fabs(primitive_info[0].point.y-
6743 primitive_info[primitive_info->coordinates-1].point.y);
6744 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6745 primitive_info->closed_subpath=MagickTrue;
6746 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6748 p->primitive=primitive_info->primitive;
6754static MagickBooleanType TraceLine(PrimitiveInfo *primitive_info,
6755 const PointInfo start,
const PointInfo end)
6757 if (TracePoint(primitive_info,start) == MagickFalse)
6758 return(MagickFalse);
6759 if (TracePoint(primitive_info+1,end) == MagickFalse)
6760 return(MagickFalse);
6761 (primitive_info+1)->primitive=primitive_info->primitive;
6762 primitive_info->coordinates=2;
6763 primitive_info->closed_subpath=MagickFalse;
6767static ssize_t TracePath(MVGInfo *mvg_info,
const char *path,
6768 ExceptionInfo *exception)
6772 token[MagickPathExtent] =
"";
6790 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6813 subpath_offset=mvg_info->offset;
6814 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6817 number_coordinates=0;
6819 primitive_type=primitive_info->primitive;
6821 for (p=path; *p !=
'\0'; )
6823 if (status == MagickFalse)
6825 while (isspace((
int) ((
unsigned char) *p)) != 0)
6829 last_attribute=attribute;
6830 attribute=(int) (*p++);
6840 large_arc = MagickFalse,
6841 sweep = MagickFalse;
6851 (void) GetNextToken(p,&p,MagickPathExtent,token);
6852 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6853 ThrowPointExpectedException(token,exception);
6855 (void) GetNextToken(p,&p,MagickPathExtent,token);
6856 arc.x=GetDrawValue(token,&next_token);
6857 if (token == next_token)
6858 ThrowPointExpectedException(token,exception);
6859 (void) GetNextToken(p,&p,MagickPathExtent,token);
6860 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6861 ThrowPointExpectedException(token,exception);
6863 (void) GetNextToken(p,&p,MagickPathExtent,token);
6864 arc.y=GetDrawValue(token,&next_token);
6865 if (token == next_token)
6866 ThrowPointExpectedException(token,exception);
6867 (void) GetNextToken(p,&p,MagickPathExtent,token);
6868 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6869 ThrowPointExpectedException(token,exception);
6871 (void) GetNextToken(p,&p,MagickPathExtent,token);
6872 angle=GetDrawValue(token,&next_token);
6873 if (token == next_token)
6874 ThrowPointExpectedException(token,exception);
6875 (void) GetNextToken(p,&p,MagickPathExtent,token);
6876 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6877 ThrowPointExpectedException(token,exception);
6879 (void) GetNextToken(p,&p,MagickPathExtent,token);
6880 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6881 (void) GetNextToken(p,&p,MagickPathExtent,token);
6882 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6883 ThrowPointExpectedException(token,exception);
6885 (void) GetNextToken(p,&p,MagickPathExtent,token);
6886 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6887 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6888 ThrowPointExpectedException(token,exception);
6890 (void) GetNextToken(p,&p,MagickPathExtent,token);
6891 (void) GetNextToken(p,&p,MagickPathExtent,token);
6892 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6893 ThrowPointExpectedException(token,exception);
6895 (void) GetNextToken(p,&p,MagickPathExtent,token);
6896 x=GetDrawValue(token,&next_token);
6897 if (token == next_token)
6898 ThrowPointExpectedException(token,exception);
6899 (void) GetNextToken(p,&p,MagickPathExtent,token);
6900 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6901 ThrowPointExpectedException(token,exception);
6903 (void) GetNextToken(p,&p,MagickPathExtent,token);
6904 y=GetDrawValue(token,&next_token);
6905 if (token == next_token)
6906 ThrowPointExpectedException(token,exception);
6907 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6908 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6909 if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
6911 q=(*mvg_info->primitive_info)+mvg_info->offset;
6912 mvg_info->offset+=(ssize_t) q->coordinates;
6913 q+=(ptrdiff_t) q->coordinates;
6915 while (isspace((
int) ((
unsigned char) *p)) != 0)
6919 }
while (IsValidPoint(p) != MagickFalse);
6931 for (i=1; i < 4; i++)
6933 (void) GetNextToken(p,&p,MagickPathExtent,token);
6934 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6935 ThrowPointExpectedException(token,exception);
6937 (void) GetNextToken(p,&p,MagickPathExtent,token);
6938 x=GetDrawValue(token,&next_token);
6939 if (token == next_token)
6940 ThrowPointExpectedException(token,exception);
6941 (void) GetNextToken(p,&p,MagickPathExtent,token);
6942 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6943 ThrowPointExpectedException(token,exception);
6945 (void) GetNextToken(p,&p,MagickPathExtent,token);
6946 y=GetDrawValue(token,&next_token);
6947 if (token == next_token)
6948 ThrowPointExpectedException(token,exception);
6949 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6950 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6953 for (i=0; i < 4; i++)
6954 (q+i)->point=points[i];
6955 if (TraceBezier(mvg_info,4) == MagickFalse)
6957 q=(*mvg_info->primitive_info)+mvg_info->offset;
6958 mvg_info->offset+=(ssize_t) q->coordinates;
6959 q+=(ptrdiff_t) q->coordinates;
6961 while (isspace((
int) ((
unsigned char) *p)) != 0)
6965 }
while (IsValidPoint(p) != MagickFalse);
6973 (void) GetNextToken(p,&p,MagickPathExtent,token);
6974 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6975 ThrowPointExpectedException(token,exception);
6977 (void) GetNextToken(p,&p,MagickPathExtent,token);
6978 x=GetDrawValue(token,&next_token);
6979 if (token == next_token)
6980 ThrowPointExpectedException(token,exception);
6981 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6982 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6984 q=(*mvg_info->primitive_info)+mvg_info->offset;
6985 if (TracePoint(q,point) == MagickFalse)
6987 mvg_info->offset+=(ssize_t) q->coordinates;
6988 q+=(ptrdiff_t) q->coordinates;
6989 while (isspace((
int) ((
unsigned char) *p)) != 0)
6993 }
while (IsValidPoint(p) != MagickFalse);
7004 (void) GetNextToken(p,&p,MagickPathExtent,token);
7005 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7006 ThrowPointExpectedException(token,exception);
7008 (void) GetNextToken(p,&p,MagickPathExtent,token);
7009 x=GetDrawValue(token,&next_token);
7010 if (token == next_token)
7011 ThrowPointExpectedException(token,exception);
7012 (void) GetNextToken(p,&p,MagickPathExtent,token);
7013 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7014 ThrowPointExpectedException(token,exception);
7016 (void) GetNextToken(p,&p,MagickPathExtent,token);
7017 y=GetDrawValue(token,&next_token);
7018 if (token == next_token)
7019 ThrowPointExpectedException(token,exception);
7020 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
7021 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
7022 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7024 q=(*mvg_info->primitive_info)+mvg_info->offset;
7025 if (TracePoint(q,point) == MagickFalse)
7027 mvg_info->offset+=(ssize_t) q->coordinates;
7028 q+=(ptrdiff_t) q->coordinates;
7029 while (isspace((
int) ((
unsigned char) *p)) != 0)
7033 }
while (IsValidPoint(p) != MagickFalse);
7042 if (mvg_info->offset != subpath_offset)
7044 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7045 primitive_info->coordinates=(size_t) (q-primitive_info);
7046 number_coordinates+=primitive_info->coordinates;
7048 subpath_offset=mvg_info->offset;
7053 (void) GetNextToken(p,&p,MagickPathExtent,token);
7054 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7055 ThrowPointExpectedException(token,exception);
7057 (void) GetNextToken(p,&p,MagickPathExtent,token);
7058 x=GetDrawValue(token,&next_token);
7059 if (token == next_token)
7060 ThrowPointExpectedException(token,exception);
7061 (void) GetNextToken(p,&p,MagickPathExtent,token);
7062 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7063 ThrowPointExpectedException(token,exception);
7065 (void) GetNextToken(p,&p,MagickPathExtent,token);
7066 y=GetDrawValue(token,&next_token);
7067 if (token == next_token)
7068 ThrowPointExpectedException(token,exception);
7069 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
7070 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
7074 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7076 q=(*mvg_info->primitive_info)+mvg_info->offset;
7077 if (TracePoint(q,point) == MagickFalse)
7079 mvg_info->offset+=(ssize_t) q->coordinates;
7080 q+=(ptrdiff_t) q->coordinates;
7081 while (isspace((
int) ((
unsigned char) *p)) != 0)
7085 }
while (IsValidPoint(p) != MagickFalse);
7097 for (i=1; i < 3; i++)
7099 (void) GetNextToken(p,&p,MagickPathExtent,token);
7100 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7101 ThrowPointExpectedException(token,exception);
7103 (void) GetNextToken(p,&p,MagickPathExtent,token);
7104 x=GetDrawValue(token,&next_token);
7105 if (token == next_token)
7106 ThrowPointExpectedException(token,exception);
7107 (void) GetNextToken(p,&p,MagickPathExtent,token);
7108 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7109 ThrowPointExpectedException(token,exception);
7111 (void) GetNextToken(p,&p,MagickPathExtent,token);
7112 y=GetDrawValue(token,&next_token);
7113 if (token == next_token)
7114 ThrowPointExpectedException(token,exception);
7117 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
7118 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
7121 for (i=0; i < 3; i++)
7122 (q+i)->point=points[i];
7123 if (TraceBezier(mvg_info,3) == MagickFalse)
7125 q=(*mvg_info->primitive_info)+mvg_info->offset;
7126 mvg_info->offset+=(ssize_t) q->coordinates;
7127 q+=(ptrdiff_t) q->coordinates;
7129 while (isspace((
int) ((
unsigned char) *p)) != 0)
7133 }
while (IsValidPoint(p) != MagickFalse);
7144 points[0]=points[3];
7145 points[1].x=2.0*points[3].x-points[2].x;
7146 points[1].y=2.0*points[3].y-points[2].y;
7147 for (i=2; i < 4; i++)
7149 (void) GetNextToken(p,&p,MagickPathExtent,token);
7150 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7151 ThrowPointExpectedException(token,exception);
7153 (void) GetNextToken(p,&p,MagickPathExtent,token);
7154 x=GetDrawValue(token,&next_token);
7155 if (token == next_token)
7156 ThrowPointExpectedException(token,exception);
7157 (void) GetNextToken(p,&p,MagickPathExtent,token);
7158 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7159 ThrowPointExpectedException(token,exception);
7161 (void) GetNextToken(p,&p,MagickPathExtent,token);
7162 y=GetDrawValue(token,&next_token);
7163 if (token == next_token)
7164 ThrowPointExpectedException(token,exception);
7167 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
7168 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
7171 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
7176 for (i=0; i < 4; i++)
7177 (q+i)->point=points[i];
7178 if (TraceBezier(mvg_info,4) == MagickFalse)
7180 q=(*mvg_info->primitive_info)+mvg_info->offset;
7181 mvg_info->offset+=(ssize_t) q->coordinates;
7182 q+=(ptrdiff_t) q->coordinates;
7184 last_attribute=attribute;
7185 while (isspace((
int) ((
unsigned char) *p)) != 0)
7189 }
while (IsValidPoint(p) != MagickFalse);
7200 points[0]=points[2];
7201 points[1].x=2.0*points[2].x-points[1].x;
7202 points[1].y=2.0*points[2].y-points[1].y;
7203 for (i=2; i < 3; i++)
7205 (void) GetNextToken(p,&p,MagickPathExtent,token);
7206 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7207 ThrowPointExpectedException(token,exception);
7209 (void) GetNextToken(p,&p,MagickPathExtent,token);
7210 x=GetDrawValue(token,&next_token);
7211 if (token == next_token)
7212 ThrowPointExpectedException(token,exception);
7213 (void) GetNextToken(p,&p,MagickPathExtent,token);
7214 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7215 ThrowPointExpectedException(token,exception);
7217 (void) GetNextToken(p,&p,MagickPathExtent,token);
7218 y=GetDrawValue(token,&next_token);
7219 if (token == next_token)
7220 ThrowPointExpectedException(token,exception);
7221 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7222 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7225 if (status == MagickFalse)
7227 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7232 for (i=0; i < 3; i++)
7233 (q+i)->point=points[i];
7234 if (TraceBezier(mvg_info,3) == MagickFalse)
7236 q=(*mvg_info->primitive_info)+mvg_info->offset;
7237 mvg_info->offset+=(ssize_t) q->coordinates;
7238 q+=(ptrdiff_t) q->coordinates;
7240 last_attribute=attribute;
7241 while (isspace((
int) ((
unsigned char) *p)) != 0)
7245 }
while (IsValidPoint(p) != MagickFalse);
7256 (void) GetNextToken(p,&p,MagickPathExtent,token);
7257 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7258 ThrowPointExpectedException(token,exception);
7260 (void) GetNextToken(p,&p,MagickPathExtent,token);
7261 y=GetDrawValue(token,&next_token);
7262 if (token == next_token)
7263 ThrowPointExpectedException(token,exception);
7264 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
7265 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7267 q=(*mvg_info->primitive_info)+mvg_info->offset;
7268 if (TracePoint(q,point) == MagickFalse)
7270 mvg_info->offset+=(ssize_t) q->coordinates;
7271 q+=(ptrdiff_t) q->coordinates;
7272 while (isspace((
int) ((
unsigned char) *p)) != 0)
7276 }
while (IsValidPoint(p) != MagickFalse);
7286 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7288 q=(*mvg_info->primitive_info)+mvg_info->offset;
7289 if (TracePoint(q,point) == MagickFalse)
7291 mvg_info->offset+=(ssize_t) q->coordinates;
7292 q+=(ptrdiff_t) q->coordinates;
7293 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7294 primitive_info->coordinates=(size_t) (q-primitive_info);
7295 primitive_info->closed_subpath=MagickTrue;
7296 number_coordinates+=primitive_info->coordinates;
7298 subpath_offset=mvg_info->offset;
7304 ThrowPointExpectedException(token,exception);
7309 if (status == MagickFalse)
7311 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7312 primitive_info->coordinates=(size_t) (q-primitive_info);
7313 number_coordinates+=primitive_info->coordinates;
7314 for (i=0; i < (ssize_t) number_coordinates; i++)
7317 q->primitive=primitive_type;
7319 q->method=FillToBorderMethod;
7322 return((ssize_t) number_coordinates);
7325static MagickBooleanType TraceRectangle(PrimitiveInfo *primitive_info,
7326 const PointInfo start,
const PointInfo end)
7338 if (TracePoint(p,start) == MagickFalse)
7339 return(MagickFalse);
7340 p+=(ptrdiff_t) p->coordinates;
7343 if (TracePoint(p,point) == MagickFalse)
7344 return(MagickFalse);
7345 p+=(ptrdiff_t) p->coordinates;
7346 if (TracePoint(p,end) == MagickFalse)
7347 return(MagickFalse);
7348 p+=(ptrdiff_t) p->coordinates;
7351 if (TracePoint(p,point) == MagickFalse)
7352 return(MagickFalse);
7353 p+=(ptrdiff_t) p->coordinates;
7354 if (TracePoint(p,start) == MagickFalse)
7355 return(MagickFalse);
7356 p+=(ptrdiff_t) p->coordinates;
7357 primitive_info->coordinates=(size_t) (p-primitive_info);
7358 primitive_info->closed_subpath=MagickTrue;
7359 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7361 p->primitive=primitive_info->primitive;
7367static MagickBooleanType TraceRoundRectangle(MVGInfo *mvg_info,
7368 const PointInfo start,
const PointInfo end,PointInfo arc)
7387 offset=mvg_info->offset;
7388 segment.x=fabs(end.x-start.x);
7389 segment.y=fabs(end.y-start.y);
7390 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7392 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7395 if (arc.x > (0.5*segment.x))
7396 arc.x=0.5*segment.x;
7397 if (arc.y > (0.5*segment.y))
7398 arc.y=0.5*segment.y;
7399 point.x=start.x+segment.x-arc.x;
7400 point.y=start.y+arc.y;
7403 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7404 return(MagickFalse);
7405 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7406 mvg_info->offset+=(ssize_t) p->coordinates;
7407 point.x=start.x+segment.x-arc.x;
7408 point.y=start.y+segment.y-arc.y;
7411 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7412 return(MagickFalse);
7413 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7414 mvg_info->offset+=(ssize_t) p->coordinates;
7415 point.x=start.x+arc.x;
7416 point.y=start.y+segment.y-arc.y;
7419 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7420 return(MagickFalse);
7421 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7422 mvg_info->offset+=(ssize_t) p->coordinates;
7423 point.x=start.x+arc.x;
7424 point.y=start.y+arc.y;
7427 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7428 return(MagickFalse);
7429 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7430 mvg_info->offset+=(ssize_t) p->coordinates;
7431 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7432 return(MagickFalse);
7433 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7434 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7435 return(MagickFalse);
7436 p+=(ptrdiff_t) p->coordinates;
7437 mvg_info->offset=offset;
7438 primitive_info=(*mvg_info->primitive_info)+offset;
7439 primitive_info->coordinates=(size_t) (p-primitive_info);
7440 primitive_info->closed_subpath=MagickTrue;
7441 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7443 p->primitive=primitive_info->primitive;
7449static MagickBooleanType TraceSquareLinecap(PrimitiveInfo *primitive_info,
7450 const size_t number_vertices,
const double offset)
7467 for (i=1; i < (ssize_t) number_vertices; i++)
7469 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7470 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7471 if ((fabs((
double) dx) >= MagickEpsilon) ||
7472 (fabs((
double) dy) >= MagickEpsilon))
7475 if (i == (ssize_t) number_vertices)
7476 i=(ssize_t) number_vertices-1L;
7477 distance=hypot((
double) dx,(
double) dy);
7478 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7479 dx*(distance+offset)/distance);
7480 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7481 dy*(distance+offset)/distance);
7482 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7484 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7485 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7486 if ((fabs((
double) dx) >= MagickEpsilon) ||
7487 (fabs((
double) dy) >= MagickEpsilon))
7490 distance=hypot((
double) dx,(
double) dy);
7491 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7492 dx*(distance+offset)/distance);
7493 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7494 dy*(distance+offset)/distance);
7498static PrimitiveInfo *TraceStrokePolygon(
const DrawInfo *draw_info,
7499 const PrimitiveInfo *primitive_info,ExceptionInfo *exception)
7501#define MaxStrokePad (6*BezierQuantum+360)
7502#define CheckPathExtent(pad_p,pad_q) \
7504 if ((pad_p) > MaxBezierCoordinates) \
7505 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7507 if ((p+(ptrdiff_t) (pad_p)) >= (ssize_t) extent_p) \
7509 if (~extent_p < (pad_p)) \
7510 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7513 extent_p+=(pad_p); \
7514 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \
7515 MaxStrokePad,sizeof(*stroke_p)); \
7518 if ((pad_q) > MaxBezierCoordinates) \
7519 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7521 if ((q+(ptrdiff_t) (pad_q)) >= (ssize_t) extent_q) \
7523 if (~extent_q < (pad_q)) \
7524 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7527 extent_q+=(pad_q); \
7528 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \
7529 MaxStrokePad,sizeof(*stroke_q)); \
7532 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \
7534 if (stroke_p != (PointInfo *) NULL) \
7535 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7536 if (stroke_q != (PointInfo *) NULL) \
7537 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7538 polygon_primitive=(PrimitiveInfo *) \
7539 RelinquishMagickMemory(polygon_primitive); \
7540 (void) ThrowMagickException(exception,GetMagickModule(), \
7541 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \
7542 return((PrimitiveInfo *) NULL); \
7546 typedef struct _StrokeSegment
7592 inverse_slope = {0.0, 0.0},
7599 number_vertices=primitive_info->coordinates;
7600 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7601 number_vertices+2UL,
sizeof(*polygon_primitive));
7602 if (polygon_primitive == (PrimitiveInfo *) NULL)
7604 (void) ThrowMagickException(exception,GetMagickModule(),
7605 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7606 return((PrimitiveInfo *) NULL);
7608 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7609 sizeof(*polygon_primitive));
7610 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7611 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7612 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7613 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7614 if ((draw_info->linejoin == RoundJoin) ||
7615 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
7617 polygon_primitive[number_vertices]=primitive_info[1];
7620 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7624 closed_path=primitive_info[0].closed_subpath;
7627 for (n=1; n < (ssize_t) number_vertices; n++)
7629 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7630 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7631 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7634 if (n == (ssize_t) number_vertices)
7636 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7641 stroke_polygon=(PrimitiveInfo *) AcquireCriticalMemory(
7642 sizeof(*stroke_polygon));
7643 stroke_polygon[0]=polygon_primitive[0];
7644 stroke_polygon[0].coordinates=0;
7645 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7647 return(stroke_polygon);
7649 n=(ssize_t) number_vertices-1L;
7651 extent_p=2*number_vertices;
7652 extent_q=2*number_vertices;
7653 stroke_p=(PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7655 stroke_q=(PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7657 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL))
7659 if (stroke_p != (PointInfo *) NULL)
7660 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7661 if (stroke_q != (PointInfo *) NULL)
7662 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7663 polygon_primitive=(PrimitiveInfo *)
7664 RelinquishMagickMemory(polygon_primitive);
7665 (void) ThrowMagickException(exception,GetMagickModule(),
7666 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7667 return((PrimitiveInfo *) NULL);
7670 inverse_slope.p=0.0;
7671 if (fabs(dx.p) < MagickEpsilon)
7674 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7676 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7679 if (fabs(dy.p) < MagickEpsilon)
7682 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7684 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7689 inverse_slope.p=(-1.0*MagickSafeReciprocal(slope.p));
7691 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7692 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7693 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7694 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7695 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7696 offset.y=(double) (offset.x*inverse_slope.p);
7697 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7699 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7700 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7701 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7702 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7703 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7704 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7705 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7706 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7710 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7711 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7712 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7713 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7714 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7715 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7716 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7717 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7724 stroke_q[p++]=box_q[0];
7725 stroke_p[q++]=box_p[0];
7726 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7731 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7732 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7733 dot_product=dx.q*dx.q+dy.q*dy.q;
7734 if (dot_product < 0.25)
7737 inverse_slope.q=0.0;
7738 if (fabs(dx.q) < MagickEpsilon)
7741 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7743 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7746 if (fabs(dy.q) < MagickEpsilon)
7749 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7751 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7756 inverse_slope.q=(-1.0*MagickSafeReciprocal(slope.q));
7758 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7759 offset.y=(double) (offset.x*inverse_slope.q);
7760 dot_product=dy.q*offset.x-dx.q*offset.y;
7761 if (dot_product > 0.0)
7763 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7764 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7765 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7766 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7767 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7768 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7769 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7770 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7774 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7775 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7776 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7777 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7778 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7779 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7780 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7781 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7783 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7790 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7791 box_p[3].y)/(slope.p-slope.q));
7792 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7793 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7794 box_q[3].y)/(slope.p-slope.q));
7795 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7797 DisableMSCWarning(4127)
7798 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7800 dot_product=dx.q*dy.p-dx.p*dy.q;
7801 if (dot_product <= 0.0)
7802 switch (draw_info->linejoin)
7806 stroke_q[q++]=box_q[1];
7807 stroke_q[q++]=box_q[2];
7808 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7809 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7810 if (dot_product <= miterlimit)
7811 stroke_p[p++]=box_p[4];
7814 stroke_p[p++]=box_p[1];
7815 stroke_p[p++]=box_p[2];
7821 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7822 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7823 if (dot_product <= miterlimit)
7825 stroke_q[q++]=box_q[4];
7826 stroke_p[p++]=box_p[4];
7830 stroke_q[q++]=box_q[1];
7831 stroke_q[q++]=box_q[2];
7832 stroke_p[p++]=box_p[1];
7833 stroke_p[p++]=box_p[2];
7839 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7840 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7841 if (dot_product <= miterlimit)
7842 stroke_p[p++]=box_p[4];
7845 stroke_p[p++]=box_p[1];
7846 stroke_p[p++]=box_p[2];
7848 center=polygon_primitive[n].point;
7849 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7850 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7851 if (theta.q < theta.p)
7852 theta.q+=2.0*MagickPI;
7853 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.q-
7854 theta.p)/(2.0*sqrt(MagickSafeReciprocal(mid))))));
7855 DisableMSCWarning(4127)
7856 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7858 stroke_q[q].x=box_q[1].x;
7859 stroke_q[q].y=box_q[1].y;
7861 for (j=1; j < (ssize_t) arc_segments; j++)
7863 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7864 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7865 (theta.p+delta_theta),DegreesToRadians(360.0))));
7866 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7867 (theta.p+delta_theta),DegreesToRadians(360.0))));
7870 stroke_q[q++]=box_q[2];
7877 switch (draw_info->linejoin)
7881 stroke_p[p++]=box_p[1];
7882 stroke_p[p++]=box_p[2];
7883 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7884 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7885 if (dot_product <= miterlimit)
7886 stroke_q[q++]=box_q[4];
7889 stroke_q[q++]=box_q[1];
7890 stroke_q[q++]=box_q[2];
7896 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7897 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7898 if (dot_product <= miterlimit)
7900 stroke_q[q++]=box_q[4];
7901 stroke_p[p++]=box_p[4];
7905 stroke_q[q++]=box_q[1];
7906 stroke_q[q++]=box_q[2];
7907 stroke_p[p++]=box_p[1];
7908 stroke_p[p++]=box_p[2];
7914 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7915 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7916 if (dot_product <= miterlimit)
7917 stroke_q[q++]=box_q[4];
7920 stroke_q[q++]=box_q[1];
7921 stroke_q[q++]=box_q[2];
7923 center=polygon_primitive[n].point;
7924 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7925 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7926 if (theta.p < theta.q)
7927 theta.p+=2.0*MagickPI;
7928 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.p-
7929 theta.q)/(2.0*sqrt((
double) (MagickSafeReciprocal(mid)))))));
7930 DisableMSCWarning(4127)
7931 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7933 stroke_p[p++]=box_p[1];
7934 for (j=1; j < (ssize_t) arc_segments; j++)
7936 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7937 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7938 (theta.p+delta_theta),DegreesToRadians(360.0))));
7939 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7940 (theta.p+delta_theta),DegreesToRadians(360.0))));
7943 stroke_p[p++]=box_p[2];
7950 inverse_slope.p=inverse_slope.q;
7959 stroke_p[p++]=box_p[1];
7960 stroke_q[q++]=box_q[1];
7964 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7965 (p+q+2L),(
size_t) (closed_path+2L)*
sizeof(*stroke_polygon));
7966 if (stroke_polygon == (PrimitiveInfo *) NULL)
7968 (void) ThrowMagickException(exception,GetMagickModule(),
7969 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7970 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7971 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7972 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7974 return(stroke_polygon);
7976 for (i=0; i < (ssize_t) p; i++)
7978 stroke_polygon[i]=polygon_primitive[0];
7979 stroke_polygon[i].point=stroke_p[i];
7981 if (closed_path != MagickFalse)
7983 stroke_polygon[i]=polygon_primitive[0];
7984 stroke_polygon[i].point=stroke_polygon[0].point;
7987 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7989 stroke_polygon[i]=polygon_primitive[0];
7990 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7992 if (closed_path != MagickFalse)
7994 stroke_polygon[i]=polygon_primitive[0];
7995 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7998 stroke_polygon[i]=polygon_primitive[0];
7999 stroke_polygon[i].point=stroke_polygon[0].point;
8001 stroke_polygon[i].primitive=UndefinedPrimitive;
8002 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
8003 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
8004 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
8005 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
8006 return(stroke_polygon);