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 PrimitiveExtentPad 4296.0
97#define MaxBezierCoordinates 67108864
98#define MacroExpansionLimit 262144
99#define ThrowPointExpectedException(token,exception) \
101 (void) ThrowMagickException(exception,GetMagickModule(),DrawError, \
102 "NonconformingDrawingPrimitiveDefinition","`%s'",token); \
103 status=MagickFalse; \
193 *DrawClippingMask(Image *,
const DrawInfo *,
const char *,
const char *,
196static MagickBooleanType
197 DrawStrokePolygon(Image *,
const DrawInfo *,
const PrimitiveInfo *,
199 RenderMVGContent(Image *,
const DrawInfo *,
const size_t,ExceptionInfo *),
200 TraceArc(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo),
201 TraceArcPath(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo,
202 const double,
const MagickBooleanType,
const MagickBooleanType),
203 TraceBezier(MVGInfo *,
const size_t),
204 TraceCircle(MVGInfo *,
const PointInfo,
const PointInfo),
205 TraceEllipse(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo),
206 TraceLine(PrimitiveInfo *,
const PointInfo,
const PointInfo),
207 TraceRectangle(PrimitiveInfo *,
const PointInfo,
const PointInfo),
208 TraceRoundRectangle(MVGInfo *,
const PointInfo,
const PointInfo,PointInfo),
209 TraceSquareLinecap(PrimitiveInfo *,
const size_t,
const double);
212 *TraceStrokePolygon(
const DrawInfo *,
const PrimitiveInfo *,ExceptionInfo *);
215 TracePath(MVGInfo *,
const char *,ExceptionInfo *);
235MagickExport DrawInfo *AcquireDrawInfo(
void)
240 draw_info=(DrawInfo *) AcquireCriticalMemory(
sizeof(*draw_info));
241 GetDrawInfo((ImageInfo *) NULL,draw_info);
272MagickExport DrawInfo *CloneDrawInfo(
const ImageInfo *image_info,
273 const DrawInfo *draw_info)
281 clone_info=(DrawInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
282 GetDrawInfo(image_info,clone_info);
283 if (draw_info == (DrawInfo *) NULL)
285 exception=AcquireExceptionInfo();
286 if (draw_info->id != (
char *) NULL)
287 (void) CloneString(&clone_info->id,draw_info->id);
288 if (draw_info->primitive != (
char *) NULL)
289 (void) CloneString(&clone_info->primitive,draw_info->primitive);
290 if (draw_info->geometry != (
char *) NULL)
291 (void) CloneString(&clone_info->geometry,draw_info->geometry);
292 clone_info->compliance=draw_info->compliance;
293 clone_info->viewbox=draw_info->viewbox;
294 clone_info->affine=draw_info->affine;
295 clone_info->gravity=draw_info->gravity;
296 clone_info->fill=draw_info->fill;
297 clone_info->stroke=draw_info->stroke;
298 clone_info->stroke_width=draw_info->stroke_width;
299 if (draw_info->fill_pattern != (Image *) NULL)
300 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
302 if (draw_info->stroke_pattern != (Image *) NULL)
303 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
304 MagickTrue,exception);
305 clone_info->stroke_antialias=draw_info->stroke_antialias;
306 clone_info->text_antialias=draw_info->text_antialias;
307 clone_info->fill_rule=draw_info->fill_rule;
308 clone_info->linecap=draw_info->linecap;
309 clone_info->linejoin=draw_info->linejoin;
310 clone_info->miterlimit=draw_info->miterlimit;
311 clone_info->dash_offset=draw_info->dash_offset;
312 clone_info->decorate=draw_info->decorate;
313 clone_info->compose=draw_info->compose;
314 if (draw_info->text != (
char *) NULL)
315 (void) CloneString(&clone_info->text,draw_info->text);
316 if (draw_info->font != (
char *) NULL)
317 (void) CloneString(&clone_info->font,draw_info->font);
318 if (draw_info->metrics != (
char *) NULL)
319 (void) CloneString(&clone_info->metrics,draw_info->metrics);
320 if (draw_info->family != (
char *) NULL)
321 (void) CloneString(&clone_info->family,draw_info->family);
322 clone_info->style=draw_info->style;
323 clone_info->stretch=draw_info->stretch;
324 clone_info->weight=draw_info->weight;
325 if (draw_info->encoding != (
char *) NULL)
326 (void) CloneString(&clone_info->encoding,draw_info->encoding);
327 clone_info->pointsize=draw_info->pointsize;
328 clone_info->kerning=draw_info->kerning;
329 clone_info->interline_spacing=draw_info->interline_spacing;
330 clone_info->interword_spacing=draw_info->interword_spacing;
331 clone_info->direction=draw_info->direction;
332 clone_info->word_break=draw_info->word_break;
333 if (draw_info->density != (
char *) NULL)
334 (void) CloneString(&clone_info->density,draw_info->density);
335 clone_info->align=draw_info->align;
336 clone_info->undercolor=draw_info->undercolor;
337 clone_info->border_color=draw_info->border_color;
338 if (draw_info->server_name != (
char *) NULL)
339 (void) CloneString(&clone_info->server_name,draw_info->server_name);
340 if (draw_info->dash_pattern != (
double *) NULL)
345 for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
346 clone_info->dash_pattern=(
double *) AcquireQuantumMemory((
size_t) (x+1),
347 sizeof(*clone_info->dash_pattern));
348 if (clone_info->dash_pattern == (
double *) NULL)
349 ThrowFatalException(ResourceLimitFatalError,
350 "UnableToAllocateDashPattern");
351 (void) memset(clone_info->dash_pattern,0,(
size_t) (x+1)*
352 sizeof(*clone_info->dash_pattern));
353 (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(
size_t)
354 x*
sizeof(*clone_info->dash_pattern));
356 clone_info->gradient=draw_info->gradient;
357 if (draw_info->gradient.stops != (StopInfo *) NULL)
362 number_stops=clone_info->gradient.number_stops;
363 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((
size_t)
364 number_stops,
sizeof(*clone_info->gradient.stops));
365 if (clone_info->gradient.stops == (StopInfo *) NULL)
366 ThrowFatalException(ResourceLimitFatalError,
367 "UnableToAllocateDashPattern");
368 (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
369 (
size_t) number_stops*
sizeof(*clone_info->gradient.stops));
371 clone_info->bounds=draw_info->bounds;
372 clone_info->fill_alpha=draw_info->fill_alpha;
373 clone_info->stroke_alpha=draw_info->stroke_alpha;
374 clone_info->element_reference=draw_info->element_reference;
375 clone_info->clip_path=draw_info->clip_path;
376 clone_info->clip_units=draw_info->clip_units;
377 if (draw_info->clip_mask != (
char *) NULL)
378 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
379 if (draw_info->clipping_mask != (Image *) NULL)
380 clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
381 MagickTrue,exception);
382 if (draw_info->composite_mask != (Image *) NULL)
383 clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
384 MagickTrue,exception);
385 clone_info->render=draw_info->render;
386 clone_info->debug=draw_info->debug;
387 clone_info->macro_expansion=draw_info->macro_expansion;
388 exception=DestroyExceptionInfo(exception);
423static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
428 if (polygon_info->edges != (EdgeInfo *) NULL)
430 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
431 if (polygon_info->edges[i].points != (PointInfo *) NULL)
432 polygon_info->edges[i].points=(PointInfo *)
433 RelinquishMagickMemory(polygon_info->edges[i].points);
434 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(
435 polygon_info->edges);
437 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
439#if defined(__cplusplus) || defined(c_plusplus)
443static int DrawCompareEdges(
const void *p_edge,
const void *q_edge)
445#define DrawCompareEdge(p,q) \
447 if (((p)-(q)) < 0.0) \
449 if (((p)-(q)) > 0.0) \
460 p=((
const EdgeInfo *) p_edge)->points;
461 q=((
const EdgeInfo *) q_edge)->points;
462 DrawCompareEdge(p[0].y,q[0].y);
463 DrawCompareEdge(p[0].x,q[0].x);
464 DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
466 DrawCompareEdge(p[1].y,q[1].y);
467 DrawCompareEdge(p[1].x,q[1].x);
471#if defined(__cplusplus) || defined(c_plusplus)
475static void LogPolygonInfo(
const PolygonInfo *polygon_info)
484 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin active-edge");
485 p=polygon_info->edges;
486 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
488 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" edge %.17g:",
490 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" direction: %s",
491 p->direction != MagickFalse ?
"down" :
"up");
492 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" ghostline: %s",
493 p->ghostline != MagickFalse ?
"transparent" :
"opaque");
494 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
495 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
496 p->bounds.x2,p->bounds.y2);
497 for (j=0; j < (ssize_t) p->number_points; j++)
498 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %g,%g",
499 p->points[j].x,p->points[j].y);
502 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end active-edge");
505static void ReversePoints(PointInfo *points,
const size_t number_points)
513 for (i=0; i < (number_points >> 1); i++)
516 points[i]=points[number_points-(i+1)];
517 points[number_points-(i+1)]=point;
521static PolygonInfo *ConvertPathToPolygon(
const PathInfo *path_info,
522 ExceptionInfo *exception)
553 polygon_info=(PolygonInfo *) AcquireMagickMemory(
sizeof(*polygon_info));
554 if (polygon_info == (PolygonInfo *) NULL)
556 (void) ThrowMagickException(exception,GetMagickModule(),
557 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
558 return((PolygonInfo *) NULL);
561 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory(number_edges,
562 sizeof(*polygon_info->edges));
563 if (polygon_info->edges == (EdgeInfo *) NULL)
565 (void) ThrowMagickException(exception,GetMagickModule(),
566 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
567 return(DestroyPolygonInfo(polygon_info));
569 (void) memset(polygon_info->edges,0,number_edges*
570 sizeof(*polygon_info->edges));
573 ghostline=MagickFalse;
576 points=(PointInfo *) NULL;
577 (void) memset(&point,0,
sizeof(point));
578 (void) memset(&bounds,0,
sizeof(bounds));
579 polygon_info->edges[edge].number_points=(size_t) n;
580 polygon_info->edges[edge].scanline=0.0;
581 polygon_info->edges[edge].highwater=0;
582 polygon_info->edges[edge].ghostline=ghostline;
583 polygon_info->edges[edge].direction=(ssize_t) direction;
584 polygon_info->edges[edge].points=points;
585 polygon_info->edges[edge].bounds=bounds;
586 polygon_info->number_edges=0;
587 for (i=0; path_info[i].code != EndCode; i++)
589 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
590 (path_info[i].code == GhostlineCode))
595 if ((points != (PointInfo *) NULL) && (n >= 2))
597 if (edge == number_edges)
600 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
601 polygon_info->edges,(
size_t) number_edges,
602 sizeof(*polygon_info->edges));
603 if (polygon_info->edges == (EdgeInfo *) NULL)
605 (void) ThrowMagickException(exception,GetMagickModule(),
606 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
607 points=(PointInfo *) RelinquishMagickMemory(points);
608 return(DestroyPolygonInfo(polygon_info));
611 polygon_info->edges[edge].number_points=(size_t) n;
612 polygon_info->edges[edge].scanline=(-1.0);
613 polygon_info->edges[edge].highwater=0;
614 polygon_info->edges[edge].ghostline=ghostline;
615 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
617 ReversePoints(points,(
size_t) n);
618 polygon_info->edges[edge].points=points;
619 polygon_info->edges[edge].bounds=bounds;
620 polygon_info->edges[edge].bounds.y1=points[0].y;
621 polygon_info->edges[edge].bounds.y2=points[n-1].y;
622 points=(PointInfo *) NULL;
623 ghostline=MagickFalse;
625 polygon_info->number_edges=edge;
627 if (points == (PointInfo *) NULL)
630 points=(PointInfo *) AcquireQuantumMemory((
size_t) number_points,
632 if (points == (PointInfo *) NULL)
634 (void) ThrowMagickException(exception,GetMagickModule(),
635 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
636 return(DestroyPolygonInfo(polygon_info));
639 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
640 point=path_info[i].point;
651 next_direction=((path_info[i].point.y > point.y) ||
652 ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
653 (path_info[i].point.x > point.x))) ? 1 : -1;
654 if ((points != (PointInfo *) NULL) && (direction != 0) &&
655 (direction != next_direction))
661 if (edge == number_edges)
664 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
665 polygon_info->edges,(
size_t) number_edges,
666 sizeof(*polygon_info->edges));
667 if (polygon_info->edges == (EdgeInfo *) NULL)
669 (void) ThrowMagickException(exception,GetMagickModule(),
670 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
671 points=(PointInfo *) RelinquishMagickMemory(points);
672 return(DestroyPolygonInfo(polygon_info));
675 polygon_info->edges[edge].number_points=(size_t) n;
676 polygon_info->edges[edge].scanline=(-1.0);
677 polygon_info->edges[edge].highwater=0;
678 polygon_info->edges[edge].ghostline=ghostline;
679 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
681 ReversePoints(points,(
size_t) n);
682 polygon_info->edges[edge].points=points;
683 polygon_info->edges[edge].bounds=bounds;
684 polygon_info->edges[edge].bounds.y1=points[0].y;
685 polygon_info->edges[edge].bounds.y2=points[n-1].y;
686 polygon_info->number_edges=edge+1;
687 points=(PointInfo *) NULL;
689 points=(PointInfo *) AcquireQuantumMemory((
size_t) number_points,
691 if (points == (PointInfo *) NULL)
693 (void) ThrowMagickException(exception,GetMagickModule(),
694 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
695 return(DestroyPolygonInfo(polygon_info));
698 ghostline=MagickFalse;
704 direction=next_direction;
705 if (points == (PointInfo *) NULL)
707 if (n == (ssize_t) number_points)
710 points=(PointInfo *) ResizeQuantumMemory(points,(
size_t) number_points,
712 if (points == (PointInfo *) NULL)
714 (void) ThrowMagickException(exception,GetMagickModule(),
715 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
716 return(DestroyPolygonInfo(polygon_info));
719 point=path_info[i].point;
721 if (point.x < bounds.x1)
723 if (point.x > bounds.x2)
727 if (points != (PointInfo *) NULL)
730 points=(PointInfo *) RelinquishMagickMemory(points);
733 if (edge == number_edges)
736 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
737 polygon_info->edges,(
size_t) number_edges,
738 sizeof(*polygon_info->edges));
739 if (polygon_info->edges == (EdgeInfo *) NULL)
741 (void) ThrowMagickException(exception,GetMagickModule(),
742 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
743 return(DestroyPolygonInfo(polygon_info));
746 polygon_info->edges[edge].number_points=(size_t) n;
747 polygon_info->edges[edge].scanline=(-1.0);
748 polygon_info->edges[edge].highwater=0;
749 polygon_info->edges[edge].ghostline=ghostline;
750 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
752 ReversePoints(points,(
size_t) n);
753 polygon_info->edges[edge].points=points;
754 polygon_info->edges[edge].bounds=bounds;
755 polygon_info->edges[edge].bounds.y1=points[0].y;
756 polygon_info->edges[edge].bounds.y2=points[n-1].y;
757 points=(PointInfo *) NULL;
758 ghostline=MagickFalse;
760 polygon_info->number_edges=edge;
763 polygon_info->number_edges=edge;
764 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(polygon_info->edges,
765 polygon_info->number_edges,
sizeof(*polygon_info->edges));
766 if (polygon_info->edges == (EdgeInfo *) NULL)
768 (void) ThrowMagickException(exception,GetMagickModule(),
769 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
770 return(DestroyPolygonInfo(polygon_info));
772 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
777 edge_info=polygon_info->edges+i;
778 edge_info->points=(PointInfo *) ResizeQuantumMemory(edge_info->points,
779 edge_info->number_points,
sizeof(*edge_info->points));
780 if (edge_info->points == (PointInfo *) NULL)
782 (void) ThrowMagickException(exception,GetMagickModule(),
783 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
784 return(DestroyPolygonInfo(polygon_info));
787 qsort(polygon_info->edges,(
size_t) polygon_info->number_edges,
788 sizeof(*polygon_info->edges),DrawCompareEdges);
789 if ((GetLogEventMask() & DrawEvent) != 0)
790 LogPolygonInfo(polygon_info);
791 return(polygon_info);
824static void LogPathInfo(
const PathInfo *path_info)
829 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin vector-path");
830 for (p=path_info; p->code != EndCode; p++)
831 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
832 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
833 "moveto ghostline" : p->code == OpenCode ?
"moveto open" :
834 p->code == MoveToCode ?
"moveto" : p->code == LineToCode ?
"lineto" :
836 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end vector-path");
839static PathInfo *ConvertPrimitiveToPath(
const PrimitiveInfo *primitive_info,
840 ExceptionInfo *exception)
866 switch (primitive_info->primitive)
873 return((PathInfo *) NULL);
877 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
878 path_info=(PathInfo *) AcquireQuantumMemory((
size_t) (3UL*i+1UL),
880 if (path_info == (PathInfo *) NULL)
882 (void) ThrowMagickException(exception,GetMagickModule(),
883 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
884 return((PathInfo *) NULL);
887 closed_subpath=MagickFalse;
894 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
897 if (coordinates <= 0)
902 coordinates=primitive_info[i].coordinates;
903 p=primitive_info[i].point;
906 closed_subpath=primitive_info[i].closed_subpath;
909 if ((code == MoveToCode) || (coordinates <= 0) ||
910 (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
911 (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
916 path_info[n].code=code;
917 path_info[n].point=primitive_info[i].point;
918 q=primitive_info[i].point;
923 if (closed_subpath != MagickFalse)
925 closed_subpath=MagickFalse;
931 path_info[start].code=OpenCode;
932 path_info[n].code=GhostlineCode;
933 path_info[n].point=primitive_info[i].point;
935 path_info[n].code=LineToCode;
936 path_info[n].point=p;
939 path_info[n].code=EndCode;
940 path_info[n].point.x=0.0;
941 path_info[n].point.y=0.0;
942 if (IsEventLogging() != MagickFalse)
943 LogPathInfo(path_info);
944 path_info=(PathInfo *) ResizeQuantumMemory(path_info,(
size_t) (n+1),
971MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
973 assert(draw_info != (DrawInfo *) NULL);
974 assert(draw_info->signature == MagickCoreSignature);
975 if (IsEventLogging() != MagickFalse)
976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
977 if (draw_info->id != (
char *) NULL)
978 draw_info->id=DestroyString(draw_info->id);
979 if (draw_info->primitive != (
char *) NULL)
980 draw_info->primitive=DestroyString(draw_info->primitive);
981 if (draw_info->text != (
char *) NULL)
982 draw_info->text=DestroyString(draw_info->text);
983 if (draw_info->geometry != (
char *) NULL)
984 draw_info->geometry=DestroyString(draw_info->geometry);
985 if (draw_info->fill_pattern != (Image *) NULL)
986 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
987 if (draw_info->stroke_pattern != (Image *) NULL)
988 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
989 if (draw_info->font != (
char *) NULL)
990 draw_info->font=DestroyString(draw_info->font);
991 if (draw_info->metrics != (
char *) NULL)
992 draw_info->metrics=DestroyString(draw_info->metrics);
993 if (draw_info->family != (
char *) NULL)
994 draw_info->family=DestroyString(draw_info->family);
995 if (draw_info->encoding != (
char *) NULL)
996 draw_info->encoding=DestroyString(draw_info->encoding);
997 if (draw_info->density != (
char *) NULL)
998 draw_info->density=DestroyString(draw_info->density);
999 if (draw_info->server_name != (
char *) NULL)
1000 draw_info->server_name=(
char *)
1001 RelinquishMagickMemory(draw_info->server_name);
1002 if (draw_info->dash_pattern != (
double *) NULL)
1003 draw_info->dash_pattern=(
double *) RelinquishMagickMemory(
1004 draw_info->dash_pattern);
1005 if (draw_info->gradient.stops != (StopInfo *) NULL)
1006 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
1007 draw_info->gradient.stops);
1008 if (draw_info->clip_mask != (
char *) NULL)
1009 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
1010 if (draw_info->clipping_mask != (Image *) NULL)
1011 draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
1012 if (draw_info->composite_mask != (Image *) NULL)
1013 draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
1014 if (draw_info->image_info != (ImageInfo *) NULL)
1015 draw_info->image_info=DestroyImageInfo(draw_info->image_info);
1016 draw_info->signature=(~MagickCoreSignature);
1017 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
1052static SegmentInfo AffineEdge(
const Image *image,
const AffineMatrix *affine,
1053 const double y,
const SegmentInfo *edge)
1068 inverse_edge.x1=edge->x1;
1069 inverse_edge.y1=edge->y1;
1070 inverse_edge.x2=edge->x2;
1071 inverse_edge.y2=edge->y2;
1072 z=affine->ry*y+affine->tx;
1073 if (affine->sx >= MagickEpsilon)
1075 intercept=(-z/affine->sx);
1077 if (x > inverse_edge.x1)
1079 intercept=(-z+(double) image->columns)/affine->sx;
1081 if (x < inverse_edge.x2)
1085 if (affine->sx < -MagickEpsilon)
1087 intercept=(-z+(double) image->columns)/affine->sx;
1089 if (x > inverse_edge.x1)
1091 intercept=(-z/affine->sx);
1093 if (x < inverse_edge.x2)
1097 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->columns))
1099 inverse_edge.x2=edge->x1;
1100 return(inverse_edge);
1105 z=affine->sy*y+affine->ty;
1106 if (affine->rx >= MagickEpsilon)
1108 intercept=(-z/affine->rx);
1110 if (x > inverse_edge.x1)
1112 intercept=(-z+(double) image->rows)/affine->rx;
1114 if (x < inverse_edge.x2)
1118 if (affine->rx < -MagickEpsilon)
1120 intercept=(-z+(double) image->rows)/affine->rx;
1122 if (x > inverse_edge.x1)
1124 intercept=(-z/affine->rx);
1126 if (x < inverse_edge.x2)
1130 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->rows))
1132 inverse_edge.x2=edge->x2;
1133 return(inverse_edge);
1135 return(inverse_edge);
1138static AffineMatrix InverseAffineMatrix(
const AffineMatrix *affine)
1146 determinant=MagickSafeReciprocal(affine->sx*affine->sy-affine->rx*
1148 inverse_affine.sx=determinant*affine->sy;
1149 inverse_affine.rx=determinant*(-affine->rx);
1150 inverse_affine.ry=determinant*(-affine->ry);
1151 inverse_affine.sy=determinant*affine->sx;
1152 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1154 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1156 return(inverse_affine);
1159MagickExport MagickBooleanType DrawAffineImage(Image *image,
1160 const Image *source,
const AffineMatrix *affine,ExceptionInfo *exception)
1194 assert(image != (Image *) NULL);
1195 assert(image->signature == MagickCoreSignature);
1196 if (IsEventLogging() != MagickFalse)
1197 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1198 assert(source != (
const Image *) NULL);
1199 assert(source->signature == MagickCoreSignature);
1200 assert(affine != (AffineMatrix *) NULL);
1203 extent[1].x=(double) source->columns;
1205 extent[2].x=(double) source->columns;
1206 extent[2].y=(double) source->rows;
1208 extent[3].y=(double) source->rows;
1209 for (i=0; i < 4; i++)
1215 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1216 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1220 for (i=1; i < 4; i++)
1222 if (min.x > extent[i].x)
1224 if (min.y > extent[i].y)
1226 if (max.x < extent[i].x)
1228 if (max.y < extent[i].y)
1234 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1235 return(MagickFalse);
1241 inverse_affine=InverseAffineMatrix(affine);
1244 if (edge.y2 > ((
double) image->rows-1.0))
1245 edge.y2=(double) image->rows-1.0;
1246 GetPixelInfo(image,&zero);
1247 start=CastDoubleToSsizeT(ceil(edge.y1-0.5));
1248 stop=CastDoubleToSsizeT(floor(edge.y2+0.5));
1249 source_view=AcquireVirtualCacheView(source,exception);
1250 image_view=AcquireAuthenticCacheView(image,exception);
1251#if defined(MAGICKCORE_OPENMP_SUPPORT)
1252 #pragma omp parallel for schedule(static) shared(status) \
1253 magick_number_threads(source,image,(size_t) (stop-start),2)
1255 for (y=start; y <= stop; y++)
1273 if (status == MagickFalse)
1275 inverse_edge=AffineEdge(source,&inverse_affine,(
double) y,&edge);
1276 if (inverse_edge.x2 < inverse_edge.x1)
1278 if (inverse_edge.x1 < 0.0)
1279 inverse_edge.x1=0.0;
1280 if (inverse_edge.x2 > ((
double) image->columns-1.0))
1281 inverse_edge.x2=(double) image->columns-1.0;
1282 q=GetCacheViewAuthenticPixels(image_view,CastDoubleToSsizeT(
1283 ceil(inverse_edge.x1-0.5)),y,(
size_t) CastDoubleToSsizeT(floor(
1284 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
1285 if (q == (Quantum *) NULL)
1289 for (x=CastDoubleToSsizeT(ceil(inverse_edge.x1-0.5));
1290 x <= CastDoubleToSsizeT(floor(inverse_edge.x2+0.5)); x++)
1292 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1294 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1296 status=InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
1297 point.x,point.y,&pixel,exception);
1298 if (status == MagickFalse)
1300 GetPixelInfoPixel(image,q,&composite);
1301 CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
1303 SetPixelViaPixelInfo(image,&composite,q);
1304 q+=(ptrdiff_t) GetPixelChannels(image);
1306 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1309 source_view=DestroyCacheView(source_view);
1310 image_view=DestroyCacheView(image_view);
1346static MagickBooleanType DrawBoundingRectangles(Image *image,
1347 const DrawInfo *draw_info,
const PolygonInfo *polygon_info,
1348 ExceptionInfo *exception)
1376 (void) memset(primitive_info,0,
sizeof(primitive_info));
1377 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1378 status=QueryColorCompliance(
"#000F",AllCompliance,&clone_info->fill,
1380 if (status == MagickFalse)
1382 clone_info=DestroyDrawInfo(clone_info);
1383 return(MagickFalse);
1387 if (clone_info->density != (
char *) NULL)
1395 flags=ParseGeometry(clone_info->density,&geometry_info);
1396 if ((flags & RhoValue) != 0)
1397 resolution.x=geometry_info.rho;
1398 resolution.y=resolution.x;
1399 if ((flags & SigmaValue) != 0)
1400 resolution.y=geometry_info.sigma;
1402 mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
1403 clone_info->stroke_width/2.0;
1408 if (polygon_info != (PolygonInfo *) NULL)
1410 bounds=polygon_info->edges[0].bounds;
1411 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1413 if (polygon_info->edges[i].bounds.x1 < (
double) bounds.x1)
1414 bounds.x1=polygon_info->edges[i].bounds.x1;
1415 if (polygon_info->edges[i].bounds.y1 < (
double) bounds.y1)
1416 bounds.y1=polygon_info->edges[i].bounds.y1;
1417 if (polygon_info->edges[i].bounds.x2 > (
double) bounds.x2)
1418 bounds.x2=polygon_info->edges[i].bounds.x2;
1419 if (polygon_info->edges[i].bounds.y2 > (
double) bounds.y2)
1420 bounds.y2=polygon_info->edges[i].bounds.y2;
1423 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1424 image->columns ? (
double) image->columns-1 : bounds.x1;
1426 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1427 image->rows ? (
double) image->rows-1 : bounds.y1;
1429 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1430 image->columns ? (
double) image->columns-1 : bounds.x2;
1432 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1433 image->rows ? (
double) image->rows-1 : bounds.y2;
1434 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1436 if (polygon_info->edges[i].direction != 0)
1437 status=QueryColorCompliance(
"#f00",AllCompliance,&clone_info->stroke,
1440 status=QueryColorCompliance(
"#0f0",AllCompliance,&clone_info->stroke,
1442 if (status == MagickFalse)
1444 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1445 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1446 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1447 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1448 primitive_info[0].primitive=RectanglePrimitive;
1449 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1450 primitive_info[0].method=ReplaceMethod;
1451 coordinates=(ssize_t) primitive_info[0].coordinates;
1452 primitive_info[coordinates].primitive=UndefinedPrimitive;
1453 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1454 if (status == MagickFalse)
1457 if (i < (ssize_t) polygon_info->number_edges)
1459 clone_info=DestroyDrawInfo(clone_info);
1460 return(status == 0 ? MagickFalse : MagickTrue);
1463 status=QueryColorCompliance(
"#00f",AllCompliance,&clone_info->stroke,
1465 if (status == MagickFalse)
1467 clone_info=DestroyDrawInfo(clone_info);
1468 return(MagickFalse);
1470 start.x=(double) (bounds.x1-mid);
1471 start.y=(double) (bounds.y1-mid);
1472 end.x=(double) (bounds.x2+mid);
1473 end.y=(double) (bounds.y2+mid);
1474 primitive_info[0].primitive=RectanglePrimitive;
1475 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1476 primitive_info[0].method=ReplaceMethod;
1477 coordinates=(ssize_t) primitive_info[0].coordinates;
1478 primitive_info[coordinates].primitive=UndefinedPrimitive;
1479 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1480 clone_info=DestroyDrawInfo(clone_info);
1481 return(status == 0 ? MagickFalse : MagickTrue);
1513MagickExport MagickBooleanType DrawClipPath(Image *image,
1514 const DrawInfo *draw_info,
const char *
id,ExceptionInfo *exception)
1525 clip_path=GetImageArtifact(image,
id);
1526 if (clip_path == (
const char *) NULL)
1527 return(MagickFalse);
1528 clipping_mask=DrawClippingMask(image,draw_info,draw_info->clip_mask,clip_path,
1530 if (clipping_mask == (Image *) NULL)
1531 return(MagickFalse);
1532 status=SetImageMask(image,WritePixelMask,clipping_mask,exception);
1533 clipping_mask=DestroyImage(clipping_mask);
1569static Image *DrawClippingMask(Image *image,
const DrawInfo *draw_info,
1570 const char *
id,
const char *clip_path,ExceptionInfo *exception)
1585 assert(image != (Image *) NULL);
1586 assert(image->signature == MagickCoreSignature);
1587 assert(draw_info != (
const DrawInfo *) NULL);
1588 if (IsEventLogging() != MagickFalse)
1589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1590 clip_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1591 status=SetImageExtent(clip_mask,image->columns,image->rows,exception);
1592 if (status == MagickFalse)
1593 return(DestroyImage(clip_mask));
1594 status=SetImageMask(clip_mask,WritePixelMask,(Image *) NULL,exception);
1595 status=QueryColorCompliance(
"#0000",AllCompliance,
1596 &clip_mask->background_color,exception);
1597 clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1598 clip_mask->background_color.alpha_trait=BlendPixelTrait;
1599 status=SetImageBackgroundColor(clip_mask,exception);
1600 if (draw_info->debug != MagickFalse)
1601 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin clip-path %s",
1603 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1604 (void) CloneString(&clone_info->primitive,clip_path);
1605 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1607 if (clone_info->clip_mask != (
char *) NULL)
1608 clone_info->clip_mask=DestroyString(clone_info->clip_mask);
1609 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1611 clone_info->stroke_width=0.0;
1612 clone_info->alpha=OpaqueAlpha;
1613 clone_info->clip_path=MagickTrue;
1614 status=RenderMVGContent(clip_mask,clone_info,0,exception);
1615 clone_info=DestroyDrawInfo(clone_info);
1616 separate_mask=SeparateImage(clip_mask,AlphaChannel,exception);
1617 if (separate_mask == (Image *) NULL)
1621 clip_mask=DestroyImage(clip_mask);
1622 clip_mask=separate_mask;
1623 status&=(MagickStatusType) NegateImage(clip_mask,MagickFalse,exception);
1625 if (status == MagickFalse)
1626 clip_mask=DestroyImage(clip_mask);
1627 if (draw_info->debug != MagickFalse)
1628 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end clip-path");
1663static Image *DrawCompositeMask(Image *image,
const DrawInfo *draw_info,
1664 const char *
id,
const char *mask_path,ExceptionInfo *exception)
1679 assert(image != (Image *) NULL);
1680 assert(image->signature == MagickCoreSignature);
1681 assert(draw_info != (
const DrawInfo *) NULL);
1682 if (IsEventLogging() != MagickFalse)
1683 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1684 composite_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1685 status=SetImageExtent(composite_mask,image->columns,image->rows,exception);
1686 if (status == MagickFalse)
1687 return(DestroyImage(composite_mask));
1688 status=SetImageMask(composite_mask,CompositePixelMask,(Image *) NULL,
1690 status=QueryColorCompliance(
"#0000",AllCompliance,
1691 &composite_mask->background_color,exception);
1692 composite_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1693 composite_mask->background_color.alpha_trait=BlendPixelTrait;
1694 (void) SetImageBackgroundColor(composite_mask,exception);
1695 if (draw_info->debug != MagickFalse)
1696 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin mask-path %s",
1698 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1699 (void) CloneString(&clone_info->primitive,mask_path);
1700 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1702 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1704 clone_info->stroke_width=0.0;
1705 clone_info->alpha=OpaqueAlpha;
1706 status=RenderMVGContent(composite_mask,clone_info,0,exception);
1707 clone_info=DestroyDrawInfo(clone_info);
1708 separate_mask=SeparateImage(composite_mask,AlphaChannel,exception);
1709 if (separate_mask != (Image *) NULL)
1711 composite_mask=DestroyImage(composite_mask);
1712 composite_mask=separate_mask;
1713 status=NegateImage(composite_mask,MagickFalse,exception);
1714 if (status == MagickFalse)
1715 composite_mask=DestroyImage(composite_mask);
1717 if (status == MagickFalse)
1718 composite_mask=DestroyImage(composite_mask);
1719 if (draw_info->debug != MagickFalse)
1720 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end mask-path");
1721 return(composite_mask);
1755static MagickBooleanType DrawDashPolygon(
const DrawInfo *draw_info,
1756 const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception)
1786 assert(draw_info != (
const DrawInfo *) NULL);
1787 if (draw_info->debug != MagickFalse)
1788 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-dash");
1789 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1790 number_vertices=(size_t) i;
1791 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
1792 (2UL*number_vertices+32UL),
sizeof(*dash_polygon));
1793 if (dash_polygon == (PrimitiveInfo *) NULL)
1795 (void) ThrowMagickException(exception,GetMagickModule(),
1796 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1797 return(MagickFalse);
1799 (void) memset(dash_polygon,0,(2UL*number_vertices+32UL)*
1800 sizeof(*dash_polygon));
1801 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1802 clone_info->miterlimit=0;
1803 dash_polygon[0]=primitive_info[0];
1804 dash_polygon[0].closed_subpath=MagickFalse;
1805 scale=ExpandAffine(&draw_info->affine);
1806 length=scale*draw_info->dash_pattern[0];
1807 offset=fabs(draw_info->dash_offset) >= MagickEpsilon ?
1808 scale*draw_info->dash_offset : 0.0;
1810 for (n=0; offset > 0.0; j=0)
1812 if (draw_info->dash_pattern[n] <= 0.0)
1814 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1815 if (offset > length)
1819 length=scale*draw_info->dash_pattern[n];
1822 if (offset < length)
1834 for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
1836 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1837 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1838 maximum_length=hypot(dx,dy);
1839 if (maximum_length > (
double) (MaxBezierCoordinates >> 2))
1841 if (fabs(length) < MagickEpsilon)
1843 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1845 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1847 length=scale*draw_info->dash_pattern[n];
1849 for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); )
1851 total_length+=length;
1852 if ((n & 0x01) != 0)
1854 dash_polygon[0]=primitive_info[0];
1855 dash_polygon[0].closed_subpath=MagickFalse;
1856 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1857 total_length*MagickSafeReciprocal(maximum_length));
1858 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1859 total_length*MagickSafeReciprocal(maximum_length));
1864 if ((j+1) > (ssize_t) number_vertices)
1866 dash_polygon[j]=primitive_info[i-1];
1867 dash_polygon[j].closed_subpath=MagickFalse;
1868 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1869 total_length*MagickSafeReciprocal(maximum_length));
1870 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1871 total_length*MagickSafeReciprocal(maximum_length));
1872 dash_polygon[j].coordinates=1;
1874 dash_polygon[0].coordinates=(size_t) j;
1875 dash_polygon[j].primitive=UndefinedPrimitive;
1876 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1877 dash_polygon,exception);
1878 if (status == MagickFalse)
1881 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1883 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1885 length=scale*draw_info->dash_pattern[n];
1887 length-=(maximum_length-total_length);
1888 if ((n & 0x01) != 0)
1890 dash_polygon[j]=primitive_info[i];
1891 dash_polygon[j].coordinates=1;
1894 if ((status != MagickFalse) && (total_length < maximum_length) &&
1895 ((n & 0x01) == 0) && (j > 1))
1897 dash_polygon[j]=primitive_info[i-1];
1898 dash_polygon[j].closed_subpath=MagickFalse;
1899 dash_polygon[j].point.x+=MagickEpsilon;
1900 dash_polygon[j].point.y+=MagickEpsilon;
1901 dash_polygon[j].coordinates=1;
1903 dash_polygon[0].coordinates=(size_t) j;
1904 dash_polygon[j].primitive=UndefinedPrimitive;
1905 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1906 dash_polygon,exception);
1908 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1909 clone_info=DestroyDrawInfo(clone_info);
1910 if (draw_info->debug != MagickFalse)
1911 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-dash");
1912 return(status != 0 ? MagickTrue : MagickFalse);
1943static inline double GetStopColorOffset(
const GradientInfo *gradient,
1944 const ssize_t x,
const ssize_t y)
1946 switch (gradient->type)
1948 case UndefinedGradient:
1949 case LinearGradient:
1964 gradient_vector=(&gradient->gradient_vector);
1965 p.x=gradient_vector->x2-gradient_vector->x1;
1966 p.y=gradient_vector->y2-gradient_vector->y1;
1967 q.x=(double) x-gradient_vector->x1;
1968 q.y=(double) y-gradient_vector->y1;
1969 length=sqrt(q.x*q.x+q.y*q.y);
1970 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
1971 gamma=MagickSafeReciprocal(gamma);
1972 scale=p.x*q.x+p.y*q.y;
1973 offset=gamma*scale*length;
1976 case RadialGradient:
1981 if (gradient->spread == RepeatSpread)
1983 v.x=(double) x-gradient->center.x;
1984 v.y=(double) y-gradient->center.y;
1985 return(sqrt(v.x*v.x+v.y*v.y));
1987 v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians(
1988 gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians(
1989 gradient->angle))))*MagickSafeReciprocal(gradient->radii.x);
1990 v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians(
1991 gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians(
1992 gradient->angle))))*MagickSafeReciprocal(gradient->radii.y);
1993 return(sqrt(v.x*v.x+v.y*v.y));
1999static int StopInfoCompare(
const void *x,
const void *y)
2005 stop_1=(StopInfo *) x;
2006 stop_2=(StopInfo *) y;
2007 if (stop_1->offset > stop_2->offset)
2009 if (fabs(stop_1->offset-stop_2->offset) <= MagickEpsilon)
2014MagickExport MagickBooleanType DrawGradientImage(Image *image,
2015 const DrawInfo *draw_info,ExceptionInfo *exception)
2050 assert(image != (Image *) NULL);
2051 assert(image->signature == MagickCoreSignature);
2052 assert(draw_info != (
const DrawInfo *) NULL);
2053 if (IsEventLogging() != MagickFalse)
2054 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2055 gradient=(&draw_info->gradient);
2056 qsort(gradient->stops,gradient->number_stops,
sizeof(StopInfo),
2058 gradient_vector=(&gradient->gradient_vector);
2059 point.x=gradient_vector->x2-gradient_vector->x1;
2060 point.y=gradient_vector->y2-gradient_vector->y1;
2061 length=sqrt(point.x*point.x+point.y*point.y);
2062 bounding_box=gradient->bounding_box;
2064 GetPixelInfo(image,&zero);
2065 image_view=AcquireAuthenticCacheView(image,exception);
2066 height=(size_t) (bounding_box.y+(ssize_t) bounding_box.height);
2067#if defined(MAGICKCORE_OPENMP_SUPPORT)
2068 #pragma omp parallel for schedule(static) shared(status) \
2069 magick_number_threads(image,image,height,1)
2071 for (y=bounding_box.y; y < (ssize_t) height; y++)
2092 if (status == MagickFalse)
2094 q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,y,(
size_t)
2095 bounding_box.width,1,exception);
2096 if (q == (Quantum *) NULL)
2103 offset=GetStopColorOffset(gradient,0,y);
2104 if (gradient->type != RadialGradient)
2105 offset*=MagickSafeReciprocal(length);
2106 width=(size_t) (bounding_box.x+(ssize_t) bounding_box.width);
2107 for (x=bounding_box.x; x < (ssize_t) width; x++)
2109 GetPixelInfoPixel(image,q,&pixel);
2110 switch (gradient->spread)
2112 case UndefinedSpread:
2115 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2116 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2118 offset=GetStopColorOffset(gradient,x,y);
2119 if (gradient->type != RadialGradient)
2120 offset*=MagickSafeReciprocal(length);
2122 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2123 if (offset < gradient->stops[i].offset)
2125 if ((offset < 0.0) || (i == 0))
2126 composite=gradient->stops[0].color;
2128 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
2129 composite=gradient->stops[gradient->number_stops-1].color;
2134 alpha=(offset-gradient->stops[i].offset)/
2135 (gradient->stops[j].offset-gradient->stops[i].offset);
2136 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2137 &gradient->stops[j].color,alpha,&composite);
2143 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2144 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2146 offset=GetStopColorOffset(gradient,x,y);
2147 if (gradient->type != RadialGradient)
2148 offset*=MagickSafeReciprocal(length);
2152 if ((ssize_t) fmod(offset,2.0) == 0)
2153 offset=fmod(offset,1.0);
2155 offset=1.0-fmod(offset,1.0);
2156 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2157 if (offset < gradient->stops[i].offset)
2160 composite=gradient->stops[0].color;
2162 if (i == (ssize_t) gradient->number_stops)
2163 composite=gradient->stops[gradient->number_stops-1].color;
2168 alpha=(offset-gradient->stops[i].offset)/
2169 (gradient->stops[j].offset-gradient->stops[i].offset);
2170 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2171 &gradient->stops[j].color,alpha,&composite);
2183 antialias=MagickFalse;
2185 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2186 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2188 offset=GetStopColorOffset(gradient,x,y);
2189 if (gradient->type == LinearGradient)
2191 repeat=fmod(offset,length);
2193 repeat=length-fmod(-repeat,length);
2195 repeat=fmod(offset,length);
2196 antialias=(repeat < length) && ((repeat+1.0) > length) ?
2197 MagickTrue : MagickFalse;
2198 offset=MagickSafeReciprocal(length)*repeat;
2202 repeat=fmod(offset,gradient->radius);
2204 repeat=gradient->radius-fmod(-repeat,gradient->radius);
2206 repeat=fmod(offset,gradient->radius);
2207 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
2209 offset=repeat*MagickSafeReciprocal(gradient->radius);
2212 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2213 if (offset < gradient->stops[i].offset)
2216 composite=gradient->stops[0].color;
2218 if (i == (ssize_t) gradient->number_stops)
2219 composite=gradient->stops[gradient->number_stops-1].color;
2224 alpha=(offset-gradient->stops[i].offset)/
2225 (gradient->stops[j].offset-gradient->stops[i].offset);
2226 if (antialias != MagickFalse)
2228 if (gradient->type == LinearGradient)
2229 alpha=length-repeat;
2231 alpha=gradient->radius-repeat;
2233 j=(ssize_t) gradient->number_stops-1L;
2235 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2236 &gradient->stops[j].color,alpha,&composite);
2241 CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha,
2243 SetPixelViaPixelInfo(image,&pixel,q);
2244 q+=(ptrdiff_t) GetPixelChannels(image);
2246 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2249 image_view=DestroyCacheView(image_view);
2285static inline MagickBooleanType CheckPrimitiveExtent(MVGInfo *mvg_info,
2300 if ((mvg_info == (MVGInfo *) NULL) ||
2301 (mvg_info->primitive_info == (PrimitiveInfo **) NULL) ||
2302 (*mvg_info->primitive_info == (PrimitiveInfo *) NULL) ||
2303 (mvg_info->extent == (
size_t *) NULL))
2304 return(MagickFalse);
2305 proposed_extent=mvg_info->offset+pad+PrimitiveExtentPad+1.0;
2306 if ((proposed_extent <= 0.0) || (proposed_extent > (
double) MAGICK_SIZE_MAX))
2307 return(MagickFalse);
2308 extent=CastDoubleToSizeT(ceil(proposed_extent));
2309 if (extent <= *mvg_info->extent)
2311 if (extent > (GetMaxMemoryRequest()/
sizeof(PrimitiveInfo)))
2312 return(MagickFalse);
2313 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(
2314 *mvg_info->primitive_info,extent+1,
sizeof(PrimitiveInfo));
2315 if (primitive_info == (PrimitiveInfo *) NULL)
2320 extent=(size_t) PrimitiveExtentPad;
2321 primitive_info=(PrimitiveInfo *) AcquireCriticalMemory(extent*
2322 sizeof(*primitive_info));
2323 (void) memset(primitive_info,0,extent*
sizeof(*primitive_info));
2324 *mvg_info->primitive_info=primitive_info;
2325 *mvg_info->extent=extent;
2327 ThrowMagickException(mvg_info->exception,GetMagickModule(),
2328 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2329 return(MagickFalse);
2331 primitive_info[extent].primitive=UndefinedPrimitive;
2332 primitive_info[extent].text=(
char *) NULL;
2336 for (i=(ssize_t) *mvg_info->extent; i < (ssize_t) extent; i++)
2338 primitive_info[i].primitive=UndefinedPrimitive;
2339 primitive_info[i].text=(
char *) NULL;
2341 *mvg_info->primitive_info=primitive_info;
2342 *mvg_info->extent=extent;
2346static inline double GetDrawValue(
const char *magick_restrict
string,
2347 char **magick_restrict sentinel)
2350 **magick_restrict q;
2356 value=InterpretLocaleValue(
string,q);
2361static int MVGMacroCompare(
const void *target,
const void *source)
2367 p=(
const char *) target;
2368 q=(
const char *) source;
2369 return(strcmp(p,q));
2372static SplayTreeInfo *GetMVGMacros(
const char *primitive,
2373 ExceptionInfo *exception)
2391 if (primitive == (
const char *) NULL)
2392 return((SplayTreeInfo *) NULL);
2393 macros=NewSplayTree(MVGMacroCompare,RelinquishMagickMemory,
2394 RelinquishMagickMemory);
2395 macro=AcquireString(primitive);
2396 token=AcquireString(primitive);
2397 extent=strlen(token)+MagickPathExtent;
2398 for (q=primitive; *q !=
'\0'; )
2400 if (GetNextToken(q,&q,extent,token) < 1)
2404 if (LocaleCompare(
"push",token) == 0)
2410 (void) GetNextToken(q,&q,extent,token);
2414 name[MagickPathExtent];
2425 (void) GetNextToken(q,&q,extent,token);
2428 (void) CopyMagickString(name,token,MagickPathExtent);
2430 for (p=q; *p !=
'\0'; )
2432 if (GetNextToken(p,&p,extent,token) < 1)
2436 if (LocaleCompare(token,
"pop") == 0)
2438 end=p-strlen(token)-1;
2441 if (LocaleCompare(token,
"push") == 0)
2443 if (n++ >= MagickMaxRecursionDepth)
2445 (void) ThrowMagickException(exception,GetMagickModule(),
2446 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2450 if ((n == 0) && (end >= start))
2453 length=(size_t) (end-start);
2458 (void) GetNextToken(p,&p,extent,token);
2461 (void) CopyMagickString(macro,start,length);
2462 (void) AddValueToSplayTree(macros,ConstantString(name),
2463 ConstantString(macro));
2471 token=DestroyString(token);
2472 macro=DestroyString(macro);
2476static inline MagickBooleanType IsValidListChar(
int c)
2478 if ((c >=
'0') && (c <=
'9'))
2492 return(MagickFalse);
2497static inline MagickBooleanType IsValidPoint(
const char *point)
2505 value=GetDrawValue(point,&p);
2506 return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
2510static inline MagickBooleanType TracePoint(PrimitiveInfo *primitive_info,
2511 const PointInfo point)
2513 primitive_info->point=point;
2514 primitive_info->coordinates=1;
2515 primitive_info->closed_subpath=MagickFalse;
2516 primitive_info->text=(
char *) NULL;
2520static MagickBooleanType RenderMVGContent(Image *image,
2521 const DrawInfo *draw_info,
const size_t depth,ExceptionInfo *exception)
2523#define RenderImageTag "Render/Image"
2530 keyword[MagickPathExtent],
2531 geometry[MagickPathExtent],
2533 pattern[MagickPathExtent],
2597 assert(image != (Image *) NULL);
2598 assert(image->signature == MagickCoreSignature);
2599 assert(draw_info != (DrawInfo *) NULL);
2600 assert(draw_info->signature == MagickCoreSignature);
2601 if (IsEventLogging() != MagickFalse)
2602 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2603 if (depth >= MagickMaxRecursionDepth)
2604 ThrowBinaryException(DrawError,
"VectorGraphicsNestedTooDeeply",
2606 if ((draw_info->primitive == (
char *) NULL) ||
2607 (*draw_info->primitive ==
'\0'))
2608 return(MagickFalse);
2609 if (draw_info->debug != MagickFalse)
2610 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"begin draw-image");
2611 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2612 return(MagickFalse);
2613 if ((image->alpha_trait & BlendPixelTrait) == 0)
2615 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2616 if (status == MagickFalse)
2617 return(MagickFalse);
2619 if ((*draw_info->primitive ==
'@') && (strlen(draw_info->primitive) > 1) &&
2620 (*(draw_info->primitive+1) !=
'-') && (depth == 0))
2621 primitive=FileToString(draw_info->primitive,~0UL,exception);
2623 primitive=AcquireString(draw_info->primitive);
2624 if (primitive == (
char *) NULL)
2625 return(MagickFalse);
2626 primitive_extent=(double) strlen(primitive);
2627 (void) SetImageArtifact(image,
"mvg:vector-graphics",primitive);
2630 stops=(StopInfo *) NULL;
2634 graphic_context=(DrawInfo **) AcquireMagickMemory(
sizeof(*graphic_context));
2635 if (graphic_context == (DrawInfo **) NULL)
2637 primitive=DestroyString(primitive);
2638 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2641 number_points=(size_t) PrimitiveExtentPad;
2642 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
2643 (number_points+1),
sizeof(*primitive_info));
2644 if (primitive_info == (PrimitiveInfo *) NULL)
2646 primitive=DestroyString(primitive);
2647 for ( ; n >= 0; n--)
2648 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2649 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
2650 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2653 (void) memset(primitive_info,0,(
size_t) (number_points+1)*
2654 sizeof(*primitive_info));
2655 (void) memset(&mvg_info,0,
sizeof(mvg_info));
2656 mvg_info.primitive_info=(&primitive_info);
2657 mvg_info.extent=(&number_points);
2658 mvg_info.exception=exception;
2659 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
2660 if (graphic_context[n]->primitive != (
char *) NULL)
2661 graphic_context[n]->primitive=DestroyString(graphic_context[n]->primitive);
2662 graphic_context[n]->viewbox=image->page;
2663 if ((image->page.width == 0) || (image->page.height == 0))
2665 graphic_context[n]->viewbox.width=image->columns;
2666 graphic_context[n]->viewbox.height=image->rows;
2668 token=AcquireString(primitive);
2669 extent=strlen(token)+MagickPathExtent;
2673 macros=GetMVGMacros(primitive,exception);
2675 for (q=primitive; *q !=
'\0'; )
2680 if (GetNextToken(q,&q,MagickPathExtent,keyword) < 1)
2682 if (*keyword ==
'\0')
2684 if (*keyword ==
'#')
2689 while ((*q !=
'\n') && (*q !=
'\0'))
2693 p=q-strlen(keyword)-1;
2694 primitive_type=UndefinedPrimitive;
2695 current=graphic_context[n]->affine;
2696 GetAffineMatrix(&affine);
2705 if (LocaleCompare(
"affine",keyword) == 0)
2707 (void) GetNextToken(q,&q,extent,token);
2708 affine.sx=GetDrawValue(token,&next_token);
2709 if (token == next_token)
2710 ThrowPointExpectedException(token,exception);
2711 (void) GetNextToken(q,&q,extent,token);
2712 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2713 ThrowPointExpectedException(token,exception);
2715 (void) GetNextToken(q,&q,extent,token);
2716 affine.ry=GetDrawValue(token,&next_token);
2717 if (token == next_token)
2718 ThrowPointExpectedException(token,exception);
2719 (void) GetNextToken(q,&q,extent,token);
2720 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2721 ThrowPointExpectedException(token,exception);
2723 (void) GetNextToken(q,&q,extent,token);
2724 affine.rx=GetDrawValue(token,&next_token);
2725 if (token == next_token)
2726 ThrowPointExpectedException(token,exception);
2727 (void) GetNextToken(q,&q,extent,token);
2728 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2729 ThrowPointExpectedException(token,exception);
2731 (void) GetNextToken(q,&q,extent,token);
2732 affine.sy=GetDrawValue(token,&next_token);
2733 if (token == next_token)
2734 ThrowPointExpectedException(token,exception);
2735 (void) GetNextToken(q,&q,extent,token);
2736 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2737 ThrowPointExpectedException(token,exception);
2739 (void) GetNextToken(q,&q,extent,token);
2740 affine.tx=GetDrawValue(token,&next_token);
2741 if (token == next_token)
2742 ThrowPointExpectedException(token,exception);
2743 (void) GetNextToken(q,&q,extent,token);
2744 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2745 ThrowPointExpectedException(token,exception);
2747 (void) GetNextToken(q,&q,extent,token);
2748 affine.ty=GetDrawValue(token,&next_token);
2749 if (token == next_token)
2750 ThrowPointExpectedException(token,exception);
2753 if (LocaleCompare(
"alpha",keyword) == 0)
2755 primitive_type=AlphaPrimitive;
2758 if (LocaleCompare(
"arc",keyword) == 0)
2760 primitive_type=ArcPrimitive;
2769 if (LocaleCompare(
"bezier",keyword) == 0)
2771 primitive_type=BezierPrimitive;
2774 if (LocaleCompare(
"border-color",keyword) == 0)
2776 (void) GetNextToken(q,&q,extent,token);
2777 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2778 &graphic_context[n]->border_color,exception);
2787 if (LocaleCompare(
"class",keyword) == 0)
2792 (void) GetNextToken(q,&q,extent,token);
2793 if ((*token ==
'\0') || (*token ==
';'))
2801 for (i=0; i <= n; i++)
2802 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2806 if (classDepth++ >= MagickMaxRecursionDepth)
2808 (void) ThrowMagickException(exception,GetMagickModule(),
2809 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2813 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2814 if ((graphic_context[n]->render != MagickFalse) &&
2815 (mvg_class != (
const char *) NULL) && (p > primitive))
2826 (void) CloneString(&graphic_context[n]->
id,token);
2827 offset=(ssize_t) (p-primitive);
2828 elements=AcquireString(primitive);
2829 elements[offset]=
'\0';
2830 (void) ConcatenateString(&elements,mvg_class);
2831 (void) ConcatenateString(&elements,
"\n");
2832 (void) ConcatenateString(&elements,q);
2833 primitive=DestroyString(primitive);
2839 if (LocaleCompare(
"clip-path",keyword) == 0)
2847 (void) GetNextToken(q,&q,extent,token);
2853 (void) CloneString(&graphic_context[n]->clip_mask,token);
2854 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2855 if (clip_path != (
const char *) NULL)
2857 if (graphic_context[n]->clipping_mask != (Image *) NULL)
2858 graphic_context[n]->clipping_mask=
2859 DestroyImage(graphic_context[n]->clipping_mask);
2860 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2861 graphic_context[n],token,clip_path,exception);
2862 if (graphic_context[n]->compliance != SVGCompliance)
2864 clip_path=(
const char *) GetValueFromSplayTree(macros,
2865 graphic_context[n]->clip_mask);
2866 if (clip_path != (
const char *) NULL)
2867 (void) SetImageArtifact(image,
2868 graphic_context[n]->clip_mask,clip_path);
2869 status&=(MagickStatusType) DrawClipPath(image,
2870 graphic_context[n],graphic_context[n]->clip_mask,
2876 if (LocaleCompare(
"clip-rule",keyword) == 0)
2881 (void) GetNextToken(q,&q,extent,token);
2882 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2884 if (fill_rule == -1)
2889 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2892 if (LocaleCompare(
"clip-units",keyword) == 0)
2897 (void) GetNextToken(q,&q,extent,token);
2898 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2900 if (clip_units == -1)
2905 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2906 if (clip_units == ObjectBoundingBox)
2908 GetAffineMatrix(¤t);
2909 affine.sx=draw_info->bounds.x2;
2910 affine.sy=draw_info->bounds.y2;
2911 affine.tx=draw_info->bounds.x1;
2912 affine.ty=draw_info->bounds.y1;
2917 if (LocaleCompare(
"circle",keyword) == 0)
2919 primitive_type=CirclePrimitive;
2922 if (LocaleCompare(
"color",keyword) == 0)
2924 primitive_type=ColorPrimitive;
2927 if (LocaleCompare(
"compliance",keyword) == 0)
2933 (void) GetNextToken(q,&q,extent,token);
2934 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2935 MagickComplianceOptions,MagickFalse,token);
2938 if (LocaleCompare(
"currentColor",keyword) == 0)
2940 (void) GetNextToken(q,&q,extent,token);
2949 if (LocaleCompare(
"decorate",keyword) == 0)
2954 (void) GetNextToken(q,&q,extent,token);
2955 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2962 graphic_context[n]->decorate=(DecorationType) decorate;
2965 if (LocaleCompare(
"density",keyword) == 0)
2967 (void) GetNextToken(q,&q,extent,token);
2968 (void) CloneString(&graphic_context[n]->density,token);
2971 if (LocaleCompare(
"direction",keyword) == 0)
2976 (void) GetNextToken(q,&q,extent,token);
2977 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2979 if (direction == -1)
2982 graphic_context[n]->direction=(DirectionType) direction;
2991 if (LocaleCompare(
"ellipse",keyword) == 0)
2993 primitive_type=EllipsePrimitive;
2996 if (LocaleCompare(
"encoding",keyword) == 0)
2998 (void) GetNextToken(q,&q,extent,token);
2999 (void) CloneString(&graphic_context[n]->encoding,token);
3008 if (LocaleCompare(
"fill",keyword) == 0)
3013 (void) GetNextToken(q,&q,extent,token);
3014 if (graphic_context[n]->clip_path != MagickFalse)
3016 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3017 if (mvg_class != (
const char *) NULL)
3019 (void) DrawPatternPath(image,draw_info,mvg_class,
3020 &graphic_context[n]->fill_pattern,exception);
3023 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3024 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3026 (void) DrawPatternPath(image,draw_info,token,
3027 &graphic_context[n]->fill_pattern,exception);
3030 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3031 &graphic_context[n]->fill,exception);
3032 if (graphic_context[n]->fill_alpha != (
double) OpaqueAlpha)
3033 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3036 if (LocaleCompare(
"fill-opacity",keyword) == 0)
3041 (void) GetNextToken(q,&q,extent,token);
3042 if (graphic_context[n]->clip_path != MagickFalse)
3044 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3045 opacity=MagickMin(MagickMax(factor*
3046 GetDrawValue(token,&next_token),0.0),1.0);
3047 if (token == next_token)
3048 ThrowPointExpectedException(token,exception);
3049 if (graphic_context[n]->compliance == SVGCompliance)
3050 graphic_context[n]->fill_alpha*=opacity;
3052 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3053 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3054 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3056 graphic_context[n]->fill.alpha=(MagickRealType)
3057 ClampToQuantum((
double) QuantumRange*opacity);
3058 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3061 if (LocaleCompare(
"fill-rule",keyword) == 0)
3066 (void) GetNextToken(q,&q,extent,token);
3067 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3069 if (fill_rule == -1)
3074 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3077 if (LocaleCompare(
"font",keyword) == 0)
3079 (void) GetNextToken(q,&q,extent,token);
3080 (void) CloneString(&graphic_context[n]->font,token);
3081 if (LocaleCompare(
"none",token) == 0)
3082 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3083 graphic_context[n]->font);
3086 if (LocaleCompare(
"font-family",keyword) == 0)
3088 (void) GetNextToken(q,&q,extent,token);
3089 (void) CloneString(&graphic_context[n]->family,token);
3092 if (LocaleCompare(
"font-size",keyword) == 0)
3094 (void) GetNextToken(q,&q,extent,token);
3095 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3096 if (token == next_token)
3097 ThrowPointExpectedException(token,exception);
3100 if (LocaleCompare(
"font-stretch",keyword) == 0)
3105 (void) GetNextToken(q,&q,extent,token);
3106 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3112 graphic_context[n]->stretch=(StretchType) stretch;
3115 if (LocaleCompare(
"font-style",keyword) == 0)
3120 (void) GetNextToken(q,&q,extent,token);
3121 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3127 graphic_context[n]->style=(StyleType) style;
3130 if (LocaleCompare(
"font-weight",keyword) == 0)
3135 (void) GetNextToken(q,&q,extent,token);
3136 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3138 weight=(ssize_t) StringToUnsignedLong(token);
3139 graphic_context[n]->weight=(size_t) weight;
3148 if (LocaleCompare(
"gradient-units",keyword) == 0)
3150 (void) GetNextToken(q,&q,extent,token);
3153 if (LocaleCompare(
"gravity",keyword) == 0)
3158 (void) GetNextToken(q,&q,extent,token);
3159 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3165 graphic_context[n]->gravity=(GravityType) gravity;
3174 if (LocaleCompare(
"image",keyword) == 0)
3179 primitive_type=ImagePrimitive;
3180 (void) GetNextToken(q,&q,extent,token);
3181 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3187 graphic_context[n]->compose=(CompositeOperator) compose;
3190 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3192 (void) GetNextToken(q,&q,extent,token);
3193 graphic_context[n]->interline_spacing=GetDrawValue(token,
3195 if (token == next_token)
3196 ThrowPointExpectedException(token,exception);
3199 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3201 (void) GetNextToken(q,&q,extent,token);
3202 graphic_context[n]->interword_spacing=GetDrawValue(token,
3204 if (token == next_token)
3205 ThrowPointExpectedException(token,exception);
3214 if (LocaleCompare(
"kerning",keyword) == 0)
3216 (void) GetNextToken(q,&q,extent,token);
3217 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3218 if (token == next_token)
3219 ThrowPointExpectedException(token,exception);
3228 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3230 (void) GetNextToken(q,&q,extent,token);
3231 if (IsValidPoint(token) == MagickFalse)
3233 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
3234 clone_info->text=AcquireString(
" ");
3235 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,&metrics,
3237 graphic_context[n]->kerning=metrics.width*
3238 GetDrawValue(token,&next_token);
3239 clone_info=DestroyDrawInfo(clone_info);
3240 if (token == next_token)
3241 ThrowPointExpectedException(token,exception);
3244 if (LocaleCompare(
"line",keyword) == 0)
3246 primitive_type=LinePrimitive;
3255 if (LocaleCompare(
"mask",keyword) == 0)
3263 (void) GetNextToken(q,&q,extent,token);
3264 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3265 if (mask_path != (
const char *) NULL)
3267 if (graphic_context[n]->composite_mask != (Image *) NULL)
3268 graphic_context[n]->composite_mask=
3269 DestroyImage(graphic_context[n]->composite_mask);
3270 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3271 graphic_context[n],token,mask_path,exception);
3272 if (graphic_context[n]->compliance != SVGCompliance)
3273 status=SetImageMask(image,CompositePixelMask,
3274 graphic_context[n]->composite_mask,exception);
3284 if (LocaleCompare(
"offset",keyword) == 0)
3286 (void) GetNextToken(q,&q,extent,token);
3289 if (LocaleCompare(
"opacity",keyword) == 0)
3294 (void) GetNextToken(q,&q,extent,token);
3295 if (graphic_context[n]->clip_path != MagickFalse)
3297 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3298 opacity=MagickMin(MagickMax(factor*
3299 GetDrawValue(token,&next_token),0.0),1.0);
3300 if (token == next_token)
3301 ThrowPointExpectedException(token,exception);
3302 if (graphic_context[n]->compliance == SVGCompliance)
3304 graphic_context[n]->fill_alpha*=opacity;
3305 graphic_context[n]->stroke_alpha*=opacity;
3309 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3310 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3312 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3314 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3315 graphic_context[n]->stroke.alpha=
3316 graphic_context[n]->stroke_alpha;
3320 graphic_context[n]->fill.alpha=(MagickRealType)
3321 ClampToQuantum((
double) QuantumRange*opacity);
3322 graphic_context[n]->stroke.alpha=(MagickRealType)
3323 ClampToQuantum((
double) QuantumRange*opacity);
3325 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3326 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3335 if (LocaleCompare(
"path",keyword) == 0)
3337 primitive_type=PathPrimitive;
3340 if (LocaleCompare(
"point",keyword) == 0)
3342 primitive_type=PointPrimitive;
3345 if (LocaleCompare(
"polyline",keyword) == 0)
3347 primitive_type=PolylinePrimitive;
3350 if (LocaleCompare(
"polygon",keyword) == 0)
3352 primitive_type=PolygonPrimitive;
3355 if (LocaleCompare(
"pop",keyword) == 0)
3357 if (GetNextToken(q,&q,extent,token) < 1)
3359 if (LocaleCompare(
"class",token) == 0)
3361 if (LocaleCompare(
"clip-path",token) == 0)
3363 if (LocaleCompare(
"defs",token) == 0)
3366 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3370 if (LocaleCompare(
"gradient",token) == 0)
3372 if (LocaleCompare(
"graphic-context",token) == 0)
3376 (void) ThrowMagickException(exception,GetMagickModule(),
3377 DrawError,
"UnbalancedGraphicContextPushPop",
"`%s'",token);
3382 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3383 (graphic_context[n]->compliance != SVGCompliance))
3384 if (LocaleCompare(graphic_context[n]->clip_mask,
3385 graphic_context[n-1]->clip_mask) != 0)
3386 status=SetImageMask(image,WritePixelMask,(Image *) NULL,
3388 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3392 if (LocaleCompare(
"mask",token) == 0)
3394 if (LocaleCompare(
"pattern",token) == 0)
3396 if (LocaleCompare(
"symbol",token) == 0)
3399 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3406 if (LocaleCompare(
"push",keyword) == 0)
3408 if (GetNextToken(q,&q,extent,token) < 1)
3410 if (LocaleCompare(
"class",token) == 0)
3415 for (p=q; *q !=
'\0'; )
3417 if (GetNextToken(q,&q,extent,token) < 1)
3419 if (LocaleCompare(token,
"pop") != 0)
3421 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3422 if (LocaleCompare(token,
"class") != 0)
3426 (void) GetNextToken(q,&q,extent,token);
3429 if (LocaleCompare(
"clip-path",token) == 0)
3431 (void) GetNextToken(q,&q,extent,token);
3432 for (p=q; *q !=
'\0'; )
3434 if (GetNextToken(q,&q,extent,token) < 1)
3436 if (LocaleCompare(token,
"pop") != 0)
3438 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3439 if (LocaleCompare(token,
"clip-path") != 0)
3443 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3448 (void) GetNextToken(q,&q,extent,token);
3451 if (LocaleCompare(
"defs",token) == 0)
3454 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3458 if (LocaleCompare(
"gradient",token) == 0)
3461 key[2*MagickPathExtent],
3462 name[MagickPathExtent],
3463 type[MagickPathExtent];
3468 (void) GetNextToken(q,&q,extent,token);
3469 (void) CopyMagickString(name,token,MagickPathExtent);
3470 (void) GetNextToken(q,&q,extent,token);
3471 (void) CopyMagickString(type,token,MagickPathExtent);
3472 (void) GetNextToken(q,&q,extent,token);
3473 segment.x1=GetDrawValue(token,&next_token);
3474 if (token == next_token)
3475 ThrowPointExpectedException(token,exception);
3476 (void) GetNextToken(q,&q,extent,token);
3477 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3478 ThrowPointExpectedException(token,exception);
3480 (void) GetNextToken(q,&q,extent,token);
3481 segment.y1=GetDrawValue(token,&next_token);
3482 if (token == next_token)
3483 ThrowPointExpectedException(token,exception);
3484 (void) GetNextToken(q,&q,extent,token);
3485 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3486 ThrowPointExpectedException(token,exception);
3488 (void) GetNextToken(q,&q,extent,token);
3489 segment.x2=GetDrawValue(token,&next_token);
3490 if (token == next_token)
3491 ThrowPointExpectedException(token,exception);
3492 (void) GetNextToken(q,&q,extent,token);
3493 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3494 ThrowPointExpectedException(token,exception);
3496 (void) GetNextToken(q,&q,extent,token);
3497 segment.y2=GetDrawValue(token,&next_token);
3498 if (token == next_token)
3499 ThrowPointExpectedException(token,exception);
3500 if (LocaleCompare(type,
"radial") == 0)
3502 (void) GetNextToken(q,&q,extent,token);
3503 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3504 ThrowPointExpectedException(token,exception);
3506 (void) GetNextToken(q,&q,extent,token);
3508 for (p=q; *q !=
'\0'; )
3510 if (GetNextToken(q,&q,extent,token) < 1)
3512 if (LocaleCompare(token,
"pop") != 0)
3514 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3515 if (LocaleCompare(token,
"gradient") != 0)
3519 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3520 (p == (
char *) NULL) || ((q-4) < p) ||
3521 ((
size_t) (q-p+4+1) > extent))
3526 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3527 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3528 graphic_context[n]->affine.ry*segment.y1+
3529 graphic_context[n]->affine.tx;
3530 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3531 graphic_context[n]->affine.sy*segment.y1+
3532 graphic_context[n]->affine.ty;
3533 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3534 graphic_context[n]->affine.ry*segment.y2+
3535 graphic_context[n]->affine.tx;
3536 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3537 graphic_context[n]->affine.sy*segment.y2+
3538 graphic_context[n]->affine.ty;
3539 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3540 (void) SetImageArtifact(image,key,token);
3541 (void) FormatLocaleString(key,MagickPathExtent,
"%s-type",name);
3542 (void) SetImageArtifact(image,key,type);
3543 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3545 (void) FormatLocaleString(geometry,MagickPathExtent,
3546 "%gx%g%+.15g%+.15g",
3547 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3548 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3549 bounds.x1,bounds.y1);
3550 (void) SetImageArtifact(image,key,geometry);
3551 (void) GetNextToken(q,&q,extent,token);
3554 if (LocaleCompare(
"graphic-context",token) == 0)
3557 graphic_context=(DrawInfo **) ResizeQuantumMemory(
3558 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3559 if (graphic_context == (DrawInfo **) NULL)
3561 (void) ThrowMagickException(exception,GetMagickModule(),
3562 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3567 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
3568 graphic_context[n-1]);
3571 (void) GetNextToken(q,&q,extent,token);
3572 (void) CloneString(&graphic_context[n]->
id,token);
3574 if (n >= MagickMaxRecursionDepth)
3576 (void) ThrowMagickException(exception,GetMagickModule(),
3577 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",
3583 if (LocaleCompare(
"mask",token) == 0)
3585 (void) GetNextToken(q,&q,extent,token);
3588 if (LocaleCompare(
"pattern",token) == 0)
3591 key[2*MagickPathExtent],
3592 name[MagickPathExtent];
3597 (void) GetNextToken(q,&q,extent,token);
3598 (void) CopyMagickString(name,token,MagickPathExtent);
3599 (void) GetNextToken(q,&q,extent,token);
3600 region.x=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3602 if (token == next_token)
3603 ThrowPointExpectedException(token,exception);
3604 (void) GetNextToken(q,&q,extent,token);
3605 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3606 ThrowPointExpectedException(token,exception);
3608 (void) GetNextToken(q,&q,extent,token);
3609 region.y=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3611 if (token == next_token)
3612 ThrowPointExpectedException(token,exception);
3613 (void) GetNextToken(q,&q,extent,token);
3614 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3615 ThrowPointExpectedException(token,exception);
3617 (void) GetNextToken(q,&q,extent,token);
3618 region.width=CastDoubleToSizeT(floor(GetDrawValue(token,
3620 if (token == next_token)
3621 ThrowPointExpectedException(token,exception);
3622 (void) GetNextToken(q,&q,extent,token);
3623 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3624 ThrowPointExpectedException(token,exception);
3626 (void) GetNextToken(q,&q,extent,token);
3627 region.height=CastDoubleToSizeT(GetDrawValue(token,
3629 if (token == next_token)
3630 ThrowPointExpectedException(token,exception);
3631 for (p=q; *q !=
'\0'; )
3633 if (GetNextToken(q,&q,extent,token) < 1)
3635 if (LocaleCompare(token,
"pop") != 0)
3637 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3638 if (LocaleCompare(token,
"pattern") != 0)
3642 if ((q == (
char *) NULL) || (p == (
char *) NULL) ||
3643 ((q-4) < p) || ((
size_t) (q-p+4+1) > extent))
3648 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3649 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3650 (void) SetImageArtifact(image,key,token);
3651 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3653 (void) FormatLocaleString(geometry,MagickPathExtent,
3654 "%.17gx%.17g%+.20g%+.20g",(
double) region.width,(
double)
3655 region.height,(
double) region.x,(
double) region.y);
3656 (void) SetImageArtifact(image,key,geometry);
3657 (void) GetNextToken(q,&q,extent,token);
3660 if (LocaleCompare(
"symbol",token) == 0)
3663 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3676 if (LocaleCompare(
"rectangle",keyword) == 0)
3678 primitive_type=RectanglePrimitive;
3681 if (LocaleCompare(
"rotate",keyword) == 0)
3683 (void) GetNextToken(q,&q,extent,token);
3684 angle=GetDrawValue(token,&next_token);
3685 if (token == next_token)
3686 ThrowPointExpectedException(token,exception);
3687 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3688 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3689 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3690 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3693 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3695 primitive_type=RoundRectanglePrimitive;
3704 if (LocaleCompare(
"scale",keyword) == 0)
3706 (void) GetNextToken(q,&q,extent,token);
3707 affine.sx=GetDrawValue(token,&next_token);
3708 if (token == next_token)
3709 ThrowPointExpectedException(token,exception);
3710 (void) GetNextToken(q,&q,extent,token);
3711 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3712 ThrowPointExpectedException(token,exception);
3714 (void) GetNextToken(q,&q,extent,token);
3715 affine.sy=GetDrawValue(token,&next_token);
3716 if (token == next_token)
3717 ThrowPointExpectedException(token,exception);
3720 if (LocaleCompare(
"skewX",keyword) == 0)
3722 (void) GetNextToken(q,&q,extent,token);
3723 angle=GetDrawValue(token,&next_token);
3724 if (token == next_token)
3725 ThrowPointExpectedException(token,exception);
3726 affine.ry=sin(DegreesToRadians(angle));
3729 if (LocaleCompare(
"skewY",keyword) == 0)
3731 (void) GetNextToken(q,&q,extent,token);
3732 angle=GetDrawValue(token,&next_token);
3733 if (token == next_token)
3734 ThrowPointExpectedException(token,exception);
3735 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3738 if (LocaleCompare(
"stop-color",keyword) == 0)
3744 if (number_stops == 1)
3745 stops=(StopInfo *) AcquireQuantumMemory(2,
sizeof(*stops));
3747 if (number_stops > 2)
3748 stops=(StopInfo *) ResizeQuantumMemory(stops,number_stops,
3750 if (stops == (StopInfo *) NULL)
3752 (void) ThrowMagickException(exception,GetMagickModule(),
3753 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3758 (void) GetNextToken(q,&q,extent,token);
3759 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3760 &stop_color,exception);
3761 stops[number_stops-1].color=stop_color;
3762 (void) GetNextToken(q,&q,extent,token);
3763 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3764 stops[number_stops-1].offset=factor*GetDrawValue(token,
3766 if (token == next_token)
3767 ThrowPointExpectedException(token,exception);
3770 if (LocaleCompare(
"stroke",keyword) == 0)
3775 (void) GetNextToken(q,&q,extent,token);
3776 if (graphic_context[n]->clip_path != MagickFalse)
3778 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3779 if (mvg_class != (
const char *) NULL)
3781 (void) DrawPatternPath(image,draw_info,mvg_class,
3782 &graphic_context[n]->stroke_pattern,exception);
3785 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3786 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3788 (void) DrawPatternPath(image,draw_info,token,
3789 &graphic_context[n]->stroke_pattern,exception);
3792 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3793 &graphic_context[n]->stroke,exception);
3794 if (graphic_context[n]->stroke_alpha != (
double) OpaqueAlpha)
3795 graphic_context[n]->stroke.alpha=
3796 graphic_context[n]->stroke_alpha;
3799 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3801 (void) GetNextToken(q,&q,extent,token);
3802 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3803 MagickTrue : MagickFalse;
3806 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3808 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3809 graphic_context[n]->dash_pattern=(
double *)
3810 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3811 if (IsValidPoint(q) != MagickFalse)
3817 (void) GetNextToken(r,&r,extent,token);
3818 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3819 ThrowPointExpectedException(token,exception);
3821 (void) GetNextToken(r,&r,extent,token);
3822 for (x=0; IsValidPoint(token) != MagickFalse; x++)
3824 (void) GetNextToken(r,&r,extent,token);
3826 (void) GetNextToken(r,&r,extent,token);
3828 graphic_context[n]->dash_pattern=(
double *)
3829 AcquireQuantumMemory((
size_t) (2*x+2),
3830 sizeof(*graphic_context[n]->dash_pattern));
3831 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3833 (void) ThrowMagickException(exception,GetMagickModule(),
3834 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3839 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3840 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3841 for (j=0; j < x; j++)
3843 (void) GetNextToken(q,&q,extent,token);
3844 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3845 ThrowPointExpectedException(token,exception);
3847 (void) GetNextToken(q,&q,extent,token);
3848 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3850 if (token == next_token)
3851 ThrowPointExpectedException(token,exception);
3852 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3855 if (((x & 0x01) != 0) && (j == x))
3856 for ( ; j < (2*x); j++)
3857 graphic_context[n]->dash_pattern[j]=
3858 graphic_context[n]->dash_pattern[j-x];
3859 graphic_context[n]->dash_pattern[j]=0.0;
3862 (void) GetNextToken(q,&q,extent,token);
3865 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3867 (void) GetNextToken(q,&q,extent,token);
3868 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3869 if (token == next_token)
3870 ThrowPointExpectedException(token,exception);
3873 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3878 (void) GetNextToken(q,&q,extent,token);
3879 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3885 graphic_context[n]->linecap=(LineCap) linecap;
3888 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3893 (void) GetNextToken(q,&q,extent,token);
3894 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3901 graphic_context[n]->linejoin=(LineJoin) linejoin;
3904 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3906 (void) GetNextToken(q,&q,extent,token);
3907 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3910 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3915 (void) GetNextToken(q,&q,extent,token);
3916 if (graphic_context[n]->clip_path != MagickFalse)
3918 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3919 opacity=MagickMin(MagickMax(factor*GetDrawValue(token,&next_token),
3921 if (token == next_token)
3922 ThrowPointExpectedException(token,exception);
3923 if (graphic_context[n]->compliance == SVGCompliance)
3924 graphic_context[n]->stroke_alpha*=opacity;
3926 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3927 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3928 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3930 graphic_context[n]->stroke.alpha=(MagickRealType)
3931 ClampToQuantum((
double) QuantumRange*opacity);
3932 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3935 if (LocaleCompare(
"stroke-width",keyword) == 0)
3937 (void) GetNextToken(q,&q,extent,token);
3938 if (graphic_context[n]->clip_path != MagickFalse)
3940 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3941 if ((token == next_token) ||
3942 (graphic_context[n]->stroke_width < 0.0))
3943 ThrowPointExpectedException(token,exception);
3952 if (LocaleCompare(
"text",keyword) == 0)
3954 primitive_type=TextPrimitive;
3958 if (LocaleCompare(
"text-align",keyword) == 0)
3963 (void) GetNextToken(q,&q,extent,token);
3964 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3970 graphic_context[n]->align=(AlignType) align;
3973 if (LocaleCompare(
"text-anchor",keyword) == 0)
3978 (void) GetNextToken(q,&q,extent,token);
3979 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3985 graphic_context[n]->align=(AlignType) align;
3988 if (LocaleCompare(
"text-antialias",keyword) == 0)
3990 (void) GetNextToken(q,&q,extent,token);
3991 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
3992 MagickTrue : MagickFalse;
3995 if (LocaleCompare(
"text-undercolor",keyword) == 0)
3997 (void) GetNextToken(q,&q,extent,token);
3998 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3999 &graphic_context[n]->undercolor,exception);
4002 if (LocaleCompare(
"translate",keyword) == 0)
4004 (void) GetNextToken(q,&q,extent,token);
4005 affine.tx=GetDrawValue(token,&next_token);
4006 if (token == next_token)
4007 ThrowPointExpectedException(token,exception);
4008 (void) GetNextToken(q,&q,extent,token);
4009 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4010 ThrowPointExpectedException(token,exception);
4012 (void) GetNextToken(q,&q,extent,token);
4013 affine.ty=GetDrawValue(token,&next_token);
4014 if (token == next_token)
4015 ThrowPointExpectedException(token,exception);
4025 if (LocaleCompare(
"use",keyword) == 0)
4033 (void) GetNextToken(q,&q,extent,token);
4034 use=(
const char *) GetValueFromSplayTree(macros,token);
4035 if (use != (
const char *) NULL)
4037 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4038 if (draw_info->macro_expansion != (
size_t *) NULL)
4040 if (*draw_info->macro_expansion >= MacroExpansionLimit)
4042 (void) ThrowMagickException(exception,GetMagickModule(),
4043 DrawError,
"NonconformingDrawingPrimitiveDefinition",
4045 clone_info=DestroyDrawInfo(clone_info);
4046 return(MagickFalse);
4048 (*draw_info->macro_expansion)++;
4050 (void) CloneString(&clone_info->primitive,use);
4051 status=RenderMVGContent(image,clone_info,depth+1,exception);
4052 clone_info=DestroyDrawInfo(clone_info);
4062 if (LocaleCompare(
"viewbox",keyword) == 0)
4064 (void) GetNextToken(q,&q,extent,token);
4065 graphic_context[n]->viewbox.x=CastDoubleToSsizeT(ceil(
4066 GetDrawValue(token,&next_token)-0.5));
4067 if (token == next_token)
4068 ThrowPointExpectedException(token,exception);
4069 (void) GetNextToken(q,&q,extent,token);
4070 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4071 ThrowPointExpectedException(token,exception);
4073 (void) GetNextToken(q,&q,extent,token);
4074 graphic_context[n]->viewbox.y=CastDoubleToSsizeT(
4075 ceil(GetDrawValue(token,&next_token)-0.5));
4076 if (token == next_token)
4077 ThrowPointExpectedException(token,exception);
4078 (void) GetNextToken(q,&q,extent,token);
4079 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4080 ThrowPointExpectedException(token,exception);
4082 (void) GetNextToken(q,&q,extent,token);
4083 graphic_context[n]->viewbox.width=CastDoubleToSizeT(floor(
4084 GetDrawValue(token,&next_token)+0.5));
4085 if (token == next_token)
4086 ThrowPointExpectedException(token,exception);
4087 (void) GetNextToken(q,&q,extent,token);
4088 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4089 ThrowPointExpectedException(token,exception);
4091 (void) GetNextToken(q,&q,extent,token);
4092 graphic_context[n]->viewbox.height=CastDoubleToSizeT(floor(
4093 GetDrawValue(token,&next_token)+0.5));
4094 if (token == next_token)
4095 ThrowPointExpectedException(token,exception);
4104 if (LocaleCompare(
"word-spacing",keyword) == 0)
4106 (void) GetNextToken(q,&q,extent,token);
4107 graphic_context[n]->interword_spacing=GetDrawValue(token,
4109 if (token == next_token)
4110 ThrowPointExpectedException(token,exception);
4122 if (status == MagickFalse)
4124 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4125 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4126 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4127 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4129 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4130 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4131 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4132 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4133 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4135 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4138 if (primitive_type == UndefinedPrimitive)
4142 if (number_stops > 1)
4147 type=LinearGradient;
4148 if (draw_info->gradient.type == RadialGradient)
4149 type=RadialGradient;
4150 (void) GradientImage(image,type,PadSpread,stops,number_stops,
4153 if (number_stops > 0)
4154 stops=(StopInfo *) RelinquishMagickMemory(stops);
4156 if ((draw_info->debug != MagickFalse) && (q > p))
4157 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int)
4164 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4165 if (primitive_info[i].text != (
char *) NULL)
4166 primitive_info[i].text=DestroyString(primitive_info[i].text);
4170 primitive_info[0].primitive=primitive_type;
4171 primitive_info[0].point.x=0.0;
4172 primitive_info[0].point.y=0.0;
4173 primitive_info[0].coordinates=0;
4174 primitive_info[0].method=FloodfillMethod;
4175 primitive_info[0].closed_subpath=MagickFalse;
4176 for (x=0; *q !=
'\0'; x++)
4181 if (IsValidPoint(q) == MagickFalse)
4183 (void) GetNextToken(q,&q,extent,token);
4184 point.x=GetDrawValue(token,&next_token);
4185 if (token == next_token)
4186 ThrowPointExpectedException(token,exception);
4187 (void) GetNextToken(q,&q,extent,token);
4188 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4189 ThrowPointExpectedException(token,exception);
4191 (void) GetNextToken(q,&q,extent,token);
4192 point.y=GetDrawValue(token,&next_token);
4193 if (token == next_token)
4194 ThrowPointExpectedException(token,exception);
4195 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4197 (void) GetNextToken(q,&q,extent,token);
4198 primitive_info[i].primitive=primitive_type;
4199 primitive_info[i].point=point;
4200 primitive_info[i].coordinates=0;
4201 primitive_info[i].method=FloodfillMethod;
4202 primitive_info[i].closed_subpath=MagickFalse;
4205 if (i < (ssize_t) number_points)
4207 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4209 primitive_info=(*mvg_info.primitive_info);
4210 if (status == MagickFalse)
4213 if (status == MagickFalse)
4215 if (primitive_info[j].text != (
char *) NULL)
4216 primitive_info[j].text=DestroyString(primitive_info[j].text);
4217 primitive_info[j].primitive=primitive_type;
4218 primitive_info[j].coordinates=(size_t) x;
4219 primitive_info[j].method=FloodfillMethod;
4220 primitive_info[j].closed_subpath=MagickFalse;
4224 bounds.x1=primitive_info[j].point.x;
4225 bounds.y1=primitive_info[j].point.y;
4226 bounds.x2=primitive_info[j].point.x;
4227 bounds.y2=primitive_info[j].point.y;
4228 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4230 point=primitive_info[j+k].point;
4231 if (point.x < bounds.x1)
4233 if (point.y < bounds.y1)
4235 if (point.x > bounds.x2)
4237 if (point.y > bounds.y2)
4243 coordinates=(double) primitive_info[j].coordinates;
4244 switch (primitive_type)
4246 case RectanglePrimitive:
4251 case RoundRectanglePrimitive:
4258 alpha=bounds.x2-bounds.x1;
4259 beta=bounds.y2-bounds.y1;
4260 radius=hypot(alpha,beta);
4262 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4263 BezierQuantum+360.0;
4266 case BezierPrimitive:
4268 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4277 (void) GetNextToken(q,&q,extent,token);
4280 for (s=token; *s !=
'\0'; s=t)
4285 value=GetDrawValue(s,&t);
4294 for (s=token; *s !=
'\0'; s++)
4295 if (strspn(s,
"AaCcQqSsTt") != 0)
4296 coordinates+=(20.0*BezierQuantum)+360.0;
4302 if (status == MagickFalse)
4304 if (((
size_t) (i+coordinates)) >= number_points)
4309 number_points+=(size_t) coordinates+1;
4310 if (number_points < (
size_t) coordinates)
4312 (void) ThrowMagickException(exception,GetMagickModule(),
4313 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4319 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points+
4320 (
double) coordinates+1.0);
4321 primitive_info=(*mvg_info.primitive_info);
4322 if (status == MagickFalse)
4325 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,
4326 PrimitiveExtentPad);
4327 primitive_info=(*mvg_info.primitive_info);
4328 if (status == MagickFalse)
4331 switch (primitive_type)
4333 case PointPrimitive:
4336 if (primitive_info[j].coordinates != 1)
4341 status&=(MagickStatusType) TracePoint(primitive_info+j,
4342 primitive_info[j].point);
4343 primitive_info=(*mvg_info.primitive_info);
4344 if (status == MagickFalse)
4346 i=j+(ssize_t) primitive_info[j].coordinates;
4351 if (primitive_info[j].coordinates != 2)
4356 status&=(MagickStatusType) TraceLine(primitive_info+j,
4357 primitive_info[j].point,primitive_info[j+1].point);
4358 primitive_info=(*mvg_info.primitive_info);
4359 if (status == MagickFalse)
4361 i=j+(ssize_t) primitive_info[j].coordinates;
4364 case RectanglePrimitive:
4366 if (primitive_info[j].coordinates != 2)
4371 status&=(MagickStatusType) TraceRectangle(primitive_info+j,
4372 primitive_info[j].point,primitive_info[j+1].point);
4373 primitive_info=(*mvg_info.primitive_info);
4374 if (status == MagickFalse)
4376 i=j+(ssize_t) primitive_info[j].coordinates;
4379 case RoundRectanglePrimitive:
4381 if (primitive_info[j].coordinates != 3)
4386 if ((primitive_info[j+2].point.x < 0.0) ||
4387 (primitive_info[j+2].point.y < 0.0))
4392 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4397 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4402 status&=(MagickStatusType) TraceRoundRectangle(&mvg_info,
4403 primitive_info[j].point,primitive_info[j+1].point,
4404 primitive_info[j+2].point);
4405 primitive_info=(*mvg_info.primitive_info);
4406 if (status == MagickFalse)
4408 i=j+(ssize_t) primitive_info[j].coordinates;
4413 if (primitive_info[j].coordinates != 3)
4418 status&=(MagickStatusType) TraceArc(&mvg_info,primitive_info[j].point,
4419 primitive_info[j+1].point,primitive_info[j+2].point);
4420 primitive_info=(*mvg_info.primitive_info);
4421 if (status == MagickFalse)
4423 i=j+(ssize_t) primitive_info[j].coordinates;
4426 case EllipsePrimitive:
4428 if (primitive_info[j].coordinates != 3)
4433 if ((primitive_info[j+1].point.x < 0.0) ||
4434 (primitive_info[j+1].point.y < 0.0))
4439 status&=(MagickStatusType) TraceEllipse(&mvg_info,
4440 primitive_info[j].point,primitive_info[j+1].point,
4441 primitive_info[j+2].point);
4442 primitive_info=(*mvg_info.primitive_info);
4443 if (status == MagickFalse)
4445 i=j+(ssize_t) primitive_info[j].coordinates;
4448 case CirclePrimitive:
4450 if (primitive_info[j].coordinates != 2)
4455 status&=(MagickStatusType) TraceCircle(&mvg_info,
4456 primitive_info[j].point,primitive_info[j+1].point);
4457 primitive_info=(*mvg_info.primitive_info);
4458 if (status == MagickFalse)
4460 i=j+(ssize_t) primitive_info[j].coordinates;
4463 case PolylinePrimitive:
4465 if (primitive_info[j].coordinates < 1)
4472 case PolygonPrimitive:
4474 if (primitive_info[j].coordinates < 3)
4479 primitive_info[i]=primitive_info[j];
4480 primitive_info[i].coordinates=0;
4481 primitive_info[j].coordinates++;
4482 primitive_info[j].closed_subpath=MagickTrue;
4486 case BezierPrimitive:
4488 if (primitive_info[j].coordinates < 3)
4493 status&=(MagickStatusType) TraceBezier(&mvg_info,
4494 primitive_info[j].coordinates);
4495 primitive_info=(*mvg_info.primitive_info);
4496 if (status == MagickFalse)
4498 i=j+(ssize_t) primitive_info[j].coordinates;
4503 coordinates=(double) TracePath(&mvg_info,token,exception);
4504 primitive_info=(*mvg_info.primitive_info);
4505 if (status == MagickFalse)
4507 if (coordinates < 0.0)
4512 i=(ssize_t) (j+coordinates);
4515 case AlphaPrimitive:
4516 case ColorPrimitive:
4521 if (primitive_info[j].coordinates != 1)
4526 (void) GetNextToken(q,&q,extent,token);
4527 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4533 primitive_info[j].method=(PaintMethod) method;
4538 if (primitive_info[j].coordinates != 1)
4544 (void) GetNextToken(q,&q,extent,token);
4545 (void) CloneString(&primitive_info[j].text,token);
4549 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4550 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4551 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4553 mvg_info.point=primitive_info->point;
4554 primitive_info->point.x+=cursor;
4558 mvg_info.point=primitive_info->point;
4561 clone_info->render=MagickFalse;
4562 clone_info->text=AcquireString(token);
4563 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,
4564 &metrics,exception);
4565 clone_info=DestroyDrawInfo(clone_info);
4566 cursor+=metrics.width;
4567 if (graphic_context[n]->compliance != SVGCompliance)
4571 case ImagePrimitive:
4573 if (primitive_info[j].coordinates != 2)
4578 (void) GetNextToken(q,&q,extent,token);
4579 (void) CloneString(&primitive_info[j].text,token);
4586 primitive_info[i].primitive=UndefinedPrimitive;
4587 if ((draw_info->debug != MagickFalse) && (q > p))
4588 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int) (q-p),p);
4592 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4593 &graphic_context[n]->affine));
4594 primitive_info=(*mvg_info.primitive_info);
4597 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4598 graphic_context[n]->stroke_width);
4599 primitive_info=(*mvg_info.primitive_info);
4607 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4609 point=primitive_info[i].point;
4610 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4611 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4612 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4613 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4614 point=primitive_info[i].point;
4615 if (point.x < graphic_context[n]->bounds.x1)
4616 graphic_context[n]->bounds.x1=point.x;
4617 if (point.y < graphic_context[n]->bounds.y1)
4618 graphic_context[n]->bounds.y1=point.y;
4619 if (point.x > graphic_context[n]->bounds.x2)
4620 graphic_context[n]->bounds.x2=point.x;
4621 if (point.y > graphic_context[n]->bounds.y2)
4622 graphic_context[n]->bounds.y2=point.y;
4623 if (primitive_info[i].primitive == ImagePrimitive)
4625 if (i >= (ssize_t) number_points)
4626 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4628 if (graphic_context[n]->render != MagickFalse)
4630 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4631 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4632 (LocaleCompare(graphic_context[n]->clip_mask,
4633 graphic_context[n-1]->clip_mask) != 0))
4638 clip_path=(
const char *) GetValueFromSplayTree(macros,
4639 graphic_context[n]->clip_mask);
4640 if (clip_path != (
const char *) NULL)
4641 (void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4643 status&=(MagickStatusType) DrawClipPath(image,graphic_context[n],
4644 graphic_context[n]->clip_mask,exception);
4646 status&=(MagickStatusType) DrawPrimitive(image,graphic_context[n],
4647 primitive_info,exception);
4649 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4651 if (proceed == MagickFalse)
4656 if (draw_info->debug != MagickFalse)
4657 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4661 macros=DestroySplayTree(macros);
4662 token=DestroyString(token);
4663 if (primitive_info != (PrimitiveInfo *) NULL)
4665 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4666 if (primitive_info[i].text != (
char *) NULL)
4667 primitive_info[i].text=DestroyString(primitive_info[i].text);
4668 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4670 primitive=DestroyString(primitive);
4671 if (stops != (StopInfo *) NULL)
4672 stops=(StopInfo *) RelinquishMagickMemory(stops);
4673 for ( ; n >= 0; n--)
4674 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4675 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
4676 if ((status == MagickFalse) && (exception->severity < ErrorException))
4677 ThrowBinaryException(DrawError,
"NonconformingDrawingPrimitiveDefinition",
4679 return(status != 0 ? MagickTrue : MagickFalse);
4682MagickExport MagickBooleanType DrawImage(Image *image,
const DrawInfo *draw_info,
4683 ExceptionInfo *exception)
4689 macro_expansion = 0;
4691 ((DrawInfo *) draw_info)->macro_expansion=(¯o_expansion);
4692 status=RenderMVGContent(image,draw_info,0,exception);
4693 ((DrawInfo *) draw_info)->macro_expansion=(
size_t *) NULL;
4728MagickExport MagickBooleanType DrawPatternPath(Image *image,
4729 const DrawInfo *draw_info,
const char *name,Image **pattern,
4730 ExceptionInfo *exception)
4733 property[MagickPathExtent];
4749 assert(image != (Image *) NULL);
4750 assert(image->signature == MagickCoreSignature);
4751 assert(draw_info != (
const DrawInfo *) NULL);
4752 assert(name != (
const char *) NULL);
4753 if (IsEventLogging() != MagickFalse)
4754 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4755 (void) FormatLocaleString(property,MagickPathExtent,
"%s",name);
4756 path=GetImageArtifact(image,property);
4757 if (path == (
const char *) NULL)
4758 return(MagickFalse);
4759 (void) FormatLocaleString(property,MagickPathExtent,
"%s-geometry",name);
4760 geometry=GetImageArtifact(image,property);
4761 if (geometry == (
const char *) NULL)
4762 return(MagickFalse);
4763 if ((*pattern) != (Image *) NULL)
4764 *pattern=DestroyImage(*pattern);
4765 image_info=AcquireImageInfo();
4766 image_info->size=AcquireString(geometry);
4767 *pattern=AcquireImage(image_info,exception);
4768 image_info=DestroyImageInfo(image_info);
4769 (void) QueryColorCompliance(
"#00000000",AllCompliance,
4770 &(*pattern)->background_color,exception);
4771 (void) SetImageBackgroundColor(*pattern,exception);
4772 if (draw_info->debug != MagickFalse)
4773 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4774 "begin pattern-path %s %s",name,geometry);
4775 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4776 if (clone_info->fill_pattern != (Image *) NULL)
4777 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4778 if (clone_info->stroke_pattern != (Image *) NULL)
4779 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4780 (void) FormatLocaleString(property,MagickPathExtent,
"%s-type",name);
4781 type=GetImageArtifact(image,property);
4782 if (type != (
const char *) NULL)
4783 clone_info->gradient.type=(GradientType) ParseCommandOption(
4784 MagickGradientOptions,MagickFalse,type);
4785 (void) CloneString(&clone_info->primitive,path);
4786 status=RenderMVGContent(*pattern,clone_info,0,exception);
4787 clone_info=DestroyDrawInfo(clone_info);
4788 if (draw_info->debug != MagickFalse)
4789 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4824static PolygonInfo **DestroyPolygonTLS(PolygonInfo **polygon_info)
4829 assert(polygon_info != (PolygonInfo **) NULL);
4830 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4831 if (polygon_info[i] != (PolygonInfo *) NULL)
4832 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4833 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
4834 return(polygon_info);
4837static PolygonInfo **AcquirePolygonTLS(
const PrimitiveInfo *primitive_info,
4838 ExceptionInfo *exception)
4841 *magick_restrict path_info;
4849 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4850 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
4851 sizeof(*polygon_info));
4852 if (polygon_info == (PolygonInfo **) NULL)
4854 (void) ThrowMagickException(exception,GetMagickModule(),
4855 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4856 return((PolygonInfo **) NULL);
4858 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4859 path_info=ConvertPrimitiveToPath(primitive_info,exception);
4860 if (path_info == (PathInfo *) NULL)
4861 return(DestroyPolygonTLS(polygon_info));
4862 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4863 if (polygon_info[0] == (PolygonInfo *) NULL)
4865 (void) ThrowMagickException(exception,GetMagickModule(),
4866 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4867 return(DestroyPolygonTLS(polygon_info));
4869 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
4870 return(polygon_info);
4873static MagickBooleanType ClonePolygonEdgesTLS(PolygonInfo **polygon_info,
4874 const size_t number_threads,ExceptionInfo *exception)
4879 for (i=1; i < (ssize_t) number_threads; i++)
4887 polygon_info[i]=(PolygonInfo *) AcquireMagickMemory(
4888 sizeof(*polygon_info[i]));
4889 if (polygon_info[i] == (PolygonInfo *) NULL)
4891 (void) ThrowMagickException(exception,GetMagickModule(),
4892 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4893 return(MagickFalse);
4895 polygon_info[i]->number_edges=0;
4896 edge_info=polygon_info[0]->edges;
4897 polygon_info[i]->edges=(EdgeInfo *) AcquireQuantumMemory(
4898 polygon_info[0]->number_edges,
sizeof(*edge_info));
4899 if (polygon_info[i]->edges == (EdgeInfo *) NULL)
4901 (void) ThrowMagickException(exception,GetMagickModule(),
4902 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4903 return(MagickFalse);
4905 (void) memcpy(polygon_info[i]->edges,edge_info,
4906 polygon_info[0]->number_edges*
sizeof(*edge_info));
4907 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4908 polygon_info[i]->edges[j].points=(PointInfo *) NULL;
4909 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4910 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4912 edge_info=polygon_info[0]->edges+j;
4913 polygon_info[i]->edges[j].points=(PointInfo *) AcquireQuantumMemory(
4914 edge_info->number_points,
sizeof(*edge_info));
4915 if (polygon_info[i]->edges[j].points == (PointInfo *) NULL)
4917 (void) ThrowMagickException(exception,GetMagickModule(),
4918 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4919 return(MagickFalse);
4921 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4922 edge_info->number_points*
sizeof(*edge_info->points));
4928static size_t DestroyEdge(PolygonInfo *polygon_info,
const ssize_t edge)
4930 assert(edge < (ssize_t) polygon_info->number_edges);
4931 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
4932 polygon_info->edges[edge].points);
4933 polygon_info->number_edges--;
4934 if (edge < (ssize_t) polygon_info->number_edges)
4935 (void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4936 (polygon_info->number_edges-(
size_t) edge)*
sizeof(*polygon_info->edges));
4937 return(polygon_info->number_edges);
4940static double GetFillAlpha(PolygonInfo *polygon_info,
const double mid,
4941 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4942 const ssize_t y,
double *stroke_alpha)
4969 p=polygon_info->edges;
4970 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4972 if ((
double) y <= (p->bounds.y1-mid-0.5))
4974 if ((
double) y > (p->bounds.y2+mid+0.5))
4977 (void) DestroyEdge(polygon_info,j--);
4980 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
4981 ((
double) x > (p->bounds.x2+mid+0.5)))
4983 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
4984 for ( ; i < (ssize_t) p->number_points; i++)
4986 if ((
double) y <= (p->points[i-1].y-mid-0.5))
4988 if ((
double) y > (p->points[i].y+mid+0.5))
4990 if (p->scanline != (
double) y)
4992 p->scanline=(double) y;
4993 p->highwater=(size_t) i;
4999 delta.x=(q+1)->x-q->x;
5000 delta.y=(q+1)->y-q->y;
5001 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
5007 delta.x=(double) x-q->x;
5008 delta.y=(double) y-q->y;
5009 distance=delta.x*delta.x+delta.y*delta.y;
5013 alpha=delta.x*delta.x+delta.y*delta.y;
5019 delta.x=(double) x-(q+1)->x;
5020 delta.y=(double) y-(q+1)->y;
5021 distance=delta.x*delta.x+delta.y*delta.y;
5028 alpha=MagickSafeReciprocal(alpha);
5029 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
5030 distance=alpha*beta*beta;
5037 if (p->ghostline == MagickFalse)
5040 if ((*stroke_alpha < 1.0) &&
5041 (distance <= ((alpha+0.25)*(alpha+0.25))))
5044 if (distance <= ((alpha+0.25)*(alpha+0.25)))
5049 if (fabs(distance-1.0) >= MagickEpsilon)
5050 beta=sqrt((
double) distance);
5052 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
5053 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
5057 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
5059 if (distance <= 0.0)
5066 if (fabs(beta) < MagickEpsilon)
5069 if (fabs(distance-1.0) >= MagickEpsilon)
5070 beta=sqrt(distance);
5073 if (subpath_alpha < (alpha*alpha))
5074 subpath_alpha=alpha*alpha;
5080 if (fill == MagickFalse)
5082 if (subpath_alpha >= 1.0)
5088 p=polygon_info->edges;
5089 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
5091 if ((
double) y <= p->bounds.y1)
5093 if (((
double) y > p->bounds.y2) || ((
double) x <= p->bounds.x1))
5095 if ((
double) x > p->bounds.x2)
5097 winding_number+=p->direction != 0 ? 1 : -1;
5100 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5101 for ( ; i < (ssize_t) (p->number_points-1); i++)
5102 if ((
double) y <= p->points[i].y)
5105 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
5106 winding_number+=p->direction != 0 ? 1 : -1;
5108 if (fill_rule != NonZeroRule)
5110 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
5114 if (MagickAbsoluteValue(winding_number) != 0)
5116 return(subpath_alpha);
5119static MagickBooleanType DrawPolygonPrimitive(Image *image,
5120 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5121 ExceptionInfo *exception)
5123 typedef struct _ExtentInfo
5152 **magick_restrict polygon_info;
5164 assert(image != (Image *) NULL);
5165 assert(image->signature == MagickCoreSignature);
5166 assert(draw_info != (DrawInfo *) NULL);
5167 assert(draw_info->signature == MagickCoreSignature);
5168 assert(primitive_info != (PrimitiveInfo *) NULL);
5169 if (IsEventLogging() != MagickFalse)
5170 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5171 if (primitive_info->coordinates <= 1)
5176 polygon_info=AcquirePolygonTLS(primitive_info,exception);
5177 if (polygon_info == (PolygonInfo **) NULL)
5178 return(MagickFalse);
5179 if (draw_info->debug != MagickFalse)
5180 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5181 fill=(primitive_info->method == FillToBorderMethod) ||
5182 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5183 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5184 bounds=polygon_info[0]->edges[0].bounds;
5185 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5186 if (IsStringTrue(artifact) != MagickFalse)
5187 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
5188 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5190 p=polygon_info[0]->edges+i;
5191 if (p->bounds.x1 < bounds.x1)
5192 bounds.x1=p->bounds.x1;
5193 if (p->bounds.y1 < bounds.y1)
5194 bounds.y1=p->bounds.y1;
5195 if (p->bounds.x2 > bounds.x2)
5196 bounds.x2=p->bounds.x2;
5197 if (p->bounds.y2 > bounds.y2)
5198 bounds.y2=p->bounds.y2;
5200 bounds.x1-=(mid+1.0);
5201 bounds.y1-=(mid+1.0);
5202 bounds.x2+=(mid+1.0);
5203 bounds.y2+=(mid+1.0);
5204 if ((bounds.x1 >= (
double) image->columns) ||
5205 (bounds.y1 >= (
double) image->rows) ||
5206 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5208 polygon_info=DestroyPolygonTLS(polygon_info);
5211 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5212 (
double) image->columns-1.0 : bounds.x1;
5213 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5214 (
double) image->rows-1.0 : bounds.y1;
5215 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5216 (
double) image->columns-1.0 : bounds.x2;
5217 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5218 (
double) image->rows-1.0 : bounds.y2;
5219 poly_extent.x1=CastDoubleToSsizeT(ceil(bounds.x1-0.5));
5220 poly_extent.y1=CastDoubleToSsizeT(ceil(bounds.y1-0.5));
5221 poly_extent.x2=CastDoubleToSsizeT(floor(bounds.x2+0.5));
5222 poly_extent.y2=CastDoubleToSsizeT(floor(bounds.y2+0.5));
5223 number_threads=(size_t) GetMagickNumberThreads(image,image,(
size_t)
5224 (poly_extent.y2-poly_extent.y1+1),1);
5225 status=ClonePolygonEdgesTLS(polygon_info,number_threads,exception);
5226 if (status == MagickFalse)
5228 polygon_info=DestroyPolygonTLS(polygon_info);
5231 image_view=AcquireAuthenticCacheView(image,exception);
5232 if ((primitive_info->coordinates == 1) ||
5233 (polygon_info[0]->number_edges == 0))
5238#if defined(MAGICKCORE_OPENMP_SUPPORT)
5239 #pragma omp parallel for schedule(static) shared(status) \
5240 num_threads((int) number_threads)
5242 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5253 if (status == MagickFalse)
5256 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5258 if (q == (Quantum *) NULL)
5263 GetPixelInfo(image,&pixel);
5264 for ( ; x <= poly_extent.x2; x++)
5266 if ((x == CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5))) &&
5267 (y == CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5))))
5269 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&pixel,
5271 SetPixelViaPixelInfo(image,&pixel,q);
5273 q+=(ptrdiff_t) GetPixelChannels(image);
5275 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5278 image_view=DestroyCacheView(image_view);
5279 polygon_info=DestroyPolygonTLS(polygon_info);
5280 if (draw_info->debug != MagickFalse)
5281 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5282 " end draw-polygon");
5288#if defined(MAGICKCORE_OPENMP_SUPPORT)
5289 #pragma omp parallel for schedule(static) shared(status) \
5290 num_threads((int) number_threads)
5292 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5295 id = GetOpenMPThreadId();
5303 if (status == MagickFalse)
5305 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5306 (poly_extent.x2-poly_extent.x1+1),1,exception);
5307 if (q == (Quantum *) NULL)
5312 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5325 fill_alpha=GetFillAlpha(polygon_info[
id],mid,fill,draw_info->fill_rule,
5327 if (draw_info->stroke_antialias == MagickFalse)
5329 fill_alpha=fill_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5330 stroke_alpha=stroke_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5332 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&fill_color,
5334 CompositePixelOver(image,&fill_color,fill_alpha*fill_color.alpha,q,
5335 (
double) GetPixelAlpha(image,q),q);
5336 GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&stroke_color,
5338 CompositePixelOver(image,&stroke_color,stroke_alpha*stroke_color.alpha,q,
5339 (
double) GetPixelAlpha(image,q),q);
5340 q+=(ptrdiff_t) GetPixelChannels(image);
5342 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5345 image_view=DestroyCacheView(image_view);
5346 polygon_info=DestroyPolygonTLS(polygon_info);
5347 if (draw_info->debug != MagickFalse)
5348 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5381static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5407 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5408 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5409 switch (primitive_info->primitive)
5411 case AlphaPrimitive:
5413 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5414 "AlphaPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5415 methods[primitive_info->method]);
5418 case ColorPrimitive:
5420 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5421 "ColorPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5422 methods[primitive_info->method]);
5425 case ImagePrimitive:
5427 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5428 "ImagePrimitive %.17g,%.17g",(
double) x,(
double) y);
5431 case PointPrimitive:
5433 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5434 "PointPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5435 methods[primitive_info->method]);
5440 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5441 "TextPrimitive %.17g,%.17g",(
double) x,(
double) y);
5448 p=primitive_info[0].point;
5451 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5453 point=primitive_info[i].point;
5454 if (coordinates <= 0)
5456 coordinates=(ssize_t) primitive_info[i].coordinates;
5457 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5458 " begin open (%.17g)",(
double) coordinates);
5461 point=primitive_info[i].point;
5462 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5463 (fabs(q.y-point.y) >= MagickEpsilon))
5464 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5465 " %.17g: %.18g,%.18g",(
double) coordinates,point.x,point.y);
5467 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5468 " %.17g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5471 if (coordinates > 0)
5473 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5474 (fabs(p.y-point.y) >= MagickEpsilon))
5475 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.17g)",
5476 (
double) coordinates);
5478 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.17g)",
5479 (
double) coordinates);
5483MagickExport MagickBooleanType DrawPrimitive(Image *image,
5484 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5485 ExceptionInfo *exception)
5500 if (draw_info->debug != MagickFalse)
5502 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5503 " begin draw-primitive");
5504 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5505 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5506 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5507 draw_info->affine.tx,draw_info->affine.ty);
5510 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5511 ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
5512 (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
5513 status&=(MagickStatusType) SetImageColorspace(image,sRGBColorspace,
5515 if (draw_info->compliance == SVGCompliance)
5517 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5518 draw_info->clipping_mask,exception);
5519 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5520 draw_info->composite_mask,exception);
5522 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5523 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5524 image_view=AcquireAuthenticCacheView(image,exception);
5525 switch (primitive_info->primitive)
5527 case AlphaPrimitive:
5529 if ((image->alpha_trait & BlendPixelTrait) == 0)
5530 status&=(MagickStatusType) SetImageAlphaChannel(image,
5531 OpaqueAlphaChannel,exception);
5532 switch (primitive_info->method)
5543 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5544 if (q == (Quantum *) NULL)
5546 GetFillColor(draw_info,x,y,&pixel,exception);
5547 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5548 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5558 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5559 x,y,&target,exception);
5560 GetPixelInfo(image,&pixel);
5561 for (y=0; y < (ssize_t) image->rows; y++)
5566 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5568 if (q == (Quantum *) NULL)
5570 for (x=0; x < (ssize_t) image->columns; x++)
5572 GetPixelInfoPixel(image,q,&pixel);
5573 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5575 q+=(ptrdiff_t) GetPixelChannels(image);
5578 GetFillColor(draw_info,x,y,&pixel,exception);
5579 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5580 q+=(ptrdiff_t) GetPixelChannels(image);
5582 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5584 if (status == MagickFalse)
5589 case FloodfillMethod:
5590 case FillToBorderMethod:
5598 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5599 TileVirtualPixelMethod,x,y,&target,exception);
5600 if (primitive_info->method == FillToBorderMethod)
5602 target.red=(double) draw_info->border_color.red;
5603 target.green=(double) draw_info->border_color.green;
5604 target.blue=(double) draw_info->border_color.blue;
5606 channel_mask=SetImageChannelMask(image,AlphaChannel);
5607 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5608 &target,x,y,primitive_info->method == FloodfillMethod ?
5609 MagickFalse : MagickTrue,exception);
5610 (void) SetImageChannelMask(image,channel_mask);
5618 for (y=0; y < (ssize_t) image->rows; y++)
5623 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5625 if (q == (Quantum *) NULL)
5627 for (x=0; x < (ssize_t) image->columns; x++)
5629 GetFillColor(draw_info,x,y,&pixel,exception);
5630 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5631 q+=(ptrdiff_t) GetPixelChannels(image);
5633 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5635 if (status == MagickFalse)
5643 case ColorPrimitive:
5645 switch (primitive_info->method)
5656 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5657 if (q == (Quantum *) NULL)
5659 GetPixelInfo(image,&pixel);
5660 GetFillColor(draw_info,x,y,&pixel,exception);
5661 SetPixelViaPixelInfo(image,&pixel,q);
5662 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5672 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5673 x,y,&target,exception);
5674 for (y=0; y < (ssize_t) image->rows; y++)
5679 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5681 if (q == (Quantum *) NULL)
5683 for (x=0; x < (ssize_t) image->columns; x++)
5685 GetPixelInfoPixel(image,q,&pixel);
5686 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5688 q+=(ptrdiff_t) GetPixelChannels(image);
5691 GetFillColor(draw_info,x,y,&pixel,exception);
5692 SetPixelViaPixelInfo(image,&pixel,q);
5693 q+=(ptrdiff_t) GetPixelChannels(image);
5695 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5697 if (status == MagickFalse)
5702 case FloodfillMethod:
5703 case FillToBorderMethod:
5708 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5709 TileVirtualPixelMethod,x,y,&target,exception);
5710 if (primitive_info->method == FillToBorderMethod)
5712 target.red=(double) draw_info->border_color.red;
5713 target.green=(double) draw_info->border_color.green;
5714 target.blue=(double) draw_info->border_color.blue;
5716 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5717 &target,x,y,primitive_info->method == FloodfillMethod ?
5718 MagickFalse : MagickTrue,exception);
5726 GetPixelInfo(image,&pixel);
5727 for (y=0; y < (ssize_t) image->rows; y++)
5732 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5734 if (q == (Quantum *) NULL)
5736 for (x=0; x < (ssize_t) image->columns; x++)
5738 GetFillColor(draw_info,x,y,&pixel,exception);
5739 SetPixelViaPixelInfo(image,&pixel,q);
5740 q+=(ptrdiff_t) GetPixelChannels(image);
5742 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5744 if (status == MagickFalse)
5752 case ImagePrimitive:
5758 composite_geometry[MagickPathExtent];
5774 if (primitive_info->text == (
char *) NULL)
5776 clone_info=AcquireImageInfo();
5777 composite_images=(Image *) NULL;
5778 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5779 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5782 if (*primitive_info->text !=
'\0')
5787 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5789 (void) SetImageInfo(clone_info,1,exception);
5790 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5792 if (clone_info->size != (
char *) NULL)
5793 clone_info->size=DestroyString(clone_info->size);
5794 if (clone_info->extract != (
char *) NULL)
5795 clone_info->extract=DestroyString(clone_info->extract);
5796 clone_info->coder_depth=draw_info->image_info->coder_depth;
5797 composite_images=StrictReadImage(clone_info,exception);
5798 draw_info->image_info->coder_depth=clone_info->coder_depth;
5800 clone_info=DestroyImageInfo(clone_info);
5801 if (composite_images == (Image *) NULL)
5806 composite_image=RemoveFirstImageFromList(&composite_images);
5807 composite_images=DestroyImageList(composite_images);
5808 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5809 NULL,(
void *) NULL);
5810 x1=CastDoubleToSsizeT(ceil(primitive_info[1].point.x-0.5));
5811 y1=CastDoubleToSsizeT(ceil(primitive_info[1].point.y-0.5));
5812 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5813 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5818 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5819 "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y);
5820 composite_image->filter=image->filter;
5821 status&=(MagickStatusType) TransformImage(&composite_image,
5822 (
char *) NULL,composite_geometry,exception);
5824 if (composite_image->alpha_trait == UndefinedPixelTrait)
5825 status&=(MagickStatusType) SetImageAlphaChannel(composite_image,
5826 OpaqueAlphaChannel,exception);
5827 if (draw_info->alpha != OpaqueAlpha)
5828 status&=(MagickStatusType) SetImageAlpha(composite_image,
5829 draw_info->alpha,exception);
5830 SetGeometry(image,&geometry);
5831 image->gravity=draw_info->gravity;
5834 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5835 "%.17gx%.17g%+.20g%+.20g",(
double) composite_image->columns,(
double)
5836 composite_image->rows,(
double) geometry.x,(
double) geometry.y);
5837 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
5838 affine=draw_info->affine;
5839 affine.tx=(double) geometry.x;
5840 affine.ty=(double) geometry.y;
5841 composite_image->interpolate=image->interpolate;
5842 if ((draw_info->compose == OverCompositeOp) ||
5843 (draw_info->compose == SrcOverCompositeOp))
5844 status&=(MagickStatusType) DrawAffineImage(image,composite_image,
5847 status&=(MagickStatusType) CompositeImage(image,composite_image,
5848 draw_info->compose,MagickTrue,geometry.x,geometry.y,exception);
5849 composite_image=DestroyImage(composite_image);
5852 case PointPrimitive:
5860 if ((y < 0) || (y >= (ssize_t) image->rows))
5862 if ((x < 0) || (x >= (ssize_t) image->columns))
5864 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5865 if (q == (Quantum *) NULL)
5867 GetFillColor(draw_info,x,y,&fill_color,exception);
5868 CompositePixelOver(image,&fill_color,(
double) fill_color.alpha,q,(
double)
5869 GetPixelAlpha(image,q),q);
5870 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5877 geometry[MagickPathExtent];
5882 if (primitive_info->text == (
char *) NULL)
5884 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5885 (void) CloneString(&clone_info->text,primitive_info->text);
5886 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
5887 primitive_info->point.x,primitive_info->point.y);
5888 (void) CloneString(&clone_info->geometry,geometry);
5889 status&=(MagickStatusType) AnnotateImage(image,clone_info,exception);
5890 clone_info=DestroyDrawInfo(clone_info);
5902 if (IsEventLogging() != MagickFalse)
5903 LogPrimitiveInfo(primitive_info);
5904 scale=ExpandAffine(&draw_info->affine);
5905 if ((draw_info->dash_pattern != (
double *) NULL) &&
5906 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5907 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5908 (draw_info->stroke.alpha != (
double) TransparentAlpha))
5913 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5914 clone_info->stroke_width=0.0;
5915 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5916 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5917 primitive_info,exception);
5918 clone_info=DestroyDrawInfo(clone_info);
5919 if (status != MagickFalse)
5920 status&=(MagickStatusType) DrawDashPolygon(draw_info,primitive_info,
5924 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5926 ((draw_info->stroke.alpha != (
double) TransparentAlpha) ||
5927 (draw_info->stroke_pattern != (Image *) NULL)))
5939 closed_path=primitive_info[0].closed_subpath;
5940 i=(ssize_t) primitive_info[0].coordinates;
5941 point_x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5942 point_y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5943 if ((point_x < MagickEpsilon) && (point_y < MagickEpsilon))
5944 closed_path=MagickTrue;
5945 if ((((draw_info->linecap == RoundCap) ||
5946 (closed_path != MagickFalse)) &&
5947 (draw_info->linejoin == RoundJoin)) ||
5948 (primitive_info[i].primitive != UndefinedPrimitive))
5950 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5951 primitive_info,exception);
5954 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5955 clone_info->stroke_width=0.0;
5956 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5957 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5958 primitive_info,exception);
5959 clone_info=DestroyDrawInfo(clone_info);
5960 if (status != MagickFalse)
5961 status&=(MagickStatusType) DrawStrokePolygon(image,draw_info,
5962 primitive_info,exception);
5965 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5966 primitive_info,exception);
5970 image_view=DestroyCacheView(image_view);
5971 if (draw_info->compliance == SVGCompliance)
5973 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5974 (Image *) NULL,exception);
5975 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5976 (Image *) NULL,exception);
5978 if (draw_info->debug != MagickFalse)
5979 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
5980 return(status != 0 ? MagickTrue : MagickFalse);
6013static MagickBooleanType DrawRoundLinecap(Image *image,
6014 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6015 ExceptionInfo *exception)
6023 if (primitive_info->coordinates < 1)
6024 return(MagickFalse);
6025 for (i=0; i < 4; i++)
6026 linecap[i]=(*primitive_info);
6027 linecap[0].coordinates=4;
6028 linecap[1].point.x+=2.0*MagickEpsilon;
6029 linecap[2].point.x+=2.0*MagickEpsilon;
6030 linecap[2].point.y+=2.0*MagickEpsilon;
6031 linecap[3].point.y+=2.0*MagickEpsilon;
6032 linecap[4].primitive=UndefinedPrimitive;
6033 return(DrawPolygonPrimitive(image,draw_info,linecap,exception));
6036static MagickBooleanType DrawStrokePolygon(Image *image,
6037 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6038 ExceptionInfo *exception)
6059 if (draw_info->debug != MagickFalse)
6060 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6061 " begin draw-stroke-polygon");
6062 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
6063 clone_info->fill=draw_info->stroke;
6064 if (clone_info->fill_pattern != (Image *) NULL)
6065 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
6066 if (clone_info->stroke_pattern != (Image *) NULL)
6067 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
6068 MagickTrue,exception);
6069 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
6070 clone_info->stroke_width=0.0;
6071 clone_info->fill_rule=NonZeroRule;
6073 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ptrdiff_t) p->coordinates)
6075 if (p->coordinates == 1)
6077 stroke_polygon=TraceStrokePolygon(draw_info,p,exception);
6078 if (stroke_polygon == (PrimitiveInfo *) NULL)
6083 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
6084 stroke_polygon,exception);
6085 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
6088 q=p+p->coordinates-1;
6089 closed_path=p->closed_subpath;
6090 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
6092 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,p,
6094 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,q,
6098 clone_info=DestroyDrawInfo(clone_info);
6099 if (draw_info->debug != MagickFalse)
6100 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6101 " end draw-stroke-polygon");
6102 return(status != 0 ? MagickTrue : MagickFalse);
6128MagickExport
void GetAffineMatrix(AffineMatrix *affine_matrix)
6130 if (IsEventLogging() != MagickFalse)
6131 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6132 assert(affine_matrix != (AffineMatrix *) NULL);
6133 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
6134 affine_matrix->sx=1.0;
6135 affine_matrix->sy=1.0;
6162MagickExport
void GetDrawInfo(
const ImageInfo *image_info,DrawInfo *draw_info)
6176 assert(draw_info != (DrawInfo *) NULL);
6177 if (IsEventLogging() != MagickFalse)
6178 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6179 (void) memset(draw_info,0,
sizeof(*draw_info));
6180 draw_info->image_info=CloneImageInfo(image_info);
6181 GetAffineMatrix(&draw_info->affine);
6182 exception=AcquireExceptionInfo();
6183 (void) QueryColorCompliance(
"#000F",AllCompliance,&draw_info->fill,
6185 (void) QueryColorCompliance(
"#FFF0",AllCompliance,&draw_info->stroke,
6187 draw_info->stroke_antialias=draw_info->image_info->antialias;
6188 draw_info->stroke_width=1.0;
6189 draw_info->fill_rule=EvenOddRule;
6190 draw_info->alpha=OpaqueAlpha;
6191 draw_info->fill_alpha=OpaqueAlpha;
6192 draw_info->stroke_alpha=OpaqueAlpha;
6193 draw_info->linecap=ButtCap;
6194 draw_info->linejoin=MiterJoin;
6195 draw_info->miterlimit=10;
6196 draw_info->decorate=NoDecoration;
6197 draw_info->pointsize=12.0;
6198 draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
6199 draw_info->compose=OverCompositeOp;
6200 draw_info->render=MagickTrue;
6201 draw_info->clip_path=MagickFalse;
6202 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6203 MagickTrue : MagickFalse;
6204 draw_info->macro_expansion=(
size_t *) NULL;
6205 if (draw_info->image_info->font != (
char *) NULL)
6206 draw_info->font=AcquireString(draw_info->image_info->font);
6207 if (draw_info->image_info->density != (
char *) NULL)
6208 draw_info->density=AcquireString(draw_info->image_info->density);
6209 draw_info->text_antialias=draw_info->image_info->antialias;
6210 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6211 draw_info->pointsize=draw_info->image_info->pointsize;
6212 draw_info->border_color=draw_info->image_info->border_color;
6213 if (draw_info->image_info->server_name != (
char *) NULL)
6214 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6215 option=GetImageOption(draw_info->image_info,
"direction");
6216 if (option != (
const char *) NULL)
6217 draw_info->direction=(DirectionType) ParseCommandOption(
6218 MagickDirectionOptions,MagickFalse,option);
6220 draw_info->direction=UndefinedDirection;
6221 option=GetImageOption(draw_info->image_info,
"encoding");
6222 if (option != (
const char *) NULL)
6223 (void) CloneString(&draw_info->encoding,option);
6224 option=GetImageOption(draw_info->image_info,
"family");
6225 if (option != (
const char *) NULL)
6226 (void) CloneString(&draw_info->family,option);
6227 option=GetImageOption(draw_info->image_info,
"fill");
6228 if (option != (
const char *) NULL)
6229 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
6231 option=GetImageOption(draw_info->image_info,
"gravity");
6232 if (option != (
const char *) NULL)
6233 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6234 MagickFalse,option);
6235 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6236 if (option != (
const char *) NULL)
6237 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6238 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6239 if (option != (
const char *) NULL)
6240 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6241 option=GetImageOption(draw_info->image_info,
"kerning");
6242 if (option != (
const char *) NULL)
6243 draw_info->kerning=GetDrawValue(option,&next_token);
6244 option=GetImageOption(draw_info->image_info,
"stroke");
6245 if (option != (
const char *) NULL)
6246 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
6248 option=GetImageOption(draw_info->image_info,
"strokewidth");
6249 if (option != (
const char *) NULL)
6250 draw_info->stroke_width=GetDrawValue(option,&next_token);
6251 option=GetImageOption(draw_info->image_info,
"style");
6252 if (option != (
const char *) NULL)
6253 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6254 MagickFalse,option);
6255 option=GetImageOption(draw_info->image_info,
"undercolor");
6256 if (option != (
const char *) NULL)
6257 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
6259 option=GetImageOption(draw_info->image_info,
"weight");
6260 if (option != (
const char *) NULL)
6265 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6267 weight=(ssize_t) StringToUnsignedLong(option);
6268 draw_info->weight=(size_t) weight;
6270 option=GetImageOption(draw_info->image_info,
"word-break");
6271 if (option != (
const char *) NULL)
6272 draw_info->word_break=(WordBreakType) ParseCommandOption(
6273 MagickWordBreakOptions,MagickFalse,option);
6274 exception=DestroyExceptionInfo(exception);
6275 draw_info->signature=MagickCoreSignature;
6303static inline double Permutate(
const ssize_t n,
const ssize_t k)
6312 for (i=k+1; i <= n; i++)
6314 for (i=1; i <= (n-k); i++)
6335static MagickBooleanType TraceArc(MVGInfo *mvg_info,
const PointInfo start,
6336 const PointInfo end,
const PointInfo degrees)
6342 center.x=0.5*(end.x+start.x);
6343 center.y=0.5*(end.y+start.y);
6344 radius.x=fabs(center.x-start.x);
6345 radius.y=fabs(center.y-start.y);
6346 return(TraceEllipse(mvg_info,center,radius,degrees));
6349static MagickBooleanType TraceArcPath(MVGInfo *mvg_info,
const PointInfo start,
6350 const PointInfo end,
const PointInfo arc,
const double angle,
6351 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6388 offset=mvg_info->offset;
6389 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6390 primitive_info->coordinates=0;
6391 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6392 (fabs(start.y-end.y) < MagickEpsilon))
6393 return(TracePoint(primitive_info,end));
6394 radii.x=fabs(arc.x);
6395 radii.y=fabs(arc.y);
6396 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6397 return(TraceLine(primitive_info,start,end));
6398 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6399 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6400 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6401 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6402 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6404 if (delta < MagickEpsilon)
6405 return(TraceLine(primitive_info,start,end));
6408 radii.x*=sqrt((
double) delta);
6409 radii.y*=sqrt((
double) delta);
6411 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6412 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6413 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6414 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6415 alpha=points[1].x-points[0].x;
6416 beta=points[1].y-points[0].y;
6417 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6418 return(TraceLine(primitive_info,start,end));
6419 factor=MagickSafeReciprocal(alpha*alpha+beta*beta)-0.25;
6424 factor=sqrt((
double) factor);
6425 if (sweep == large_arc)
6428 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6429 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6430 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6431 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6432 if ((theta < 0.0) && (sweep != MagickFalse))
6433 theta+=2.0*MagickPI;
6435 if ((theta > 0.0) && (sweep == MagickFalse))
6436 theta-=2.0*MagickPI;
6437 arc_segments=(size_t) CastDoubleToSsizeT(ceil(fabs((
double) (theta/(0.5*
6438 MagickPI+MagickEpsilon)))));
6441 for (i=0; i < (ssize_t) arc_segments; i++)
6443 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6444 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6445 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6446 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6447 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6448 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6449 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6450 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6451 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6452 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6453 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) (i+1)*
6454 theta/arc_segments),DegreesToRadians(360.0))));
6455 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) (i+1)*
6456 theta/arc_segments),DegreesToRadians(360.0))));
6457 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(
double)
6458 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6459 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(
double)
6460 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6461 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6462 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6463 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
6465 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
6467 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
6469 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
6471 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
6473 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
6475 if (i == (ssize_t) (arc_segments-1))
6477 status&=(MagickStatusType) TraceBezier(mvg_info,4);
6480 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
6481 mvg_info->offset+=(ssize_t) p->coordinates;
6482 p+=(ptrdiff_t) p->coordinates;
6485 return(MagickFalse);
6486 mvg_info->offset=offset;
6487 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6488 primitive_info->coordinates=(size_t) (p-primitive_info);
6489 primitive_info->closed_subpath=MagickFalse;
6490 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6492 p->primitive=primitive_info->primitive;
6498static MagickBooleanType TraceBezier(MVGInfo *mvg_info,
6499 const size_t number_coordinates)
6528 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6529 quantum=number_coordinates;
6530 for (i=0; i < (ssize_t) number_coordinates; i++)
6532 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6534 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6535 if (alpha > (
double) GetMaxMemoryRequest())
6537 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6538 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6539 return(MagickFalse);
6541 if (alpha > (
double) quantum)
6542 quantum=(size_t) alpha;
6543 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6544 if (alpha > (
double) quantum)
6545 quantum=(size_t) alpha;
6548 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6549 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6550 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6551 sizeof(*coefficients));
6552 points=(PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6554 if ((coefficients == (
double *) NULL) || (points == (PointInfo *) NULL))
6556 if (points != (PointInfo *) NULL)
6557 points=(PointInfo *) RelinquishMagickMemory(points);
6558 if (coefficients != (
double *) NULL)
6559 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6560 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6561 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6562 return(MagickFalse);
6564 control_points=quantum*number_coordinates;
6565 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6567 points=(PointInfo *) RelinquishMagickMemory(points);
6568 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6569 return(MagickFalse);
6571 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6575 end=primitive_info[number_coordinates-1].point;
6576 for (i=0; i < (ssize_t) number_coordinates; i++)
6577 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6579 for (i=0; i < (ssize_t) control_points; i++)
6584 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6585 for (j=0; j < (ssize_t) number_coordinates; j++)
6587 point.x+=alpha*coefficients[j]*p->point.x;
6588 point.y+=alpha*coefficients[j]*p->point.y;
6589 alpha*=weight/(1.0-weight);
6593 weight+=1.0/control_points;
6599 for (i=0; i < (ssize_t) control_points; i++)
6601 if (TracePoint(p,points[i]) == MagickFalse)
6603 points=(PointInfo *) RelinquishMagickMemory(points);
6604 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6605 return(MagickFalse);
6607 p+=(ptrdiff_t) p->coordinates;
6609 if (TracePoint(p,end) == MagickFalse)
6611 points=(PointInfo *) RelinquishMagickMemory(points);
6612 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6613 return(MagickFalse);
6615 p+=(ptrdiff_t) p->coordinates;
6616 primitive_info->coordinates=(size_t) (p-primitive_info);
6617 primitive_info->closed_subpath=MagickFalse;
6618 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6620 p->primitive=primitive_info->primitive;
6623 points=(PointInfo *) RelinquishMagickMemory(points);
6624 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6628static MagickBooleanType TraceCircle(MVGInfo *mvg_info,
const PointInfo start,
6629 const PointInfo end)
6640 alpha=end.x-start.x;
6642 radius=hypot((
double) alpha,(
double) beta);
6643 offset.x=(double) radius;
6644 offset.y=(double) radius;
6647 return(TraceEllipse(mvg_info,start,offset,degrees));
6650static MagickBooleanType TraceEllipse(MVGInfo *mvg_info,
const PointInfo center,
6651 const PointInfo radii,
const PointInfo arc)
6676 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6677 primitive_info->coordinates=0;
6678 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6680 delta=MagickSafeReciprocal(MagickMax(radii.x,radii.y));
6681 step=MagickPI/(MagickPI*MagickSafeReciprocal(delta))/8.0;
6682 angle.x=DegreesToRadians(arc.x);
6686 angle.y=DegreesToRadians(y);
6687 coordinates=ceil((angle.y-angle.x)/step+1.0);
6688 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6689 return(MagickFalse);
6691 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6692 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6694 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6695 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6696 if (i++ >= (ssize_t) coordinates)
6698 if (TracePoint(p,point) == MagickFalse)
6699 return(MagickFalse);
6700 p+=(ptrdiff_t) p->coordinates;
6702 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6703 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6704 if (TracePoint(p,point) == MagickFalse)
6705 return(MagickFalse);
6706 p+=(ptrdiff_t) p->coordinates;
6707 primitive_info->coordinates=(size_t) (p-primitive_info);
6708 primitive_info->closed_subpath=MagickFalse;
6709 x=fabs(primitive_info[0].point.x-
6710 primitive_info[primitive_info->coordinates-1].point.x);
6711 y=fabs(primitive_info[0].point.y-
6712 primitive_info[primitive_info->coordinates-1].point.y);
6713 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6714 primitive_info->closed_subpath=MagickTrue;
6715 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6717 p->primitive=primitive_info->primitive;
6723static MagickBooleanType TraceLine(PrimitiveInfo *primitive_info,
6724 const PointInfo start,
const PointInfo end)
6726 if (TracePoint(primitive_info,start) == MagickFalse)
6727 return(MagickFalse);
6728 if (TracePoint(primitive_info+1,end) == MagickFalse)
6729 return(MagickFalse);
6730 (primitive_info+1)->primitive=primitive_info->primitive;
6731 primitive_info->coordinates=2;
6732 primitive_info->closed_subpath=MagickFalse;
6736static ssize_t TracePath(MVGInfo *mvg_info,
const char *path,
6737 ExceptionInfo *exception)
6741 token[MagickPathExtent] =
"";
6759 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6782 subpath_offset=mvg_info->offset;
6783 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6786 number_coordinates=0;
6788 primitive_type=primitive_info->primitive;
6790 for (p=path; *p !=
'\0'; )
6792 if (status == MagickFalse)
6794 while (isspace((
int) ((
unsigned char) *p)) != 0)
6798 last_attribute=attribute;
6799 attribute=(int) (*p++);
6809 large_arc = MagickFalse,
6810 sweep = MagickFalse;
6820 (void) GetNextToken(p,&p,MagickPathExtent,token);
6821 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6822 ThrowPointExpectedException(token,exception);
6824 (void) GetNextToken(p,&p,MagickPathExtent,token);
6825 arc.x=GetDrawValue(token,&next_token);
6826 if (token == next_token)
6827 ThrowPointExpectedException(token,exception);
6828 (void) GetNextToken(p,&p,MagickPathExtent,token);
6829 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6830 ThrowPointExpectedException(token,exception);
6832 (void) GetNextToken(p,&p,MagickPathExtent,token);
6833 arc.y=GetDrawValue(token,&next_token);
6834 if (token == next_token)
6835 ThrowPointExpectedException(token,exception);
6836 (void) GetNextToken(p,&p,MagickPathExtent,token);
6837 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6838 ThrowPointExpectedException(token,exception);
6840 (void) GetNextToken(p,&p,MagickPathExtent,token);
6841 angle=GetDrawValue(token,&next_token);
6842 if (token == next_token)
6843 ThrowPointExpectedException(token,exception);
6844 (void) GetNextToken(p,&p,MagickPathExtent,token);
6845 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6846 ThrowPointExpectedException(token,exception);
6848 (void) GetNextToken(p,&p,MagickPathExtent,token);
6849 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6850 (void) GetNextToken(p,&p,MagickPathExtent,token);
6851 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6852 ThrowPointExpectedException(token,exception);
6854 (void) GetNextToken(p,&p,MagickPathExtent,token);
6855 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6856 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6857 ThrowPointExpectedException(token,exception);
6859 (void) GetNextToken(p,&p,MagickPathExtent,token);
6860 (void) GetNextToken(p,&p,MagickPathExtent,token);
6861 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6862 ThrowPointExpectedException(token,exception);
6864 (void) GetNextToken(p,&p,MagickPathExtent,token);
6865 x=GetDrawValue(token,&next_token);
6866 if (token == next_token)
6867 ThrowPointExpectedException(token,exception);
6868 (void) GetNextToken(p,&p,MagickPathExtent,token);
6869 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6870 ThrowPointExpectedException(token,exception);
6872 (void) GetNextToken(p,&p,MagickPathExtent,token);
6873 y=GetDrawValue(token,&next_token);
6874 if (token == next_token)
6875 ThrowPointExpectedException(token,exception);
6876 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6877 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6878 if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
6880 q=(*mvg_info->primitive_info)+mvg_info->offset;
6881 mvg_info->offset+=(ssize_t) q->coordinates;
6882 q+=(ptrdiff_t) q->coordinates;
6884 while (isspace((
int) ((
unsigned char) *p)) != 0)
6888 }
while (IsValidPoint(p) != MagickFalse);
6900 for (i=1; i < 4; i++)
6902 (void) GetNextToken(p,&p,MagickPathExtent,token);
6903 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6904 ThrowPointExpectedException(token,exception);
6906 (void) GetNextToken(p,&p,MagickPathExtent,token);
6907 x=GetDrawValue(token,&next_token);
6908 if (token == next_token)
6909 ThrowPointExpectedException(token,exception);
6910 (void) GetNextToken(p,&p,MagickPathExtent,token);
6911 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6912 ThrowPointExpectedException(token,exception);
6914 (void) GetNextToken(p,&p,MagickPathExtent,token);
6915 y=GetDrawValue(token,&next_token);
6916 if (token == next_token)
6917 ThrowPointExpectedException(token,exception);
6918 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6919 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6922 for (i=0; i < 4; i++)
6923 (q+i)->point=points[i];
6924 if (TraceBezier(mvg_info,4) == MagickFalse)
6926 q=(*mvg_info->primitive_info)+mvg_info->offset;
6927 mvg_info->offset+=(ssize_t) q->coordinates;
6928 q+=(ptrdiff_t) q->coordinates;
6930 while (isspace((
int) ((
unsigned char) *p)) != 0)
6934 }
while (IsValidPoint(p) != MagickFalse);
6942 (void) GetNextToken(p,&p,MagickPathExtent,token);
6943 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6944 ThrowPointExpectedException(token,exception);
6946 (void) GetNextToken(p,&p,MagickPathExtent,token);
6947 x=GetDrawValue(token,&next_token);
6948 if (token == next_token)
6949 ThrowPointExpectedException(token,exception);
6950 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6951 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6953 q=(*mvg_info->primitive_info)+mvg_info->offset;
6954 if (TracePoint(q,point) == MagickFalse)
6956 mvg_info->offset+=(ssize_t) q->coordinates;
6957 q+=(ptrdiff_t) q->coordinates;
6958 while (isspace((
int) ((
unsigned char) *p)) != 0)
6962 }
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 (void) GetNextToken(p,&p,MagickPathExtent,token);
6982 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6983 ThrowPointExpectedException(token,exception);
6985 (void) GetNextToken(p,&p,MagickPathExtent,token);
6986 y=GetDrawValue(token,&next_token);
6987 if (token == next_token)
6988 ThrowPointExpectedException(token,exception);
6989 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
6990 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
6991 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6993 q=(*mvg_info->primitive_info)+mvg_info->offset;
6994 if (TracePoint(q,point) == MagickFalse)
6996 mvg_info->offset+=(ssize_t) q->coordinates;
6997 q+=(ptrdiff_t) q->coordinates;
6998 while (isspace((
int) ((
unsigned char) *p)) != 0)
7002 }
while (IsValidPoint(p) != MagickFalse);
7011 if (mvg_info->offset != subpath_offset)
7013 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7014 primitive_info->coordinates=(size_t) (q-primitive_info);
7015 number_coordinates+=primitive_info->coordinates;
7017 subpath_offset=mvg_info->offset;
7022 (void) GetNextToken(p,&p,MagickPathExtent,token);
7023 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7024 ThrowPointExpectedException(token,exception);
7026 (void) GetNextToken(p,&p,MagickPathExtent,token);
7027 x=GetDrawValue(token,&next_token);
7028 if (token == next_token)
7029 ThrowPointExpectedException(token,exception);
7030 (void) GetNextToken(p,&p,MagickPathExtent,token);
7031 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7032 ThrowPointExpectedException(token,exception);
7034 (void) GetNextToken(p,&p,MagickPathExtent,token);
7035 y=GetDrawValue(token,&next_token);
7036 if (token == next_token)
7037 ThrowPointExpectedException(token,exception);
7038 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
7039 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
7043 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7045 q=(*mvg_info->primitive_info)+mvg_info->offset;
7046 if (TracePoint(q,point) == MagickFalse)
7048 mvg_info->offset+=(ssize_t) q->coordinates;
7049 q+=(ptrdiff_t) q->coordinates;
7050 while (isspace((
int) ((
unsigned char) *p)) != 0)
7054 }
while (IsValidPoint(p) != MagickFalse);
7066 for (i=1; i < 3; i++)
7068 (void) GetNextToken(p,&p,MagickPathExtent,token);
7069 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7070 ThrowPointExpectedException(token,exception);
7072 (void) GetNextToken(p,&p,MagickPathExtent,token);
7073 x=GetDrawValue(token,&next_token);
7074 if (token == next_token)
7075 ThrowPointExpectedException(token,exception);
7076 (void) GetNextToken(p,&p,MagickPathExtent,token);
7077 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7078 ThrowPointExpectedException(token,exception);
7080 (void) GetNextToken(p,&p,MagickPathExtent,token);
7081 y=GetDrawValue(token,&next_token);
7082 if (token == next_token)
7083 ThrowPointExpectedException(token,exception);
7086 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
7087 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
7090 for (i=0; i < 3; i++)
7091 (q+i)->point=points[i];
7092 if (TraceBezier(mvg_info,3) == MagickFalse)
7094 q=(*mvg_info->primitive_info)+mvg_info->offset;
7095 mvg_info->offset+=(ssize_t) q->coordinates;
7096 q+=(ptrdiff_t) q->coordinates;
7098 while (isspace((
int) ((
unsigned char) *p)) != 0)
7102 }
while (IsValidPoint(p) != MagickFalse);
7113 points[0]=points[3];
7114 points[1].x=2.0*points[3].x-points[2].x;
7115 points[1].y=2.0*points[3].y-points[2].y;
7116 for (i=2; i < 4; i++)
7118 (void) GetNextToken(p,&p,MagickPathExtent,token);
7119 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7120 ThrowPointExpectedException(token,exception);
7122 (void) GetNextToken(p,&p,MagickPathExtent,token);
7123 x=GetDrawValue(token,&next_token);
7124 if (token == next_token)
7125 ThrowPointExpectedException(token,exception);
7126 (void) GetNextToken(p,&p,MagickPathExtent,token);
7127 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7128 ThrowPointExpectedException(token,exception);
7130 (void) GetNextToken(p,&p,MagickPathExtent,token);
7131 y=GetDrawValue(token,&next_token);
7132 if (token == next_token)
7133 ThrowPointExpectedException(token,exception);
7136 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
7137 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
7140 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
7145 for (i=0; i < 4; i++)
7146 (q+i)->point=points[i];
7147 if (TraceBezier(mvg_info,4) == MagickFalse)
7149 q=(*mvg_info->primitive_info)+mvg_info->offset;
7150 mvg_info->offset+=(ssize_t) q->coordinates;
7151 q+=(ptrdiff_t) q->coordinates;
7153 last_attribute=attribute;
7154 while (isspace((
int) ((
unsigned char) *p)) != 0)
7158 }
while (IsValidPoint(p) != MagickFalse);
7169 points[0]=points[2];
7170 points[1].x=2.0*points[2].x-points[1].x;
7171 points[1].y=2.0*points[2].y-points[1].y;
7172 for (i=2; i < 3; i++)
7174 (void) GetNextToken(p,&p,MagickPathExtent,token);
7175 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7176 ThrowPointExpectedException(token,exception);
7178 (void) GetNextToken(p,&p,MagickPathExtent,token);
7179 x=GetDrawValue(token,&next_token);
7180 if (token == next_token)
7181 ThrowPointExpectedException(token,exception);
7182 (void) GetNextToken(p,&p,MagickPathExtent,token);
7183 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7184 ThrowPointExpectedException(token,exception);
7186 (void) GetNextToken(p,&p,MagickPathExtent,token);
7187 y=GetDrawValue(token,&next_token);
7188 if (token == next_token)
7189 ThrowPointExpectedException(token,exception);
7190 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7191 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7194 if (status == MagickFalse)
7196 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7201 for (i=0; i < 3; i++)
7202 (q+i)->point=points[i];
7203 if (TraceBezier(mvg_info,3) == MagickFalse)
7205 q=(*mvg_info->primitive_info)+mvg_info->offset;
7206 mvg_info->offset+=(ssize_t) q->coordinates;
7207 q+=(ptrdiff_t) q->coordinates;
7209 last_attribute=attribute;
7210 while (isspace((
int) ((
unsigned char) *p)) != 0)
7214 }
while (IsValidPoint(p) != MagickFalse);
7225 (void) GetNextToken(p,&p,MagickPathExtent,token);
7226 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7227 ThrowPointExpectedException(token,exception);
7229 (void) GetNextToken(p,&p,MagickPathExtent,token);
7230 y=GetDrawValue(token,&next_token);
7231 if (token == next_token)
7232 ThrowPointExpectedException(token,exception);
7233 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
7234 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7236 q=(*mvg_info->primitive_info)+mvg_info->offset;
7237 if (TracePoint(q,point) == MagickFalse)
7239 mvg_info->offset+=(ssize_t) q->coordinates;
7240 q+=(ptrdiff_t) q->coordinates;
7241 while (isspace((
int) ((
unsigned char) *p)) != 0)
7245 }
while (IsValidPoint(p) != MagickFalse);
7255 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7257 q=(*mvg_info->primitive_info)+mvg_info->offset;
7258 if (TracePoint(q,point) == MagickFalse)
7260 mvg_info->offset+=(ssize_t) q->coordinates;
7261 q+=(ptrdiff_t) q->coordinates;
7262 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7263 primitive_info->coordinates=(size_t) (q-primitive_info);
7264 primitive_info->closed_subpath=MagickTrue;
7265 number_coordinates+=primitive_info->coordinates;
7267 subpath_offset=mvg_info->offset;
7273 ThrowPointExpectedException(token,exception);
7278 if (status == MagickFalse)
7280 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7281 primitive_info->coordinates=(size_t) (q-primitive_info);
7282 number_coordinates+=primitive_info->coordinates;
7283 for (i=0; i < (ssize_t) number_coordinates; i++)
7286 q->primitive=primitive_type;
7288 q->method=FillToBorderMethod;
7291 return((ssize_t) number_coordinates);
7294static MagickBooleanType TraceRectangle(PrimitiveInfo *primitive_info,
7295 const PointInfo start,
const PointInfo end)
7307 if (TracePoint(p,start) == MagickFalse)
7308 return(MagickFalse);
7309 p+=(ptrdiff_t) p->coordinates;
7312 if (TracePoint(p,point) == MagickFalse)
7313 return(MagickFalse);
7314 p+=(ptrdiff_t) p->coordinates;
7315 if (TracePoint(p,end) == MagickFalse)
7316 return(MagickFalse);
7317 p+=(ptrdiff_t) p->coordinates;
7320 if (TracePoint(p,point) == MagickFalse)
7321 return(MagickFalse);
7322 p+=(ptrdiff_t) p->coordinates;
7323 if (TracePoint(p,start) == MagickFalse)
7324 return(MagickFalse);
7325 p+=(ptrdiff_t) p->coordinates;
7326 primitive_info->coordinates=(size_t) (p-primitive_info);
7327 primitive_info->closed_subpath=MagickTrue;
7328 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7330 p->primitive=primitive_info->primitive;
7336static MagickBooleanType TraceRoundRectangle(MVGInfo *mvg_info,
7337 const PointInfo start,
const PointInfo end,PointInfo arc)
7356 offset=mvg_info->offset;
7357 segment.x=fabs(end.x-start.x);
7358 segment.y=fabs(end.y-start.y);
7359 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7361 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7364 if (arc.x > (0.5*segment.x))
7365 arc.x=0.5*segment.x;
7366 if (arc.y > (0.5*segment.y))
7367 arc.y=0.5*segment.y;
7368 point.x=start.x+segment.x-arc.x;
7369 point.y=start.y+arc.y;
7372 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7373 return(MagickFalse);
7374 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7375 mvg_info->offset+=(ssize_t) p->coordinates;
7376 point.x=start.x+segment.x-arc.x;
7377 point.y=start.y+segment.y-arc.y;
7380 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7381 return(MagickFalse);
7382 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7383 mvg_info->offset+=(ssize_t) p->coordinates;
7384 point.x=start.x+arc.x;
7385 point.y=start.y+segment.y-arc.y;
7388 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7389 return(MagickFalse);
7390 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7391 mvg_info->offset+=(ssize_t) p->coordinates;
7392 point.x=start.x+arc.x;
7393 point.y=start.y+arc.y;
7396 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7397 return(MagickFalse);
7398 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7399 mvg_info->offset+=(ssize_t) p->coordinates;
7400 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7401 return(MagickFalse);
7402 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7403 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7404 return(MagickFalse);
7405 p+=(ptrdiff_t) p->coordinates;
7406 mvg_info->offset=offset;
7407 primitive_info=(*mvg_info->primitive_info)+offset;
7408 primitive_info->coordinates=(size_t) (p-primitive_info);
7409 primitive_info->closed_subpath=MagickTrue;
7410 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7412 p->primitive=primitive_info->primitive;
7418static MagickBooleanType TraceSquareLinecap(PrimitiveInfo *primitive_info,
7419 const size_t number_vertices,
const double offset)
7436 for (i=1; i < (ssize_t) number_vertices; i++)
7438 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7439 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7440 if ((fabs((
double) dx) >= MagickEpsilon) ||
7441 (fabs((
double) dy) >= MagickEpsilon))
7444 if (i == (ssize_t) number_vertices)
7445 i=(ssize_t) number_vertices-1L;
7446 distance=hypot((
double) dx,(
double) dy);
7447 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7448 dx*(distance+offset)/distance);
7449 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7450 dy*(distance+offset)/distance);
7451 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7453 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7454 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7455 if ((fabs((
double) dx) >= MagickEpsilon) ||
7456 (fabs((
double) dy) >= MagickEpsilon))
7459 distance=hypot((
double) dx,(
double) dy);
7460 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7461 dx*(distance+offset)/distance);
7462 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7463 dy*(distance+offset)/distance);
7467static PrimitiveInfo *TraceStrokePolygon(
const DrawInfo *draw_info,
7468 const PrimitiveInfo *primitive_info,ExceptionInfo *exception)
7470#define MaxStrokePad (6*BezierQuantum+360)
7471#define CheckPathExtent(pad_p,pad_q) \
7473 if ((pad_p) > MaxBezierCoordinates) \
7474 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7476 if ((p+(ptrdiff_t) (pad_p)) >= (ssize_t) extent_p) \
7478 if (~extent_p < (pad_p)) \
7479 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7482 extent_p+=(pad_p); \
7483 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \
7484 MaxStrokePad,sizeof(*stroke_p)); \
7487 if ((pad_q) > MaxBezierCoordinates) \
7488 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7490 if ((q+(ptrdiff_t) (pad_q)) >= (ssize_t) extent_q) \
7492 if (~extent_q < (pad_q)) \
7493 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7496 extent_q+=(pad_q); \
7497 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \
7498 MaxStrokePad,sizeof(*stroke_q)); \
7501 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \
7503 if (stroke_p != (PointInfo *) NULL) \
7504 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7505 if (stroke_q != (PointInfo *) NULL) \
7506 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7507 polygon_primitive=(PrimitiveInfo *) \
7508 RelinquishMagickMemory(polygon_primitive); \
7509 (void) ThrowMagickException(exception,GetMagickModule(), \
7510 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \
7511 return((PrimitiveInfo *) NULL); \
7515 typedef struct _StrokeSegment
7561 inverse_slope = {0.0, 0.0},
7568 number_vertices=primitive_info->coordinates;
7569 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7570 number_vertices+2UL,
sizeof(*polygon_primitive));
7571 if (polygon_primitive == (PrimitiveInfo *) NULL)
7573 (void) ThrowMagickException(exception,GetMagickModule(),
7574 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7575 return((PrimitiveInfo *) NULL);
7577 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7578 sizeof(*polygon_primitive));
7579 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7580 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7581 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7582 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7583 if ((draw_info->linejoin == RoundJoin) ||
7584 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
7586 polygon_primitive[number_vertices]=primitive_info[1];
7589 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7593 closed_path=primitive_info[0].closed_subpath;
7596 for (n=1; n < (ssize_t) number_vertices; n++)
7598 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7599 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7600 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7603 if (n == (ssize_t) number_vertices)
7605 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7610 stroke_polygon=(PrimitiveInfo *) AcquireCriticalMemory(
7611 sizeof(*stroke_polygon));
7612 stroke_polygon[0]=polygon_primitive[0];
7613 stroke_polygon[0].coordinates=0;
7614 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7616 return(stroke_polygon);
7618 n=(ssize_t) number_vertices-1L;
7620 extent_p=2*number_vertices;
7621 extent_q=2*number_vertices;
7622 stroke_p=(PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7624 stroke_q=(PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7626 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL))
7628 if (stroke_p != (PointInfo *) NULL)
7629 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7630 if (stroke_q != (PointInfo *) NULL)
7631 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7632 polygon_primitive=(PrimitiveInfo *)
7633 RelinquishMagickMemory(polygon_primitive);
7634 (void) ThrowMagickException(exception,GetMagickModule(),
7635 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7636 return((PrimitiveInfo *) NULL);
7639 inverse_slope.p=0.0;
7640 if (fabs(dx.p) < MagickEpsilon)
7643 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7645 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7648 if (fabs(dy.p) < MagickEpsilon)
7651 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7653 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7658 inverse_slope.p=(-1.0*MagickSafeReciprocal(slope.p));
7660 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7661 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7662 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7663 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7664 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7665 offset.y=(double) (offset.x*inverse_slope.p);
7666 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7668 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7669 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7670 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7671 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7672 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7673 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7674 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7675 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7679 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7680 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7681 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7682 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7683 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7684 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7685 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7686 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7693 stroke_q[p++]=box_q[0];
7694 stroke_p[q++]=box_p[0];
7695 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7700 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7701 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7702 dot_product=dx.q*dx.q+dy.q*dy.q;
7703 if (dot_product < 0.25)
7706 inverse_slope.q=0.0;
7707 if (fabs(dx.q) < MagickEpsilon)
7710 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7712 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7715 if (fabs(dy.q) < MagickEpsilon)
7718 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7720 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7725 inverse_slope.q=(-1.0*MagickSafeReciprocal(slope.q));
7727 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7728 offset.y=(double) (offset.x*inverse_slope.q);
7729 dot_product=dy.q*offset.x-dx.q*offset.y;
7730 if (dot_product > 0.0)
7732 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7733 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7734 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7735 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7736 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7737 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7738 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7739 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7743 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7744 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7745 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7746 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7747 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7748 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7749 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7750 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7752 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7759 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7760 box_p[3].y)/(slope.p-slope.q));
7761 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7762 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7763 box_q[3].y)/(slope.p-slope.q));
7764 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7766 DisableMSCWarning(4127)
7767 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7769 dot_product=dx.q*dy.p-dx.p*dy.q;
7770 if (dot_product <= 0.0)
7771 switch (draw_info->linejoin)
7775 stroke_q[q++]=box_q[1];
7776 stroke_q[q++]=box_q[2];
7777 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7778 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7779 if (dot_product <= miterlimit)
7780 stroke_p[p++]=box_p[4];
7783 stroke_p[p++]=box_p[1];
7784 stroke_p[p++]=box_p[2];
7790 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7791 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7792 if (dot_product <= miterlimit)
7794 stroke_q[q++]=box_q[4];
7795 stroke_p[p++]=box_p[4];
7799 stroke_q[q++]=box_q[1];
7800 stroke_q[q++]=box_q[2];
7801 stroke_p[p++]=box_p[1];
7802 stroke_p[p++]=box_p[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];
7817 center=polygon_primitive[n].point;
7818 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7819 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7820 if (theta.q < theta.p)
7821 theta.q+=2.0*MagickPI;
7822 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.q-
7823 theta.p)/(2.0*sqrt(MagickSafeReciprocal(mid))))));
7824 DisableMSCWarning(4127)
7825 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7827 stroke_q[q].x=box_q[1].x;
7828 stroke_q[q].y=box_q[1].y;
7830 for (j=1; j < (ssize_t) arc_segments; j++)
7832 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7833 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7834 (theta.p+delta_theta),DegreesToRadians(360.0))));
7835 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7836 (theta.p+delta_theta),DegreesToRadians(360.0))));
7839 stroke_q[q++]=box_q[2];
7846 switch (draw_info->linejoin)
7850 stroke_p[p++]=box_p[1];
7851 stroke_p[p++]=box_p[2];
7852 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7853 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7854 if (dot_product <= miterlimit)
7855 stroke_q[q++]=box_q[4];
7858 stroke_q[q++]=box_q[1];
7859 stroke_q[q++]=box_q[2];
7865 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7866 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7867 if (dot_product <= miterlimit)
7869 stroke_q[q++]=box_q[4];
7870 stroke_p[p++]=box_p[4];
7874 stroke_q[q++]=box_q[1];
7875 stroke_q[q++]=box_q[2];
7876 stroke_p[p++]=box_p[1];
7877 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];
7892 center=polygon_primitive[n].point;
7893 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7894 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7895 if (theta.p < theta.q)
7896 theta.p+=2.0*MagickPI;
7897 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.p-
7898 theta.q)/(2.0*sqrt((
double) (MagickSafeReciprocal(mid)))))));
7899 DisableMSCWarning(4127)
7900 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7902 stroke_p[p++]=box_p[1];
7903 for (j=1; j < (ssize_t) arc_segments; j++)
7905 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7906 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7907 (theta.p+delta_theta),DegreesToRadians(360.0))));
7908 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7909 (theta.p+delta_theta),DegreesToRadians(360.0))));
7912 stroke_p[p++]=box_p[2];
7919 inverse_slope.p=inverse_slope.q;
7928 stroke_p[p++]=box_p[1];
7929 stroke_q[q++]=box_q[1];
7933 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7934 (p+q+2L),(
size_t) (closed_path+2L)*
sizeof(*stroke_polygon));
7935 if (stroke_polygon == (PrimitiveInfo *) NULL)
7937 (void) ThrowMagickException(exception,GetMagickModule(),
7938 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7939 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7940 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7941 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7943 return(stroke_polygon);
7945 for (i=0; i < (ssize_t) p; i++)
7947 stroke_polygon[i]=polygon_primitive[0];
7948 stroke_polygon[i].point=stroke_p[i];
7950 if (closed_path != MagickFalse)
7952 stroke_polygon[i]=polygon_primitive[0];
7953 stroke_polygon[i].point=stroke_polygon[0].point;
7956 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7958 stroke_polygon[i]=polygon_primitive[0];
7959 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7961 if (closed_path != MagickFalse)
7963 stroke_polygon[i]=polygon_primitive[0];
7964 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7967 stroke_polygon[i]=polygon_primitive[0];
7968 stroke_polygon[i].point=stroke_polygon[0].point;
7970 stroke_polygon[i].primitive=UndefinedPrimitive;
7971 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
7972 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7973 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7974 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
7975 return(stroke_polygon);