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 graphic_context[n]->viewbox=image->page;
2661 if ((image->page.width == 0) || (image->page.height == 0))
2663 graphic_context[n]->viewbox.width=image->columns;
2664 graphic_context[n]->viewbox.height=image->rows;
2666 token=AcquireString(primitive);
2667 extent=strlen(token)+MagickPathExtent;
2671 macros=GetMVGMacros(primitive,exception);
2673 for (q=primitive; *q !=
'\0'; )
2678 if (GetNextToken(q,&q,MagickPathExtent,keyword) < 1)
2680 if (*keyword ==
'\0')
2682 if (*keyword ==
'#')
2687 while ((*q !=
'\n') && (*q !=
'\0'))
2691 p=q-strlen(keyword)-1;
2692 primitive_type=UndefinedPrimitive;
2693 current=graphic_context[n]->affine;
2694 GetAffineMatrix(&affine);
2703 if (LocaleCompare(
"affine",keyword) == 0)
2705 (void) GetNextToken(q,&q,extent,token);
2706 affine.sx=GetDrawValue(token,&next_token);
2707 if (token == next_token)
2708 ThrowPointExpectedException(token,exception);
2709 (void) GetNextToken(q,&q,extent,token);
2710 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2711 ThrowPointExpectedException(token,exception);
2713 (void) GetNextToken(q,&q,extent,token);
2714 affine.ry=GetDrawValue(token,&next_token);
2715 if (token == next_token)
2716 ThrowPointExpectedException(token,exception);
2717 (void) GetNextToken(q,&q,extent,token);
2718 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2719 ThrowPointExpectedException(token,exception);
2721 (void) GetNextToken(q,&q,extent,token);
2722 affine.rx=GetDrawValue(token,&next_token);
2723 if (token == next_token)
2724 ThrowPointExpectedException(token,exception);
2725 (void) GetNextToken(q,&q,extent,token);
2726 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2727 ThrowPointExpectedException(token,exception);
2729 (void) GetNextToken(q,&q,extent,token);
2730 affine.sy=GetDrawValue(token,&next_token);
2731 if (token == next_token)
2732 ThrowPointExpectedException(token,exception);
2733 (void) GetNextToken(q,&q,extent,token);
2734 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2735 ThrowPointExpectedException(token,exception);
2737 (void) GetNextToken(q,&q,extent,token);
2738 affine.tx=GetDrawValue(token,&next_token);
2739 if (token == next_token)
2740 ThrowPointExpectedException(token,exception);
2741 (void) GetNextToken(q,&q,extent,token);
2742 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2743 ThrowPointExpectedException(token,exception);
2745 (void) GetNextToken(q,&q,extent,token);
2746 affine.ty=GetDrawValue(token,&next_token);
2747 if (token == next_token)
2748 ThrowPointExpectedException(token,exception);
2751 if (LocaleCompare(
"alpha",keyword) == 0)
2753 primitive_type=AlphaPrimitive;
2756 if (LocaleCompare(
"arc",keyword) == 0)
2758 primitive_type=ArcPrimitive;
2767 if (LocaleCompare(
"bezier",keyword) == 0)
2769 primitive_type=BezierPrimitive;
2772 if (LocaleCompare(
"border-color",keyword) == 0)
2774 (void) GetNextToken(q,&q,extent,token);
2775 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2776 &graphic_context[n]->border_color,exception);
2785 if (LocaleCompare(
"class",keyword) == 0)
2790 (void) GetNextToken(q,&q,extent,token);
2791 if ((*token ==
'\0') || (*token ==
';'))
2799 for (i=0; i <= n; i++)
2800 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2804 if (classDepth++ > MagickMaxRecursionDepth)
2806 (void) ThrowMagickException(exception,GetMagickModule(),
2807 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2811 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2812 if ((graphic_context[n]->render != MagickFalse) &&
2813 (mvg_class != (
const char *) NULL) && (p > primitive))
2824 (void) CloneString(&graphic_context[n]->
id,token);
2825 offset=(ssize_t) (p-primitive);
2826 elements=AcquireString(primitive);
2827 elements[offset]=
'\0';
2828 (void) ConcatenateString(&elements,mvg_class);
2829 (void) ConcatenateString(&elements,
"\n");
2830 (void) ConcatenateString(&elements,q);
2831 primitive=DestroyString(primitive);
2837 if (LocaleCompare(
"clip-path",keyword) == 0)
2845 (void) GetNextToken(q,&q,extent,token);
2851 (void) CloneString(&graphic_context[n]->clip_mask,token);
2852 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2853 if (clip_path != (
const char *) NULL)
2855 if (graphic_context[n]->clipping_mask != (Image *) NULL)
2856 graphic_context[n]->clipping_mask=
2857 DestroyImage(graphic_context[n]->clipping_mask);
2858 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2859 graphic_context[n],token,clip_path,exception);
2860 if (graphic_context[n]->compliance != SVGCompliance)
2862 clip_path=(
const char *) GetValueFromSplayTree(macros,
2863 graphic_context[n]->clip_mask);
2864 if (clip_path != (
const char *) NULL)
2865 (void) SetImageArtifact(image,
2866 graphic_context[n]->clip_mask,clip_path);
2867 status&=(MagickStatusType) DrawClipPath(image,
2868 graphic_context[n],graphic_context[n]->clip_mask,
2874 if (LocaleCompare(
"clip-rule",keyword) == 0)
2879 (void) GetNextToken(q,&q,extent,token);
2880 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2882 if (fill_rule == -1)
2887 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2890 if (LocaleCompare(
"clip-units",keyword) == 0)
2895 (void) GetNextToken(q,&q,extent,token);
2896 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2898 if (clip_units == -1)
2903 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2904 if (clip_units == ObjectBoundingBox)
2906 GetAffineMatrix(¤t);
2907 affine.sx=draw_info->bounds.x2;
2908 affine.sy=draw_info->bounds.y2;
2909 affine.tx=draw_info->bounds.x1;
2910 affine.ty=draw_info->bounds.y1;
2915 if (LocaleCompare(
"circle",keyword) == 0)
2917 primitive_type=CirclePrimitive;
2920 if (LocaleCompare(
"color",keyword) == 0)
2922 primitive_type=ColorPrimitive;
2925 if (LocaleCompare(
"compliance",keyword) == 0)
2931 (void) GetNextToken(q,&q,extent,token);
2932 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2933 MagickComplianceOptions,MagickFalse,token);
2936 if (LocaleCompare(
"currentColor",keyword) == 0)
2938 (void) GetNextToken(q,&q,extent,token);
2947 if (LocaleCompare(
"decorate",keyword) == 0)
2952 (void) GetNextToken(q,&q,extent,token);
2953 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2960 graphic_context[n]->decorate=(DecorationType) decorate;
2963 if (LocaleCompare(
"density",keyword) == 0)
2965 (void) GetNextToken(q,&q,extent,token);
2966 (void) CloneString(&graphic_context[n]->density,token);
2969 if (LocaleCompare(
"direction",keyword) == 0)
2974 (void) GetNextToken(q,&q,extent,token);
2975 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2977 if (direction == -1)
2980 graphic_context[n]->direction=(DirectionType) direction;
2989 if (LocaleCompare(
"ellipse",keyword) == 0)
2991 primitive_type=EllipsePrimitive;
2994 if (LocaleCompare(
"encoding",keyword) == 0)
2996 (void) GetNextToken(q,&q,extent,token);
2997 (void) CloneString(&graphic_context[n]->encoding,token);
3006 if (LocaleCompare(
"fill",keyword) == 0)
3011 (void) GetNextToken(q,&q,extent,token);
3012 if (graphic_context[n]->clip_path != MagickFalse)
3014 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3015 if (mvg_class != (
const char *) NULL)
3017 (void) DrawPatternPath(image,draw_info,mvg_class,
3018 &graphic_context[n]->fill_pattern,exception);
3021 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3022 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3024 (void) DrawPatternPath(image,draw_info,token,
3025 &graphic_context[n]->fill_pattern,exception);
3028 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3029 &graphic_context[n]->fill,exception);
3030 if (graphic_context[n]->fill_alpha != (
double) OpaqueAlpha)
3031 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3034 if (LocaleCompare(
"fill-opacity",keyword) == 0)
3039 (void) GetNextToken(q,&q,extent,token);
3040 if (graphic_context[n]->clip_path != MagickFalse)
3042 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3043 opacity=MagickMin(MagickMax(factor*
3044 GetDrawValue(token,&next_token),0.0),1.0);
3045 if (token == next_token)
3046 ThrowPointExpectedException(token,exception);
3047 if (graphic_context[n]->compliance == SVGCompliance)
3048 graphic_context[n]->fill_alpha*=opacity;
3050 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3051 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3052 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3054 graphic_context[n]->fill.alpha=(MagickRealType)
3055 ClampToQuantum((
double) QuantumRange*opacity);
3056 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3059 if (LocaleCompare(
"fill-rule",keyword) == 0)
3064 (void) GetNextToken(q,&q,extent,token);
3065 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3067 if (fill_rule == -1)
3072 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3075 if (LocaleCompare(
"font",keyword) == 0)
3077 (void) GetNextToken(q,&q,extent,token);
3078 (void) CloneString(&graphic_context[n]->font,token);
3079 if (LocaleCompare(
"none",token) == 0)
3080 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3081 graphic_context[n]->font);
3084 if (LocaleCompare(
"font-family",keyword) == 0)
3086 (void) GetNextToken(q,&q,extent,token);
3087 (void) CloneString(&graphic_context[n]->family,token);
3090 if (LocaleCompare(
"font-size",keyword) == 0)
3092 (void) GetNextToken(q,&q,extent,token);
3093 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3094 if (token == next_token)
3095 ThrowPointExpectedException(token,exception);
3098 if (LocaleCompare(
"font-stretch",keyword) == 0)
3103 (void) GetNextToken(q,&q,extent,token);
3104 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3110 graphic_context[n]->stretch=(StretchType) stretch;
3113 if (LocaleCompare(
"font-style",keyword) == 0)
3118 (void) GetNextToken(q,&q,extent,token);
3119 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3125 graphic_context[n]->style=(StyleType) style;
3128 if (LocaleCompare(
"font-weight",keyword) == 0)
3133 (void) GetNextToken(q,&q,extent,token);
3134 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3136 weight=(ssize_t) StringToUnsignedLong(token);
3137 graphic_context[n]->weight=(size_t) weight;
3146 if (LocaleCompare(
"gradient-units",keyword) == 0)
3148 (void) GetNextToken(q,&q,extent,token);
3151 if (LocaleCompare(
"gravity",keyword) == 0)
3156 (void) GetNextToken(q,&q,extent,token);
3157 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3163 graphic_context[n]->gravity=(GravityType) gravity;
3172 if (LocaleCompare(
"image",keyword) == 0)
3177 primitive_type=ImagePrimitive;
3178 (void) GetNextToken(q,&q,extent,token);
3179 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3185 graphic_context[n]->compose=(CompositeOperator) compose;
3188 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3190 (void) GetNextToken(q,&q,extent,token);
3191 graphic_context[n]->interline_spacing=GetDrawValue(token,
3193 if (token == next_token)
3194 ThrowPointExpectedException(token,exception);
3197 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3199 (void) GetNextToken(q,&q,extent,token);
3200 graphic_context[n]->interword_spacing=GetDrawValue(token,
3202 if (token == next_token)
3203 ThrowPointExpectedException(token,exception);
3212 if (LocaleCompare(
"kerning",keyword) == 0)
3214 (void) GetNextToken(q,&q,extent,token);
3215 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3216 if (token == next_token)
3217 ThrowPointExpectedException(token,exception);
3226 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3228 (void) GetNextToken(q,&q,extent,token);
3229 if (IsValidPoint(token) == MagickFalse)
3231 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
3232 clone_info->text=AcquireString(
" ");
3233 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,&metrics,
3235 graphic_context[n]->kerning=metrics.width*
3236 GetDrawValue(token,&next_token);
3237 clone_info=DestroyDrawInfo(clone_info);
3238 if (token == next_token)
3239 ThrowPointExpectedException(token,exception);
3242 if (LocaleCompare(
"line",keyword) == 0)
3244 primitive_type=LinePrimitive;
3253 if (LocaleCompare(
"mask",keyword) == 0)
3261 (void) GetNextToken(q,&q,extent,token);
3262 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3263 if (mask_path != (
const char *) NULL)
3265 if (graphic_context[n]->composite_mask != (Image *) NULL)
3266 graphic_context[n]->composite_mask=
3267 DestroyImage(graphic_context[n]->composite_mask);
3268 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3269 graphic_context[n],token,mask_path,exception);
3270 if (graphic_context[n]->compliance != SVGCompliance)
3271 status=SetImageMask(image,CompositePixelMask,
3272 graphic_context[n]->composite_mask,exception);
3282 if (LocaleCompare(
"offset",keyword) == 0)
3284 (void) GetNextToken(q,&q,extent,token);
3287 if (LocaleCompare(
"opacity",keyword) == 0)
3292 (void) GetNextToken(q,&q,extent,token);
3293 if (graphic_context[n]->clip_path != MagickFalse)
3295 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3296 opacity=MagickMin(MagickMax(factor*
3297 GetDrawValue(token,&next_token),0.0),1.0);
3298 if (token == next_token)
3299 ThrowPointExpectedException(token,exception);
3300 if (graphic_context[n]->compliance == SVGCompliance)
3302 graphic_context[n]->fill_alpha*=opacity;
3303 graphic_context[n]->stroke_alpha*=opacity;
3307 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3308 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3310 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3312 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3313 graphic_context[n]->stroke.alpha=
3314 graphic_context[n]->stroke_alpha;
3318 graphic_context[n]->fill.alpha=(MagickRealType)
3319 ClampToQuantum((
double) QuantumRange*opacity);
3320 graphic_context[n]->stroke.alpha=(MagickRealType)
3321 ClampToQuantum((
double) QuantumRange*opacity);
3323 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3324 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3333 if (LocaleCompare(
"path",keyword) == 0)
3335 primitive_type=PathPrimitive;
3338 if (LocaleCompare(
"point",keyword) == 0)
3340 primitive_type=PointPrimitive;
3343 if (LocaleCompare(
"polyline",keyword) == 0)
3345 primitive_type=PolylinePrimitive;
3348 if (LocaleCompare(
"polygon",keyword) == 0)
3350 primitive_type=PolygonPrimitive;
3353 if (LocaleCompare(
"pop",keyword) == 0)
3355 if (GetNextToken(q,&q,extent,token) < 1)
3357 if (LocaleCompare(
"class",token) == 0)
3359 if (LocaleCompare(
"clip-path",token) == 0)
3361 if (LocaleCompare(
"defs",token) == 0)
3364 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3368 if (LocaleCompare(
"gradient",token) == 0)
3370 if (LocaleCompare(
"graphic-context",token) == 0)
3374 (void) ThrowMagickException(exception,GetMagickModule(),
3375 DrawError,
"UnbalancedGraphicContextPushPop",
"`%s'",token);
3380 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3381 (graphic_context[n]->compliance != SVGCompliance))
3382 if (LocaleCompare(graphic_context[n]->clip_mask,
3383 graphic_context[n-1]->clip_mask) != 0)
3384 status=SetImageMask(image,WritePixelMask,(Image *) NULL,
3386 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3390 if (LocaleCompare(
"mask",token) == 0)
3392 if (LocaleCompare(
"pattern",token) == 0)
3394 if (LocaleCompare(
"symbol",token) == 0)
3397 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3404 if (LocaleCompare(
"push",keyword) == 0)
3406 if (GetNextToken(q,&q,extent,token) < 1)
3408 if (LocaleCompare(
"class",token) == 0)
3413 for (p=q; *q !=
'\0'; )
3415 if (GetNextToken(q,&q,extent,token) < 1)
3417 if (LocaleCompare(token,
"pop") != 0)
3419 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3420 if (LocaleCompare(token,
"class") != 0)
3424 (void) GetNextToken(q,&q,extent,token);
3427 if (LocaleCompare(
"clip-path",token) == 0)
3429 (void) GetNextToken(q,&q,extent,token);
3430 for (p=q; *q !=
'\0'; )
3432 if (GetNextToken(q,&q,extent,token) < 1)
3434 if (LocaleCompare(token,
"pop") != 0)
3436 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3437 if (LocaleCompare(token,
"clip-path") != 0)
3441 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3446 (void) GetNextToken(q,&q,extent,token);
3449 if (LocaleCompare(
"defs",token) == 0)
3452 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3456 if (LocaleCompare(
"gradient",token) == 0)
3459 key[2*MagickPathExtent],
3460 name[MagickPathExtent],
3461 type[MagickPathExtent];
3466 (void) GetNextToken(q,&q,extent,token);
3467 (void) CopyMagickString(name,token,MagickPathExtent);
3468 (void) GetNextToken(q,&q,extent,token);
3469 (void) CopyMagickString(type,token,MagickPathExtent);
3470 (void) GetNextToken(q,&q,extent,token);
3471 segment.x1=GetDrawValue(token,&next_token);
3472 if (token == next_token)
3473 ThrowPointExpectedException(token,exception);
3474 (void) GetNextToken(q,&q,extent,token);
3475 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3476 ThrowPointExpectedException(token,exception);
3478 (void) GetNextToken(q,&q,extent,token);
3479 segment.y1=GetDrawValue(token,&next_token);
3480 if (token == next_token)
3481 ThrowPointExpectedException(token,exception);
3482 (void) GetNextToken(q,&q,extent,token);
3483 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3484 ThrowPointExpectedException(token,exception);
3486 (void) GetNextToken(q,&q,extent,token);
3487 segment.x2=GetDrawValue(token,&next_token);
3488 if (token == next_token)
3489 ThrowPointExpectedException(token,exception);
3490 (void) GetNextToken(q,&q,extent,token);
3491 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3492 ThrowPointExpectedException(token,exception);
3494 (void) GetNextToken(q,&q,extent,token);
3495 segment.y2=GetDrawValue(token,&next_token);
3496 if (token == next_token)
3497 ThrowPointExpectedException(token,exception);
3498 if (LocaleCompare(type,
"radial") == 0)
3500 (void) GetNextToken(q,&q,extent,token);
3501 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3502 ThrowPointExpectedException(token,exception);
3504 (void) GetNextToken(q,&q,extent,token);
3506 for (p=q; *q !=
'\0'; )
3508 if (GetNextToken(q,&q,extent,token) < 1)
3510 if (LocaleCompare(token,
"pop") != 0)
3512 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3513 if (LocaleCompare(token,
"gradient") != 0)
3517 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3518 (p == (
char *) NULL) || ((q-4) < p) ||
3519 ((
size_t) (q-p+4+1) > extent))
3524 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3525 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3526 graphic_context[n]->affine.ry*segment.y1+
3527 graphic_context[n]->affine.tx;
3528 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3529 graphic_context[n]->affine.sy*segment.y1+
3530 graphic_context[n]->affine.ty;
3531 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3532 graphic_context[n]->affine.ry*segment.y2+
3533 graphic_context[n]->affine.tx;
3534 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3535 graphic_context[n]->affine.sy*segment.y2+
3536 graphic_context[n]->affine.ty;
3537 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3538 (void) SetImageArtifact(image,key,token);
3539 (void) FormatLocaleString(key,MagickPathExtent,
"%s-type",name);
3540 (void) SetImageArtifact(image,key,type);
3541 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3543 (void) FormatLocaleString(geometry,MagickPathExtent,
3544 "%gx%g%+.15g%+.15g",
3545 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3546 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3547 bounds.x1,bounds.y1);
3548 (void) SetImageArtifact(image,key,geometry);
3549 (void) GetNextToken(q,&q,extent,token);
3552 if (LocaleCompare(
"graphic-context",token) == 0)
3555 graphic_context=(DrawInfo **) ResizeQuantumMemory(
3556 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3557 if (graphic_context == (DrawInfo **) NULL)
3559 (void) ThrowMagickException(exception,GetMagickModule(),
3560 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3565 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
3566 graphic_context[n-1]);
3569 (void) GetNextToken(q,&q,extent,token);
3570 (void) CloneString(&graphic_context[n]->
id,token);
3572 if (n > MagickMaxRecursionDepth)
3574 (void) ThrowMagickException(exception,GetMagickModule(),
3575 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",
3581 if (LocaleCompare(
"mask",token) == 0)
3583 (void) GetNextToken(q,&q,extent,token);
3586 if (LocaleCompare(
"pattern",token) == 0)
3589 key[2*MagickPathExtent],
3590 name[MagickPathExtent];
3595 (void) GetNextToken(q,&q,extent,token);
3596 (void) CopyMagickString(name,token,MagickPathExtent);
3597 (void) GetNextToken(q,&q,extent,token);
3598 region.x=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3600 if (token == next_token)
3601 ThrowPointExpectedException(token,exception);
3602 (void) GetNextToken(q,&q,extent,token);
3603 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3604 ThrowPointExpectedException(token,exception);
3606 (void) GetNextToken(q,&q,extent,token);
3607 region.y=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3609 if (token == next_token)
3610 ThrowPointExpectedException(token,exception);
3611 (void) GetNextToken(q,&q,extent,token);
3612 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3613 ThrowPointExpectedException(token,exception);
3615 (void) GetNextToken(q,&q,extent,token);
3616 region.width=CastDoubleToSizeT(floor(GetDrawValue(token,
3618 if (token == next_token)
3619 ThrowPointExpectedException(token,exception);
3620 (void) GetNextToken(q,&q,extent,token);
3621 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3622 ThrowPointExpectedException(token,exception);
3624 (void) GetNextToken(q,&q,extent,token);
3625 region.height=CastDoubleToSizeT(GetDrawValue(token,
3627 if (token == next_token)
3628 ThrowPointExpectedException(token,exception);
3629 for (p=q; *q !=
'\0'; )
3631 if (GetNextToken(q,&q,extent,token) < 1)
3633 if (LocaleCompare(token,
"pop") != 0)
3635 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3636 if (LocaleCompare(token,
"pattern") != 0)
3640 if ((q == (
char *) NULL) || (p == (
char *) NULL) ||
3641 ((q-4) < p) || ((
size_t) (q-p+4+1) > extent))
3646 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3647 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3648 (void) SetImageArtifact(image,key,token);
3649 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3651 (void) FormatLocaleString(geometry,MagickPathExtent,
3652 "%.17gx%.17g%+.20g%+.20g",(
double) region.width,(
double)
3653 region.height,(
double) region.x,(
double) region.y);
3654 (void) SetImageArtifact(image,key,geometry);
3655 (void) GetNextToken(q,&q,extent,token);
3658 if (LocaleCompare(
"symbol",token) == 0)
3661 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3674 if (LocaleCompare(
"rectangle",keyword) == 0)
3676 primitive_type=RectanglePrimitive;
3679 if (LocaleCompare(
"rotate",keyword) == 0)
3681 (void) GetNextToken(q,&q,extent,token);
3682 angle=GetDrawValue(token,&next_token);
3683 if (token == next_token)
3684 ThrowPointExpectedException(token,exception);
3685 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3686 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3687 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3688 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3691 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3693 primitive_type=RoundRectanglePrimitive;
3702 if (LocaleCompare(
"scale",keyword) == 0)
3704 (void) GetNextToken(q,&q,extent,token);
3705 affine.sx=GetDrawValue(token,&next_token);
3706 if (token == next_token)
3707 ThrowPointExpectedException(token,exception);
3708 (void) GetNextToken(q,&q,extent,token);
3709 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3710 ThrowPointExpectedException(token,exception);
3712 (void) GetNextToken(q,&q,extent,token);
3713 affine.sy=GetDrawValue(token,&next_token);
3714 if (token == next_token)
3715 ThrowPointExpectedException(token,exception);
3718 if (LocaleCompare(
"skewX",keyword) == 0)
3720 (void) GetNextToken(q,&q,extent,token);
3721 angle=GetDrawValue(token,&next_token);
3722 if (token == next_token)
3723 ThrowPointExpectedException(token,exception);
3724 affine.ry=sin(DegreesToRadians(angle));
3727 if (LocaleCompare(
"skewY",keyword) == 0)
3729 (void) GetNextToken(q,&q,extent,token);
3730 angle=GetDrawValue(token,&next_token);
3731 if (token == next_token)
3732 ThrowPointExpectedException(token,exception);
3733 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3736 if (LocaleCompare(
"stop-color",keyword) == 0)
3742 if (number_stops == 1)
3743 stops=(StopInfo *) AcquireQuantumMemory(2,
sizeof(*stops));
3745 if (number_stops > 2)
3746 stops=(StopInfo *) ResizeQuantumMemory(stops,number_stops,
3748 if (stops == (StopInfo *) NULL)
3750 (void) ThrowMagickException(exception,GetMagickModule(),
3751 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3756 (void) GetNextToken(q,&q,extent,token);
3757 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3758 &stop_color,exception);
3759 stops[number_stops-1].color=stop_color;
3760 (void) GetNextToken(q,&q,extent,token);
3761 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3762 stops[number_stops-1].offset=factor*GetDrawValue(token,
3764 if (token == next_token)
3765 ThrowPointExpectedException(token,exception);
3768 if (LocaleCompare(
"stroke",keyword) == 0)
3773 (void) GetNextToken(q,&q,extent,token);
3774 if (graphic_context[n]->clip_path != MagickFalse)
3776 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3777 if (mvg_class != (
const char *) NULL)
3779 (void) DrawPatternPath(image,draw_info,mvg_class,
3780 &graphic_context[n]->stroke_pattern,exception);
3783 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3784 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3786 (void) DrawPatternPath(image,draw_info,token,
3787 &graphic_context[n]->stroke_pattern,exception);
3790 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3791 &graphic_context[n]->stroke,exception);
3792 if (graphic_context[n]->stroke_alpha != (
double) OpaqueAlpha)
3793 graphic_context[n]->stroke.alpha=
3794 graphic_context[n]->stroke_alpha;
3797 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3799 (void) GetNextToken(q,&q,extent,token);
3800 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3801 MagickTrue : MagickFalse;
3804 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3806 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3807 graphic_context[n]->dash_pattern=(
double *)
3808 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3809 if (IsValidPoint(q) != MagickFalse)
3815 (void) GetNextToken(r,&r,extent,token);
3816 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3817 ThrowPointExpectedException(token,exception);
3819 (void) GetNextToken(r,&r,extent,token);
3820 for (x=0; IsValidPoint(token) != MagickFalse; x++)
3822 (void) GetNextToken(r,&r,extent,token);
3824 (void) GetNextToken(r,&r,extent,token);
3826 graphic_context[n]->dash_pattern=(
double *)
3827 AcquireQuantumMemory((
size_t) (2*x+2),
3828 sizeof(*graphic_context[n]->dash_pattern));
3829 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3831 (void) ThrowMagickException(exception,GetMagickModule(),
3832 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3837 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3838 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3839 for (j=0; j < x; j++)
3841 (void) GetNextToken(q,&q,extent,token);
3842 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3843 ThrowPointExpectedException(token,exception);
3845 (void) GetNextToken(q,&q,extent,token);
3846 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3848 if (token == next_token)
3849 ThrowPointExpectedException(token,exception);
3850 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3853 if (((x & 0x01) != 0) && (j == x))
3854 for ( ; j < (2*x); j++)
3855 graphic_context[n]->dash_pattern[j]=
3856 graphic_context[n]->dash_pattern[j-x];
3857 graphic_context[n]->dash_pattern[j]=0.0;
3860 (void) GetNextToken(q,&q,extent,token);
3863 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3865 (void) GetNextToken(q,&q,extent,token);
3866 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3867 if (token == next_token)
3868 ThrowPointExpectedException(token,exception);
3871 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3876 (void) GetNextToken(q,&q,extent,token);
3877 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3883 graphic_context[n]->linecap=(LineCap) linecap;
3886 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3891 (void) GetNextToken(q,&q,extent,token);
3892 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3899 graphic_context[n]->linejoin=(LineJoin) linejoin;
3902 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3904 (void) GetNextToken(q,&q,extent,token);
3905 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3908 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3913 (void) GetNextToken(q,&q,extent,token);
3914 if (graphic_context[n]->clip_path != MagickFalse)
3916 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3917 opacity=MagickMin(MagickMax(factor*GetDrawValue(token,&next_token),
3919 if (token == next_token)
3920 ThrowPointExpectedException(token,exception);
3921 if (graphic_context[n]->compliance == SVGCompliance)
3922 graphic_context[n]->stroke_alpha*=opacity;
3924 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3925 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3926 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3928 graphic_context[n]->stroke.alpha=(MagickRealType)
3929 ClampToQuantum((
double) QuantumRange*opacity);
3930 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3933 if (LocaleCompare(
"stroke-width",keyword) == 0)
3935 (void) GetNextToken(q,&q,extent,token);
3936 if (graphic_context[n]->clip_path != MagickFalse)
3938 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3939 if ((token == next_token) ||
3940 (graphic_context[n]->stroke_width < 0.0))
3941 ThrowPointExpectedException(token,exception);
3950 if (LocaleCompare(
"text",keyword) == 0)
3952 primitive_type=TextPrimitive;
3956 if (LocaleCompare(
"text-align",keyword) == 0)
3961 (void) GetNextToken(q,&q,extent,token);
3962 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3968 graphic_context[n]->align=(AlignType) align;
3971 if (LocaleCompare(
"text-anchor",keyword) == 0)
3976 (void) GetNextToken(q,&q,extent,token);
3977 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3983 graphic_context[n]->align=(AlignType) align;
3986 if (LocaleCompare(
"text-antialias",keyword) == 0)
3988 (void) GetNextToken(q,&q,extent,token);
3989 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
3990 MagickTrue : MagickFalse;
3993 if (LocaleCompare(
"text-undercolor",keyword) == 0)
3995 (void) GetNextToken(q,&q,extent,token);
3996 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3997 &graphic_context[n]->undercolor,exception);
4000 if (LocaleCompare(
"translate",keyword) == 0)
4002 (void) GetNextToken(q,&q,extent,token);
4003 affine.tx=GetDrawValue(token,&next_token);
4004 if (token == next_token)
4005 ThrowPointExpectedException(token,exception);
4006 (void) GetNextToken(q,&q,extent,token);
4007 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4008 ThrowPointExpectedException(token,exception);
4010 (void) GetNextToken(q,&q,extent,token);
4011 affine.ty=GetDrawValue(token,&next_token);
4012 if (token == next_token)
4013 ThrowPointExpectedException(token,exception);
4023 if (LocaleCompare(
"use",keyword) == 0)
4031 (void) GetNextToken(q,&q,extent,token);
4032 use=(
const char *) GetValueFromSplayTree(macros,token);
4033 if (use != (
const char *) NULL)
4035 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4036 if (draw_info->macro_expansion != (
size_t *) NULL)
4038 if (*draw_info->macro_expansion >= MacroExpansionLimit)
4040 (void) ThrowMagickException(exception,GetMagickModule(),
4041 DrawError,
"NonconformingDrawingPrimitiveDefinition",
4043 clone_info=DestroyDrawInfo(clone_info);
4044 return(MagickFalse);
4046 (*draw_info->macro_expansion)++;
4048 (void) CloneString(&clone_info->primitive,use);
4049 status=RenderMVGContent(image,clone_info,depth+1,exception);
4050 clone_info=DestroyDrawInfo(clone_info);
4060 if (LocaleCompare(
"viewbox",keyword) == 0)
4062 (void) GetNextToken(q,&q,extent,token);
4063 graphic_context[n]->viewbox.x=CastDoubleToSsizeT(ceil(
4064 GetDrawValue(token,&next_token)-0.5));
4065 if (token == next_token)
4066 ThrowPointExpectedException(token,exception);
4067 (void) GetNextToken(q,&q,extent,token);
4068 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4069 ThrowPointExpectedException(token,exception);
4071 (void) GetNextToken(q,&q,extent,token);
4072 graphic_context[n]->viewbox.y=CastDoubleToSsizeT(
4073 ceil(GetDrawValue(token,&next_token)-0.5));
4074 if (token == next_token)
4075 ThrowPointExpectedException(token,exception);
4076 (void) GetNextToken(q,&q,extent,token);
4077 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4078 ThrowPointExpectedException(token,exception);
4080 (void) GetNextToken(q,&q,extent,token);
4081 graphic_context[n]->viewbox.width=CastDoubleToSizeT(floor(
4082 GetDrawValue(token,&next_token)+0.5));
4083 if (token == next_token)
4084 ThrowPointExpectedException(token,exception);
4085 (void) GetNextToken(q,&q,extent,token);
4086 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4087 ThrowPointExpectedException(token,exception);
4089 (void) GetNextToken(q,&q,extent,token);
4090 graphic_context[n]->viewbox.height=CastDoubleToSizeT(floor(
4091 GetDrawValue(token,&next_token)+0.5));
4092 if (token == next_token)
4093 ThrowPointExpectedException(token,exception);
4102 if (LocaleCompare(
"word-spacing",keyword) == 0)
4104 (void) GetNextToken(q,&q,extent,token);
4105 graphic_context[n]->interword_spacing=GetDrawValue(token,
4107 if (token == next_token)
4108 ThrowPointExpectedException(token,exception);
4120 if (status == MagickFalse)
4122 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4123 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4124 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4125 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4127 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4128 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4129 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4130 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4131 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4133 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4136 if (primitive_type == UndefinedPrimitive)
4140 if (number_stops > 1)
4145 type=LinearGradient;
4146 if (draw_info->gradient.type == RadialGradient)
4147 type=RadialGradient;
4148 (void) GradientImage(image,type,PadSpread,stops,number_stops,
4151 if (number_stops > 0)
4152 stops=(StopInfo *) RelinquishMagickMemory(stops);
4154 if ((draw_info->debug != MagickFalse) && (q > p))
4155 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int)
4162 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4163 if (primitive_info[i].text != (
char *) NULL)
4164 primitive_info[i].text=DestroyString(primitive_info[i].text);
4168 primitive_info[0].primitive=primitive_type;
4169 primitive_info[0].point.x=0.0;
4170 primitive_info[0].point.y=0.0;
4171 primitive_info[0].coordinates=0;
4172 primitive_info[0].method=FloodfillMethod;
4173 primitive_info[0].closed_subpath=MagickFalse;
4174 for (x=0; *q !=
'\0'; x++)
4179 if (IsValidPoint(q) == MagickFalse)
4181 (void) GetNextToken(q,&q,extent,token);
4182 point.x=GetDrawValue(token,&next_token);
4183 if (token == next_token)
4184 ThrowPointExpectedException(token,exception);
4185 (void) GetNextToken(q,&q,extent,token);
4186 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4187 ThrowPointExpectedException(token,exception);
4189 (void) GetNextToken(q,&q,extent,token);
4190 point.y=GetDrawValue(token,&next_token);
4191 if (token == next_token)
4192 ThrowPointExpectedException(token,exception);
4193 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4195 (void) GetNextToken(q,&q,extent,token);
4196 primitive_info[i].primitive=primitive_type;
4197 primitive_info[i].point=point;
4198 primitive_info[i].coordinates=0;
4199 primitive_info[i].method=FloodfillMethod;
4200 primitive_info[i].closed_subpath=MagickFalse;
4203 if (i < (ssize_t) number_points)
4205 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4207 primitive_info=(*mvg_info.primitive_info);
4208 if (status == MagickFalse)
4211 if (status == MagickFalse)
4213 if (primitive_info[j].text != (
char *) NULL)
4214 primitive_info[j].text=DestroyString(primitive_info[j].text);
4215 primitive_info[j].primitive=primitive_type;
4216 primitive_info[j].coordinates=(size_t) x;
4217 primitive_info[j].method=FloodfillMethod;
4218 primitive_info[j].closed_subpath=MagickFalse;
4222 bounds.x1=primitive_info[j].point.x;
4223 bounds.y1=primitive_info[j].point.y;
4224 bounds.x2=primitive_info[j].point.x;
4225 bounds.y2=primitive_info[j].point.y;
4226 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4228 point=primitive_info[j+k].point;
4229 if (point.x < bounds.x1)
4231 if (point.y < bounds.y1)
4233 if (point.x > bounds.x2)
4235 if (point.y > bounds.y2)
4241 coordinates=(double) primitive_info[j].coordinates;
4242 switch (primitive_type)
4244 case RectanglePrimitive:
4249 case RoundRectanglePrimitive:
4256 alpha=bounds.x2-bounds.x1;
4257 beta=bounds.y2-bounds.y1;
4258 radius=hypot(alpha,beta);
4260 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4261 BezierQuantum+360.0;
4264 case BezierPrimitive:
4266 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4275 (void) GetNextToken(q,&q,extent,token);
4278 for (s=token; *s !=
'\0'; s=t)
4283 value=GetDrawValue(s,&t);
4292 for (s=token; *s !=
'\0'; s++)
4293 if (strspn(s,
"AaCcQqSsTt") != 0)
4294 coordinates+=(20.0*BezierQuantum)+360.0;
4300 if (status == MagickFalse)
4302 if (((
size_t) (i+coordinates)) >= number_points)
4307 number_points+=(size_t) coordinates+1;
4308 if (number_points < (
size_t) coordinates)
4310 (void) ThrowMagickException(exception,GetMagickModule(),
4311 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4317 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points+
4318 (
double) coordinates+1.0);
4319 primitive_info=(*mvg_info.primitive_info);
4320 if (status == MagickFalse)
4323 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,
4324 PrimitiveExtentPad);
4325 primitive_info=(*mvg_info.primitive_info);
4326 if (status == MagickFalse)
4329 switch (primitive_type)
4331 case PointPrimitive:
4334 if (primitive_info[j].coordinates != 1)
4339 status&=(MagickStatusType) TracePoint(primitive_info+j,
4340 primitive_info[j].point);
4341 primitive_info=(*mvg_info.primitive_info);
4342 if (status == MagickFalse)
4344 i=j+(ssize_t) primitive_info[j].coordinates;
4349 if (primitive_info[j].coordinates != 2)
4354 status&=(MagickStatusType) TraceLine(primitive_info+j,
4355 primitive_info[j].point,primitive_info[j+1].point);
4356 primitive_info=(*mvg_info.primitive_info);
4357 if (status == MagickFalse)
4359 i=j+(ssize_t) primitive_info[j].coordinates;
4362 case RectanglePrimitive:
4364 if (primitive_info[j].coordinates != 2)
4369 status&=(MagickStatusType) TraceRectangle(primitive_info+j,
4370 primitive_info[j].point,primitive_info[j+1].point);
4371 primitive_info=(*mvg_info.primitive_info);
4372 if (status == MagickFalse)
4374 i=j+(ssize_t) primitive_info[j].coordinates;
4377 case RoundRectanglePrimitive:
4379 if (primitive_info[j].coordinates != 3)
4384 if ((primitive_info[j+2].point.x < 0.0) ||
4385 (primitive_info[j+2].point.y < 0.0))
4390 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4395 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4400 status&=(MagickStatusType) TraceRoundRectangle(&mvg_info,
4401 primitive_info[j].point,primitive_info[j+1].point,
4402 primitive_info[j+2].point);
4403 primitive_info=(*mvg_info.primitive_info);
4404 if (status == MagickFalse)
4406 i=j+(ssize_t) primitive_info[j].coordinates;
4411 if (primitive_info[j].coordinates != 3)
4416 status&=(MagickStatusType) TraceArc(&mvg_info,primitive_info[j].point,
4417 primitive_info[j+1].point,primitive_info[j+2].point);
4418 primitive_info=(*mvg_info.primitive_info);
4419 if (status == MagickFalse)
4421 i=j+(ssize_t) primitive_info[j].coordinates;
4424 case EllipsePrimitive:
4426 if (primitive_info[j].coordinates != 3)
4431 if ((primitive_info[j+1].point.x < 0.0) ||
4432 (primitive_info[j+1].point.y < 0.0))
4437 status&=(MagickStatusType) TraceEllipse(&mvg_info,
4438 primitive_info[j].point,primitive_info[j+1].point,
4439 primitive_info[j+2].point);
4440 primitive_info=(*mvg_info.primitive_info);
4441 if (status == MagickFalse)
4443 i=j+(ssize_t) primitive_info[j].coordinates;
4446 case CirclePrimitive:
4448 if (primitive_info[j].coordinates != 2)
4453 status&=(MagickStatusType) TraceCircle(&mvg_info,
4454 primitive_info[j].point,primitive_info[j+1].point);
4455 primitive_info=(*mvg_info.primitive_info);
4456 if (status == MagickFalse)
4458 i=j+(ssize_t) primitive_info[j].coordinates;
4461 case PolylinePrimitive:
4463 if (primitive_info[j].coordinates < 1)
4470 case PolygonPrimitive:
4472 if (primitive_info[j].coordinates < 3)
4477 primitive_info[i]=primitive_info[j];
4478 primitive_info[i].coordinates=0;
4479 primitive_info[j].coordinates++;
4480 primitive_info[j].closed_subpath=MagickTrue;
4484 case BezierPrimitive:
4486 if (primitive_info[j].coordinates < 3)
4491 status&=(MagickStatusType) TraceBezier(&mvg_info,
4492 primitive_info[j].coordinates);
4493 primitive_info=(*mvg_info.primitive_info);
4494 if (status == MagickFalse)
4496 i=j+(ssize_t) primitive_info[j].coordinates;
4501 coordinates=(double) TracePath(&mvg_info,token,exception);
4502 primitive_info=(*mvg_info.primitive_info);
4503 if (status == MagickFalse)
4505 if (coordinates < 0.0)
4510 i=(ssize_t) (j+coordinates);
4513 case AlphaPrimitive:
4514 case ColorPrimitive:
4519 if (primitive_info[j].coordinates != 1)
4524 (void) GetNextToken(q,&q,extent,token);
4525 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4531 primitive_info[j].method=(PaintMethod) method;
4536 if (primitive_info[j].coordinates != 1)
4542 (void) GetNextToken(q,&q,extent,token);
4543 (void) CloneString(&primitive_info[j].text,token);
4547 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4548 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4549 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4551 mvg_info.point=primitive_info->point;
4552 primitive_info->point.x+=cursor;
4556 mvg_info.point=primitive_info->point;
4559 clone_info->render=MagickFalse;
4560 clone_info->text=AcquireString(token);
4561 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,
4562 &metrics,exception);
4563 clone_info=DestroyDrawInfo(clone_info);
4564 cursor+=metrics.width;
4565 if (graphic_context[n]->compliance != SVGCompliance)
4569 case ImagePrimitive:
4571 if (primitive_info[j].coordinates != 2)
4576 (void) GetNextToken(q,&q,extent,token);
4577 (void) CloneString(&primitive_info[j].text,token);
4584 primitive_info[i].primitive=UndefinedPrimitive;
4585 if ((draw_info->debug != MagickFalse) && (q > p))
4586 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int) (q-p),p);
4590 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4591 &graphic_context[n]->affine));
4592 primitive_info=(*mvg_info.primitive_info);
4595 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4596 graphic_context[n]->stroke_width);
4597 primitive_info=(*mvg_info.primitive_info);
4605 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4607 point=primitive_info[i].point;
4608 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4609 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4610 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4611 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4612 point=primitive_info[i].point;
4613 if (point.x < graphic_context[n]->bounds.x1)
4614 graphic_context[n]->bounds.x1=point.x;
4615 if (point.y < graphic_context[n]->bounds.y1)
4616 graphic_context[n]->bounds.y1=point.y;
4617 if (point.x > graphic_context[n]->bounds.x2)
4618 graphic_context[n]->bounds.x2=point.x;
4619 if (point.y > graphic_context[n]->bounds.y2)
4620 graphic_context[n]->bounds.y2=point.y;
4621 if (primitive_info[i].primitive == ImagePrimitive)
4623 if (i >= (ssize_t) number_points)
4624 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4626 if (graphic_context[n]->render != MagickFalse)
4628 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4629 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4630 (LocaleCompare(graphic_context[n]->clip_mask,
4631 graphic_context[n-1]->clip_mask) != 0))
4636 clip_path=(
const char *) GetValueFromSplayTree(macros,
4637 graphic_context[n]->clip_mask);
4638 if (clip_path != (
const char *) NULL)
4639 (void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4641 status&=(MagickStatusType) DrawClipPath(image,graphic_context[n],
4642 graphic_context[n]->clip_mask,exception);
4644 status&=(MagickStatusType) DrawPrimitive(image,graphic_context[n],
4645 primitive_info,exception);
4647 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4649 if (proceed == MagickFalse)
4654 if (draw_info->debug != MagickFalse)
4655 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4659 macros=DestroySplayTree(macros);
4660 token=DestroyString(token);
4661 if (primitive_info != (PrimitiveInfo *) NULL)
4663 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4664 if (primitive_info[i].text != (
char *) NULL)
4665 primitive_info[i].text=DestroyString(primitive_info[i].text);
4666 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4668 primitive=DestroyString(primitive);
4669 if (stops != (StopInfo *) NULL)
4670 stops=(StopInfo *) RelinquishMagickMemory(stops);
4671 for ( ; n >= 0; n--)
4672 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4673 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
4674 if ((status == MagickFalse) && (exception->severity < ErrorException))
4675 ThrowBinaryException(DrawError,
"NonconformingDrawingPrimitiveDefinition",
4677 return(status != 0 ? MagickTrue : MagickFalse);
4680MagickExport MagickBooleanType DrawImage(Image *image,
const DrawInfo *draw_info,
4681 ExceptionInfo *exception)
4687 macro_expansion = 0;
4689 ((DrawInfo *) draw_info)->macro_expansion=(¯o_expansion);
4690 status=RenderMVGContent(image,draw_info,0,exception);
4691 ((DrawInfo *) draw_info)->macro_expansion=(
size_t *) NULL;
4726MagickExport MagickBooleanType DrawPatternPath(Image *image,
4727 const DrawInfo *draw_info,
const char *name,Image **pattern,
4728 ExceptionInfo *exception)
4731 property[MagickPathExtent];
4747 assert(image != (Image *) NULL);
4748 assert(image->signature == MagickCoreSignature);
4749 assert(draw_info != (
const DrawInfo *) NULL);
4750 assert(name != (
const char *) NULL);
4751 if (IsEventLogging() != MagickFalse)
4752 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4753 (void) FormatLocaleString(property,MagickPathExtent,
"%s",name);
4754 path=GetImageArtifact(image,property);
4755 if (path == (
const char *) NULL)
4756 return(MagickFalse);
4757 (void) FormatLocaleString(property,MagickPathExtent,
"%s-geometry",name);
4758 geometry=GetImageArtifact(image,property);
4759 if (geometry == (
const char *) NULL)
4760 return(MagickFalse);
4761 if ((*pattern) != (Image *) NULL)
4762 *pattern=DestroyImage(*pattern);
4763 image_info=AcquireImageInfo();
4764 image_info->size=AcquireString(geometry);
4765 *pattern=AcquireImage(image_info,exception);
4766 image_info=DestroyImageInfo(image_info);
4767 (void) QueryColorCompliance(
"#00000000",AllCompliance,
4768 &(*pattern)->background_color,exception);
4769 (void) SetImageBackgroundColor(*pattern,exception);
4770 if (draw_info->debug != MagickFalse)
4771 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4772 "begin pattern-path %s %s",name,geometry);
4773 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4774 if (clone_info->fill_pattern != (Image *) NULL)
4775 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4776 if (clone_info->stroke_pattern != (Image *) NULL)
4777 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4778 (void) FormatLocaleString(property,MagickPathExtent,
"%s-type",name);
4779 type=GetImageArtifact(image,property);
4780 if (type != (
const char *) NULL)
4781 clone_info->gradient.type=(GradientType) ParseCommandOption(
4782 MagickGradientOptions,MagickFalse,type);
4783 (void) CloneString(&clone_info->primitive,path);
4784 status=RenderMVGContent(*pattern,clone_info,0,exception);
4785 clone_info=DestroyDrawInfo(clone_info);
4786 if (draw_info->debug != MagickFalse)
4787 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4822static PolygonInfo **DestroyPolygonTLS(PolygonInfo **polygon_info)
4827 assert(polygon_info != (PolygonInfo **) NULL);
4828 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4829 if (polygon_info[i] != (PolygonInfo *) NULL)
4830 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4831 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
4832 return(polygon_info);
4835static PolygonInfo **AcquirePolygonTLS(
const PrimitiveInfo *primitive_info,
4836 ExceptionInfo *exception)
4839 *magick_restrict path_info;
4847 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4848 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
4849 sizeof(*polygon_info));
4850 if (polygon_info == (PolygonInfo **) NULL)
4852 (void) ThrowMagickException(exception,GetMagickModule(),
4853 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4854 return((PolygonInfo **) NULL);
4856 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4857 path_info=ConvertPrimitiveToPath(primitive_info,exception);
4858 if (path_info == (PathInfo *) NULL)
4859 return(DestroyPolygonTLS(polygon_info));
4860 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4861 if (polygon_info[0] == (PolygonInfo *) NULL)
4863 (void) ThrowMagickException(exception,GetMagickModule(),
4864 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4865 return(DestroyPolygonTLS(polygon_info));
4867 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
4868 return(polygon_info);
4871static MagickBooleanType ClonePolygonEdgesTLS(PolygonInfo **polygon_info,
4872 const size_t number_threads,ExceptionInfo *exception)
4877 for (i=1; i < (ssize_t) number_threads; i++)
4885 polygon_info[i]=(PolygonInfo *) AcquireMagickMemory(
4886 sizeof(*polygon_info[i]));
4887 if (polygon_info[i] == (PolygonInfo *) NULL)
4889 (void) ThrowMagickException(exception,GetMagickModule(),
4890 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4891 return(MagickFalse);
4893 polygon_info[i]->number_edges=0;
4894 edge_info=polygon_info[0]->edges;
4895 polygon_info[i]->edges=(EdgeInfo *) AcquireQuantumMemory(
4896 polygon_info[0]->number_edges,
sizeof(*edge_info));
4897 if (polygon_info[i]->edges == (EdgeInfo *) NULL)
4899 (void) ThrowMagickException(exception,GetMagickModule(),
4900 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4901 return(MagickFalse);
4903 (void) memcpy(polygon_info[i]->edges,edge_info,
4904 polygon_info[0]->number_edges*
sizeof(*edge_info));
4905 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4906 polygon_info[i]->edges[j].points=(PointInfo *) NULL;
4907 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4908 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4910 edge_info=polygon_info[0]->edges+j;
4911 polygon_info[i]->edges[j].points=(PointInfo *) AcquireQuantumMemory(
4912 edge_info->number_points,
sizeof(*edge_info));
4913 if (polygon_info[i]->edges[j].points == (PointInfo *) NULL)
4915 (void) ThrowMagickException(exception,GetMagickModule(),
4916 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4917 return(MagickFalse);
4919 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4920 edge_info->number_points*
sizeof(*edge_info->points));
4926static size_t DestroyEdge(PolygonInfo *polygon_info,
const ssize_t edge)
4928 assert(edge < (ssize_t) polygon_info->number_edges);
4929 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
4930 polygon_info->edges[edge].points);
4931 polygon_info->number_edges--;
4932 if (edge < (ssize_t) polygon_info->number_edges)
4933 (void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4934 (polygon_info->number_edges-(
size_t) edge)*
sizeof(*polygon_info->edges));
4935 return(polygon_info->number_edges);
4938static double GetFillAlpha(PolygonInfo *polygon_info,
const double mid,
4939 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4940 const ssize_t y,
double *stroke_alpha)
4967 p=polygon_info->edges;
4968 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4970 if ((
double) y <= (p->bounds.y1-mid-0.5))
4972 if ((
double) y > (p->bounds.y2+mid+0.5))
4975 (void) DestroyEdge(polygon_info,j--);
4978 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
4979 ((
double) x > (p->bounds.x2+mid+0.5)))
4981 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
4982 for ( ; i < (ssize_t) p->number_points; i++)
4984 if ((
double) y <= (p->points[i-1].y-mid-0.5))
4986 if ((
double) y > (p->points[i].y+mid+0.5))
4988 if (p->scanline != (
double) y)
4990 p->scanline=(double) y;
4991 p->highwater=(size_t) i;
4997 delta.x=(q+1)->x-q->x;
4998 delta.y=(q+1)->y-q->y;
4999 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
5005 delta.x=(double) x-q->x;
5006 delta.y=(double) y-q->y;
5007 distance=delta.x*delta.x+delta.y*delta.y;
5011 alpha=delta.x*delta.x+delta.y*delta.y;
5017 delta.x=(double) x-(q+1)->x;
5018 delta.y=(double) y-(q+1)->y;
5019 distance=delta.x*delta.x+delta.y*delta.y;
5026 alpha=MagickSafeReciprocal(alpha);
5027 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
5028 distance=alpha*beta*beta;
5035 if (p->ghostline == MagickFalse)
5038 if ((*stroke_alpha < 1.0) &&
5039 (distance <= ((alpha+0.25)*(alpha+0.25))))
5042 if (distance <= ((alpha+0.25)*(alpha+0.25)))
5047 if (fabs(distance-1.0) >= MagickEpsilon)
5048 beta=sqrt((
double) distance);
5050 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
5051 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
5055 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
5057 if (distance <= 0.0)
5064 if (fabs(beta) < MagickEpsilon)
5067 if (fabs(distance-1.0) >= MagickEpsilon)
5068 beta=sqrt(distance);
5071 if (subpath_alpha < (alpha*alpha))
5072 subpath_alpha=alpha*alpha;
5078 if (fill == MagickFalse)
5080 if (subpath_alpha >= 1.0)
5086 p=polygon_info->edges;
5087 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
5089 if ((
double) y <= p->bounds.y1)
5091 if (((
double) y > p->bounds.y2) || ((
double) x <= p->bounds.x1))
5093 if ((
double) x > p->bounds.x2)
5095 winding_number+=p->direction != 0 ? 1 : -1;
5098 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5099 for ( ; i < (ssize_t) (p->number_points-1); i++)
5100 if ((
double) y <= p->points[i].y)
5103 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
5104 winding_number+=p->direction != 0 ? 1 : -1;
5106 if (fill_rule != NonZeroRule)
5108 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
5112 if (MagickAbsoluteValue(winding_number) != 0)
5114 return(subpath_alpha);
5117static MagickBooleanType DrawPolygonPrimitive(Image *image,
5118 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5119 ExceptionInfo *exception)
5121 typedef struct _ExtentInfo
5150 **magick_restrict polygon_info;
5162 assert(image != (Image *) NULL);
5163 assert(image->signature == MagickCoreSignature);
5164 assert(draw_info != (DrawInfo *) NULL);
5165 assert(draw_info->signature == MagickCoreSignature);
5166 assert(primitive_info != (PrimitiveInfo *) NULL);
5167 if (IsEventLogging() != MagickFalse)
5168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5169 if (primitive_info->coordinates <= 1)
5174 polygon_info=AcquirePolygonTLS(primitive_info,exception);
5175 if (polygon_info == (PolygonInfo **) NULL)
5176 return(MagickFalse);
5177 if (draw_info->debug != MagickFalse)
5178 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5179 fill=(primitive_info->method == FillToBorderMethod) ||
5180 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5181 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5182 bounds=polygon_info[0]->edges[0].bounds;
5183 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5184 if (IsStringTrue(artifact) != MagickFalse)
5185 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
5186 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5188 p=polygon_info[0]->edges+i;
5189 if (p->bounds.x1 < bounds.x1)
5190 bounds.x1=p->bounds.x1;
5191 if (p->bounds.y1 < bounds.y1)
5192 bounds.y1=p->bounds.y1;
5193 if (p->bounds.x2 > bounds.x2)
5194 bounds.x2=p->bounds.x2;
5195 if (p->bounds.y2 > bounds.y2)
5196 bounds.y2=p->bounds.y2;
5198 bounds.x1-=(mid+1.0);
5199 bounds.y1-=(mid+1.0);
5200 bounds.x2+=(mid+1.0);
5201 bounds.y2+=(mid+1.0);
5202 if ((bounds.x1 >= (
double) image->columns) ||
5203 (bounds.y1 >= (
double) image->rows) ||
5204 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5206 polygon_info=DestroyPolygonTLS(polygon_info);
5209 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5210 (
double) image->columns-1.0 : bounds.x1;
5211 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5212 (
double) image->rows-1.0 : bounds.y1;
5213 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5214 (
double) image->columns-1.0 : bounds.x2;
5215 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5216 (
double) image->rows-1.0 : bounds.y2;
5217 poly_extent.x1=CastDoubleToSsizeT(ceil(bounds.x1-0.5));
5218 poly_extent.y1=CastDoubleToSsizeT(ceil(bounds.y1-0.5));
5219 poly_extent.x2=CastDoubleToSsizeT(floor(bounds.x2+0.5));
5220 poly_extent.y2=CastDoubleToSsizeT(floor(bounds.y2+0.5));
5221 number_threads=(size_t) GetMagickNumberThreads(image,image,(
size_t)
5222 (poly_extent.y2-poly_extent.y1+1),1);
5223 status=ClonePolygonEdgesTLS(polygon_info,number_threads,exception);
5224 if (status == MagickFalse)
5226 polygon_info=DestroyPolygonTLS(polygon_info);
5229 image_view=AcquireAuthenticCacheView(image,exception);
5230 if ((primitive_info->coordinates == 1) ||
5231 (polygon_info[0]->number_edges == 0))
5236#if defined(MAGICKCORE_OPENMP_SUPPORT)
5237 #pragma omp parallel for schedule(static) shared(status) \
5238 num_threads((int) number_threads)
5240 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5251 if (status == MagickFalse)
5254 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5256 if (q == (Quantum *) NULL)
5261 GetPixelInfo(image,&pixel);
5262 for ( ; x <= poly_extent.x2; x++)
5264 if ((x == CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5))) &&
5265 (y == CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5))))
5267 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&pixel,
5269 SetPixelViaPixelInfo(image,&pixel,q);
5271 q+=(ptrdiff_t) GetPixelChannels(image);
5273 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5276 image_view=DestroyCacheView(image_view);
5277 polygon_info=DestroyPolygonTLS(polygon_info);
5278 if (draw_info->debug != MagickFalse)
5279 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5280 " end draw-polygon");
5286#if defined(MAGICKCORE_OPENMP_SUPPORT)
5287 #pragma omp parallel for schedule(static) shared(status) \
5288 num_threads((int) number_threads)
5290 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5293 id = GetOpenMPThreadId();
5301 if (status == MagickFalse)
5303 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5304 (poly_extent.x2-poly_extent.x1+1),1,exception);
5305 if (q == (Quantum *) NULL)
5310 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5323 fill_alpha=GetFillAlpha(polygon_info[
id],mid,fill,draw_info->fill_rule,
5325 if (draw_info->stroke_antialias == MagickFalse)
5327 fill_alpha=fill_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5328 stroke_alpha=stroke_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5330 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&fill_color,
5332 CompositePixelOver(image,&fill_color,fill_alpha*fill_color.alpha,q,
5333 (
double) GetPixelAlpha(image,q),q);
5334 GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&stroke_color,
5336 CompositePixelOver(image,&stroke_color,stroke_alpha*stroke_color.alpha,q,
5337 (
double) GetPixelAlpha(image,q),q);
5338 q+=(ptrdiff_t) GetPixelChannels(image);
5340 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5343 image_view=DestroyCacheView(image_view);
5344 polygon_info=DestroyPolygonTLS(polygon_info);
5345 if (draw_info->debug != MagickFalse)
5346 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5379static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5405 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5406 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5407 switch (primitive_info->primitive)
5409 case AlphaPrimitive:
5411 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5412 "AlphaPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5413 methods[primitive_info->method]);
5416 case ColorPrimitive:
5418 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5419 "ColorPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5420 methods[primitive_info->method]);
5423 case ImagePrimitive:
5425 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5426 "ImagePrimitive %.17g,%.17g",(
double) x,(
double) y);
5429 case PointPrimitive:
5431 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5432 "PointPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5433 methods[primitive_info->method]);
5438 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5439 "TextPrimitive %.17g,%.17g",(
double) x,(
double) y);
5446 p=primitive_info[0].point;
5449 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5451 point=primitive_info[i].point;
5452 if (coordinates <= 0)
5454 coordinates=(ssize_t) primitive_info[i].coordinates;
5455 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5456 " begin open (%.17g)",(
double) coordinates);
5459 point=primitive_info[i].point;
5460 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5461 (fabs(q.y-point.y) >= MagickEpsilon))
5462 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5463 " %.17g: %.18g,%.18g",(
double) coordinates,point.x,point.y);
5465 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5466 " %.17g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5469 if (coordinates > 0)
5471 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5472 (fabs(p.y-point.y) >= MagickEpsilon))
5473 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.17g)",
5474 (
double) coordinates);
5476 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.17g)",
5477 (
double) coordinates);
5481MagickExport MagickBooleanType DrawPrimitive(Image *image,
5482 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5483 ExceptionInfo *exception)
5498 if (draw_info->debug != MagickFalse)
5500 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5501 " begin draw-primitive");
5502 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5503 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5504 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5505 draw_info->affine.tx,draw_info->affine.ty);
5508 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5509 ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
5510 (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
5511 status&=(MagickStatusType) SetImageColorspace(image,sRGBColorspace,
5513 if (draw_info->compliance == SVGCompliance)
5515 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5516 draw_info->clipping_mask,exception);
5517 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5518 draw_info->composite_mask,exception);
5520 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5521 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5522 image_view=AcquireAuthenticCacheView(image,exception);
5523 switch (primitive_info->primitive)
5525 case AlphaPrimitive:
5527 if ((image->alpha_trait & BlendPixelTrait) == 0)
5528 status&=(MagickStatusType) SetImageAlphaChannel(image,
5529 OpaqueAlphaChannel,exception);
5530 switch (primitive_info->method)
5541 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5542 if (q == (Quantum *) NULL)
5544 GetFillColor(draw_info,x,y,&pixel,exception);
5545 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5546 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5556 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5557 x,y,&target,exception);
5558 GetPixelInfo(image,&pixel);
5559 for (y=0; y < (ssize_t) image->rows; y++)
5564 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5566 if (q == (Quantum *) NULL)
5568 for (x=0; x < (ssize_t) image->columns; x++)
5570 GetPixelInfoPixel(image,q,&pixel);
5571 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5573 q+=(ptrdiff_t) GetPixelChannels(image);
5576 GetFillColor(draw_info,x,y,&pixel,exception);
5577 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5578 q+=(ptrdiff_t) GetPixelChannels(image);
5580 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5582 if (status == MagickFalse)
5587 case FloodfillMethod:
5588 case FillToBorderMethod:
5596 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5597 TileVirtualPixelMethod,x,y,&target,exception);
5598 if (primitive_info->method == FillToBorderMethod)
5600 target.red=(double) draw_info->border_color.red;
5601 target.green=(double) draw_info->border_color.green;
5602 target.blue=(double) draw_info->border_color.blue;
5604 channel_mask=SetImageChannelMask(image,AlphaChannel);
5605 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5606 &target,x,y,primitive_info->method == FloodfillMethod ?
5607 MagickFalse : MagickTrue,exception);
5608 (void) SetImageChannelMask(image,channel_mask);
5616 for (y=0; y < (ssize_t) image->rows; y++)
5621 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5623 if (q == (Quantum *) NULL)
5625 for (x=0; x < (ssize_t) image->columns; x++)
5627 GetFillColor(draw_info,x,y,&pixel,exception);
5628 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5629 q+=(ptrdiff_t) GetPixelChannels(image);
5631 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5633 if (status == MagickFalse)
5641 case ColorPrimitive:
5643 switch (primitive_info->method)
5654 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5655 if (q == (Quantum *) NULL)
5657 GetPixelInfo(image,&pixel);
5658 GetFillColor(draw_info,x,y,&pixel,exception);
5659 SetPixelViaPixelInfo(image,&pixel,q);
5660 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5670 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5671 x,y,&target,exception);
5672 for (y=0; y < (ssize_t) image->rows; y++)
5677 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5679 if (q == (Quantum *) NULL)
5681 for (x=0; x < (ssize_t) image->columns; x++)
5683 GetPixelInfoPixel(image,q,&pixel);
5684 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5686 q+=(ptrdiff_t) GetPixelChannels(image);
5689 GetFillColor(draw_info,x,y,&pixel,exception);
5690 SetPixelViaPixelInfo(image,&pixel,q);
5691 q+=(ptrdiff_t) GetPixelChannels(image);
5693 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5695 if (status == MagickFalse)
5700 case FloodfillMethod:
5701 case FillToBorderMethod:
5706 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5707 TileVirtualPixelMethod,x,y,&target,exception);
5708 if (primitive_info->method == FillToBorderMethod)
5710 target.red=(double) draw_info->border_color.red;
5711 target.green=(double) draw_info->border_color.green;
5712 target.blue=(double) draw_info->border_color.blue;
5714 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5715 &target,x,y,primitive_info->method == FloodfillMethod ?
5716 MagickFalse : MagickTrue,exception);
5724 GetPixelInfo(image,&pixel);
5725 for (y=0; y < (ssize_t) image->rows; y++)
5730 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5732 if (q == (Quantum *) NULL)
5734 for (x=0; x < (ssize_t) image->columns; x++)
5736 GetFillColor(draw_info,x,y,&pixel,exception);
5737 SetPixelViaPixelInfo(image,&pixel,q);
5738 q+=(ptrdiff_t) GetPixelChannels(image);
5740 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5742 if (status == MagickFalse)
5750 case ImagePrimitive:
5756 composite_geometry[MagickPathExtent];
5772 if (primitive_info->text == (
char *) NULL)
5774 clone_info=AcquireImageInfo();
5775 composite_images=(Image *) NULL;
5776 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5777 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5780 if (*primitive_info->text !=
'\0')
5785 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5787 (void) SetImageInfo(clone_info,1,exception);
5788 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5790 if (clone_info->size != (
char *) NULL)
5791 clone_info->size=DestroyString(clone_info->size);
5792 if (clone_info->extract != (
char *) NULL)
5793 clone_info->extract=DestroyString(clone_info->extract);
5794 composite_images=StrictReadImage(clone_info,exception);
5796 clone_info=DestroyImageInfo(clone_info);
5797 if (composite_images == (Image *) NULL)
5802 composite_image=RemoveFirstImageFromList(&composite_images);
5803 composite_images=DestroyImageList(composite_images);
5804 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5805 NULL,(
void *) NULL);
5806 x1=CastDoubleToSsizeT(ceil(primitive_info[1].point.x-0.5));
5807 y1=CastDoubleToSsizeT(ceil(primitive_info[1].point.y-0.5));
5808 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5809 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5814 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5815 "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y);
5816 composite_image->filter=image->filter;
5817 status&=(MagickStatusType) TransformImage(&composite_image,
5818 (
char *) NULL,composite_geometry,exception);
5820 if (composite_image->alpha_trait == UndefinedPixelTrait)
5821 status&=(MagickStatusType) SetImageAlphaChannel(composite_image,
5822 OpaqueAlphaChannel,exception);
5823 if (draw_info->alpha != OpaqueAlpha)
5824 status&=(MagickStatusType) SetImageAlpha(composite_image,
5825 draw_info->alpha,exception);
5826 SetGeometry(image,&geometry);
5827 image->gravity=draw_info->gravity;
5830 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5831 "%.17gx%.17g%+.20g%+.20g",(
double) composite_image->columns,(
double)
5832 composite_image->rows,(
double) geometry.x,(
double) geometry.y);
5833 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
5834 affine=draw_info->affine;
5835 affine.tx=(double) geometry.x;
5836 affine.ty=(double) geometry.y;
5837 composite_image->interpolate=image->interpolate;
5838 if ((draw_info->compose == OverCompositeOp) ||
5839 (draw_info->compose == SrcOverCompositeOp))
5840 status&=(MagickStatusType) DrawAffineImage(image,composite_image,
5843 status&=(MagickStatusType) CompositeImage(image,composite_image,
5844 draw_info->compose,MagickTrue,geometry.x,geometry.y,exception);
5845 composite_image=DestroyImage(composite_image);
5848 case PointPrimitive:
5856 if ((y < 0) || (y >= (ssize_t) image->rows))
5858 if ((x < 0) || (x >= (ssize_t) image->columns))
5860 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5861 if (q == (Quantum *) NULL)
5863 GetFillColor(draw_info,x,y,&fill_color,exception);
5864 CompositePixelOver(image,&fill_color,(
double) fill_color.alpha,q,(
double)
5865 GetPixelAlpha(image,q),q);
5866 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5873 geometry[MagickPathExtent];
5878 if (primitive_info->text == (
char *) NULL)
5880 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5881 (void) CloneString(&clone_info->text,primitive_info->text);
5882 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
5883 primitive_info->point.x,primitive_info->point.y);
5884 (void) CloneString(&clone_info->geometry,geometry);
5885 status&=(MagickStatusType) AnnotateImage(image,clone_info,exception);
5886 clone_info=DestroyDrawInfo(clone_info);
5898 if (IsEventLogging() != MagickFalse)
5899 LogPrimitiveInfo(primitive_info);
5900 scale=ExpandAffine(&draw_info->affine);
5901 if ((draw_info->dash_pattern != (
double *) NULL) &&
5902 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5903 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5904 (draw_info->stroke.alpha != (
double) TransparentAlpha))
5909 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5910 clone_info->stroke_width=0.0;
5911 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5912 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5913 primitive_info,exception);
5914 clone_info=DestroyDrawInfo(clone_info);
5915 if (status != MagickFalse)
5916 status&=(MagickStatusType) DrawDashPolygon(draw_info,primitive_info,
5920 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5922 ((draw_info->stroke.alpha != (
double) TransparentAlpha) ||
5923 (draw_info->stroke_pattern != (Image *) NULL)))
5935 closed_path=primitive_info[0].closed_subpath;
5936 i=(ssize_t) primitive_info[0].coordinates;
5937 point_x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5938 point_y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5939 if ((point_x < MagickEpsilon) && (point_y < MagickEpsilon))
5940 closed_path=MagickTrue;
5941 if ((((draw_info->linecap == RoundCap) ||
5942 (closed_path != MagickFalse)) &&
5943 (draw_info->linejoin == RoundJoin)) ||
5944 (primitive_info[i].primitive != UndefinedPrimitive))
5946 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5947 primitive_info,exception);
5950 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5951 clone_info->stroke_width=0.0;
5952 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5953 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5954 primitive_info,exception);
5955 clone_info=DestroyDrawInfo(clone_info);
5956 if (status != MagickFalse)
5957 status&=(MagickStatusType) DrawStrokePolygon(image,draw_info,
5958 primitive_info,exception);
5961 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5962 primitive_info,exception);
5966 image_view=DestroyCacheView(image_view);
5967 if (draw_info->compliance == SVGCompliance)
5969 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5970 (Image *) NULL,exception);
5971 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5972 (Image *) NULL,exception);
5974 if (draw_info->debug != MagickFalse)
5975 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
5976 return(status != 0 ? MagickTrue : MagickFalse);
6009static MagickBooleanType DrawRoundLinecap(Image *image,
6010 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6011 ExceptionInfo *exception)
6019 if (primitive_info->coordinates < 1)
6020 return(MagickFalse);
6021 for (i=0; i < 4; i++)
6022 linecap[i]=(*primitive_info);
6023 linecap[0].coordinates=4;
6024 linecap[1].point.x+=2.0*MagickEpsilon;
6025 linecap[2].point.x+=2.0*MagickEpsilon;
6026 linecap[2].point.y+=2.0*MagickEpsilon;
6027 linecap[3].point.y+=2.0*MagickEpsilon;
6028 linecap[4].primitive=UndefinedPrimitive;
6029 return(DrawPolygonPrimitive(image,draw_info,linecap,exception));
6032static MagickBooleanType DrawStrokePolygon(Image *image,
6033 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6034 ExceptionInfo *exception)
6055 if (draw_info->debug != MagickFalse)
6056 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6057 " begin draw-stroke-polygon");
6058 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
6059 clone_info->fill=draw_info->stroke;
6060 if (clone_info->fill_pattern != (Image *) NULL)
6061 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
6062 if (clone_info->stroke_pattern != (Image *) NULL)
6063 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
6064 MagickTrue,exception);
6065 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
6066 clone_info->stroke_width=0.0;
6067 clone_info->fill_rule=NonZeroRule;
6069 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ptrdiff_t) p->coordinates)
6071 if (p->coordinates == 1)
6073 stroke_polygon=TraceStrokePolygon(draw_info,p,exception);
6074 if (stroke_polygon == (PrimitiveInfo *) NULL)
6079 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
6080 stroke_polygon,exception);
6081 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
6084 q=p+p->coordinates-1;
6085 closed_path=p->closed_subpath;
6086 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
6088 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,p,
6090 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,q,
6094 clone_info=DestroyDrawInfo(clone_info);
6095 if (draw_info->debug != MagickFalse)
6096 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6097 " end draw-stroke-polygon");
6098 return(status != 0 ? MagickTrue : MagickFalse);
6124MagickExport
void GetAffineMatrix(AffineMatrix *affine_matrix)
6126 if (IsEventLogging() != MagickFalse)
6127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6128 assert(affine_matrix != (AffineMatrix *) NULL);
6129 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
6130 affine_matrix->sx=1.0;
6131 affine_matrix->sy=1.0;
6158MagickExport
void GetDrawInfo(
const ImageInfo *image_info,DrawInfo *draw_info)
6172 assert(draw_info != (DrawInfo *) NULL);
6173 if (IsEventLogging() != MagickFalse)
6174 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6175 (void) memset(draw_info,0,
sizeof(*draw_info));
6176 draw_info->image_info=CloneImageInfo(image_info);
6177 GetAffineMatrix(&draw_info->affine);
6178 exception=AcquireExceptionInfo();
6179 (void) QueryColorCompliance(
"#000F",AllCompliance,&draw_info->fill,
6181 (void) QueryColorCompliance(
"#FFF0",AllCompliance,&draw_info->stroke,
6183 draw_info->stroke_antialias=draw_info->image_info->antialias;
6184 draw_info->stroke_width=1.0;
6185 draw_info->fill_rule=EvenOddRule;
6186 draw_info->alpha=OpaqueAlpha;
6187 draw_info->fill_alpha=OpaqueAlpha;
6188 draw_info->stroke_alpha=OpaqueAlpha;
6189 draw_info->linecap=ButtCap;
6190 draw_info->linejoin=MiterJoin;
6191 draw_info->miterlimit=10;
6192 draw_info->decorate=NoDecoration;
6193 draw_info->pointsize=12.0;
6194 draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
6195 draw_info->compose=OverCompositeOp;
6196 draw_info->render=MagickTrue;
6197 draw_info->clip_path=MagickFalse;
6198 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6199 MagickTrue : MagickFalse;
6200 draw_info->macro_expansion=(
size_t *) NULL;
6201 if (draw_info->image_info->font != (
char *) NULL)
6202 draw_info->font=AcquireString(draw_info->image_info->font);
6203 if (draw_info->image_info->density != (
char *) NULL)
6204 draw_info->density=AcquireString(draw_info->image_info->density);
6205 draw_info->text_antialias=draw_info->image_info->antialias;
6206 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6207 draw_info->pointsize=draw_info->image_info->pointsize;
6208 draw_info->border_color=draw_info->image_info->border_color;
6209 if (draw_info->image_info->server_name != (
char *) NULL)
6210 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6211 option=GetImageOption(draw_info->image_info,
"direction");
6212 if (option != (
const char *) NULL)
6213 draw_info->direction=(DirectionType) ParseCommandOption(
6214 MagickDirectionOptions,MagickFalse,option);
6216 draw_info->direction=UndefinedDirection;
6217 option=GetImageOption(draw_info->image_info,
"encoding");
6218 if (option != (
const char *) NULL)
6219 (void) CloneString(&draw_info->encoding,option);
6220 option=GetImageOption(draw_info->image_info,
"family");
6221 if (option != (
const char *) NULL)
6222 (void) CloneString(&draw_info->family,option);
6223 option=GetImageOption(draw_info->image_info,
"fill");
6224 if (option != (
const char *) NULL)
6225 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
6227 option=GetImageOption(draw_info->image_info,
"gravity");
6228 if (option != (
const char *) NULL)
6229 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6230 MagickFalse,option);
6231 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6232 if (option != (
const char *) NULL)
6233 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6234 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6235 if (option != (
const char *) NULL)
6236 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6237 option=GetImageOption(draw_info->image_info,
"kerning");
6238 if (option != (
const char *) NULL)
6239 draw_info->kerning=GetDrawValue(option,&next_token);
6240 option=GetImageOption(draw_info->image_info,
"stroke");
6241 if (option != (
const char *) NULL)
6242 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
6244 option=GetImageOption(draw_info->image_info,
"strokewidth");
6245 if (option != (
const char *) NULL)
6246 draw_info->stroke_width=GetDrawValue(option,&next_token);
6247 option=GetImageOption(draw_info->image_info,
"style");
6248 if (option != (
const char *) NULL)
6249 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6250 MagickFalse,option);
6251 option=GetImageOption(draw_info->image_info,
"undercolor");
6252 if (option != (
const char *) NULL)
6253 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
6255 option=GetImageOption(draw_info->image_info,
"weight");
6256 if (option != (
const char *) NULL)
6261 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6263 weight=(ssize_t) StringToUnsignedLong(option);
6264 draw_info->weight=(size_t) weight;
6266 option=GetImageOption(draw_info->image_info,
"word-break");
6267 if (option != (
const char *) NULL)
6268 draw_info->word_break=(WordBreakType) ParseCommandOption(
6269 MagickWordBreakOptions,MagickFalse,option);
6270 exception=DestroyExceptionInfo(exception);
6271 draw_info->signature=MagickCoreSignature;
6299static inline double Permutate(
const ssize_t n,
const ssize_t k)
6308 for (i=k+1; i <= n; i++)
6310 for (i=1; i <= (n-k); i++)
6331static MagickBooleanType TraceArc(MVGInfo *mvg_info,
const PointInfo start,
6332 const PointInfo end,
const PointInfo degrees)
6338 center.x=0.5*(end.x+start.x);
6339 center.y=0.5*(end.y+start.y);
6340 radius.x=fabs(center.x-start.x);
6341 radius.y=fabs(center.y-start.y);
6342 return(TraceEllipse(mvg_info,center,radius,degrees));
6345static MagickBooleanType TraceArcPath(MVGInfo *mvg_info,
const PointInfo start,
6346 const PointInfo end,
const PointInfo arc,
const double angle,
6347 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6384 offset=mvg_info->offset;
6385 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6386 primitive_info->coordinates=0;
6387 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6388 (fabs(start.y-end.y) < MagickEpsilon))
6389 return(TracePoint(primitive_info,end));
6390 radii.x=fabs(arc.x);
6391 radii.y=fabs(arc.y);
6392 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6393 return(TraceLine(primitive_info,start,end));
6394 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6395 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6396 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6397 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6398 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6400 if (delta < MagickEpsilon)
6401 return(TraceLine(primitive_info,start,end));
6404 radii.x*=sqrt((
double) delta);
6405 radii.y*=sqrt((
double) delta);
6407 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6408 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6409 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6410 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6411 alpha=points[1].x-points[0].x;
6412 beta=points[1].y-points[0].y;
6413 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6414 return(TraceLine(primitive_info,start,end));
6415 factor=MagickSafeReciprocal(alpha*alpha+beta*beta)-0.25;
6420 factor=sqrt((
double) factor);
6421 if (sweep == large_arc)
6424 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6425 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6426 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6427 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6428 if ((theta < 0.0) && (sweep != MagickFalse))
6429 theta+=2.0*MagickPI;
6431 if ((theta > 0.0) && (sweep == MagickFalse))
6432 theta-=2.0*MagickPI;
6433 arc_segments=(size_t) CastDoubleToSsizeT(ceil(fabs((
double) (theta/(0.5*
6434 MagickPI+MagickEpsilon)))));
6437 for (i=0; i < (ssize_t) arc_segments; i++)
6439 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6440 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6441 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6442 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6443 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6444 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6445 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6446 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6447 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6448 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6449 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) (i+1)*
6450 theta/arc_segments),DegreesToRadians(360.0))));
6451 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) (i+1)*
6452 theta/arc_segments),DegreesToRadians(360.0))));
6453 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(
double)
6454 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6455 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(
double)
6456 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6457 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6458 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6459 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
6461 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
6463 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
6465 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
6467 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
6469 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
6471 if (i == (ssize_t) (arc_segments-1))
6473 status&=(MagickStatusType) TraceBezier(mvg_info,4);
6476 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
6477 mvg_info->offset+=(ssize_t) p->coordinates;
6478 p+=(ptrdiff_t) p->coordinates;
6481 return(MagickFalse);
6482 mvg_info->offset=offset;
6483 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6484 primitive_info->coordinates=(size_t) (p-primitive_info);
6485 primitive_info->closed_subpath=MagickFalse;
6486 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6488 p->primitive=primitive_info->primitive;
6494static MagickBooleanType TraceBezier(MVGInfo *mvg_info,
6495 const size_t number_coordinates)
6524 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6525 quantum=number_coordinates;
6526 for (i=0; i < (ssize_t) number_coordinates; i++)
6528 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6530 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6531 if (alpha > (
double) GetMaxMemoryRequest())
6533 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6534 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6535 return(MagickFalse);
6537 if (alpha > (
double) quantum)
6538 quantum=(size_t) alpha;
6539 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6540 if (alpha > (
double) quantum)
6541 quantum=(size_t) alpha;
6544 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6545 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6546 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6547 sizeof(*coefficients));
6548 points=(PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6550 if ((coefficients == (
double *) NULL) || (points == (PointInfo *) NULL))
6552 if (points != (PointInfo *) NULL)
6553 points=(PointInfo *) RelinquishMagickMemory(points);
6554 if (coefficients != (
double *) NULL)
6555 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6556 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6557 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6558 return(MagickFalse);
6560 control_points=quantum*number_coordinates;
6561 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6563 points=(PointInfo *) RelinquishMagickMemory(points);
6564 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6565 return(MagickFalse);
6567 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6571 end=primitive_info[number_coordinates-1].point;
6572 for (i=0; i < (ssize_t) number_coordinates; i++)
6573 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6575 for (i=0; i < (ssize_t) control_points; i++)
6580 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6581 for (j=0; j < (ssize_t) number_coordinates; j++)
6583 point.x+=alpha*coefficients[j]*p->point.x;
6584 point.y+=alpha*coefficients[j]*p->point.y;
6585 alpha*=weight/(1.0-weight);
6589 weight+=1.0/control_points;
6595 for (i=0; i < (ssize_t) control_points; i++)
6597 if (TracePoint(p,points[i]) == MagickFalse)
6599 points=(PointInfo *) RelinquishMagickMemory(points);
6600 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6601 return(MagickFalse);
6603 p+=(ptrdiff_t) p->coordinates;
6605 if (TracePoint(p,end) == MagickFalse)
6607 points=(PointInfo *) RelinquishMagickMemory(points);
6608 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6609 return(MagickFalse);
6611 p+=(ptrdiff_t) p->coordinates;
6612 primitive_info->coordinates=(size_t) (p-primitive_info);
6613 primitive_info->closed_subpath=MagickFalse;
6614 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6616 p->primitive=primitive_info->primitive;
6619 points=(PointInfo *) RelinquishMagickMemory(points);
6620 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6624static MagickBooleanType TraceCircle(MVGInfo *mvg_info,
const PointInfo start,
6625 const PointInfo end)
6636 alpha=end.x-start.x;
6638 radius=hypot((
double) alpha,(
double) beta);
6639 offset.x=(double) radius;
6640 offset.y=(double) radius;
6643 return(TraceEllipse(mvg_info,start,offset,degrees));
6646static MagickBooleanType TraceEllipse(MVGInfo *mvg_info,
const PointInfo center,
6647 const PointInfo radii,
const PointInfo arc)
6672 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6673 primitive_info->coordinates=0;
6674 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6676 delta=MagickSafeReciprocal(MagickMax(radii.x,radii.y));
6677 step=MagickPI/(MagickPI*MagickSafeReciprocal(delta))/8.0;
6678 angle.x=DegreesToRadians(arc.x);
6682 angle.y=DegreesToRadians(y);
6683 coordinates=ceil((angle.y-angle.x)/step+1.0);
6684 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6685 return(MagickFalse);
6687 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6688 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6690 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6691 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6692 if (i++ >= (ssize_t) coordinates)
6694 if (TracePoint(p,point) == MagickFalse)
6695 return(MagickFalse);
6696 p+=(ptrdiff_t) p->coordinates;
6698 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6699 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6700 if (TracePoint(p,point) == MagickFalse)
6701 return(MagickFalse);
6702 p+=(ptrdiff_t) p->coordinates;
6703 primitive_info->coordinates=(size_t) (p-primitive_info);
6704 primitive_info->closed_subpath=MagickFalse;
6705 x=fabs(primitive_info[0].point.x-
6706 primitive_info[primitive_info->coordinates-1].point.x);
6707 y=fabs(primitive_info[0].point.y-
6708 primitive_info[primitive_info->coordinates-1].point.y);
6709 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6710 primitive_info->closed_subpath=MagickTrue;
6711 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6713 p->primitive=primitive_info->primitive;
6719static MagickBooleanType TraceLine(PrimitiveInfo *primitive_info,
6720 const PointInfo start,
const PointInfo end)
6722 if (TracePoint(primitive_info,start) == MagickFalse)
6723 return(MagickFalse);
6724 if (TracePoint(primitive_info+1,end) == MagickFalse)
6725 return(MagickFalse);
6726 (primitive_info+1)->primitive=primitive_info->primitive;
6727 primitive_info->coordinates=2;
6728 primitive_info->closed_subpath=MagickFalse;
6732static ssize_t TracePath(MVGInfo *mvg_info,
const char *path,
6733 ExceptionInfo *exception)
6737 token[MagickPathExtent] =
"";
6755 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6778 subpath_offset=mvg_info->offset;
6779 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6782 number_coordinates=0;
6784 primitive_type=primitive_info->primitive;
6786 for (p=path; *p !=
'\0'; )
6788 if (status == MagickFalse)
6790 while (isspace((
int) ((
unsigned char) *p)) != 0)
6794 last_attribute=attribute;
6795 attribute=(int) (*p++);
6805 large_arc = MagickFalse,
6806 sweep = MagickFalse;
6816 (void) GetNextToken(p,&p,MagickPathExtent,token);
6817 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6818 ThrowPointExpectedException(token,exception);
6820 (void) GetNextToken(p,&p,MagickPathExtent,token);
6821 arc.x=GetDrawValue(token,&next_token);
6822 if (token == next_token)
6823 ThrowPointExpectedException(token,exception);
6824 (void) GetNextToken(p,&p,MagickPathExtent,token);
6825 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6826 ThrowPointExpectedException(token,exception);
6828 (void) GetNextToken(p,&p,MagickPathExtent,token);
6829 arc.y=GetDrawValue(token,&next_token);
6830 if (token == next_token)
6831 ThrowPointExpectedException(token,exception);
6832 (void) GetNextToken(p,&p,MagickPathExtent,token);
6833 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6834 ThrowPointExpectedException(token,exception);
6836 (void) GetNextToken(p,&p,MagickPathExtent,token);
6837 angle=GetDrawValue(token,&next_token);
6838 if (token == next_token)
6839 ThrowPointExpectedException(token,exception);
6840 (void) GetNextToken(p,&p,MagickPathExtent,token);
6841 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6842 ThrowPointExpectedException(token,exception);
6844 (void) GetNextToken(p,&p,MagickPathExtent,token);
6845 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6846 (void) GetNextToken(p,&p,MagickPathExtent,token);
6847 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6848 ThrowPointExpectedException(token,exception);
6850 (void) GetNextToken(p,&p,MagickPathExtent,token);
6851 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6852 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6853 ThrowPointExpectedException(token,exception);
6855 (void) GetNextToken(p,&p,MagickPathExtent,token);
6856 (void) GetNextToken(p,&p,MagickPathExtent,token);
6857 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6858 ThrowPointExpectedException(token,exception);
6860 (void) GetNextToken(p,&p,MagickPathExtent,token);
6861 x=GetDrawValue(token,&next_token);
6862 if (token == next_token)
6863 ThrowPointExpectedException(token,exception);
6864 (void) GetNextToken(p,&p,MagickPathExtent,token);
6865 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6866 ThrowPointExpectedException(token,exception);
6868 (void) GetNextToken(p,&p,MagickPathExtent,token);
6869 y=GetDrawValue(token,&next_token);
6870 if (token == next_token)
6871 ThrowPointExpectedException(token,exception);
6872 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6873 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6874 if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
6876 q=(*mvg_info->primitive_info)+mvg_info->offset;
6877 mvg_info->offset+=(ssize_t) q->coordinates;
6878 q+=(ptrdiff_t) q->coordinates;
6880 while (isspace((
int) ((
unsigned char) *p)) != 0)
6884 }
while (IsValidPoint(p) != MagickFalse);
6896 for (i=1; i < 4; i++)
6898 (void) GetNextToken(p,&p,MagickPathExtent,token);
6899 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6900 ThrowPointExpectedException(token,exception);
6902 (void) GetNextToken(p,&p,MagickPathExtent,token);
6903 x=GetDrawValue(token,&next_token);
6904 if (token == next_token)
6905 ThrowPointExpectedException(token,exception);
6906 (void) GetNextToken(p,&p,MagickPathExtent,token);
6907 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6908 ThrowPointExpectedException(token,exception);
6910 (void) GetNextToken(p,&p,MagickPathExtent,token);
6911 y=GetDrawValue(token,&next_token);
6912 if (token == next_token)
6913 ThrowPointExpectedException(token,exception);
6914 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6915 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6918 for (i=0; i < 4; i++)
6919 (q+i)->point=points[i];
6920 if (TraceBezier(mvg_info,4) == MagickFalse)
6922 q=(*mvg_info->primitive_info)+mvg_info->offset;
6923 mvg_info->offset+=(ssize_t) q->coordinates;
6924 q+=(ptrdiff_t) q->coordinates;
6926 while (isspace((
int) ((
unsigned char) *p)) != 0)
6930 }
while (IsValidPoint(p) != MagickFalse);
6938 (void) GetNextToken(p,&p,MagickPathExtent,token);
6939 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6940 ThrowPointExpectedException(token,exception);
6942 (void) GetNextToken(p,&p,MagickPathExtent,token);
6943 x=GetDrawValue(token,&next_token);
6944 if (token == next_token)
6945 ThrowPointExpectedException(token,exception);
6946 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6947 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6949 q=(*mvg_info->primitive_info)+mvg_info->offset;
6950 if (TracePoint(q,point) == MagickFalse)
6952 mvg_info->offset+=(ssize_t) q->coordinates;
6953 q+=(ptrdiff_t) q->coordinates;
6954 while (isspace((
int) ((
unsigned char) *p)) != 0)
6958 }
while (IsValidPoint(p) != MagickFalse);
6969 (void) GetNextToken(p,&p,MagickPathExtent,token);
6970 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6971 ThrowPointExpectedException(token,exception);
6973 (void) GetNextToken(p,&p,MagickPathExtent,token);
6974 x=GetDrawValue(token,&next_token);
6975 if (token == next_token)
6976 ThrowPointExpectedException(token,exception);
6977 (void) GetNextToken(p,&p,MagickPathExtent,token);
6978 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6979 ThrowPointExpectedException(token,exception);
6981 (void) GetNextToken(p,&p,MagickPathExtent,token);
6982 y=GetDrawValue(token,&next_token);
6983 if (token == next_token)
6984 ThrowPointExpectedException(token,exception);
6985 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
6986 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
6987 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6989 q=(*mvg_info->primitive_info)+mvg_info->offset;
6990 if (TracePoint(q,point) == MagickFalse)
6992 mvg_info->offset+=(ssize_t) q->coordinates;
6993 q+=(ptrdiff_t) q->coordinates;
6994 while (isspace((
int) ((
unsigned char) *p)) != 0)
6998 }
while (IsValidPoint(p) != MagickFalse);
7007 if (mvg_info->offset != subpath_offset)
7009 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7010 primitive_info->coordinates=(size_t) (q-primitive_info);
7011 number_coordinates+=primitive_info->coordinates;
7013 subpath_offset=mvg_info->offset;
7018 (void) GetNextToken(p,&p,MagickPathExtent,token);
7019 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7020 ThrowPointExpectedException(token,exception);
7022 (void) GetNextToken(p,&p,MagickPathExtent,token);
7023 x=GetDrawValue(token,&next_token);
7024 if (token == next_token)
7025 ThrowPointExpectedException(token,exception);
7026 (void) GetNextToken(p,&p,MagickPathExtent,token);
7027 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7028 ThrowPointExpectedException(token,exception);
7030 (void) GetNextToken(p,&p,MagickPathExtent,token);
7031 y=GetDrawValue(token,&next_token);
7032 if (token == next_token)
7033 ThrowPointExpectedException(token,exception);
7034 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
7035 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
7039 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7041 q=(*mvg_info->primitive_info)+mvg_info->offset;
7042 if (TracePoint(q,point) == MagickFalse)
7044 mvg_info->offset+=(ssize_t) q->coordinates;
7045 q+=(ptrdiff_t) q->coordinates;
7046 while (isspace((
int) ((
unsigned char) *p)) != 0)
7050 }
while (IsValidPoint(p) != MagickFalse);
7062 for (i=1; i < 3; i++)
7064 (void) GetNextToken(p,&p,MagickPathExtent,token);
7065 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7066 ThrowPointExpectedException(token,exception);
7068 (void) GetNextToken(p,&p,MagickPathExtent,token);
7069 x=GetDrawValue(token,&next_token);
7070 if (token == next_token)
7071 ThrowPointExpectedException(token,exception);
7072 (void) GetNextToken(p,&p,MagickPathExtent,token);
7073 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7074 ThrowPointExpectedException(token,exception);
7076 (void) GetNextToken(p,&p,MagickPathExtent,token);
7077 y=GetDrawValue(token,&next_token);
7078 if (token == next_token)
7079 ThrowPointExpectedException(token,exception);
7082 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
7083 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
7086 for (i=0; i < 3; i++)
7087 (q+i)->point=points[i];
7088 if (TraceBezier(mvg_info,3) == MagickFalse)
7090 q=(*mvg_info->primitive_info)+mvg_info->offset;
7091 mvg_info->offset+=(ssize_t) q->coordinates;
7092 q+=(ptrdiff_t) q->coordinates;
7094 while (isspace((
int) ((
unsigned char) *p)) != 0)
7098 }
while (IsValidPoint(p) != MagickFalse);
7109 points[0]=points[3];
7110 points[1].x=2.0*points[3].x-points[2].x;
7111 points[1].y=2.0*points[3].y-points[2].y;
7112 for (i=2; i < 4; i++)
7114 (void) GetNextToken(p,&p,MagickPathExtent,token);
7115 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7116 ThrowPointExpectedException(token,exception);
7118 (void) GetNextToken(p,&p,MagickPathExtent,token);
7119 x=GetDrawValue(token,&next_token);
7120 if (token == next_token)
7121 ThrowPointExpectedException(token,exception);
7122 (void) GetNextToken(p,&p,MagickPathExtent,token);
7123 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7124 ThrowPointExpectedException(token,exception);
7126 (void) GetNextToken(p,&p,MagickPathExtent,token);
7127 y=GetDrawValue(token,&next_token);
7128 if (token == next_token)
7129 ThrowPointExpectedException(token,exception);
7132 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
7133 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
7136 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
7141 for (i=0; i < 4; i++)
7142 (q+i)->point=points[i];
7143 if (TraceBezier(mvg_info,4) == MagickFalse)
7145 q=(*mvg_info->primitive_info)+mvg_info->offset;
7146 mvg_info->offset+=(ssize_t) q->coordinates;
7147 q+=(ptrdiff_t) q->coordinates;
7149 last_attribute=attribute;
7150 while (isspace((
int) ((
unsigned char) *p)) != 0)
7154 }
while (IsValidPoint(p) != MagickFalse);
7165 points[0]=points[2];
7166 points[1].x=2.0*points[2].x-points[1].x;
7167 points[1].y=2.0*points[2].y-points[1].y;
7168 for (i=2; i < 3; i++)
7170 (void) GetNextToken(p,&p,MagickPathExtent,token);
7171 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7172 ThrowPointExpectedException(token,exception);
7174 (void) GetNextToken(p,&p,MagickPathExtent,token);
7175 x=GetDrawValue(token,&next_token);
7176 if (token == next_token)
7177 ThrowPointExpectedException(token,exception);
7178 (void) GetNextToken(p,&p,MagickPathExtent,token);
7179 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7180 ThrowPointExpectedException(token,exception);
7182 (void) GetNextToken(p,&p,MagickPathExtent,token);
7183 y=GetDrawValue(token,&next_token);
7184 if (token == next_token)
7185 ThrowPointExpectedException(token,exception);
7186 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7187 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7190 if (status == MagickFalse)
7192 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7197 for (i=0; i < 3; i++)
7198 (q+i)->point=points[i];
7199 if (TraceBezier(mvg_info,3) == MagickFalse)
7201 q=(*mvg_info->primitive_info)+mvg_info->offset;
7202 mvg_info->offset+=(ssize_t) q->coordinates;
7203 q+=(ptrdiff_t) q->coordinates;
7205 last_attribute=attribute;
7206 while (isspace((
int) ((
unsigned char) *p)) != 0)
7210 }
while (IsValidPoint(p) != MagickFalse);
7221 (void) GetNextToken(p,&p,MagickPathExtent,token);
7222 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7223 ThrowPointExpectedException(token,exception);
7225 (void) GetNextToken(p,&p,MagickPathExtent,token);
7226 y=GetDrawValue(token,&next_token);
7227 if (token == next_token)
7228 ThrowPointExpectedException(token,exception);
7229 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
7230 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7232 q=(*mvg_info->primitive_info)+mvg_info->offset;
7233 if (TracePoint(q,point) == MagickFalse)
7235 mvg_info->offset+=(ssize_t) q->coordinates;
7236 q+=(ptrdiff_t) q->coordinates;
7237 while (isspace((
int) ((
unsigned char) *p)) != 0)
7241 }
while (IsValidPoint(p) != MagickFalse);
7251 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7253 q=(*mvg_info->primitive_info)+mvg_info->offset;
7254 if (TracePoint(q,point) == MagickFalse)
7256 mvg_info->offset+=(ssize_t) q->coordinates;
7257 q+=(ptrdiff_t) q->coordinates;
7258 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7259 primitive_info->coordinates=(size_t) (q-primitive_info);
7260 primitive_info->closed_subpath=MagickTrue;
7261 number_coordinates+=primitive_info->coordinates;
7263 subpath_offset=mvg_info->offset;
7269 ThrowPointExpectedException(token,exception);
7274 if (status == MagickFalse)
7276 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7277 primitive_info->coordinates=(size_t) (q-primitive_info);
7278 number_coordinates+=primitive_info->coordinates;
7279 for (i=0; i < (ssize_t) number_coordinates; i++)
7282 q->primitive=primitive_type;
7284 q->method=FillToBorderMethod;
7287 return((ssize_t) number_coordinates);
7290static MagickBooleanType TraceRectangle(PrimitiveInfo *primitive_info,
7291 const PointInfo start,
const PointInfo end)
7303 if (TracePoint(p,start) == MagickFalse)
7304 return(MagickFalse);
7305 p+=(ptrdiff_t) p->coordinates;
7308 if (TracePoint(p,point) == MagickFalse)
7309 return(MagickFalse);
7310 p+=(ptrdiff_t) p->coordinates;
7311 if (TracePoint(p,end) == MagickFalse)
7312 return(MagickFalse);
7313 p+=(ptrdiff_t) p->coordinates;
7316 if (TracePoint(p,point) == MagickFalse)
7317 return(MagickFalse);
7318 p+=(ptrdiff_t) p->coordinates;
7319 if (TracePoint(p,start) == MagickFalse)
7320 return(MagickFalse);
7321 p+=(ptrdiff_t) p->coordinates;
7322 primitive_info->coordinates=(size_t) (p-primitive_info);
7323 primitive_info->closed_subpath=MagickTrue;
7324 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7326 p->primitive=primitive_info->primitive;
7332static MagickBooleanType TraceRoundRectangle(MVGInfo *mvg_info,
7333 const PointInfo start,
const PointInfo end,PointInfo arc)
7352 offset=mvg_info->offset;
7353 segment.x=fabs(end.x-start.x);
7354 segment.y=fabs(end.y-start.y);
7355 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7357 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7360 if (arc.x > (0.5*segment.x))
7361 arc.x=0.5*segment.x;
7362 if (arc.y > (0.5*segment.y))
7363 arc.y=0.5*segment.y;
7364 point.x=start.x+segment.x-arc.x;
7365 point.y=start.y+arc.y;
7368 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7369 return(MagickFalse);
7370 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7371 mvg_info->offset+=(ssize_t) p->coordinates;
7372 point.x=start.x+segment.x-arc.x;
7373 point.y=start.y+segment.y-arc.y;
7376 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7377 return(MagickFalse);
7378 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7379 mvg_info->offset+=(ssize_t) p->coordinates;
7380 point.x=start.x+arc.x;
7381 point.y=start.y+segment.y-arc.y;
7384 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7385 return(MagickFalse);
7386 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7387 mvg_info->offset+=(ssize_t) p->coordinates;
7388 point.x=start.x+arc.x;
7389 point.y=start.y+arc.y;
7392 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7393 return(MagickFalse);
7394 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7395 mvg_info->offset+=(ssize_t) p->coordinates;
7396 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7397 return(MagickFalse);
7398 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7399 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7400 return(MagickFalse);
7401 p+=(ptrdiff_t) p->coordinates;
7402 mvg_info->offset=offset;
7403 primitive_info=(*mvg_info->primitive_info)+offset;
7404 primitive_info->coordinates=(size_t) (p-primitive_info);
7405 primitive_info->closed_subpath=MagickTrue;
7406 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7408 p->primitive=primitive_info->primitive;
7414static MagickBooleanType TraceSquareLinecap(PrimitiveInfo *primitive_info,
7415 const size_t number_vertices,
const double offset)
7432 for (i=1; i < (ssize_t) number_vertices; i++)
7434 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7435 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7436 if ((fabs((
double) dx) >= MagickEpsilon) ||
7437 (fabs((
double) dy) >= MagickEpsilon))
7440 if (i == (ssize_t) number_vertices)
7441 i=(ssize_t) number_vertices-1L;
7442 distance=hypot((
double) dx,(
double) dy);
7443 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7444 dx*(distance+offset)/distance);
7445 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7446 dy*(distance+offset)/distance);
7447 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7449 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7450 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7451 if ((fabs((
double) dx) >= MagickEpsilon) ||
7452 (fabs((
double) dy) >= MagickEpsilon))
7455 distance=hypot((
double) dx,(
double) dy);
7456 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7457 dx*(distance+offset)/distance);
7458 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7459 dy*(distance+offset)/distance);
7463static PrimitiveInfo *TraceStrokePolygon(
const DrawInfo *draw_info,
7464 const PrimitiveInfo *primitive_info,ExceptionInfo *exception)
7466#define MaxStrokePad (6*BezierQuantum+360)
7467#define CheckPathExtent(pad_p,pad_q) \
7469 if ((pad_p) > MaxBezierCoordinates) \
7470 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7472 if ((p+(ptrdiff_t) (pad_p)) >= (ssize_t) extent_p) \
7474 if (~extent_p < (pad_p)) \
7475 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7478 extent_p+=(pad_p); \
7479 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \
7480 MaxStrokePad,sizeof(*stroke_p)); \
7483 if ((pad_q) > MaxBezierCoordinates) \
7484 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7486 if ((q+(ptrdiff_t) (pad_q)) >= (ssize_t) extent_q) \
7488 if (~extent_q < (pad_q)) \
7489 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7492 extent_q+=(pad_q); \
7493 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \
7494 MaxStrokePad,sizeof(*stroke_q)); \
7497 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \
7499 if (stroke_p != (PointInfo *) NULL) \
7500 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7501 if (stroke_q != (PointInfo *) NULL) \
7502 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7503 polygon_primitive=(PrimitiveInfo *) \
7504 RelinquishMagickMemory(polygon_primitive); \
7505 (void) ThrowMagickException(exception,GetMagickModule(), \
7506 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \
7507 return((PrimitiveInfo *) NULL); \
7511 typedef struct _StrokeSegment
7557 inverse_slope = {0.0, 0.0},
7564 number_vertices=primitive_info->coordinates;
7565 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7566 number_vertices+2UL,
sizeof(*polygon_primitive));
7567 if (polygon_primitive == (PrimitiveInfo *) NULL)
7569 (void) ThrowMagickException(exception,GetMagickModule(),
7570 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7571 return((PrimitiveInfo *) NULL);
7573 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7574 sizeof(*polygon_primitive));
7575 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7576 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7577 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7578 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7579 if ((draw_info->linejoin == RoundJoin) ||
7580 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
7582 polygon_primitive[number_vertices]=primitive_info[1];
7585 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7589 closed_path=primitive_info[0].closed_subpath;
7592 for (n=1; n < (ssize_t) number_vertices; n++)
7594 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7595 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7596 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7599 if (n == (ssize_t) number_vertices)
7601 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7606 stroke_polygon=(PrimitiveInfo *) AcquireCriticalMemory(
7607 sizeof(*stroke_polygon));
7608 stroke_polygon[0]=polygon_primitive[0];
7609 stroke_polygon[0].coordinates=0;
7610 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7612 return(stroke_polygon);
7614 n=(ssize_t) number_vertices-1L;
7616 extent_p=2*number_vertices;
7617 extent_q=2*number_vertices;
7618 stroke_p=(PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7620 stroke_q=(PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7622 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL))
7624 if (stroke_p != (PointInfo *) NULL)
7625 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7626 if (stroke_q != (PointInfo *) NULL)
7627 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7628 polygon_primitive=(PrimitiveInfo *)
7629 RelinquishMagickMemory(polygon_primitive);
7630 (void) ThrowMagickException(exception,GetMagickModule(),
7631 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7632 return((PrimitiveInfo *) NULL);
7635 inverse_slope.p=0.0;
7636 if (fabs(dx.p) < MagickEpsilon)
7639 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7641 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7644 if (fabs(dy.p) < MagickEpsilon)
7647 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7649 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7654 inverse_slope.p=(-1.0*MagickSafeReciprocal(slope.p));
7656 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7657 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7658 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7659 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7660 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7661 offset.y=(double) (offset.x*inverse_slope.p);
7662 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7664 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7665 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7666 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7667 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7668 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7669 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7670 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7671 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7675 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7676 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7677 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7678 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7679 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7680 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7681 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7682 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7689 stroke_q[p++]=box_q[0];
7690 stroke_p[q++]=box_p[0];
7691 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7696 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7697 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7698 dot_product=dx.q*dx.q+dy.q*dy.q;
7699 if (dot_product < 0.25)
7702 inverse_slope.q=0.0;
7703 if (fabs(dx.q) < MagickEpsilon)
7706 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7708 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7711 if (fabs(dy.q) < MagickEpsilon)
7714 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7716 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7721 inverse_slope.q=(-1.0*MagickSafeReciprocal(slope.q));
7723 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7724 offset.y=(double) (offset.x*inverse_slope.q);
7725 dot_product=dy.q*offset.x-dx.q*offset.y;
7726 if (dot_product > 0.0)
7728 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7729 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7730 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7731 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7732 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7733 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7734 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7735 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7739 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7740 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7741 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7742 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7743 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7744 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7745 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7746 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7748 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7755 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7756 box_p[3].y)/(slope.p-slope.q));
7757 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7758 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7759 box_q[3].y)/(slope.p-slope.q));
7760 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7762 DisableMSCWarning(4127)
7763 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7765 dot_product=dx.q*dy.p-dx.p*dy.q;
7766 if (dot_product <= 0.0)
7767 switch (draw_info->linejoin)
7771 stroke_q[q++]=box_q[1];
7772 stroke_q[q++]=box_q[2];
7773 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7774 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7775 if (dot_product <= miterlimit)
7776 stroke_p[p++]=box_p[4];
7779 stroke_p[p++]=box_p[1];
7780 stroke_p[p++]=box_p[2];
7786 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7787 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7788 if (dot_product <= miterlimit)
7790 stroke_q[q++]=box_q[4];
7791 stroke_p[p++]=box_p[4];
7795 stroke_q[q++]=box_q[1];
7796 stroke_q[q++]=box_q[2];
7797 stroke_p[p++]=box_p[1];
7798 stroke_p[p++]=box_p[2];
7804 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7805 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7806 if (dot_product <= miterlimit)
7807 stroke_p[p++]=box_p[4];
7810 stroke_p[p++]=box_p[1];
7811 stroke_p[p++]=box_p[2];
7813 center=polygon_primitive[n].point;
7814 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7815 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7816 if (theta.q < theta.p)
7817 theta.q+=2.0*MagickPI;
7818 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.q-
7819 theta.p)/(2.0*sqrt(MagickSafeReciprocal(mid))))));
7820 DisableMSCWarning(4127)
7821 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7823 stroke_q[q].x=box_q[1].x;
7824 stroke_q[q].y=box_q[1].y;
7826 for (j=1; j < (ssize_t) arc_segments; j++)
7828 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7829 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7830 (theta.p+delta_theta),DegreesToRadians(360.0))));
7831 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7832 (theta.p+delta_theta),DegreesToRadians(360.0))));
7835 stroke_q[q++]=box_q[2];
7842 switch (draw_info->linejoin)
7846 stroke_p[p++]=box_p[1];
7847 stroke_p[p++]=box_p[2];
7848 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7849 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7850 if (dot_product <= miterlimit)
7851 stroke_q[q++]=box_q[4];
7854 stroke_q[q++]=box_q[1];
7855 stroke_q[q++]=box_q[2];
7861 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7862 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7863 if (dot_product <= miterlimit)
7865 stroke_q[q++]=box_q[4];
7866 stroke_p[p++]=box_p[4];
7870 stroke_q[q++]=box_q[1];
7871 stroke_q[q++]=box_q[2];
7872 stroke_p[p++]=box_p[1];
7873 stroke_p[p++]=box_p[2];
7879 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7880 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7881 if (dot_product <= miterlimit)
7882 stroke_q[q++]=box_q[4];
7885 stroke_q[q++]=box_q[1];
7886 stroke_q[q++]=box_q[2];
7888 center=polygon_primitive[n].point;
7889 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7890 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7891 if (theta.p < theta.q)
7892 theta.p+=2.0*MagickPI;
7893 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.p-
7894 theta.q)/(2.0*sqrt((
double) (MagickSafeReciprocal(mid)))))));
7895 DisableMSCWarning(4127)
7896 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7898 stroke_p[p++]=box_p[1];
7899 for (j=1; j < (ssize_t) arc_segments; j++)
7901 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7902 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7903 (theta.p+delta_theta),DegreesToRadians(360.0))));
7904 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7905 (theta.p+delta_theta),DegreesToRadians(360.0))));
7908 stroke_p[p++]=box_p[2];
7915 inverse_slope.p=inverse_slope.q;
7924 stroke_p[p++]=box_p[1];
7925 stroke_q[q++]=box_q[1];
7929 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7930 (p+q+2L),(
size_t) (closed_path+2L)*
sizeof(*stroke_polygon));
7931 if (stroke_polygon == (PrimitiveInfo *) NULL)
7933 (void) ThrowMagickException(exception,GetMagickModule(),
7934 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7935 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7936 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7937 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7939 return(stroke_polygon);
7941 for (i=0; i < (ssize_t) p; i++)
7943 stroke_polygon[i]=polygon_primitive[0];
7944 stroke_polygon[i].point=stroke_p[i];
7946 if (closed_path != MagickFalse)
7948 stroke_polygon[i]=polygon_primitive[0];
7949 stroke_polygon[i].point=stroke_polygon[0].point;
7952 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7954 stroke_polygon[i]=polygon_primitive[0];
7955 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7957 if (closed_path != MagickFalse)
7959 stroke_polygon[i]=polygon_primitive[0];
7960 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7963 stroke_polygon[i]=polygon_primitive[0];
7964 stroke_polygon[i].point=stroke_polygon[0].point;
7966 stroke_polygon[i].primitive=UndefinedPrimitive;
7967 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
7968 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7969 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7970 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
7971 return(stroke_polygon);