48#include "MagickCore/studio.h"
49#include "MagickCore/annotate.h"
50#include "MagickCore/artifact.h"
51#include "MagickCore/blob.h"
52#include "MagickCore/cache.h"
53#include "MagickCore/cache-private.h"
54#include "MagickCore/cache-view.h"
55#include "MagickCore/channel.h"
56#include "MagickCore/color.h"
57#include "MagickCore/colorspace-private.h"
58#include "MagickCore/composite.h"
59#include "MagickCore/composite-private.h"
60#include "MagickCore/constitute.h"
61#include "MagickCore/constitute-private.h"
62#include "MagickCore/draw.h"
63#include "MagickCore/draw-private.h"
64#include "MagickCore/enhance.h"
65#include "MagickCore/exception.h"
66#include "MagickCore/exception-private.h"
67#include "MagickCore/gem.h"
68#include "MagickCore/geometry.h"
69#include "MagickCore/image-private.h"
70#include "MagickCore/list.h"
71#include "MagickCore/log.h"
72#include "MagickCore/magick.h"
73#include "MagickCore/memory-private.h"
74#include "MagickCore/monitor.h"
75#include "MagickCore/monitor-private.h"
76#include "MagickCore/option.h"
77#include "MagickCore/paint.h"
78#include "MagickCore/pixel-accessor.h"
79#include "MagickCore/property.h"
80#include "MagickCore/resample.h"
81#include "MagickCore/resample-private.h"
82#include "MagickCore/resource_.h"
83#include "MagickCore/splay-tree.h"
84#include "MagickCore/string_.h"
85#include "MagickCore/string-private.h"
86#include "MagickCore/thread-private.h"
87#include "MagickCore/token.h"
88#include "MagickCore/transform-private.h"
89#include "MagickCore/utility.h"
94#define AntialiasThreshold (1.0/3.0)
95#define BezierQuantum 200
96#define MaxVectorRecursionDepth 400
97#define PrimitiveExtentPad 4296.0
98#define MaxBezierCoordinates 67108864
99#define MacroExpansionLimit 262144
100#define ThrowPointExpectedException(token,exception) \
102 (void) ThrowMagickException(exception,GetMagickModule(),DrawError, \
103 "NonconformingDrawingPrimitiveDefinition","`%s'",token); \
104 status=MagickFalse; \
194 *DrawClippingMask(Image *,
const DrawInfo *,
const char *,
const char *,
195 const size_t,ExceptionInfo *);
197static MagickBooleanType
198 DrawStrokePolygon(Image *,
const DrawInfo *,
const PrimitiveInfo *,
200 RenderMVGContent(Image *,
const DrawInfo *,
const size_t,ExceptionInfo *),
201 TraceArc(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo),
202 TraceArcPath(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo,
203 const double,
const MagickBooleanType,
const MagickBooleanType),
204 TraceBezier(MVGInfo *,
const size_t),
205 TraceCircle(MVGInfo *,
const PointInfo,
const PointInfo),
206 TraceEllipse(MVGInfo *,
const PointInfo,
const PointInfo,
const PointInfo),
207 TraceLine(PrimitiveInfo *,
const PointInfo,
const PointInfo),
208 TraceRectangle(PrimitiveInfo *,
const PointInfo,
const PointInfo),
209 TraceRoundRectangle(MVGInfo *,
const PointInfo,
const PointInfo,PointInfo),
210 TraceSquareLinecap(PrimitiveInfo *,
const size_t,
const double);
213 *TraceStrokePolygon(
const DrawInfo *,
const PrimitiveInfo *,ExceptionInfo *);
216 TracePath(MVGInfo *,
const char *,ExceptionInfo *);
236MagickExport DrawInfo *AcquireDrawInfo(
void)
241 draw_info=(DrawInfo *) AcquireCriticalMemory(
sizeof(*draw_info));
242 GetDrawInfo((ImageInfo *) NULL,draw_info);
273MagickExport DrawInfo *CloneDrawInfo(
const ImageInfo *image_info,
274 const DrawInfo *draw_info)
282 clone_info=(DrawInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
283 GetDrawInfo(image_info,clone_info);
284 if (draw_info == (DrawInfo *) NULL)
286 exception=AcquireExceptionInfo();
287 if (draw_info->id != (
char *) NULL)
288 (void) CloneString(&clone_info->id,draw_info->id);
289 if (draw_info->primitive != (
char *) NULL)
290 (void) CloneString(&clone_info->primitive,draw_info->primitive);
291 if (draw_info->geometry != (
char *) NULL)
292 (void) CloneString(&clone_info->geometry,draw_info->geometry);
293 clone_info->compliance=draw_info->compliance;
294 clone_info->viewbox=draw_info->viewbox;
295 clone_info->affine=draw_info->affine;
296 clone_info->gravity=draw_info->gravity;
297 clone_info->fill=draw_info->fill;
298 clone_info->stroke=draw_info->stroke;
299 clone_info->stroke_width=draw_info->stroke_width;
300 if (draw_info->fill_pattern != (Image *) NULL)
301 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
303 if (draw_info->stroke_pattern != (Image *) NULL)
304 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
305 MagickTrue,exception);
306 clone_info->stroke_antialias=draw_info->stroke_antialias;
307 clone_info->text_antialias=draw_info->text_antialias;
308 clone_info->fill_rule=draw_info->fill_rule;
309 clone_info->linecap=draw_info->linecap;
310 clone_info->linejoin=draw_info->linejoin;
311 clone_info->miterlimit=draw_info->miterlimit;
312 clone_info->dash_offset=draw_info->dash_offset;
313 clone_info->decorate=draw_info->decorate;
314 clone_info->compose=draw_info->compose;
315 if (draw_info->text != (
char *) NULL)
316 (void) CloneString(&clone_info->text,draw_info->text);
317 if (draw_info->font != (
char *) NULL)
318 (void) CloneString(&clone_info->font,draw_info->font);
319 if (draw_info->metrics != (
char *) NULL)
320 (void) CloneString(&clone_info->metrics,draw_info->metrics);
321 if (draw_info->family != (
char *) NULL)
322 (void) CloneString(&clone_info->family,draw_info->family);
323 clone_info->style=draw_info->style;
324 clone_info->stretch=draw_info->stretch;
325 clone_info->weight=draw_info->weight;
326 if (draw_info->encoding != (
char *) NULL)
327 (void) CloneString(&clone_info->encoding,draw_info->encoding);
328 clone_info->pointsize=draw_info->pointsize;
329 clone_info->kerning=draw_info->kerning;
330 clone_info->interline_spacing=draw_info->interline_spacing;
331 clone_info->interword_spacing=draw_info->interword_spacing;
332 clone_info->direction=draw_info->direction;
333 clone_info->word_break=draw_info->word_break;
334 if (draw_info->density != (
char *) NULL)
335 (void) CloneString(&clone_info->density,draw_info->density);
336 clone_info->align=draw_info->align;
337 clone_info->undercolor=draw_info->undercolor;
338 clone_info->border_color=draw_info->border_color;
339 if (draw_info->server_name != (
char *) NULL)
340 (void) CloneString(&clone_info->server_name,draw_info->server_name);
341 if (draw_info->dash_pattern != (
double *) NULL)
346 for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
347 clone_info->dash_pattern=(
double *) AcquireQuantumMemory((
size_t) (x+1),
348 sizeof(*clone_info->dash_pattern));
349 if (clone_info->dash_pattern == (
double *) NULL)
350 ThrowFatalException(ResourceLimitFatalError,
351 "UnableToAllocateDashPattern");
352 (void) memset(clone_info->dash_pattern,0,(
size_t) (x+1)*
353 sizeof(*clone_info->dash_pattern));
354 (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(
size_t)
355 x*
sizeof(*clone_info->dash_pattern));
357 clone_info->gradient=draw_info->gradient;
358 if (draw_info->gradient.stops != (StopInfo *) NULL)
363 number_stops=clone_info->gradient.number_stops;
364 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((
size_t)
365 number_stops,
sizeof(*clone_info->gradient.stops));
366 if (clone_info->gradient.stops == (StopInfo *) NULL)
367 ThrowFatalException(ResourceLimitFatalError,
368 "UnableToAllocateDashPattern");
369 (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
370 (
size_t) number_stops*
sizeof(*clone_info->gradient.stops));
372 clone_info->bounds=draw_info->bounds;
373 clone_info->fill_alpha=draw_info->fill_alpha;
374 clone_info->stroke_alpha=draw_info->stroke_alpha;
375 clone_info->element_reference=draw_info->element_reference;
376 clone_info->clip_path=draw_info->clip_path;
377 clone_info->clip_units=draw_info->clip_units;
378 if (draw_info->clip_mask != (
char *) NULL)
379 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
380 if (draw_info->clipping_mask != (Image *) NULL)
381 clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
382 MagickTrue,exception);
383 if (draw_info->composite_mask != (Image *) NULL)
384 clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
385 MagickTrue,exception);
386 clone_info->render=draw_info->render;
387 clone_info->debug=draw_info->debug;
388 clone_info->macro_expansion=draw_info->macro_expansion;
389 exception=DestroyExceptionInfo(exception);
424static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
429 if (polygon_info->edges != (EdgeInfo *) NULL)
431 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
432 if (polygon_info->edges[i].points != (PointInfo *) NULL)
433 polygon_info->edges[i].points=(PointInfo *)
434 RelinquishMagickMemory(polygon_info->edges[i].points);
435 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(
436 polygon_info->edges);
438 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
440#if defined(__cplusplus) || defined(c_plusplus)
444static int DrawCompareEdges(
const void *p_edge,
const void *q_edge)
446#define DrawCompareEdge(p,q) \
448 if (((p)-(q)) < 0.0) \
450 if (((p)-(q)) > 0.0) \
461 p=((
const EdgeInfo *) p_edge)->points;
462 q=((
const EdgeInfo *) q_edge)->points;
463 DrawCompareEdge(p[0].y,q[0].y);
464 DrawCompareEdge(p[0].x,q[0].x);
465 DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
467 DrawCompareEdge(p[1].y,q[1].y);
468 DrawCompareEdge(p[1].x,q[1].x);
472#if defined(__cplusplus) || defined(c_plusplus)
476static void LogPolygonInfo(
const PolygonInfo *polygon_info)
485 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin active-edge");
486 p=polygon_info->edges;
487 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
489 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" edge %.17g:",
491 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" direction: %s",
492 p->direction != MagickFalse ?
"down" :
"up");
493 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" ghostline: %s",
494 p->ghostline != MagickFalse ?
"transparent" :
"opaque");
495 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
496 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
497 p->bounds.x2,p->bounds.y2);
498 for (j=0; j < (ssize_t) p->number_points; j++)
499 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %g,%g",
500 p->points[j].x,p->points[j].y);
503 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end active-edge");
506static void ReversePoints(PointInfo *points,
const size_t number_points)
514 for (i=0; i < (number_points >> 1); i++)
517 points[i]=points[number_points-(i+1)];
518 points[number_points-(i+1)]=point;
522static PolygonInfo *ConvertPathToPolygon(
const PathInfo *path_info,
523 ExceptionInfo *exception)
554 polygon_info=(PolygonInfo *) AcquireMagickMemory(
sizeof(*polygon_info));
555 if (polygon_info == (PolygonInfo *) NULL)
557 (void) ThrowMagickException(exception,GetMagickModule(),
558 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
559 return((PolygonInfo *) NULL);
562 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory(number_edges,
563 sizeof(*polygon_info->edges));
564 if (polygon_info->edges == (EdgeInfo *) NULL)
566 (void) ThrowMagickException(exception,GetMagickModule(),
567 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
568 return(DestroyPolygonInfo(polygon_info));
570 (void) memset(polygon_info->edges,0,number_edges*
571 sizeof(*polygon_info->edges));
574 ghostline=MagickFalse;
577 points=(PointInfo *) NULL;
578 (void) memset(&point,0,
sizeof(point));
579 (void) memset(&bounds,0,
sizeof(bounds));
580 polygon_info->edges[edge].number_points=(size_t) n;
581 polygon_info->edges[edge].scanline=0.0;
582 polygon_info->edges[edge].highwater=0;
583 polygon_info->edges[edge].ghostline=ghostline;
584 polygon_info->edges[edge].direction=(ssize_t) direction;
585 polygon_info->edges[edge].points=points;
586 polygon_info->edges[edge].bounds=bounds;
587 polygon_info->number_edges=0;
588 for (i=0; path_info[i].code != EndCode; i++)
590 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
591 (path_info[i].code == GhostlineCode))
596 if ((points != (PointInfo *) NULL) && (n >= 2))
598 if (edge == number_edges)
601 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
602 polygon_info->edges,(
size_t) number_edges,
603 sizeof(*polygon_info->edges));
604 if (polygon_info->edges == (EdgeInfo *) NULL)
606 (void) ThrowMagickException(exception,GetMagickModule(),
607 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
608 points=(PointInfo *) RelinquishMagickMemory(points);
609 return(DestroyPolygonInfo(polygon_info));
612 polygon_info->edges[edge].number_points=(size_t) n;
613 polygon_info->edges[edge].scanline=(-1.0);
614 polygon_info->edges[edge].highwater=0;
615 polygon_info->edges[edge].ghostline=ghostline;
616 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
618 ReversePoints(points,(
size_t) n);
619 polygon_info->edges[edge].points=points;
620 polygon_info->edges[edge].bounds=bounds;
621 polygon_info->edges[edge].bounds.y1=points[0].y;
622 polygon_info->edges[edge].bounds.y2=points[n-1].y;
623 points=(PointInfo *) NULL;
624 ghostline=MagickFalse;
626 polygon_info->number_edges=edge;
628 if (points == (PointInfo *) NULL)
631 points=(PointInfo *) AcquireQuantumMemory((
size_t) number_points,
633 if (points == (PointInfo *) NULL)
635 (void) ThrowMagickException(exception,GetMagickModule(),
636 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
637 return(DestroyPolygonInfo(polygon_info));
640 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
641 point=path_info[i].point;
652 next_direction=((path_info[i].point.y > point.y) ||
653 ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
654 (path_info[i].point.x > point.x))) ? 1 : -1;
655 if ((points != (PointInfo *) NULL) && (direction != 0) &&
656 (direction != next_direction))
662 if (edge == number_edges)
665 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
666 polygon_info->edges,(
size_t) number_edges,
667 sizeof(*polygon_info->edges));
668 if (polygon_info->edges == (EdgeInfo *) NULL)
670 (void) ThrowMagickException(exception,GetMagickModule(),
671 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
672 points=(PointInfo *) RelinquishMagickMemory(points);
673 return(DestroyPolygonInfo(polygon_info));
676 polygon_info->edges[edge].number_points=(size_t) n;
677 polygon_info->edges[edge].scanline=(-1.0);
678 polygon_info->edges[edge].highwater=0;
679 polygon_info->edges[edge].ghostline=ghostline;
680 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
682 ReversePoints(points,(
size_t) n);
683 polygon_info->edges[edge].points=points;
684 polygon_info->edges[edge].bounds=bounds;
685 polygon_info->edges[edge].bounds.y1=points[0].y;
686 polygon_info->edges[edge].bounds.y2=points[n-1].y;
687 polygon_info->number_edges=edge+1;
688 points=(PointInfo *) NULL;
690 points=(PointInfo *) AcquireQuantumMemory((
size_t) number_points,
692 if (points == (PointInfo *) NULL)
694 (void) ThrowMagickException(exception,GetMagickModule(),
695 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
696 return(DestroyPolygonInfo(polygon_info));
699 ghostline=MagickFalse;
705 direction=next_direction;
706 if (points == (PointInfo *) NULL)
708 if (n == (ssize_t) number_points)
711 points=(PointInfo *) ResizeQuantumMemory(points,(
size_t) number_points,
713 if (points == (PointInfo *) NULL)
715 (void) ThrowMagickException(exception,GetMagickModule(),
716 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
717 return(DestroyPolygonInfo(polygon_info));
720 point=path_info[i].point;
722 if (point.x < bounds.x1)
724 if (point.x > bounds.x2)
728 if (points != (PointInfo *) NULL)
731 points=(PointInfo *) RelinquishMagickMemory(points);
734 if (edge == number_edges)
737 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
738 polygon_info->edges,(
size_t) number_edges,
739 sizeof(*polygon_info->edges));
740 if (polygon_info->edges == (EdgeInfo *) NULL)
742 (void) ThrowMagickException(exception,GetMagickModule(),
743 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
744 return(DestroyPolygonInfo(polygon_info));
747 polygon_info->edges[edge].number_points=(size_t) n;
748 polygon_info->edges[edge].scanline=(-1.0);
749 polygon_info->edges[edge].highwater=0;
750 polygon_info->edges[edge].ghostline=ghostline;
751 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
753 ReversePoints(points,(
size_t) n);
754 polygon_info->edges[edge].points=points;
755 polygon_info->edges[edge].bounds=bounds;
756 polygon_info->edges[edge].bounds.y1=points[0].y;
757 polygon_info->edges[edge].bounds.y2=points[n-1].y;
758 points=(PointInfo *) NULL;
759 ghostline=MagickFalse;
761 polygon_info->number_edges=edge;
764 polygon_info->number_edges=edge;
765 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(polygon_info->edges,
766 polygon_info->number_edges,
sizeof(*polygon_info->edges));
767 if (polygon_info->edges == (EdgeInfo *) NULL)
769 (void) ThrowMagickException(exception,GetMagickModule(),
770 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
771 return(DestroyPolygonInfo(polygon_info));
773 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
778 edge_info=polygon_info->edges+i;
779 edge_info->points=(PointInfo *) ResizeQuantumMemory(edge_info->points,
780 edge_info->number_points,
sizeof(*edge_info->points));
781 if (edge_info->points == (PointInfo *) NULL)
783 (void) ThrowMagickException(exception,GetMagickModule(),
784 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
785 return(DestroyPolygonInfo(polygon_info));
788 qsort(polygon_info->edges,(
size_t) polygon_info->number_edges,
789 sizeof(*polygon_info->edges),DrawCompareEdges);
790 if ((GetLogEventMask() & DrawEvent) != 0)
791 LogPolygonInfo(polygon_info);
792 return(polygon_info);
825static void LogPathInfo(
const PathInfo *path_info)
830 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin vector-path");
831 for (p=path_info; p->code != EndCode; p++)
832 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
833 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
834 "moveto ghostline" : p->code == OpenCode ?
"moveto open" :
835 p->code == MoveToCode ?
"moveto" : p->code == LineToCode ?
"lineto" :
837 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end vector-path");
840static PathInfo *ConvertPrimitiveToPath(
const PrimitiveInfo *primitive_info,
841 ExceptionInfo *exception)
867 switch (primitive_info->primitive)
874 return((PathInfo *) NULL);
878 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
879 path_info=(PathInfo *) AcquireQuantumMemory((
size_t) (3UL*i+1UL),
881 if (path_info == (PathInfo *) NULL)
883 (void) ThrowMagickException(exception,GetMagickModule(),
884 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
885 return((PathInfo *) NULL);
888 closed_subpath=MagickFalse;
895 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
898 if (coordinates <= 0)
903 coordinates=primitive_info[i].coordinates;
904 p=primitive_info[i].point;
907 closed_subpath=primitive_info[i].closed_subpath;
910 if ((code == MoveToCode) || (coordinates <= 0) ||
911 (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
912 (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
917 path_info[n].code=code;
918 path_info[n].point=primitive_info[i].point;
919 q=primitive_info[i].point;
924 if (closed_subpath != MagickFalse)
926 closed_subpath=MagickFalse;
932 path_info[start].code=OpenCode;
933 path_info[n].code=GhostlineCode;
934 path_info[n].point=primitive_info[i].point;
936 path_info[n].code=LineToCode;
937 path_info[n].point=p;
940 path_info[n].code=EndCode;
941 path_info[n].point.x=0.0;
942 path_info[n].point.y=0.0;
943 if (IsEventLogging() != MagickFalse)
944 LogPathInfo(path_info);
945 path_info=(PathInfo *) ResizeQuantumMemory(path_info,(
size_t) (n+1),
972MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
974 assert(draw_info != (DrawInfo *) NULL);
975 assert(draw_info->signature == MagickCoreSignature);
976 if (IsEventLogging() != MagickFalse)
977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
978 if (draw_info->id != (
char *) NULL)
979 draw_info->id=DestroyString(draw_info->id);
980 if (draw_info->primitive != (
char *) NULL)
981 draw_info->primitive=DestroyString(draw_info->primitive);
982 if (draw_info->text != (
char *) NULL)
983 draw_info->text=DestroyString(draw_info->text);
984 if (draw_info->geometry != (
char *) NULL)
985 draw_info->geometry=DestroyString(draw_info->geometry);
986 if (draw_info->fill_pattern != (Image *) NULL)
987 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
988 if (draw_info->stroke_pattern != (Image *) NULL)
989 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
990 if (draw_info->font != (
char *) NULL)
991 draw_info->font=DestroyString(draw_info->font);
992 if (draw_info->metrics != (
char *) NULL)
993 draw_info->metrics=DestroyString(draw_info->metrics);
994 if (draw_info->family != (
char *) NULL)
995 draw_info->family=DestroyString(draw_info->family);
996 if (draw_info->encoding != (
char *) NULL)
997 draw_info->encoding=DestroyString(draw_info->encoding);
998 if (draw_info->density != (
char *) NULL)
999 draw_info->density=DestroyString(draw_info->density);
1000 if (draw_info->server_name != (
char *) NULL)
1001 draw_info->server_name=(
char *)
1002 RelinquishMagickMemory(draw_info->server_name);
1003 if (draw_info->dash_pattern != (
double *) NULL)
1004 draw_info->dash_pattern=(
double *) RelinquishMagickMemory(
1005 draw_info->dash_pattern);
1006 if (draw_info->gradient.stops != (StopInfo *) NULL)
1007 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
1008 draw_info->gradient.stops);
1009 if (draw_info->clip_mask != (
char *) NULL)
1010 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
1011 if (draw_info->clipping_mask != (Image *) NULL)
1012 draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
1013 if (draw_info->composite_mask != (Image *) NULL)
1014 draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
1015 if (draw_info->image_info != (ImageInfo *) NULL)
1016 draw_info->image_info=DestroyImageInfo(draw_info->image_info);
1017 draw_info->signature=(~MagickCoreSignature);
1018 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
1053static SegmentInfo AffineEdge(
const Image *image,
const AffineMatrix *affine,
1054 const double y,
const SegmentInfo *edge)
1069 inverse_edge.x1=edge->x1;
1070 inverse_edge.y1=edge->y1;
1071 inverse_edge.x2=edge->x2;
1072 inverse_edge.y2=edge->y2;
1073 z=affine->ry*y+affine->tx;
1074 if (affine->sx >= MagickEpsilon)
1076 intercept=(-z/affine->sx);
1078 if (x > inverse_edge.x1)
1080 intercept=(-z+(double) image->columns)/affine->sx;
1082 if (x < inverse_edge.x2)
1086 if (affine->sx < -MagickEpsilon)
1088 intercept=(-z+(double) image->columns)/affine->sx;
1090 if (x > inverse_edge.x1)
1092 intercept=(-z/affine->sx);
1094 if (x < inverse_edge.x2)
1098 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->columns))
1100 inverse_edge.x2=edge->x1;
1101 return(inverse_edge);
1106 z=affine->sy*y+affine->ty;
1107 if (affine->rx >= MagickEpsilon)
1109 intercept=(-z/affine->rx);
1111 if (x > inverse_edge.x1)
1113 intercept=(-z+(double) image->rows)/affine->rx;
1115 if (x < inverse_edge.x2)
1119 if (affine->rx < -MagickEpsilon)
1121 intercept=(-z+(double) image->rows)/affine->rx;
1123 if (x > inverse_edge.x1)
1125 intercept=(-z/affine->rx);
1127 if (x < inverse_edge.x2)
1131 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->rows))
1133 inverse_edge.x2=edge->x2;
1134 return(inverse_edge);
1136 return(inverse_edge);
1139static AffineMatrix InverseAffineMatrix(
const AffineMatrix *affine)
1147 determinant=MagickSafeReciprocal(affine->sx*affine->sy-affine->rx*
1149 inverse_affine.sx=determinant*affine->sy;
1150 inverse_affine.rx=determinant*(-affine->rx);
1151 inverse_affine.ry=determinant*(-affine->ry);
1152 inverse_affine.sy=determinant*affine->sx;
1153 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1155 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1157 return(inverse_affine);
1160MagickExport MagickBooleanType DrawAffineImage(Image *image,
1161 const Image *source,
const AffineMatrix *affine,ExceptionInfo *exception)
1195 assert(image != (Image *) NULL);
1196 assert(image->signature == MagickCoreSignature);
1197 if (IsEventLogging() != MagickFalse)
1198 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1199 assert(source != (
const Image *) NULL);
1200 assert(source->signature == MagickCoreSignature);
1201 assert(affine != (AffineMatrix *) NULL);
1204 extent[1].x=(double) source->columns;
1206 extent[2].x=(double) source->columns;
1207 extent[2].y=(double) source->rows;
1209 extent[3].y=(double) source->rows;
1210 for (i=0; i < 4; i++)
1216 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1217 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1221 for (i=1; i < 4; i++)
1223 if (min.x > extent[i].x)
1225 if (min.y > extent[i].y)
1227 if (max.x < extent[i].x)
1229 if (max.y < extent[i].y)
1235 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1236 return(MagickFalse);
1242 inverse_affine=InverseAffineMatrix(affine);
1245 if (edge.y2 > ((
double) image->rows-1.0))
1246 edge.y2=(double) image->rows-1.0;
1247 GetPixelInfo(image,&zero);
1248 start=CastDoubleToSsizeT(ceil(edge.y1-0.5));
1249 stop=CastDoubleToSsizeT(floor(edge.y2+0.5));
1250 source_view=AcquireVirtualCacheView(source,exception);
1251 image_view=AcquireAuthenticCacheView(image,exception);
1252#if defined(MAGICKCORE_OPENMP_SUPPORT)
1253 #pragma omp parallel for schedule(static) shared(status) \
1254 magick_number_threads(source,image,(size_t) (stop-start),2)
1256 for (y=start; y <= stop; y++)
1274 if (status == MagickFalse)
1276 inverse_edge=AffineEdge(source,&inverse_affine,(
double) y,&edge);
1277 if (inverse_edge.x2 < inverse_edge.x1)
1279 if (inverse_edge.x1 < 0.0)
1280 inverse_edge.x1=0.0;
1281 if (inverse_edge.x2 > ((
double) image->columns-1.0))
1282 inverse_edge.x2=(double) image->columns-1.0;
1283 q=GetCacheViewAuthenticPixels(image_view,CastDoubleToSsizeT(
1284 ceil(inverse_edge.x1-0.5)),y,(
size_t) CastDoubleToSsizeT(floor(
1285 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
1286 if (q == (Quantum *) NULL)
1290 for (x=CastDoubleToSsizeT(ceil(inverse_edge.x1-0.5));
1291 x <= CastDoubleToSsizeT(floor(inverse_edge.x2+0.5)); x++)
1293 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1295 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1297 status=InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
1298 point.x,point.y,&pixel,exception);
1299 if (status == MagickFalse)
1301 GetPixelInfoPixel(image,q,&composite);
1302 CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
1304 SetPixelViaPixelInfo(image,&composite,q);
1305 q+=(ptrdiff_t) GetPixelChannels(image);
1307 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1310 source_view=DestroyCacheView(source_view);
1311 image_view=DestroyCacheView(image_view);
1347static MagickBooleanType DrawBoundingRectangles(Image *image,
1348 const DrawInfo *draw_info,
const PolygonInfo *polygon_info,
1349 ExceptionInfo *exception)
1377 (void) memset(primitive_info,0,
sizeof(primitive_info));
1378 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1379 status=QueryColorCompliance(
"#000F",AllCompliance,&clone_info->fill,
1381 if (status == MagickFalse)
1383 clone_info=DestroyDrawInfo(clone_info);
1384 return(MagickFalse);
1388 if (clone_info->density != (
char *) NULL)
1396 flags=ParseGeometry(clone_info->density,&geometry_info);
1397 if ((flags & RhoValue) != 0)
1398 resolution.x=geometry_info.rho;
1399 resolution.y=resolution.x;
1400 if ((flags & SigmaValue) != 0)
1401 resolution.y=geometry_info.sigma;
1403 mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
1404 clone_info->stroke_width/2.0;
1409 if (polygon_info != (PolygonInfo *) NULL)
1411 bounds=polygon_info->edges[0].bounds;
1412 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1414 if (polygon_info->edges[i].bounds.x1 < (
double) bounds.x1)
1415 bounds.x1=polygon_info->edges[i].bounds.x1;
1416 if (polygon_info->edges[i].bounds.y1 < (
double) bounds.y1)
1417 bounds.y1=polygon_info->edges[i].bounds.y1;
1418 if (polygon_info->edges[i].bounds.x2 > (
double) bounds.x2)
1419 bounds.x2=polygon_info->edges[i].bounds.x2;
1420 if (polygon_info->edges[i].bounds.y2 > (
double) bounds.y2)
1421 bounds.y2=polygon_info->edges[i].bounds.y2;
1424 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1425 image->columns ? (
double) image->columns-1 : bounds.x1;
1427 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1428 image->rows ? (
double) image->rows-1 : bounds.y1;
1430 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1431 image->columns ? (
double) image->columns-1 : bounds.x2;
1433 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1434 image->rows ? (
double) image->rows-1 : bounds.y2;
1435 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1437 if (polygon_info->edges[i].direction != 0)
1438 status=QueryColorCompliance(
"#f00",AllCompliance,&clone_info->stroke,
1441 status=QueryColorCompliance(
"#0f0",AllCompliance,&clone_info->stroke,
1443 if (status == MagickFalse)
1445 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1446 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1447 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1448 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1449 primitive_info[0].primitive=RectanglePrimitive;
1450 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1451 primitive_info[0].method=ReplaceMethod;
1452 coordinates=(ssize_t) primitive_info[0].coordinates;
1453 primitive_info[coordinates].primitive=UndefinedPrimitive;
1454 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1455 if (status == MagickFalse)
1458 if (i < (ssize_t) polygon_info->number_edges)
1460 clone_info=DestroyDrawInfo(clone_info);
1461 return(status == 0 ? MagickFalse : MagickTrue);
1464 status=QueryColorCompliance(
"#00f",AllCompliance,&clone_info->stroke,
1466 if (status == MagickFalse)
1468 clone_info=DestroyDrawInfo(clone_info);
1469 return(MagickFalse);
1471 start.x=(double) (bounds.x1-mid);
1472 start.y=(double) (bounds.y1-mid);
1473 end.x=(double) (bounds.x2+mid);
1474 end.y=(double) (bounds.y2+mid);
1475 primitive_info[0].primitive=RectanglePrimitive;
1476 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1477 primitive_info[0].method=ReplaceMethod;
1478 coordinates=(ssize_t) primitive_info[0].coordinates;
1479 primitive_info[coordinates].primitive=UndefinedPrimitive;
1480 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1481 clone_info=DestroyDrawInfo(clone_info);
1482 return(status == 0 ? MagickFalse : MagickTrue);
1515static MagickBooleanType DrawClipPath_(Image *image,
1516 const DrawInfo *draw_info,
const char *
id,
const size_t depth,
1517 ExceptionInfo *exception)
1528 clip_path=GetImageArtifact(image,
id);
1529 if (clip_path == (
const char *) NULL)
1530 return(MagickFalse);
1531 clipping_mask=DrawClippingMask(image,draw_info,draw_info->clip_mask,clip_path,
1533 if (clipping_mask == (Image *) NULL)
1534 return(MagickFalse);
1535 status=SetImageMask(image,WritePixelMask,clipping_mask,exception);
1536 clipping_mask=DestroyImage(clipping_mask);
1540MagickExport MagickBooleanType DrawClipPath(Image *image,
1541 const DrawInfo *draw_info,
const char *
id,ExceptionInfo *exception)
1543 return(DrawClipPath_(image,draw_info,
id,0,exception));
1581static Image *DrawClippingMask(Image *image,
const DrawInfo *draw_info,
1582 const char *
id,
const char *clip_path,
const size_t depth,
1583 ExceptionInfo *exception)
1598 assert(image != (Image *) NULL);
1599 assert(image->signature == MagickCoreSignature);
1600 assert(draw_info != (
const DrawInfo *) NULL);
1601 if (IsEventLogging() != MagickFalse)
1602 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1603 clip_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1604 status=SetImageExtent(clip_mask,image->columns,image->rows,exception);
1605 if (status == MagickFalse)
1606 return(DestroyImage(clip_mask));
1607 status=SetImageMask(clip_mask,WritePixelMask,(Image *) NULL,exception);
1608 status=QueryColorCompliance(
"#0000",AllCompliance,
1609 &clip_mask->background_color,exception);
1610 clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1611 clip_mask->background_color.alpha_trait=BlendPixelTrait;
1612 status=SetImageBackgroundColor(clip_mask,exception);
1613 if (draw_info->debug != MagickFalse)
1614 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin clip-path %s",
1616 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1617 (void) CloneString(&clone_info->primitive,clip_path);
1618 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1620 if (clone_info->clip_mask != (
char *) NULL)
1621 clone_info->clip_mask=DestroyString(clone_info->clip_mask);
1622 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1624 clone_info->stroke_width=0.0;
1625 clone_info->alpha=OpaqueAlpha;
1626 clone_info->clip_path=MagickTrue;
1627 status=RenderMVGContent(clip_mask,clone_info,depth+1,exception);
1628 clone_info=DestroyDrawInfo(clone_info);
1629 separate_mask=SeparateImage(clip_mask,AlphaChannel,exception);
1630 if (separate_mask == (Image *) NULL)
1634 clip_mask=DestroyImage(clip_mask);
1635 clip_mask=separate_mask;
1636 status&=(MagickStatusType) NegateImage(clip_mask,MagickFalse,exception);
1638 if (status == MagickFalse)
1639 clip_mask=DestroyImage(clip_mask);
1640 if (draw_info->debug != MagickFalse)
1641 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end clip-path");
1679static Image *DrawCompositeMask(Image *image,
const DrawInfo *draw_info,
1680 const char *
id,
const char *mask_path,
const size_t depth,
1681 ExceptionInfo *exception)
1696 assert(image != (Image *) NULL);
1697 assert(image->signature == MagickCoreSignature);
1698 assert(draw_info != (
const DrawInfo *) NULL);
1699 if (IsEventLogging() != MagickFalse)
1700 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1701 composite_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1702 status=SetImageExtent(composite_mask,image->columns,image->rows,exception);
1703 if (status == MagickFalse)
1704 return(DestroyImage(composite_mask));
1705 status=SetImageMask(composite_mask,CompositePixelMask,(Image *) NULL,
1707 status=QueryColorCompliance(
"#0000",AllCompliance,
1708 &composite_mask->background_color,exception);
1709 composite_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1710 composite_mask->background_color.alpha_trait=BlendPixelTrait;
1711 (void) SetImageBackgroundColor(composite_mask,exception);
1712 if (draw_info->debug != MagickFalse)
1713 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin mask-path %s",
1715 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1716 (void) CloneString(&clone_info->primitive,mask_path);
1717 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1719 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1721 clone_info->stroke_width=0.0;
1722 clone_info->alpha=OpaqueAlpha;
1723 status=RenderMVGContent(composite_mask,clone_info,depth+1,exception);
1724 clone_info=DestroyDrawInfo(clone_info);
1725 separate_mask=SeparateImage(composite_mask,AlphaChannel,exception);
1726 if (separate_mask != (Image *) NULL)
1728 composite_mask=DestroyImage(composite_mask);
1729 composite_mask=separate_mask;
1730 status=NegateImage(composite_mask,MagickFalse,exception);
1731 if (status == MagickFalse)
1732 composite_mask=DestroyImage(composite_mask);
1734 if (status == MagickFalse)
1735 composite_mask=DestroyImage(composite_mask);
1736 if (draw_info->debug != MagickFalse)
1737 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end mask-path");
1738 return(composite_mask);
1772static MagickBooleanType DrawDashPolygon(
const DrawInfo *draw_info,
1773 const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception)
1803 assert(draw_info != (
const DrawInfo *) NULL);
1804 if (draw_info->debug != MagickFalse)
1805 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-dash");
1806 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1807 number_vertices=(size_t) i;
1808 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
1809 (2UL*number_vertices+32UL),
sizeof(*dash_polygon));
1810 if (dash_polygon == (PrimitiveInfo *) NULL)
1812 (void) ThrowMagickException(exception,GetMagickModule(),
1813 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1814 return(MagickFalse);
1816 (void) memset(dash_polygon,0,(2UL*number_vertices+32UL)*
1817 sizeof(*dash_polygon));
1818 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1819 clone_info->miterlimit=0;
1820 dash_polygon[0]=primitive_info[0];
1821 dash_polygon[0].closed_subpath=MagickFalse;
1822 scale=ExpandAffine(&draw_info->affine);
1823 length=scale*draw_info->dash_pattern[0];
1824 offset=fabs(draw_info->dash_offset) >= MagickEpsilon ?
1825 scale*draw_info->dash_offset : 0.0;
1827 for (n=0; offset > 0.0; j=0)
1829 if (draw_info->dash_pattern[n] <= 0.0)
1831 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1832 if (offset > length)
1836 length=scale*draw_info->dash_pattern[n];
1839 if (offset < length)
1851 for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
1853 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1854 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1855 maximum_length=hypot(dx,dy);
1856 if (maximum_length > (
double) (MaxBezierCoordinates >> 2))
1858 if (fabs(length) < MagickEpsilon)
1860 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1862 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1864 length=scale*draw_info->dash_pattern[n];
1866 for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); )
1868 total_length+=length;
1869 if ((n & 0x01) != 0)
1871 dash_polygon[0]=primitive_info[0];
1872 dash_polygon[0].closed_subpath=MagickFalse;
1873 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1874 total_length*MagickSafeReciprocal(maximum_length));
1875 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1876 total_length*MagickSafeReciprocal(maximum_length));
1881 if ((j+1) > (ssize_t) number_vertices)
1883 dash_polygon[j]=primitive_info[i-1];
1884 dash_polygon[j].closed_subpath=MagickFalse;
1885 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1886 total_length*MagickSafeReciprocal(maximum_length));
1887 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1888 total_length*MagickSafeReciprocal(maximum_length));
1889 dash_polygon[j].coordinates=1;
1891 dash_polygon[0].coordinates=(size_t) j;
1892 dash_polygon[j].primitive=UndefinedPrimitive;
1893 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1894 dash_polygon,exception);
1895 if (status == MagickFalse)
1898 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1900 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1902 length=scale*draw_info->dash_pattern[n];
1904 length-=(maximum_length-total_length);
1905 if ((n & 0x01) != 0)
1907 dash_polygon[j]=primitive_info[i];
1908 dash_polygon[j].coordinates=1;
1911 if ((status != MagickFalse) && (total_length < maximum_length) &&
1912 ((n & 0x01) == 0) && (j > 1))
1914 dash_polygon[j]=primitive_info[i-1];
1915 dash_polygon[j].closed_subpath=MagickFalse;
1916 dash_polygon[j].point.x+=MagickEpsilon;
1917 dash_polygon[j].point.y+=MagickEpsilon;
1918 dash_polygon[j].coordinates=1;
1920 dash_polygon[0].coordinates=(size_t) j;
1921 dash_polygon[j].primitive=UndefinedPrimitive;
1922 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1923 dash_polygon,exception);
1925 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1926 clone_info=DestroyDrawInfo(clone_info);
1927 if (draw_info->debug != MagickFalse)
1928 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-dash");
1929 return(status != 0 ? MagickTrue : MagickFalse);
1960static inline double GetStopColorOffset(
const GradientInfo *gradient,
1961 const ssize_t x,
const ssize_t y)
1963 switch (gradient->type)
1965 case UndefinedGradient:
1966 case LinearGradient:
1981 gradient_vector=(&gradient->gradient_vector);
1982 p.x=gradient_vector->x2-gradient_vector->x1;
1983 p.y=gradient_vector->y2-gradient_vector->y1;
1984 q.x=(double) x-gradient_vector->x1;
1985 q.y=(double) y-gradient_vector->y1;
1986 length=sqrt(q.x*q.x+q.y*q.y);
1987 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
1988 gamma=MagickSafeReciprocal(gamma);
1989 scale=p.x*q.x+p.y*q.y;
1990 offset=gamma*scale*length;
1993 case RadialGradient:
1998 if (gradient->spread == RepeatSpread)
2000 v.x=(double) x-gradient->center.x;
2001 v.y=(double) y-gradient->center.y;
2002 return(sqrt(v.x*v.x+v.y*v.y));
2004 v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians(
2005 gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians(
2006 gradient->angle))))*MagickSafeReciprocal(gradient->radii.x);
2007 v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians(
2008 gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians(
2009 gradient->angle))))*MagickSafeReciprocal(gradient->radii.y);
2010 return(sqrt(v.x*v.x+v.y*v.y));
2016static int StopInfoCompare(
const void *x,
const void *y)
2022 stop_1=(StopInfo *) x;
2023 stop_2=(StopInfo *) y;
2024 if (stop_1->offset > stop_2->offset)
2026 if (fabs(stop_1->offset-stop_2->offset) <= MagickEpsilon)
2031MagickExport MagickBooleanType DrawGradientImage(Image *image,
2032 const DrawInfo *draw_info,ExceptionInfo *exception)
2067 assert(image != (Image *) NULL);
2068 assert(image->signature == MagickCoreSignature);
2069 assert(draw_info != (
const DrawInfo *) NULL);
2070 if (IsEventLogging() != MagickFalse)
2071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2072 gradient=(&draw_info->gradient);
2073 qsort(gradient->stops,gradient->number_stops,
sizeof(StopInfo),
2075 gradient_vector=(&gradient->gradient_vector);
2076 point.x=gradient_vector->x2-gradient_vector->x1;
2077 point.y=gradient_vector->y2-gradient_vector->y1;
2078 length=sqrt(point.x*point.x+point.y*point.y);
2079 bounding_box=gradient->bounding_box;
2081 GetPixelInfo(image,&zero);
2082 image_view=AcquireAuthenticCacheView(image,exception);
2083 height=(size_t) (bounding_box.y+(ssize_t) bounding_box.height);
2084#if defined(MAGICKCORE_OPENMP_SUPPORT)
2085 #pragma omp parallel for schedule(static) shared(status) \
2086 magick_number_threads(image,image,height,1)
2088 for (y=bounding_box.y; y < (ssize_t) height; y++)
2109 if (status == MagickFalse)
2111 q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,y,(
size_t)
2112 bounding_box.width,1,exception);
2113 if (q == (Quantum *) NULL)
2120 offset=GetStopColorOffset(gradient,0,y);
2121 if (gradient->type != RadialGradient)
2122 offset*=MagickSafeReciprocal(length);
2123 width=(size_t) (bounding_box.x+(ssize_t) bounding_box.width);
2124 for (x=bounding_box.x; x < (ssize_t) width; x++)
2126 GetPixelInfoPixel(image,q,&pixel);
2127 switch (gradient->spread)
2129 case UndefinedSpread:
2132 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2133 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2135 offset=GetStopColorOffset(gradient,x,y);
2136 if (gradient->type != RadialGradient)
2137 offset*=MagickSafeReciprocal(length);
2139 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2140 if (offset < gradient->stops[i].offset)
2142 if ((offset < 0.0) || (i == 0))
2143 composite=gradient->stops[0].color;
2145 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
2146 composite=gradient->stops[gradient->number_stops-1].color;
2151 alpha=(offset-gradient->stops[i].offset)/
2152 (gradient->stops[j].offset-gradient->stops[i].offset);
2153 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2154 &gradient->stops[j].color,alpha,&composite);
2160 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2161 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2163 offset=GetStopColorOffset(gradient,x,y);
2164 if (gradient->type != RadialGradient)
2165 offset*=MagickSafeReciprocal(length);
2169 if ((ssize_t) fmod(offset,2.0) == 0)
2170 offset=fmod(offset,1.0);
2172 offset=1.0-fmod(offset,1.0);
2173 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2174 if (offset < gradient->stops[i].offset)
2177 composite=gradient->stops[0].color;
2179 if (i == (ssize_t) gradient->number_stops)
2180 composite=gradient->stops[gradient->number_stops-1].color;
2185 alpha=(offset-gradient->stops[i].offset)/
2186 (gradient->stops[j].offset-gradient->stops[i].offset);
2187 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2188 &gradient->stops[j].color,alpha,&composite);
2200 antialias=MagickFalse;
2202 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2203 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2205 offset=GetStopColorOffset(gradient,x,y);
2206 if (gradient->type == LinearGradient)
2208 repeat=fmod(offset,length);
2210 repeat=length-fmod(-repeat,length);
2212 repeat=fmod(offset,length);
2213 antialias=(repeat < length) && ((repeat+1.0) > length) ?
2214 MagickTrue : MagickFalse;
2215 offset=MagickSafeReciprocal(length)*repeat;
2219 repeat=fmod(offset,gradient->radius);
2221 repeat=gradient->radius-fmod(-repeat,gradient->radius);
2223 repeat=fmod(offset,gradient->radius);
2224 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
2226 offset=repeat*MagickSafeReciprocal(gradient->radius);
2229 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2230 if (offset < gradient->stops[i].offset)
2233 composite=gradient->stops[0].color;
2235 if (i == (ssize_t) gradient->number_stops)
2236 composite=gradient->stops[gradient->number_stops-1].color;
2241 alpha=(offset-gradient->stops[i].offset)/
2242 (gradient->stops[j].offset-gradient->stops[i].offset);
2243 if (antialias != MagickFalse)
2245 if (gradient->type == LinearGradient)
2246 alpha=length-repeat;
2248 alpha=gradient->radius-repeat;
2250 j=(ssize_t) gradient->number_stops-1L;
2252 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2253 &gradient->stops[j].color,alpha,&composite);
2258 CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha,
2260 SetPixelViaPixelInfo(image,&pixel,q);
2261 q+=(ptrdiff_t) GetPixelChannels(image);
2263 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2266 image_view=DestroyCacheView(image_view);
2302static inline MagickBooleanType CheckPrimitiveExtent(MVGInfo *mvg_info,
2317 if ((mvg_info == (MVGInfo *) NULL) ||
2318 (mvg_info->primitive_info == (PrimitiveInfo **) NULL) ||
2319 (*mvg_info->primitive_info == (PrimitiveInfo *) NULL) ||
2320 (mvg_info->extent == (
size_t *) NULL))
2321 return(MagickFalse);
2322 proposed_extent=mvg_info->offset+pad+PrimitiveExtentPad+1.0;
2323 if ((proposed_extent <= 0.0) || (proposed_extent > (
double) MAGICK_SIZE_MAX))
2324 return(MagickFalse);
2325 extent=CastDoubleToSizeT(ceil(proposed_extent));
2326 if (extent <= *mvg_info->extent)
2328 if (extent > (GetMaxMemoryRequest()/
sizeof(PrimitiveInfo)))
2329 return(MagickFalse);
2330 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(
2331 *mvg_info->primitive_info,extent+1,
sizeof(PrimitiveInfo));
2332 if (primitive_info == (PrimitiveInfo *) NULL)
2337 extent=(size_t) PrimitiveExtentPad;
2338 primitive_info=(PrimitiveInfo *) AcquireCriticalMemory(extent*
2339 sizeof(*primitive_info));
2340 (void) memset(primitive_info,0,extent*
sizeof(*primitive_info));
2341 *mvg_info->primitive_info=primitive_info;
2342 *mvg_info->extent=extent;
2344 ThrowMagickException(mvg_info->exception,GetMagickModule(),
2345 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2346 return(MagickFalse);
2348 primitive_info[extent].primitive=UndefinedPrimitive;
2349 primitive_info[extent].text=(
char *) NULL;
2353 for (i=(ssize_t) *mvg_info->extent; i < (ssize_t) extent; i++)
2355 primitive_info[i].primitive=UndefinedPrimitive;
2356 primitive_info[i].text=(
char *) NULL;
2358 *mvg_info->primitive_info=primitive_info;
2359 *mvg_info->extent=extent;
2363static inline double GetDrawValue(
const char *magick_restrict
string,
2364 char **magick_restrict sentinel)
2367 **magick_restrict q;
2373 value=InterpretLocaleValue(
string,q);
2378static int MVGMacroCompare(
const void *target,
const void *source)
2384 p=(
const char *) target;
2385 q=(
const char *) source;
2386 return(strcmp(p,q));
2389static SplayTreeInfo *GetMVGMacros(
const char *primitive,
2390 ExceptionInfo *exception)
2408 if (primitive == (
const char *) NULL)
2409 return((SplayTreeInfo *) NULL);
2410 macros=NewSplayTree(MVGMacroCompare,RelinquishMagickMemory,
2411 RelinquishMagickMemory);
2412 macro=AcquireString(primitive);
2413 token=AcquireString(primitive);
2414 extent=strlen(token)+MagickPathExtent;
2415 for (q=primitive; *q !=
'\0'; )
2417 if (GetNextToken(q,&q,extent,token) < 1)
2421 if (LocaleCompare(
"push",token) == 0)
2427 (void) GetNextToken(q,&q,extent,token);
2431 name[MagickPathExtent];
2442 (void) GetNextToken(q,&q,extent,token);
2445 (void) CopyMagickString(name,token,MagickPathExtent);
2447 for (p=q; *p !=
'\0'; )
2449 if (GetNextToken(p,&p,extent,token) < 1)
2453 if (LocaleCompare(token,
"pop") == 0)
2455 end=p-strlen(token)-1;
2458 if (LocaleCompare(token,
"push") == 0)
2460 if (n++ >= MaxVectorRecursionDepth)
2462 (void) ThrowMagickException(exception,GetMagickModule(),
2463 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2467 if ((n == 0) && (end >= start))
2470 length=(size_t) (end-start);
2475 (void) GetNextToken(p,&p,extent,token);
2478 (void) CopyMagickString(macro,start,length);
2479 (void) AddValueToSplayTree(macros,ConstantString(name),
2480 ConstantString(macro));
2488 token=DestroyString(token);
2489 macro=DestroyString(macro);
2493static inline MagickBooleanType IsValidListChar(
int c)
2495 if ((c >=
'0') && (c <=
'9'))
2509 return(MagickFalse);
2514static inline MagickBooleanType IsValidPoint(
const char *point)
2522 value=GetDrawValue(point,&p);
2523 return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
2527static inline MagickBooleanType TracePoint(PrimitiveInfo *primitive_info,
2528 const PointInfo point)
2530 primitive_info->point=point;
2531 primitive_info->coordinates=1;
2532 primitive_info->closed_subpath=MagickFalse;
2533 primitive_info->text=(
char *) NULL;
2537static MagickBooleanType RenderMVGContent(Image *image,
2538 const DrawInfo *draw_info,
const size_t depth,ExceptionInfo *exception)
2540#define RenderImageTag "Render/Image"
2547 keyword[MagickPathExtent],
2548 geometry[MagickPathExtent],
2550 pattern[MagickPathExtent],
2614 assert(image != (Image *) NULL);
2615 assert(image->signature == MagickCoreSignature);
2616 assert(draw_info != (DrawInfo *) NULL);
2617 assert(draw_info->signature == MagickCoreSignature);
2618 if (IsEventLogging() != MagickFalse)
2619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2620 if (depth >= MaxVectorRecursionDepth)
2621 ThrowBinaryException(DrawError,
"VectorGraphicsNestedTooDeeply",
2623 if ((draw_info->primitive == (
char *) NULL) ||
2624 (*draw_info->primitive ==
'\0'))
2625 return(MagickFalse);
2626 if (draw_info->debug != MagickFalse)
2627 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"begin draw-image");
2628 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2629 return(MagickFalse);
2630 if ((image->alpha_trait & BlendPixelTrait) == 0)
2632 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2633 if (status == MagickFalse)
2634 return(MagickFalse);
2636 if ((*draw_info->primitive ==
'@') && (strlen(draw_info->primitive) > 1) &&
2637 (*(draw_info->primitive+1) !=
'-') && (depth == 0))
2638 primitive=FileToString(draw_info->primitive,~0UL,exception);
2640 primitive=AcquireString(draw_info->primitive);
2641 if (primitive == (
char *) NULL)
2642 return(MagickFalse);
2643 primitive_extent=(double) strlen(primitive);
2644 (void) SetImageArtifact(image,
"mvg:vector-graphics",primitive);
2647 stops=(StopInfo *) NULL;
2651 graphic_context=(DrawInfo **) AcquireMagickMemory(
sizeof(*graphic_context));
2652 if (graphic_context == (DrawInfo **) NULL)
2654 primitive=DestroyString(primitive);
2655 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2658 number_points=(size_t) PrimitiveExtentPad;
2659 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
2660 (number_points+1),
sizeof(*primitive_info));
2661 if (primitive_info == (PrimitiveInfo *) NULL)
2663 primitive=DestroyString(primitive);
2664 for ( ; n >= 0; n--)
2665 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2666 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
2667 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2670 (void) memset(primitive_info,0,(
size_t) (number_points+1)*
2671 sizeof(*primitive_info));
2672 (void) memset(&mvg_info,0,
sizeof(mvg_info));
2673 mvg_info.primitive_info=(&primitive_info);
2674 mvg_info.extent=(&number_points);
2675 mvg_info.exception=exception;
2676 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
2677 if (graphic_context[n]->primitive != (
char *) NULL)
2678 graphic_context[n]->primitive=DestroyString(graphic_context[n]->primitive);
2679 graphic_context[n]->viewbox=image->page;
2680 if ((image->page.width == 0) || (image->page.height == 0))
2682 graphic_context[n]->viewbox.width=image->columns;
2683 graphic_context[n]->viewbox.height=image->rows;
2685 token=AcquireString(primitive);
2686 extent=strlen(token)+MagickPathExtent;
2690 macros=GetMVGMacros(primitive,exception);
2692 for (q=primitive; *q !=
'\0'; )
2697 if (GetNextToken(q,&q,MagickPathExtent,keyword) < 1)
2699 if (*keyword ==
'\0')
2701 if (*keyword ==
'#')
2706 while ((*q !=
'\n') && (*q !=
'\0'))
2710 p=q-strlen(keyword)-1;
2711 primitive_type=UndefinedPrimitive;
2712 current=graphic_context[n]->affine;
2713 GetAffineMatrix(&affine);
2722 if (LocaleCompare(
"affine",keyword) == 0)
2724 (void) GetNextToken(q,&q,extent,token);
2725 affine.sx=GetDrawValue(token,&next_token);
2726 if (token == next_token)
2727 ThrowPointExpectedException(token,exception);
2728 (void) GetNextToken(q,&q,extent,token);
2729 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2730 ThrowPointExpectedException(token,exception);
2732 (void) GetNextToken(q,&q,extent,token);
2733 affine.ry=GetDrawValue(token,&next_token);
2734 if (token == next_token)
2735 ThrowPointExpectedException(token,exception);
2736 (void) GetNextToken(q,&q,extent,token);
2737 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2738 ThrowPointExpectedException(token,exception);
2740 (void) GetNextToken(q,&q,extent,token);
2741 affine.rx=GetDrawValue(token,&next_token);
2742 if (token == next_token)
2743 ThrowPointExpectedException(token,exception);
2744 (void) GetNextToken(q,&q,extent,token);
2745 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2746 ThrowPointExpectedException(token,exception);
2748 (void) GetNextToken(q,&q,extent,token);
2749 affine.sy=GetDrawValue(token,&next_token);
2750 if (token == next_token)
2751 ThrowPointExpectedException(token,exception);
2752 (void) GetNextToken(q,&q,extent,token);
2753 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2754 ThrowPointExpectedException(token,exception);
2756 (void) GetNextToken(q,&q,extent,token);
2757 affine.tx=GetDrawValue(token,&next_token);
2758 if (token == next_token)
2759 ThrowPointExpectedException(token,exception);
2760 (void) GetNextToken(q,&q,extent,token);
2761 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2762 ThrowPointExpectedException(token,exception);
2764 (void) GetNextToken(q,&q,extent,token);
2765 affine.ty=GetDrawValue(token,&next_token);
2766 if (token == next_token)
2767 ThrowPointExpectedException(token,exception);
2770 if (LocaleCompare(
"alpha",keyword) == 0)
2772 primitive_type=AlphaPrimitive;
2775 if (LocaleCompare(
"arc",keyword) == 0)
2777 primitive_type=ArcPrimitive;
2786 if (LocaleCompare(
"bezier",keyword) == 0)
2788 primitive_type=BezierPrimitive;
2791 if (LocaleCompare(
"border-color",keyword) == 0)
2793 (void) GetNextToken(q,&q,extent,token);
2794 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2795 &graphic_context[n]->border_color,exception);
2804 if (LocaleCompare(
"class",keyword) == 0)
2809 (void) GetNextToken(q,&q,extent,token);
2810 if ((*token ==
'\0') || (*token ==
';'))
2818 for (i=0; i <= n; i++)
2819 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2823 if (classDepth++ >= MaxVectorRecursionDepth)
2825 (void) ThrowMagickException(exception,GetMagickModule(),
2826 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2830 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2831 if ((graphic_context[n]->render != MagickFalse) &&
2832 (mvg_class != (
const char *) NULL) && (p > primitive))
2843 (void) CloneString(&graphic_context[n]->
id,token);
2844 offset=(ssize_t) (p-primitive);
2845 elements=AcquireString(primitive);
2846 elements[offset]=
'\0';
2847 (void) ConcatenateString(&elements,mvg_class);
2848 (void) ConcatenateString(&elements,
"\n");
2849 (void) ConcatenateString(&elements,q);
2850 primitive=DestroyString(primitive);
2856 if (LocaleCompare(
"clip-path",keyword) == 0)
2864 (void) GetNextToken(q,&q,extent,token);
2870 (void) CloneString(&graphic_context[n]->clip_mask,token);
2871 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2872 if (clip_path != (
const char *) NULL)
2874 if (graphic_context[n]->clipping_mask != (Image *) NULL)
2875 graphic_context[n]->clipping_mask=
2876 DestroyImage(graphic_context[n]->clipping_mask);
2877 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2878 graphic_context[n],token,clip_path,depth+1,exception);
2879 if (graphic_context[n]->compliance != SVGCompliance)
2881 clip_path=(
const char *) GetValueFromSplayTree(macros,
2882 graphic_context[n]->clip_mask);
2883 if (clip_path != (
const char *) NULL)
2884 (void) SetImageArtifact(image,
2885 graphic_context[n]->clip_mask,clip_path);
2886 status&=(MagickStatusType) DrawClipPath_(image,
2887 graphic_context[n],graphic_context[n]->clip_mask,
2893 if (LocaleCompare(
"clip-rule",keyword) == 0)
2898 (void) GetNextToken(q,&q,extent,token);
2899 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2901 if (fill_rule == -1)
2906 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2909 if (LocaleCompare(
"clip-units",keyword) == 0)
2914 (void) GetNextToken(q,&q,extent,token);
2915 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2917 if (clip_units == -1)
2922 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2923 if (clip_units == ObjectBoundingBox)
2925 GetAffineMatrix(¤t);
2926 affine.sx=draw_info->bounds.x2;
2927 affine.sy=draw_info->bounds.y2;
2928 affine.tx=draw_info->bounds.x1;
2929 affine.ty=draw_info->bounds.y1;
2934 if (LocaleCompare(
"circle",keyword) == 0)
2936 primitive_type=CirclePrimitive;
2939 if (LocaleCompare(
"color",keyword) == 0)
2941 primitive_type=ColorPrimitive;
2944 if (LocaleCompare(
"compliance",keyword) == 0)
2950 (void) GetNextToken(q,&q,extent,token);
2951 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2952 MagickComplianceOptions,MagickFalse,token);
2955 if (LocaleCompare(
"currentColor",keyword) == 0)
2957 (void) GetNextToken(q,&q,extent,token);
2966 if (LocaleCompare(
"decorate",keyword) == 0)
2971 (void) GetNextToken(q,&q,extent,token);
2972 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2979 graphic_context[n]->decorate=(DecorationType) decorate;
2982 if (LocaleCompare(
"density",keyword) == 0)
2984 (void) GetNextToken(q,&q,extent,token);
2985 (void) CloneString(&graphic_context[n]->density,token);
2988 if (LocaleCompare(
"direction",keyword) == 0)
2993 (void) GetNextToken(q,&q,extent,token);
2994 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2996 if (direction == -1)
2999 graphic_context[n]->direction=(DirectionType) direction;
3008 if (LocaleCompare(
"ellipse",keyword) == 0)
3010 primitive_type=EllipsePrimitive;
3013 if (LocaleCompare(
"encoding",keyword) == 0)
3015 (void) GetNextToken(q,&q,extent,token);
3016 (void) CloneString(&graphic_context[n]->encoding,token);
3025 if (LocaleCompare(
"fill",keyword) == 0)
3030 (void) GetNextToken(q,&q,extent,token);
3031 if (graphic_context[n]->clip_path != MagickFalse)
3033 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3034 if (mvg_class != (
const char *) NULL)
3036 (void) DrawPatternPath(image,draw_info,mvg_class,
3037 &graphic_context[n]->fill_pattern,exception);
3040 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3041 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3043 (void) DrawPatternPath(image,draw_info,token,
3044 &graphic_context[n]->fill_pattern,exception);
3047 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3048 &graphic_context[n]->fill,exception);
3049 if (graphic_context[n]->fill_alpha != (
double) OpaqueAlpha)
3050 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3053 if (LocaleCompare(
"fill-opacity",keyword) == 0)
3058 (void) GetNextToken(q,&q,extent,token);
3059 if (graphic_context[n]->clip_path != MagickFalse)
3061 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3062 opacity=MagickMin(MagickMax(factor*
3063 GetDrawValue(token,&next_token),0.0),1.0);
3064 if (token == next_token)
3065 ThrowPointExpectedException(token,exception);
3066 if (graphic_context[n]->compliance == SVGCompliance)
3067 graphic_context[n]->fill_alpha*=opacity;
3069 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3070 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3071 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3073 graphic_context[n]->fill.alpha=(MagickRealType)
3074 ClampToQuantum((
double) QuantumRange*opacity);
3075 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3078 if (LocaleCompare(
"fill-rule",keyword) == 0)
3083 (void) GetNextToken(q,&q,extent,token);
3084 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3086 if (fill_rule == -1)
3091 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3094 if (LocaleCompare(
"font",keyword) == 0)
3096 (void) GetNextToken(q,&q,extent,token);
3097 (void) CloneString(&graphic_context[n]->font,token);
3098 if (LocaleCompare(
"none",token) == 0)
3099 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3100 graphic_context[n]->font);
3103 if (LocaleCompare(
"font-family",keyword) == 0)
3105 (void) GetNextToken(q,&q,extent,token);
3106 (void) CloneString(&graphic_context[n]->family,token);
3109 if (LocaleCompare(
"font-size",keyword) == 0)
3111 (void) GetNextToken(q,&q,extent,token);
3112 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3113 if (token == next_token)
3114 ThrowPointExpectedException(token,exception);
3117 if (LocaleCompare(
"font-stretch",keyword) == 0)
3122 (void) GetNextToken(q,&q,extent,token);
3123 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3129 graphic_context[n]->stretch=(StretchType) stretch;
3132 if (LocaleCompare(
"font-style",keyword) == 0)
3137 (void) GetNextToken(q,&q,extent,token);
3138 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3144 graphic_context[n]->style=(StyleType) style;
3147 if (LocaleCompare(
"font-weight",keyword) == 0)
3152 (void) GetNextToken(q,&q,extent,token);
3153 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3155 weight=(ssize_t) StringToUnsignedLong(token);
3156 graphic_context[n]->weight=(size_t) weight;
3165 if (LocaleCompare(
"gradient-units",keyword) == 0)
3167 (void) GetNextToken(q,&q,extent,token);
3170 if (LocaleCompare(
"gravity",keyword) == 0)
3175 (void) GetNextToken(q,&q,extent,token);
3176 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3182 graphic_context[n]->gravity=(GravityType) gravity;
3191 if (LocaleCompare(
"image",keyword) == 0)
3196 primitive_type=ImagePrimitive;
3197 (void) GetNextToken(q,&q,extent,token);
3198 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3204 graphic_context[n]->compose=(CompositeOperator) compose;
3207 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3209 (void) GetNextToken(q,&q,extent,token);
3210 graphic_context[n]->interline_spacing=GetDrawValue(token,
3212 if (token == next_token)
3213 ThrowPointExpectedException(token,exception);
3216 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3218 (void) GetNextToken(q,&q,extent,token);
3219 graphic_context[n]->interword_spacing=GetDrawValue(token,
3221 if (token == next_token)
3222 ThrowPointExpectedException(token,exception);
3231 if (LocaleCompare(
"kerning",keyword) == 0)
3233 (void) GetNextToken(q,&q,extent,token);
3234 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3235 if (token == next_token)
3236 ThrowPointExpectedException(token,exception);
3245 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3247 (void) GetNextToken(q,&q,extent,token);
3248 if (IsValidPoint(token) == MagickFalse)
3250 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
3251 clone_info->text=AcquireString(
" ");
3252 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,&metrics,
3254 graphic_context[n]->kerning=metrics.width*
3255 GetDrawValue(token,&next_token);
3256 clone_info=DestroyDrawInfo(clone_info);
3257 if (token == next_token)
3258 ThrowPointExpectedException(token,exception);
3261 if (LocaleCompare(
"line",keyword) == 0)
3263 primitive_type=LinePrimitive;
3272 if (LocaleCompare(
"mask",keyword) == 0)
3280 (void) GetNextToken(q,&q,extent,token);
3281 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3282 if (mask_path != (
const char *) NULL)
3284 if (graphic_context[n]->composite_mask != (Image *) NULL)
3285 graphic_context[n]->composite_mask=
3286 DestroyImage(graphic_context[n]->composite_mask);
3287 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3288 graphic_context[n],token,mask_path,depth+1,exception);
3289 if (graphic_context[n]->compliance != SVGCompliance)
3290 status=SetImageMask(image,CompositePixelMask,
3291 graphic_context[n]->composite_mask,exception);
3301 if (LocaleCompare(
"offset",keyword) == 0)
3303 (void) GetNextToken(q,&q,extent,token);
3306 if (LocaleCompare(
"opacity",keyword) == 0)
3311 (void) GetNextToken(q,&q,extent,token);
3312 if (graphic_context[n]->clip_path != MagickFalse)
3314 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3315 opacity=MagickMin(MagickMax(factor*
3316 GetDrawValue(token,&next_token),0.0),1.0);
3317 if (token == next_token)
3318 ThrowPointExpectedException(token,exception);
3319 if (graphic_context[n]->compliance == SVGCompliance)
3321 graphic_context[n]->fill_alpha*=opacity;
3322 graphic_context[n]->stroke_alpha*=opacity;
3326 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3327 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3329 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3331 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3332 graphic_context[n]->stroke.alpha=
3333 graphic_context[n]->stroke_alpha;
3337 graphic_context[n]->fill.alpha=(MagickRealType)
3338 ClampToQuantum((
double) QuantumRange*opacity);
3339 graphic_context[n]->stroke.alpha=(MagickRealType)
3340 ClampToQuantum((
double) QuantumRange*opacity);
3342 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3343 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3352 if (LocaleCompare(
"path",keyword) == 0)
3354 primitive_type=PathPrimitive;
3357 if (LocaleCompare(
"point",keyword) == 0)
3359 primitive_type=PointPrimitive;
3362 if (LocaleCompare(
"polyline",keyword) == 0)
3364 primitive_type=PolylinePrimitive;
3367 if (LocaleCompare(
"polygon",keyword) == 0)
3369 primitive_type=PolygonPrimitive;
3372 if (LocaleCompare(
"pop",keyword) == 0)
3374 if (GetNextToken(q,&q,extent,token) < 1)
3376 if (LocaleCompare(
"class",token) == 0)
3378 if (LocaleCompare(
"clip-path",token) == 0)
3380 if (LocaleCompare(
"defs",token) == 0)
3383 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3387 if (LocaleCompare(
"gradient",token) == 0)
3389 if (LocaleCompare(
"graphic-context",token) == 0)
3393 (void) ThrowMagickException(exception,GetMagickModule(),
3394 DrawError,
"UnbalancedGraphicContextPushPop",
"`%s'",token);
3399 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3400 (graphic_context[n]->compliance != SVGCompliance))
3401 if (LocaleCompare(graphic_context[n]->clip_mask,
3402 graphic_context[n-1]->clip_mask) != 0)
3403 status=SetImageMask(image,WritePixelMask,(Image *) NULL,
3405 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3409 if (LocaleCompare(
"mask",token) == 0)
3411 if (LocaleCompare(
"pattern",token) == 0)
3413 if (LocaleCompare(
"symbol",token) == 0)
3416 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3423 if (LocaleCompare(
"push",keyword) == 0)
3425 if (GetNextToken(q,&q,extent,token) < 1)
3427 if (LocaleCompare(
"class",token) == 0)
3432 for (p=q; *q !=
'\0'; )
3434 if (GetNextToken(q,&q,extent,token) < 1)
3436 if (LocaleCompare(token,
"pop") != 0)
3438 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3439 if (LocaleCompare(token,
"class") != 0)
3443 (void) GetNextToken(q,&q,extent,token);
3446 if (LocaleCompare(
"clip-path",token) == 0)
3448 (void) GetNextToken(q,&q,extent,token);
3449 for (p=q; *q !=
'\0'; )
3451 if (GetNextToken(q,&q,extent,token) < 1)
3453 if (LocaleCompare(token,
"pop") != 0)
3455 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3456 if (LocaleCompare(token,
"clip-path") != 0)
3460 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3465 (void) GetNextToken(q,&q,extent,token);
3468 if (LocaleCompare(
"defs",token) == 0)
3471 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3475 if (LocaleCompare(
"gradient",token) == 0)
3478 key[2*MagickPathExtent],
3479 name[MagickPathExtent],
3480 type[MagickPathExtent];
3485 (void) GetNextToken(q,&q,extent,token);
3486 (void) CopyMagickString(name,token,MagickPathExtent);
3487 (void) GetNextToken(q,&q,extent,token);
3488 (void) CopyMagickString(type,token,MagickPathExtent);
3489 (void) GetNextToken(q,&q,extent,token);
3490 segment.x1=GetDrawValue(token,&next_token);
3491 if (token == next_token)
3492 ThrowPointExpectedException(token,exception);
3493 (void) GetNextToken(q,&q,extent,token);
3494 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3495 ThrowPointExpectedException(token,exception);
3497 (void) GetNextToken(q,&q,extent,token);
3498 segment.y1=GetDrawValue(token,&next_token);
3499 if (token == next_token)
3500 ThrowPointExpectedException(token,exception);
3501 (void) GetNextToken(q,&q,extent,token);
3502 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3503 ThrowPointExpectedException(token,exception);
3505 (void) GetNextToken(q,&q,extent,token);
3506 segment.x2=GetDrawValue(token,&next_token);
3507 if (token == next_token)
3508 ThrowPointExpectedException(token,exception);
3509 (void) GetNextToken(q,&q,extent,token);
3510 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3511 ThrowPointExpectedException(token,exception);
3513 (void) GetNextToken(q,&q,extent,token);
3514 segment.y2=GetDrawValue(token,&next_token);
3515 if (token == next_token)
3516 ThrowPointExpectedException(token,exception);
3517 if (LocaleCompare(type,
"radial") == 0)
3519 (void) GetNextToken(q,&q,extent,token);
3520 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3521 ThrowPointExpectedException(token,exception);
3523 (void) GetNextToken(q,&q,extent,token);
3525 for (p=q; *q !=
'\0'; )
3527 if (GetNextToken(q,&q,extent,token) < 1)
3529 if (LocaleCompare(token,
"pop") != 0)
3531 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3532 if (LocaleCompare(token,
"gradient") != 0)
3536 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3537 (p == (
char *) NULL) || ((q-4) < p) ||
3538 ((
size_t) (q-p+4+1) > extent))
3543 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3544 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3545 graphic_context[n]->affine.ry*segment.y1+
3546 graphic_context[n]->affine.tx;
3547 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3548 graphic_context[n]->affine.sy*segment.y1+
3549 graphic_context[n]->affine.ty;
3550 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3551 graphic_context[n]->affine.ry*segment.y2+
3552 graphic_context[n]->affine.tx;
3553 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3554 graphic_context[n]->affine.sy*segment.y2+
3555 graphic_context[n]->affine.ty;
3556 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3557 (void) SetImageArtifact(image,key,token);
3558 (void) FormatLocaleString(key,MagickPathExtent,
"%s-type",name);
3559 (void) SetImageArtifact(image,key,type);
3560 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3562 (void) FormatLocaleString(geometry,MagickPathExtent,
3563 "%gx%g%+.15g%+.15g",
3564 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3565 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3566 bounds.x1,bounds.y1);
3567 (void) SetImageArtifact(image,key,geometry);
3568 (void) GetNextToken(q,&q,extent,token);
3571 if (LocaleCompare(
"graphic-context",token) == 0)
3574 graphic_context=(DrawInfo **) ResizeQuantumMemory(
3575 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3576 if (graphic_context == (DrawInfo **) NULL)
3578 (void) ThrowMagickException(exception,GetMagickModule(),
3579 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3584 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
3585 graphic_context[n-1]);
3588 (void) GetNextToken(q,&q,extent,token);
3589 (void) CloneString(&graphic_context[n]->
id,token);
3591 if (n >= MaxVectorRecursionDepth)
3593 (void) ThrowMagickException(exception,GetMagickModule(),
3594 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",
3600 if (LocaleCompare(
"mask",token) == 0)
3602 (void) GetNextToken(q,&q,extent,token);
3605 if (LocaleCompare(
"pattern",token) == 0)
3608 key[2*MagickPathExtent],
3609 name[MagickPathExtent];
3614 (void) GetNextToken(q,&q,extent,token);
3615 (void) CopyMagickString(name,token,MagickPathExtent);
3616 (void) GetNextToken(q,&q,extent,token);
3617 region.x=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3619 if (token == next_token)
3620 ThrowPointExpectedException(token,exception);
3621 (void) GetNextToken(q,&q,extent,token);
3622 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3623 ThrowPointExpectedException(token,exception);
3625 (void) GetNextToken(q,&q,extent,token);
3626 region.y=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3628 if (token == next_token)
3629 ThrowPointExpectedException(token,exception);
3630 (void) GetNextToken(q,&q,extent,token);
3631 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3632 ThrowPointExpectedException(token,exception);
3634 (void) GetNextToken(q,&q,extent,token);
3635 region.width=CastDoubleToSizeT(floor(GetDrawValue(token,
3637 if (token == next_token)
3638 ThrowPointExpectedException(token,exception);
3639 (void) GetNextToken(q,&q,extent,token);
3640 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3641 ThrowPointExpectedException(token,exception);
3643 (void) GetNextToken(q,&q,extent,token);
3644 region.height=CastDoubleToSizeT(GetDrawValue(token,
3646 if (token == next_token)
3647 ThrowPointExpectedException(token,exception);
3648 for (p=q; *q !=
'\0'; )
3650 if (GetNextToken(q,&q,extent,token) < 1)
3652 if (LocaleCompare(token,
"pop") != 0)
3654 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3655 if (LocaleCompare(token,
"pattern") != 0)
3659 if ((q == (
char *) NULL) || (p == (
char *) NULL) ||
3660 ((q-4) < p) || ((
size_t) (q-p+4+1) > extent))
3665 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3666 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3667 (void) SetImageArtifact(image,key,token);
3668 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3670 (void) FormatLocaleString(geometry,MagickPathExtent,
3671 "%.17gx%.17g%+.20g%+.20g",(
double) region.width,(
double)
3672 region.height,(
double) region.x,(
double) region.y);
3673 (void) SetImageArtifact(image,key,geometry);
3674 (void) GetNextToken(q,&q,extent,token);
3677 if (LocaleCompare(
"symbol",token) == 0)
3680 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3693 if (LocaleCompare(
"rectangle",keyword) == 0)
3695 primitive_type=RectanglePrimitive;
3698 if (LocaleCompare(
"rotate",keyword) == 0)
3700 (void) GetNextToken(q,&q,extent,token);
3701 angle=GetDrawValue(token,&next_token);
3702 if (token == next_token)
3703 ThrowPointExpectedException(token,exception);
3704 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3705 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3706 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3707 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3710 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3712 primitive_type=RoundRectanglePrimitive;
3721 if (LocaleCompare(
"scale",keyword) == 0)
3723 (void) GetNextToken(q,&q,extent,token);
3724 affine.sx=GetDrawValue(token,&next_token);
3725 if (token == next_token)
3726 ThrowPointExpectedException(token,exception);
3727 (void) GetNextToken(q,&q,extent,token);
3728 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3729 ThrowPointExpectedException(token,exception);
3731 (void) GetNextToken(q,&q,extent,token);
3732 affine.sy=GetDrawValue(token,&next_token);
3733 if (token == next_token)
3734 ThrowPointExpectedException(token,exception);
3737 if (LocaleCompare(
"skewX",keyword) == 0)
3739 (void) GetNextToken(q,&q,extent,token);
3740 angle=GetDrawValue(token,&next_token);
3741 if (token == next_token)
3742 ThrowPointExpectedException(token,exception);
3743 affine.ry=sin(DegreesToRadians(angle));
3746 if (LocaleCompare(
"skewY",keyword) == 0)
3748 (void) GetNextToken(q,&q,extent,token);
3749 angle=GetDrawValue(token,&next_token);
3750 if (token == next_token)
3751 ThrowPointExpectedException(token,exception);
3752 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3755 if (LocaleCompare(
"stop-color",keyword) == 0)
3761 if (number_stops == 1)
3762 stops=(StopInfo *) AcquireQuantumMemory(2,
sizeof(*stops));
3764 if (number_stops > 2)
3765 stops=(StopInfo *) ResizeQuantumMemory(stops,number_stops,
3767 if (stops == (StopInfo *) NULL)
3769 (void) ThrowMagickException(exception,GetMagickModule(),
3770 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3775 (void) GetNextToken(q,&q,extent,token);
3776 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3777 &stop_color,exception);
3778 stops[number_stops-1].color=stop_color;
3779 (void) GetNextToken(q,&q,extent,token);
3780 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3781 stops[number_stops-1].offset=factor*GetDrawValue(token,
3783 if (token == next_token)
3784 ThrowPointExpectedException(token,exception);
3787 if (LocaleCompare(
"stroke",keyword) == 0)
3792 (void) GetNextToken(q,&q,extent,token);
3793 if (graphic_context[n]->clip_path != MagickFalse)
3795 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3796 if (mvg_class != (
const char *) NULL)
3798 (void) DrawPatternPath(image,draw_info,mvg_class,
3799 &graphic_context[n]->stroke_pattern,exception);
3802 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3803 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3805 (void) DrawPatternPath(image,draw_info,token,
3806 &graphic_context[n]->stroke_pattern,exception);
3809 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3810 &graphic_context[n]->stroke,exception);
3811 if (graphic_context[n]->stroke_alpha != (
double) OpaqueAlpha)
3812 graphic_context[n]->stroke.alpha=
3813 graphic_context[n]->stroke_alpha;
3816 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3818 (void) GetNextToken(q,&q,extent,token);
3819 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3820 MagickTrue : MagickFalse;
3823 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3825 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3826 graphic_context[n]->dash_pattern=(
double *)
3827 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3828 if (IsValidPoint(q) != MagickFalse)
3834 (void) GetNextToken(r,&r,extent,token);
3835 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3836 ThrowPointExpectedException(token,exception);
3838 (void) GetNextToken(r,&r,extent,token);
3839 for (x=0; IsValidPoint(token) != MagickFalse; x++)
3841 (void) GetNextToken(r,&r,extent,token);
3843 (void) GetNextToken(r,&r,extent,token);
3845 graphic_context[n]->dash_pattern=(
double *)
3846 AcquireQuantumMemory((
size_t) (2*x+2),
3847 sizeof(*graphic_context[n]->dash_pattern));
3848 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3850 (void) ThrowMagickException(exception,GetMagickModule(),
3851 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3856 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3857 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3858 for (j=0; j < x; j++)
3860 (void) GetNextToken(q,&q,extent,token);
3861 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3862 ThrowPointExpectedException(token,exception);
3864 (void) GetNextToken(q,&q,extent,token);
3865 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3867 if (token == next_token)
3868 ThrowPointExpectedException(token,exception);
3869 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3872 if (((x & 0x01) != 0) && (j == x))
3873 for ( ; j < (2*x); j++)
3874 graphic_context[n]->dash_pattern[j]=
3875 graphic_context[n]->dash_pattern[j-x];
3876 graphic_context[n]->dash_pattern[j]=0.0;
3879 (void) GetNextToken(q,&q,extent,token);
3882 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3884 (void) GetNextToken(q,&q,extent,token);
3885 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3886 if (token == next_token)
3887 ThrowPointExpectedException(token,exception);
3890 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3895 (void) GetNextToken(q,&q,extent,token);
3896 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3902 graphic_context[n]->linecap=(LineCap) linecap;
3905 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3910 (void) GetNextToken(q,&q,extent,token);
3911 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3918 graphic_context[n]->linejoin=(LineJoin) linejoin;
3921 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3923 (void) GetNextToken(q,&q,extent,token);
3924 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3927 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3932 (void) GetNextToken(q,&q,extent,token);
3933 if (graphic_context[n]->clip_path != MagickFalse)
3935 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3936 opacity=MagickMin(MagickMax(factor*GetDrawValue(token,&next_token),
3938 if (token == next_token)
3939 ThrowPointExpectedException(token,exception);
3940 if (graphic_context[n]->compliance == SVGCompliance)
3941 graphic_context[n]->stroke_alpha*=opacity;
3943 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3944 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3945 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3947 graphic_context[n]->stroke.alpha=(MagickRealType)
3948 ClampToQuantum((
double) QuantumRange*opacity);
3949 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3952 if (LocaleCompare(
"stroke-width",keyword) == 0)
3954 (void) GetNextToken(q,&q,extent,token);
3955 if (graphic_context[n]->clip_path != MagickFalse)
3957 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3958 if ((token == next_token) ||
3959 (graphic_context[n]->stroke_width < 0.0))
3960 ThrowPointExpectedException(token,exception);
3969 if (LocaleCompare(
"text",keyword) == 0)
3971 primitive_type=TextPrimitive;
3975 if (LocaleCompare(
"text-align",keyword) == 0)
3980 (void) GetNextToken(q,&q,extent,token);
3981 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3987 graphic_context[n]->align=(AlignType) align;
3990 if (LocaleCompare(
"text-anchor",keyword) == 0)
3995 (void) GetNextToken(q,&q,extent,token);
3996 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
4002 graphic_context[n]->align=(AlignType) align;
4005 if (LocaleCompare(
"text-antialias",keyword) == 0)
4007 (void) GetNextToken(q,&q,extent,token);
4008 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
4009 MagickTrue : MagickFalse;
4012 if (LocaleCompare(
"text-undercolor",keyword) == 0)
4014 (void) GetNextToken(q,&q,extent,token);
4015 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
4016 &graphic_context[n]->undercolor,exception);
4019 if (LocaleCompare(
"translate",keyword) == 0)
4021 (void) GetNextToken(q,&q,extent,token);
4022 affine.tx=GetDrawValue(token,&next_token);
4023 if (token == next_token)
4024 ThrowPointExpectedException(token,exception);
4025 (void) GetNextToken(q,&q,extent,token);
4026 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4027 ThrowPointExpectedException(token,exception);
4029 (void) GetNextToken(q,&q,extent,token);
4030 affine.ty=GetDrawValue(token,&next_token);
4031 if (token == next_token)
4032 ThrowPointExpectedException(token,exception);
4042 if (LocaleCompare(
"use",keyword) == 0)
4050 (void) GetNextToken(q,&q,extent,token);
4051 use=(
const char *) GetValueFromSplayTree(macros,token);
4052 if (use != (
const char *) NULL)
4054 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4055 if (draw_info->macro_expansion != (
size_t *) NULL)
4057 if (*draw_info->macro_expansion >= MacroExpansionLimit)
4059 (void) ThrowMagickException(exception,GetMagickModule(),
4060 DrawError,
"NonconformingDrawingPrimitiveDefinition",
4062 clone_info=DestroyDrawInfo(clone_info);
4063 return(MagickFalse);
4065 (*draw_info->macro_expansion)++;
4067 (void) CloneString(&clone_info->primitive,use);
4068 status=RenderMVGContent(image,clone_info,depth+1,exception);
4069 clone_info=DestroyDrawInfo(clone_info);
4079 if (LocaleCompare(
"viewbox",keyword) == 0)
4081 (void) GetNextToken(q,&q,extent,token);
4082 graphic_context[n]->viewbox.x=CastDoubleToSsizeT(ceil(
4083 GetDrawValue(token,&next_token)-0.5));
4084 if (token == next_token)
4085 ThrowPointExpectedException(token,exception);
4086 (void) GetNextToken(q,&q,extent,token);
4087 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4088 ThrowPointExpectedException(token,exception);
4090 (void) GetNextToken(q,&q,extent,token);
4091 graphic_context[n]->viewbox.y=CastDoubleToSsizeT(
4092 ceil(GetDrawValue(token,&next_token)-0.5));
4093 if (token == next_token)
4094 ThrowPointExpectedException(token,exception);
4095 (void) GetNextToken(q,&q,extent,token);
4096 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4097 ThrowPointExpectedException(token,exception);
4099 (void) GetNextToken(q,&q,extent,token);
4100 graphic_context[n]->viewbox.width=CastDoubleToSizeT(floor(
4101 GetDrawValue(token,&next_token)+0.5));
4102 if (token == next_token)
4103 ThrowPointExpectedException(token,exception);
4104 (void) GetNextToken(q,&q,extent,token);
4105 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4106 ThrowPointExpectedException(token,exception);
4108 (void) GetNextToken(q,&q,extent,token);
4109 graphic_context[n]->viewbox.height=CastDoubleToSizeT(floor(
4110 GetDrawValue(token,&next_token)+0.5));
4111 if (token == next_token)
4112 ThrowPointExpectedException(token,exception);
4121 if (LocaleCompare(
"word-spacing",keyword) == 0)
4123 (void) GetNextToken(q,&q,extent,token);
4124 graphic_context[n]->interword_spacing=GetDrawValue(token,
4126 if (token == next_token)
4127 ThrowPointExpectedException(token,exception);
4139 if (status == MagickFalse)
4141 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4142 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4143 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4144 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4146 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4147 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4148 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4149 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4150 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4152 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4155 if (primitive_type == UndefinedPrimitive)
4159 if (number_stops > 1)
4164 type=LinearGradient;
4165 if (draw_info->gradient.type == RadialGradient)
4166 type=RadialGradient;
4167 (void) GradientImage(image,type,PadSpread,stops,number_stops,
4170 if (number_stops > 0)
4171 stops=(StopInfo *) RelinquishMagickMemory(stops);
4173 if ((draw_info->debug != MagickFalse) && (q > p))
4174 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int)
4181 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4182 if (primitive_info[i].text != (
char *) NULL)
4183 primitive_info[i].text=DestroyString(primitive_info[i].text);
4187 primitive_info[0].primitive=primitive_type;
4188 primitive_info[0].point.x=0.0;
4189 primitive_info[0].point.y=0.0;
4190 primitive_info[0].coordinates=0;
4191 primitive_info[0].method=FloodfillMethod;
4192 primitive_info[0].closed_subpath=MagickFalse;
4193 for (x=0; *q !=
'\0'; x++)
4198 if (IsValidPoint(q) == MagickFalse)
4200 (void) GetNextToken(q,&q,extent,token);
4201 point.x=GetDrawValue(token,&next_token);
4202 if (token == next_token)
4203 ThrowPointExpectedException(token,exception);
4204 (void) GetNextToken(q,&q,extent,token);
4205 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4206 ThrowPointExpectedException(token,exception);
4208 (void) GetNextToken(q,&q,extent,token);
4209 point.y=GetDrawValue(token,&next_token);
4210 if (token == next_token)
4211 ThrowPointExpectedException(token,exception);
4212 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4214 (void) GetNextToken(q,&q,extent,token);
4215 primitive_info[i].primitive=primitive_type;
4216 primitive_info[i].point=point;
4217 primitive_info[i].coordinates=0;
4218 primitive_info[i].method=FloodfillMethod;
4219 primitive_info[i].closed_subpath=MagickFalse;
4222 if (i < (ssize_t) number_points)
4224 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4226 primitive_info=(*mvg_info.primitive_info);
4227 if (status == MagickFalse)
4230 if (status == MagickFalse)
4232 if (primitive_info[j].text != (
char *) NULL)
4233 primitive_info[j].text=DestroyString(primitive_info[j].text);
4234 primitive_info[j].primitive=primitive_type;
4235 primitive_info[j].coordinates=(size_t) x;
4236 primitive_info[j].method=FloodfillMethod;
4237 primitive_info[j].closed_subpath=MagickFalse;
4241 bounds.x1=primitive_info[j].point.x;
4242 bounds.y1=primitive_info[j].point.y;
4243 bounds.x2=primitive_info[j].point.x;
4244 bounds.y2=primitive_info[j].point.y;
4245 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4247 point=primitive_info[j+k].point;
4248 if (point.x < bounds.x1)
4250 if (point.y < bounds.y1)
4252 if (point.x > bounds.x2)
4254 if (point.y > bounds.y2)
4260 coordinates=(double) primitive_info[j].coordinates;
4261 switch (primitive_type)
4263 case RectanglePrimitive:
4268 case RoundRectanglePrimitive:
4275 alpha=bounds.x2-bounds.x1;
4276 beta=bounds.y2-bounds.y1;
4277 radius=hypot(alpha,beta);
4279 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4280 BezierQuantum+360.0;
4283 case BezierPrimitive:
4285 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4294 (void) GetNextToken(q,&q,extent,token);
4297 for (s=token; *s !=
'\0'; s=t)
4302 value=GetDrawValue(s,&t);
4311 for (s=token; *s !=
'\0'; s++)
4312 if (strspn(s,
"AaCcQqSsTt") != 0)
4313 coordinates+=(20.0*BezierQuantum)+360.0;
4319 if (status == MagickFalse)
4321 if (((
size_t) (i+coordinates)) >= number_points)
4326 number_points+=(size_t) coordinates+1;
4327 if (number_points < (
size_t) coordinates)
4329 (void) ThrowMagickException(exception,GetMagickModule(),
4330 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4336 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points+
4337 (
double) coordinates+1.0);
4338 primitive_info=(*mvg_info.primitive_info);
4339 if (status == MagickFalse)
4342 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,
4343 PrimitiveExtentPad);
4344 primitive_info=(*mvg_info.primitive_info);
4345 if (status == MagickFalse)
4348 switch (primitive_type)
4350 case PointPrimitive:
4353 if (primitive_info[j].coordinates != 1)
4358 status&=(MagickStatusType) TracePoint(primitive_info+j,
4359 primitive_info[j].point);
4360 primitive_info=(*mvg_info.primitive_info);
4361 if (status == MagickFalse)
4363 i=j+(ssize_t) primitive_info[j].coordinates;
4368 if (primitive_info[j].coordinates != 2)
4373 status&=(MagickStatusType) TraceLine(primitive_info+j,
4374 primitive_info[j].point,primitive_info[j+1].point);
4375 primitive_info=(*mvg_info.primitive_info);
4376 if (status == MagickFalse)
4378 i=j+(ssize_t) primitive_info[j].coordinates;
4381 case RectanglePrimitive:
4383 if (primitive_info[j].coordinates != 2)
4388 status&=(MagickStatusType) TraceRectangle(primitive_info+j,
4389 primitive_info[j].point,primitive_info[j+1].point);
4390 primitive_info=(*mvg_info.primitive_info);
4391 if (status == MagickFalse)
4393 i=j+(ssize_t) primitive_info[j].coordinates;
4396 case RoundRectanglePrimitive:
4398 if (primitive_info[j].coordinates != 3)
4403 if ((primitive_info[j+2].point.x < 0.0) ||
4404 (primitive_info[j+2].point.y < 0.0))
4409 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4414 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4419 status&=(MagickStatusType) TraceRoundRectangle(&mvg_info,
4420 primitive_info[j].point,primitive_info[j+1].point,
4421 primitive_info[j+2].point);
4422 primitive_info=(*mvg_info.primitive_info);
4423 if (status == MagickFalse)
4425 i=j+(ssize_t) primitive_info[j].coordinates;
4430 if (primitive_info[j].coordinates != 3)
4435 status&=(MagickStatusType) TraceArc(&mvg_info,primitive_info[j].point,
4436 primitive_info[j+1].point,primitive_info[j+2].point);
4437 primitive_info=(*mvg_info.primitive_info);
4438 if (status == MagickFalse)
4440 i=j+(ssize_t) primitive_info[j].coordinates;
4443 case EllipsePrimitive:
4445 if (primitive_info[j].coordinates != 3)
4450 if ((primitive_info[j+1].point.x < 0.0) ||
4451 (primitive_info[j+1].point.y < 0.0))
4456 status&=(MagickStatusType) TraceEllipse(&mvg_info,
4457 primitive_info[j].point,primitive_info[j+1].point,
4458 primitive_info[j+2].point);
4459 primitive_info=(*mvg_info.primitive_info);
4460 if (status == MagickFalse)
4462 i=j+(ssize_t) primitive_info[j].coordinates;
4465 case CirclePrimitive:
4467 if (primitive_info[j].coordinates != 2)
4472 status&=(MagickStatusType) TraceCircle(&mvg_info,
4473 primitive_info[j].point,primitive_info[j+1].point);
4474 primitive_info=(*mvg_info.primitive_info);
4475 if (status == MagickFalse)
4477 i=j+(ssize_t) primitive_info[j].coordinates;
4480 case PolylinePrimitive:
4482 if (primitive_info[j].coordinates < 1)
4489 case PolygonPrimitive:
4491 if (primitive_info[j].coordinates < 3)
4496 primitive_info[i]=primitive_info[j];
4497 primitive_info[i].coordinates=0;
4498 primitive_info[j].coordinates++;
4499 primitive_info[j].closed_subpath=MagickTrue;
4503 case BezierPrimitive:
4505 if (primitive_info[j].coordinates < 3)
4510 status&=(MagickStatusType) TraceBezier(&mvg_info,
4511 primitive_info[j].coordinates);
4512 primitive_info=(*mvg_info.primitive_info);
4513 if (status == MagickFalse)
4515 i=j+(ssize_t) primitive_info[j].coordinates;
4520 coordinates=(double) TracePath(&mvg_info,token,exception);
4521 primitive_info=(*mvg_info.primitive_info);
4522 if (status == MagickFalse)
4524 if (coordinates < 0.0)
4529 i=(ssize_t) (j+coordinates);
4532 case AlphaPrimitive:
4533 case ColorPrimitive:
4538 if (primitive_info[j].coordinates != 1)
4543 (void) GetNextToken(q,&q,extent,token);
4544 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4550 primitive_info[j].method=(PaintMethod) method;
4555 if (primitive_info[j].coordinates != 1)
4561 (void) GetNextToken(q,&q,extent,token);
4562 (void) CloneString(&primitive_info[j].text,token);
4566 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
4567 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4568 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4570 mvg_info.point=primitive_info->point;
4571 primitive_info->point.x+=cursor;
4575 mvg_info.point=primitive_info->point;
4578 clone_info->render=MagickFalse;
4579 clone_info->text=AcquireString(token);
4580 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,
4581 &metrics,exception);
4582 clone_info=DestroyDrawInfo(clone_info);
4583 cursor+=metrics.width;
4584 if (graphic_context[n]->compliance != SVGCompliance)
4588 case ImagePrimitive:
4590 if (primitive_info[j].coordinates != 2)
4595 (void) GetNextToken(q,&q,extent,token);
4596 (void) CloneString(&primitive_info[j].text,token);
4603 primitive_info[i].primitive=UndefinedPrimitive;
4604 if ((draw_info->debug != MagickFalse) && (q > p))
4605 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int) (q-p),p);
4609 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4610 &graphic_context[n]->affine));
4611 primitive_info=(*mvg_info.primitive_info);
4614 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4615 graphic_context[n]->stroke_width);
4616 primitive_info=(*mvg_info.primitive_info);
4624 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4626 point=primitive_info[i].point;
4627 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4628 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4629 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4630 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4631 point=primitive_info[i].point;
4632 if (point.x < graphic_context[n]->bounds.x1)
4633 graphic_context[n]->bounds.x1=point.x;
4634 if (point.y < graphic_context[n]->bounds.y1)
4635 graphic_context[n]->bounds.y1=point.y;
4636 if (point.x > graphic_context[n]->bounds.x2)
4637 graphic_context[n]->bounds.x2=point.x;
4638 if (point.y > graphic_context[n]->bounds.y2)
4639 graphic_context[n]->bounds.y2=point.y;
4640 if (primitive_info[i].primitive == ImagePrimitive)
4642 if (i >= (ssize_t) number_points)
4643 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4645 if (graphic_context[n]->render != MagickFalse)
4647 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4648 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4649 (LocaleCompare(graphic_context[n]->clip_mask,
4650 graphic_context[n-1]->clip_mask) != 0))
4655 clip_path=(
const char *) GetValueFromSplayTree(macros,
4656 graphic_context[n]->clip_mask);
4657 if (clip_path != (
const char *) NULL)
4658 (void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4660 status&=(MagickStatusType) DrawClipPath_(image,graphic_context[n],
4661 graphic_context[n]->clip_mask,depth+1,exception);
4663 status&=(MagickStatusType) DrawPrimitive(image,graphic_context[n],
4664 primitive_info,exception);
4666 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4668 if (proceed == MagickFalse)
4673 if (draw_info->debug != MagickFalse)
4674 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4678 macros=DestroySplayTree(macros);
4679 token=DestroyString(token);
4680 if (primitive_info != (PrimitiveInfo *) NULL)
4682 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4683 if (primitive_info[i].text != (
char *) NULL)
4684 primitive_info[i].text=DestroyString(primitive_info[i].text);
4685 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4687 primitive=DestroyString(primitive);
4688 if (stops != (StopInfo *) NULL)
4689 stops=(StopInfo *) RelinquishMagickMemory(stops);
4690 for ( ; n >= 0; n--)
4691 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4692 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
4693 if ((status == MagickFalse) && (exception->severity < ErrorException))
4694 ThrowBinaryException(DrawError,
"NonconformingDrawingPrimitiveDefinition",
4696 return(status != 0 ? MagickTrue : MagickFalse);
4699MagickExport MagickBooleanType DrawImage(Image *image,
const DrawInfo *draw_info,
4700 ExceptionInfo *exception)
4706 macro_expansion = 0;
4708 ((DrawInfo *) draw_info)->macro_expansion=(¯o_expansion);
4709 status=RenderMVGContent(image,draw_info,0,exception);
4710 ((DrawInfo *) draw_info)->macro_expansion=(
size_t *) NULL;
4745MagickExport MagickBooleanType DrawPatternPath(Image *image,
4746 const DrawInfo *draw_info,
const char *name,Image **pattern,
4747 ExceptionInfo *exception)
4750 property[MagickPathExtent];
4766 assert(image != (Image *) NULL);
4767 assert(image->signature == MagickCoreSignature);
4768 assert(draw_info != (
const DrawInfo *) NULL);
4769 assert(name != (
const char *) NULL);
4770 if (IsEventLogging() != MagickFalse)
4771 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4772 (void) FormatLocaleString(property,MagickPathExtent,
"%s",name);
4773 path=GetImageArtifact(image,property);
4774 if (path == (
const char *) NULL)
4775 return(MagickFalse);
4776 (void) FormatLocaleString(property,MagickPathExtent,
"%s-geometry",name);
4777 geometry=GetImageArtifact(image,property);
4778 if (geometry == (
const char *) NULL)
4779 return(MagickFalse);
4780 if ((*pattern) != (Image *) NULL)
4781 *pattern=DestroyImage(*pattern);
4782 image_info=AcquireImageInfo();
4783 image_info->size=AcquireString(geometry);
4784 *pattern=AcquireImage(image_info,exception);
4785 image_info=DestroyImageInfo(image_info);
4786 (void) QueryColorCompliance(
"#00000000",AllCompliance,
4787 &(*pattern)->background_color,exception);
4788 (void) SetImageBackgroundColor(*pattern,exception);
4789 if (draw_info->debug != MagickFalse)
4790 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4791 "begin pattern-path %s %s",name,geometry);
4792 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4793 if (clone_info->fill_pattern != (Image *) NULL)
4794 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4795 if (clone_info->stroke_pattern != (Image *) NULL)
4796 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4797 (void) FormatLocaleString(property,MagickPathExtent,
"%s-type",name);
4798 type=GetImageArtifact(image,property);
4799 if (type != (
const char *) NULL)
4800 clone_info->gradient.type=(GradientType) ParseCommandOption(
4801 MagickGradientOptions,MagickFalse,type);
4802 (void) CloneString(&clone_info->primitive,path);
4803 status=RenderMVGContent(*pattern,clone_info,0,exception);
4804 clone_info=DestroyDrawInfo(clone_info);
4805 if (draw_info->debug != MagickFalse)
4806 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4841static PolygonInfo **DestroyPolygonTLS(PolygonInfo **polygon_info)
4846 assert(polygon_info != (PolygonInfo **) NULL);
4847 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4848 if (polygon_info[i] != (PolygonInfo *) NULL)
4849 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4850 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
4851 return(polygon_info);
4854static PolygonInfo **AcquirePolygonTLS(
const PrimitiveInfo *primitive_info,
4855 ExceptionInfo *exception)
4858 *magick_restrict path_info;
4866 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4867 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
4868 sizeof(*polygon_info));
4869 if (polygon_info == (PolygonInfo **) NULL)
4871 (void) ThrowMagickException(exception,GetMagickModule(),
4872 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4873 return((PolygonInfo **) NULL);
4875 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4876 path_info=ConvertPrimitiveToPath(primitive_info,exception);
4877 if (path_info == (PathInfo *) NULL)
4878 return(DestroyPolygonTLS(polygon_info));
4879 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4880 if (polygon_info[0] == (PolygonInfo *) NULL)
4882 (void) ThrowMagickException(exception,GetMagickModule(),
4883 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4884 return(DestroyPolygonTLS(polygon_info));
4886 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
4887 return(polygon_info);
4890static MagickBooleanType ClonePolygonEdgesTLS(PolygonInfo **polygon_info,
4891 const size_t number_threads,ExceptionInfo *exception)
4896 for (i=1; i < (ssize_t) number_threads; i++)
4904 polygon_info[i]=(PolygonInfo *) AcquireMagickMemory(
4905 sizeof(*polygon_info[i]));
4906 if (polygon_info[i] == (PolygonInfo *) NULL)
4908 (void) ThrowMagickException(exception,GetMagickModule(),
4909 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4910 return(MagickFalse);
4912 polygon_info[i]->number_edges=0;
4913 edge_info=polygon_info[0]->edges;
4914 polygon_info[i]->edges=(EdgeInfo *) AcquireQuantumMemory(
4915 polygon_info[0]->number_edges,
sizeof(*edge_info));
4916 if (polygon_info[i]->edges == (EdgeInfo *) NULL)
4918 (void) ThrowMagickException(exception,GetMagickModule(),
4919 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4920 return(MagickFalse);
4922 (void) memcpy(polygon_info[i]->edges,edge_info,
4923 polygon_info[0]->number_edges*
sizeof(*edge_info));
4924 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4925 polygon_info[i]->edges[j].points=(PointInfo *) NULL;
4926 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4927 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4929 edge_info=polygon_info[0]->edges+j;
4930 polygon_info[i]->edges[j].points=(PointInfo *) AcquireQuantumMemory(
4931 edge_info->number_points,
sizeof(*edge_info));
4932 if (polygon_info[i]->edges[j].points == (PointInfo *) NULL)
4934 (void) ThrowMagickException(exception,GetMagickModule(),
4935 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4936 return(MagickFalse);
4938 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4939 edge_info->number_points*
sizeof(*edge_info->points));
4945static size_t DestroyEdge(PolygonInfo *polygon_info,
const ssize_t edge)
4947 assert(edge < (ssize_t) polygon_info->number_edges);
4948 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
4949 polygon_info->edges[edge].points);
4950 polygon_info->number_edges--;
4951 if (edge < (ssize_t) polygon_info->number_edges)
4952 (void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4953 (polygon_info->number_edges-(
size_t) edge)*
sizeof(*polygon_info->edges));
4954 return(polygon_info->number_edges);
4957static double GetFillAlpha(PolygonInfo *polygon_info,
const double mid,
4958 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4959 const ssize_t y,
double *stroke_alpha)
4986 p=polygon_info->edges;
4987 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4989 if ((
double) y <= (p->bounds.y1-mid-0.5))
4991 if ((
double) y > (p->bounds.y2+mid+0.5))
4994 (void) DestroyEdge(polygon_info,j--);
4997 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
4998 ((
double) x > (p->bounds.x2+mid+0.5)))
5000 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5001 for ( ; i < (ssize_t) p->number_points; i++)
5003 if ((
double) y <= (p->points[i-1].y-mid-0.5))
5005 if ((
double) y > (p->points[i].y+mid+0.5))
5007 if (p->scanline != (
double) y)
5009 p->scanline=(double) y;
5010 p->highwater=(size_t) i;
5016 delta.x=(q+1)->x-q->x;
5017 delta.y=(q+1)->y-q->y;
5018 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
5024 delta.x=(double) x-q->x;
5025 delta.y=(double) y-q->y;
5026 distance=delta.x*delta.x+delta.y*delta.y;
5030 alpha=delta.x*delta.x+delta.y*delta.y;
5036 delta.x=(double) x-(q+1)->x;
5037 delta.y=(double) y-(q+1)->y;
5038 distance=delta.x*delta.x+delta.y*delta.y;
5045 alpha=MagickSafeReciprocal(alpha);
5046 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
5047 distance=alpha*beta*beta;
5054 if (p->ghostline == MagickFalse)
5057 if ((*stroke_alpha < 1.0) &&
5058 (distance <= ((alpha+0.25)*(alpha+0.25))))
5061 if (distance <= ((alpha+0.25)*(alpha+0.25)))
5066 if (fabs(distance-1.0) >= MagickEpsilon)
5067 beta=sqrt((
double) distance);
5069 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
5070 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
5074 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
5076 if (distance <= 0.0)
5083 if (fabs(beta) < MagickEpsilon)
5086 if (fabs(distance-1.0) >= MagickEpsilon)
5087 beta=sqrt(distance);
5090 if (subpath_alpha < (alpha*alpha))
5091 subpath_alpha=alpha*alpha;
5097 if (fill == MagickFalse)
5099 if (subpath_alpha >= 1.0)
5105 p=polygon_info->edges;
5106 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
5108 if ((
double) y <= p->bounds.y1)
5110 if (((
double) y > p->bounds.y2) || ((
double) x <= p->bounds.x1))
5112 if ((
double) x > p->bounds.x2)
5114 winding_number+=p->direction != 0 ? 1 : -1;
5117 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5118 for ( ; i < (ssize_t) (p->number_points-1); i++)
5119 if ((
double) y <= p->points[i].y)
5122 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
5123 winding_number+=p->direction != 0 ? 1 : -1;
5125 if (fill_rule != NonZeroRule)
5127 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
5131 if (MagickAbsoluteValue(winding_number) != 0)
5133 return(subpath_alpha);
5136static MagickBooleanType DrawPolygonPrimitive(Image *image,
5137 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5138 ExceptionInfo *exception)
5140 typedef struct _ExtentInfo
5169 **magick_restrict polygon_info;
5181 assert(image != (Image *) NULL);
5182 assert(image->signature == MagickCoreSignature);
5183 assert(draw_info != (DrawInfo *) NULL);
5184 assert(draw_info->signature == MagickCoreSignature);
5185 assert(primitive_info != (PrimitiveInfo *) NULL);
5186 if (IsEventLogging() != MagickFalse)
5187 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5188 if (primitive_info->coordinates <= 1)
5193 polygon_info=AcquirePolygonTLS(primitive_info,exception);
5194 if (polygon_info == (PolygonInfo **) NULL)
5195 return(MagickFalse);
5196 if (draw_info->debug != MagickFalse)
5197 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5198 fill=(primitive_info->method == FillToBorderMethod) ||
5199 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5200 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5201 bounds=polygon_info[0]->edges[0].bounds;
5202 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5203 if (IsStringTrue(artifact) != MagickFalse)
5204 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
5205 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5207 p=polygon_info[0]->edges+i;
5208 if (p->bounds.x1 < bounds.x1)
5209 bounds.x1=p->bounds.x1;
5210 if (p->bounds.y1 < bounds.y1)
5211 bounds.y1=p->bounds.y1;
5212 if (p->bounds.x2 > bounds.x2)
5213 bounds.x2=p->bounds.x2;
5214 if (p->bounds.y2 > bounds.y2)
5215 bounds.y2=p->bounds.y2;
5217 bounds.x1-=(mid+1.0);
5218 bounds.y1-=(mid+1.0);
5219 bounds.x2+=(mid+1.0);
5220 bounds.y2+=(mid+1.0);
5221 if ((bounds.x1 >= (
double) image->columns) ||
5222 (bounds.y1 >= (
double) image->rows) ||
5223 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5225 polygon_info=DestroyPolygonTLS(polygon_info);
5228 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5229 (
double) image->columns-1.0 : bounds.x1;
5230 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5231 (
double) image->rows-1.0 : bounds.y1;
5232 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5233 (
double) image->columns-1.0 : bounds.x2;
5234 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5235 (
double) image->rows-1.0 : bounds.y2;
5236 poly_extent.x1=CastDoubleToSsizeT(ceil(bounds.x1-0.5));
5237 poly_extent.y1=CastDoubleToSsizeT(ceil(bounds.y1-0.5));
5238 poly_extent.x2=CastDoubleToSsizeT(floor(bounds.x2+0.5));
5239 poly_extent.y2=CastDoubleToSsizeT(floor(bounds.y2+0.5));
5240 number_threads=(size_t) GetMagickNumberThreads(image,image,(
size_t)
5241 (poly_extent.y2-poly_extent.y1+1),1);
5242 status=ClonePolygonEdgesTLS(polygon_info,number_threads,exception);
5243 if (status == MagickFalse)
5245 polygon_info=DestroyPolygonTLS(polygon_info);
5248 image_view=AcquireAuthenticCacheView(image,exception);
5249 if ((primitive_info->coordinates == 1) ||
5250 (polygon_info[0]->number_edges == 0))
5255#if defined(MAGICKCORE_OPENMP_SUPPORT)
5256 #pragma omp parallel for schedule(static) shared(status) \
5257 num_threads((int) number_threads)
5259 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5270 if (status == MagickFalse)
5273 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5275 if (q == (Quantum *) NULL)
5280 GetPixelInfo(image,&pixel);
5281 for ( ; x <= poly_extent.x2; x++)
5283 if ((x == CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5))) &&
5284 (y == CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5))))
5286 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&pixel,
5288 SetPixelViaPixelInfo(image,&pixel,q);
5290 q+=(ptrdiff_t) GetPixelChannels(image);
5292 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5295 image_view=DestroyCacheView(image_view);
5296 polygon_info=DestroyPolygonTLS(polygon_info);
5297 if (draw_info->debug != MagickFalse)
5298 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5299 " end draw-polygon");
5305#if defined(MAGICKCORE_OPENMP_SUPPORT)
5306 #pragma omp parallel for schedule(static) shared(status) \
5307 num_threads((int) number_threads)
5309 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5312 id = GetOpenMPThreadId();
5320 if (status == MagickFalse)
5322 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5323 (poly_extent.x2-poly_extent.x1+1),1,exception);
5324 if (q == (Quantum *) NULL)
5329 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5342 fill_alpha=GetFillAlpha(polygon_info[
id],mid,fill,draw_info->fill_rule,
5344 if (draw_info->stroke_antialias == MagickFalse)
5346 fill_alpha=fill_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5347 stroke_alpha=stroke_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5349 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&fill_color,
5351 CompositePixelOver(image,&fill_color,fill_alpha*fill_color.alpha,q,
5352 (
double) GetPixelAlpha(image,q),q);
5353 GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&stroke_color,
5355 CompositePixelOver(image,&stroke_color,stroke_alpha*stroke_color.alpha,q,
5356 (
double) GetPixelAlpha(image,q),q);
5357 q+=(ptrdiff_t) GetPixelChannels(image);
5359 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5362 image_view=DestroyCacheView(image_view);
5363 polygon_info=DestroyPolygonTLS(polygon_info);
5364 if (draw_info->debug != MagickFalse)
5365 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5398static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5424 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5425 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5426 switch (primitive_info->primitive)
5428 case AlphaPrimitive:
5430 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5431 "AlphaPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5432 methods[primitive_info->method]);
5435 case ColorPrimitive:
5437 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5438 "ColorPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5439 methods[primitive_info->method]);
5442 case ImagePrimitive:
5444 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5445 "ImagePrimitive %.17g,%.17g",(
double) x,(
double) y);
5448 case PointPrimitive:
5450 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5451 "PointPrimitive %.17g,%.17g %s",(
double) x,(
double) y,
5452 methods[primitive_info->method]);
5457 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5458 "TextPrimitive %.17g,%.17g",(
double) x,(
double) y);
5465 p=primitive_info[0].point;
5468 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5470 point=primitive_info[i].point;
5471 if (coordinates <= 0)
5473 coordinates=(ssize_t) primitive_info[i].coordinates;
5474 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5475 " begin open (%.17g)",(
double) coordinates);
5478 point=primitive_info[i].point;
5479 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5480 (fabs(q.y-point.y) >= MagickEpsilon))
5481 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5482 " %.17g: %.18g,%.18g",(
double) coordinates,point.x,point.y);
5484 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5485 " %.17g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5488 if (coordinates > 0)
5490 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5491 (fabs(p.y-point.y) >= MagickEpsilon))
5492 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.17g)",
5493 (
double) coordinates);
5495 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.17g)",
5496 (
double) coordinates);
5500MagickExport MagickBooleanType DrawPrimitive(Image *image,
5501 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
5502 ExceptionInfo *exception)
5517 if (draw_info->debug != MagickFalse)
5519 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5520 " begin draw-primitive");
5521 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5522 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5523 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5524 draw_info->affine.tx,draw_info->affine.ty);
5527 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5528 ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
5529 (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
5530 status&=(MagickStatusType) SetImageColorspace(image,sRGBColorspace,
5532 if (draw_info->compliance == SVGCompliance)
5534 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5535 draw_info->clipping_mask,exception);
5536 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5537 draw_info->composite_mask,exception);
5539 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5540 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5541 image_view=AcquireAuthenticCacheView(image,exception);
5542 switch (primitive_info->primitive)
5544 case AlphaPrimitive:
5546 if ((image->alpha_trait & BlendPixelTrait) == 0)
5547 status&=(MagickStatusType) SetImageAlphaChannel(image,
5548 OpaqueAlphaChannel,exception);
5549 switch (primitive_info->method)
5560 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5561 if (q == (Quantum *) NULL)
5563 GetFillColor(draw_info,x,y,&pixel,exception);
5564 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5565 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5575 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5576 x,y,&target,exception);
5577 GetPixelInfo(image,&pixel);
5578 for (y=0; y < (ssize_t) image->rows; y++)
5583 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5585 if (q == (Quantum *) NULL)
5587 for (x=0; x < (ssize_t) image->columns; x++)
5589 GetPixelInfoPixel(image,q,&pixel);
5590 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5592 q+=(ptrdiff_t) GetPixelChannels(image);
5595 GetFillColor(draw_info,x,y,&pixel,exception);
5596 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5597 q+=(ptrdiff_t) GetPixelChannels(image);
5599 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5601 if (status == MagickFalse)
5606 case FloodfillMethod:
5607 case FillToBorderMethod:
5615 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5616 TileVirtualPixelMethod,x,y,&target,exception);
5617 if (primitive_info->method == FillToBorderMethod)
5619 target.red=(double) draw_info->border_color.red;
5620 target.green=(double) draw_info->border_color.green;
5621 target.blue=(double) draw_info->border_color.blue;
5623 channel_mask=SetImageChannelMask(image,AlphaChannel);
5624 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5625 &target,x,y,primitive_info->method == FloodfillMethod ?
5626 MagickFalse : MagickTrue,exception);
5627 (void) SetImageChannelMask(image,channel_mask);
5635 for (y=0; y < (ssize_t) image->rows; y++)
5640 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5642 if (q == (Quantum *) NULL)
5644 for (x=0; x < (ssize_t) image->columns; x++)
5646 GetFillColor(draw_info,x,y,&pixel,exception);
5647 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5648 q+=(ptrdiff_t) GetPixelChannels(image);
5650 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5652 if (status == MagickFalse)
5660 case ColorPrimitive:
5662 switch (primitive_info->method)
5673 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5674 if (q == (Quantum *) NULL)
5676 GetPixelInfo(image,&pixel);
5677 GetFillColor(draw_info,x,y,&pixel,exception);
5678 SetPixelViaPixelInfo(image,&pixel,q);
5679 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5689 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5690 x,y,&target,exception);
5691 for (y=0; y < (ssize_t) image->rows; y++)
5696 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5698 if (q == (Quantum *) NULL)
5700 for (x=0; x < (ssize_t) image->columns; x++)
5702 GetPixelInfoPixel(image,q,&pixel);
5703 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5705 q+=(ptrdiff_t) GetPixelChannels(image);
5708 GetFillColor(draw_info,x,y,&pixel,exception);
5709 SetPixelViaPixelInfo(image,&pixel,q);
5710 q+=(ptrdiff_t) GetPixelChannels(image);
5712 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5714 if (status == MagickFalse)
5719 case FloodfillMethod:
5720 case FillToBorderMethod:
5725 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5726 TileVirtualPixelMethod,x,y,&target,exception);
5727 if (primitive_info->method == FillToBorderMethod)
5729 target.red=(double) draw_info->border_color.red;
5730 target.green=(double) draw_info->border_color.green;
5731 target.blue=(double) draw_info->border_color.blue;
5733 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5734 &target,x,y,primitive_info->method == FloodfillMethod ?
5735 MagickFalse : MagickTrue,exception);
5743 GetPixelInfo(image,&pixel);
5744 for (y=0; y < (ssize_t) image->rows; y++)
5749 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5751 if (q == (Quantum *) NULL)
5753 for (x=0; x < (ssize_t) image->columns; x++)
5755 GetFillColor(draw_info,x,y,&pixel,exception);
5756 SetPixelViaPixelInfo(image,&pixel,q);
5757 q+=(ptrdiff_t) GetPixelChannels(image);
5759 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5761 if (status == MagickFalse)
5769 case ImagePrimitive:
5775 composite_geometry[MagickPathExtent];
5791 if (primitive_info->text == (
char *) NULL)
5793 clone_info=AcquireImageInfo();
5794 composite_images=(Image *) NULL;
5795 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5796 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5799 if (*primitive_info->text !=
'\0')
5804 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5806 (void) SetImageInfo(clone_info,1,exception);
5807 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5809 if (clone_info->size != (
char *) NULL)
5810 clone_info->size=DestroyString(clone_info->size);
5811 if (clone_info->extract != (
char *) NULL)
5812 clone_info->extract=DestroyString(clone_info->extract);
5813 clone_info->coder_depth=draw_info->image_info->coder_depth;
5814 composite_images=StrictReadImage(clone_info,exception);
5815 draw_info->image_info->coder_depth=clone_info->coder_depth;
5817 clone_info=DestroyImageInfo(clone_info);
5818 if (composite_images == (Image *) NULL)
5823 composite_image=RemoveFirstImageFromList(&composite_images);
5824 composite_images=DestroyImageList(composite_images);
5825 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5826 NULL,(
void *) NULL);
5827 x1=CastDoubleToSsizeT(ceil(primitive_info[1].point.x-0.5));
5828 y1=CastDoubleToSsizeT(ceil(primitive_info[1].point.y-0.5));
5829 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5830 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5835 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5836 "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y);
5837 composite_image->filter=image->filter;
5838 status&=(MagickStatusType) TransformImage(&composite_image,
5839 (
char *) NULL,composite_geometry,exception);
5841 if (composite_image->alpha_trait == UndefinedPixelTrait)
5842 status&=(MagickStatusType) SetImageAlphaChannel(composite_image,
5843 OpaqueAlphaChannel,exception);
5844 if (draw_info->alpha != OpaqueAlpha)
5845 status&=(MagickStatusType) SetImageAlpha(composite_image,
5846 draw_info->alpha,exception);
5847 SetGeometry(image,&geometry);
5848 image->gravity=draw_info->gravity;
5851 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5852 "%.17gx%.17g%+.20g%+.20g",(
double) composite_image->columns,(
double)
5853 composite_image->rows,(
double) geometry.x,(
double) geometry.y);
5854 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
5855 affine=draw_info->affine;
5856 affine.tx=(double) geometry.x;
5857 affine.ty=(double) geometry.y;
5858 composite_image->interpolate=image->interpolate;
5859 if ((draw_info->compose == OverCompositeOp) ||
5860 (draw_info->compose == SrcOverCompositeOp))
5861 status&=(MagickStatusType) DrawAffineImage(image,composite_image,
5864 status&=(MagickStatusType) CompositeImage(image,composite_image,
5865 draw_info->compose,MagickTrue,geometry.x,geometry.y,exception);
5866 composite_image=DestroyImage(composite_image);
5869 case PointPrimitive:
5877 if ((y < 0) || (y >= (ssize_t) image->rows))
5879 if ((x < 0) || (x >= (ssize_t) image->columns))
5881 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5882 if (q == (Quantum *) NULL)
5884 GetFillColor(draw_info,x,y,&fill_color,exception);
5885 CompositePixelOver(image,&fill_color,(
double) fill_color.alpha,q,(
double)
5886 GetPixelAlpha(image,q),q);
5887 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5894 geometry[MagickPathExtent];
5899 if (primitive_info->text == (
char *) NULL)
5901 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5902 (void) CloneString(&clone_info->text,primitive_info->text);
5903 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
5904 primitive_info->point.x,primitive_info->point.y);
5905 (void) CloneString(&clone_info->geometry,geometry);
5906 status&=(MagickStatusType) AnnotateImage(image,clone_info,exception);
5907 clone_info=DestroyDrawInfo(clone_info);
5919 if (IsEventLogging() != MagickFalse)
5920 LogPrimitiveInfo(primitive_info);
5921 scale=ExpandAffine(&draw_info->affine);
5922 if ((draw_info->dash_pattern != (
double *) NULL) &&
5923 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5924 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5925 (draw_info->stroke.alpha != (
double) TransparentAlpha))
5930 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5931 clone_info->stroke_width=0.0;
5932 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5933 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5934 primitive_info,exception);
5935 clone_info=DestroyDrawInfo(clone_info);
5936 if (status != MagickFalse)
5937 status&=(MagickStatusType) DrawDashPolygon(draw_info,primitive_info,
5941 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5943 ((draw_info->stroke.alpha != (
double) TransparentAlpha) ||
5944 (draw_info->stroke_pattern != (Image *) NULL)))
5956 closed_path=primitive_info[0].closed_subpath;
5957 i=(ssize_t) primitive_info[0].coordinates;
5958 point_x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5959 point_y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5960 if ((point_x < MagickEpsilon) && (point_y < MagickEpsilon))
5961 closed_path=MagickTrue;
5962 if ((((draw_info->linecap == RoundCap) ||
5963 (closed_path != MagickFalse)) &&
5964 (draw_info->linejoin == RoundJoin)) ||
5965 (primitive_info[i].primitive != UndefinedPrimitive))
5967 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5968 primitive_info,exception);
5971 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
5972 clone_info->stroke_width=0.0;
5973 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5974 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5975 primitive_info,exception);
5976 clone_info=DestroyDrawInfo(clone_info);
5977 if (status != MagickFalse)
5978 status&=(MagickStatusType) DrawStrokePolygon(image,draw_info,
5979 primitive_info,exception);
5982 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5983 primitive_info,exception);
5987 image_view=DestroyCacheView(image_view);
5988 if (draw_info->compliance == SVGCompliance)
5990 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5991 (Image *) NULL,exception);
5992 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5993 (Image *) NULL,exception);
5995 if (draw_info->debug != MagickFalse)
5996 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
5997 return(status != 0 ? MagickTrue : MagickFalse);
6030static MagickBooleanType DrawRoundLinecap(Image *image,
6031 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6032 ExceptionInfo *exception)
6040 if (primitive_info->coordinates < 1)
6041 return(MagickFalse);
6042 for (i=0; i < 4; i++)
6043 linecap[i]=(*primitive_info);
6044 linecap[0].coordinates=4;
6045 linecap[1].point.x+=2.0*MagickEpsilon;
6046 linecap[2].point.x+=2.0*MagickEpsilon;
6047 linecap[2].point.y+=2.0*MagickEpsilon;
6048 linecap[3].point.y+=2.0*MagickEpsilon;
6049 linecap[4].primitive=UndefinedPrimitive;
6050 return(DrawPolygonPrimitive(image,draw_info,linecap,exception));
6053static MagickBooleanType DrawStrokePolygon(Image *image,
6054 const DrawInfo *draw_info,
const PrimitiveInfo *primitive_info,
6055 ExceptionInfo *exception)
6076 if (draw_info->debug != MagickFalse)
6077 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6078 " begin draw-stroke-polygon");
6079 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
6080 clone_info->fill=draw_info->stroke;
6081 if (clone_info->fill_pattern != (Image *) NULL)
6082 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
6083 if (clone_info->stroke_pattern != (Image *) NULL)
6084 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
6085 MagickTrue,exception);
6086 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
6087 clone_info->stroke_width=0.0;
6088 clone_info->fill_rule=NonZeroRule;
6090 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ptrdiff_t) p->coordinates)
6092 if (p->coordinates == 1)
6094 stroke_polygon=TraceStrokePolygon(draw_info,p,exception);
6095 if (stroke_polygon == (PrimitiveInfo *) NULL)
6100 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
6101 stroke_polygon,exception);
6102 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
6105 q=p+p->coordinates-1;
6106 closed_path=p->closed_subpath;
6107 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
6109 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,p,
6111 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,q,
6115 clone_info=DestroyDrawInfo(clone_info);
6116 if (draw_info->debug != MagickFalse)
6117 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6118 " end draw-stroke-polygon");
6119 return(status != 0 ? MagickTrue : MagickFalse);
6145MagickExport
void GetAffineMatrix(AffineMatrix *affine_matrix)
6147 if (IsEventLogging() != MagickFalse)
6148 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6149 assert(affine_matrix != (AffineMatrix *) NULL);
6150 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
6151 affine_matrix->sx=1.0;
6152 affine_matrix->sy=1.0;
6179MagickExport
void GetDrawInfo(
const ImageInfo *image_info,DrawInfo *draw_info)
6193 assert(draw_info != (DrawInfo *) NULL);
6194 if (IsEventLogging() != MagickFalse)
6195 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6196 (void) memset(draw_info,0,
sizeof(*draw_info));
6197 draw_info->image_info=CloneImageInfo(image_info);
6198 GetAffineMatrix(&draw_info->affine);
6199 exception=AcquireExceptionInfo();
6200 (void) QueryColorCompliance(
"#000F",AllCompliance,&draw_info->fill,
6202 (void) QueryColorCompliance(
"#FFF0",AllCompliance,&draw_info->stroke,
6204 draw_info->stroke_antialias=draw_info->image_info->antialias;
6205 draw_info->stroke_width=1.0;
6206 draw_info->fill_rule=EvenOddRule;
6207 draw_info->alpha=OpaqueAlpha;
6208 draw_info->fill_alpha=OpaqueAlpha;
6209 draw_info->stroke_alpha=OpaqueAlpha;
6210 draw_info->linecap=ButtCap;
6211 draw_info->linejoin=MiterJoin;
6212 draw_info->miterlimit=10;
6213 draw_info->decorate=NoDecoration;
6214 draw_info->pointsize=12.0;
6215 draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
6216 draw_info->compose=OverCompositeOp;
6217 draw_info->render=MagickTrue;
6218 draw_info->clip_path=MagickFalse;
6219 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6220 MagickTrue : MagickFalse;
6221 draw_info->macro_expansion=(
size_t *) NULL;
6222 if (draw_info->image_info->font != (
char *) NULL)
6223 draw_info->font=AcquireString(draw_info->image_info->font);
6224 if (draw_info->image_info->density != (
char *) NULL)
6225 draw_info->density=AcquireString(draw_info->image_info->density);
6226 draw_info->text_antialias=draw_info->image_info->antialias;
6227 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6228 draw_info->pointsize=draw_info->image_info->pointsize;
6229 draw_info->border_color=draw_info->image_info->border_color;
6230 if (draw_info->image_info->server_name != (
char *) NULL)
6231 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6232 option=GetImageOption(draw_info->image_info,
"direction");
6233 if (option != (
const char *) NULL)
6234 draw_info->direction=(DirectionType) ParseCommandOption(
6235 MagickDirectionOptions,MagickFalse,option);
6237 draw_info->direction=UndefinedDirection;
6238 option=GetImageOption(draw_info->image_info,
"encoding");
6239 if (option != (
const char *) NULL)
6240 (void) CloneString(&draw_info->encoding,option);
6241 option=GetImageOption(draw_info->image_info,
"family");
6242 if (option != (
const char *) NULL)
6243 (void) CloneString(&draw_info->family,option);
6244 option=GetImageOption(draw_info->image_info,
"fill");
6245 if (option != (
const char *) NULL)
6246 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
6248 option=GetImageOption(draw_info->image_info,
"gravity");
6249 if (option != (
const char *) NULL)
6250 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6251 MagickFalse,option);
6252 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6253 if (option != (
const char *) NULL)
6254 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6255 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6256 if (option != (
const char *) NULL)
6257 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6258 option=GetImageOption(draw_info->image_info,
"kerning");
6259 if (option != (
const char *) NULL)
6260 draw_info->kerning=GetDrawValue(option,&next_token);
6261 option=GetImageOption(draw_info->image_info,
"stroke");
6262 if (option != (
const char *) NULL)
6263 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
6265 option=GetImageOption(draw_info->image_info,
"strokewidth");
6266 if (option != (
const char *) NULL)
6267 draw_info->stroke_width=GetDrawValue(option,&next_token);
6268 option=GetImageOption(draw_info->image_info,
"style");
6269 if (option != (
const char *) NULL)
6270 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6271 MagickFalse,option);
6272 option=GetImageOption(draw_info->image_info,
"undercolor");
6273 if (option != (
const char *) NULL)
6274 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
6276 option=GetImageOption(draw_info->image_info,
"weight");
6277 if (option != (
const char *) NULL)
6282 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6284 weight=(ssize_t) StringToUnsignedLong(option);
6285 draw_info->weight=(size_t) weight;
6287 option=GetImageOption(draw_info->image_info,
"word-break");
6288 if (option != (
const char *) NULL)
6289 draw_info->word_break=(WordBreakType) ParseCommandOption(
6290 MagickWordBreakOptions,MagickFalse,option);
6291 exception=DestroyExceptionInfo(exception);
6292 draw_info->signature=MagickCoreSignature;
6320static inline double Permutate(
const ssize_t n,
const ssize_t k)
6329 for (i=k+1; i <= n; i++)
6331 for (i=1; i <= (n-k); i++)
6352static MagickBooleanType TraceArc(MVGInfo *mvg_info,
const PointInfo start,
6353 const PointInfo end,
const PointInfo degrees)
6359 center.x=0.5*(end.x+start.x);
6360 center.y=0.5*(end.y+start.y);
6361 radius.x=fabs(center.x-start.x);
6362 radius.y=fabs(center.y-start.y);
6363 return(TraceEllipse(mvg_info,center,radius,degrees));
6366static MagickBooleanType TraceArcPath(MVGInfo *mvg_info,
const PointInfo start,
6367 const PointInfo end,
const PointInfo arc,
const double angle,
6368 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6405 offset=mvg_info->offset;
6406 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6407 primitive_info->coordinates=0;
6408 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6409 (fabs(start.y-end.y) < MagickEpsilon))
6410 return(TracePoint(primitive_info,end));
6411 radii.x=fabs(arc.x);
6412 radii.y=fabs(arc.y);
6413 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6414 return(TraceLine(primitive_info,start,end));
6415 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6416 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6417 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6418 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6419 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6421 if (delta < MagickEpsilon)
6422 return(TraceLine(primitive_info,start,end));
6425 radii.x*=sqrt((
double) delta);
6426 radii.y*=sqrt((
double) delta);
6428 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6429 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6430 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6431 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6432 alpha=points[1].x-points[0].x;
6433 beta=points[1].y-points[0].y;
6434 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6435 return(TraceLine(primitive_info,start,end));
6436 factor=MagickSafeReciprocal(alpha*alpha+beta*beta)-0.25;
6441 factor=sqrt((
double) factor);
6442 if (sweep == large_arc)
6445 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6446 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6447 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6448 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6449 if ((theta < 0.0) && (sweep != MagickFalse))
6450 theta+=2.0*MagickPI;
6452 if ((theta > 0.0) && (sweep == MagickFalse))
6453 theta-=2.0*MagickPI;
6454 arc_segments=(size_t) CastDoubleToSsizeT(ceil(fabs((
double) (theta/(0.5*
6455 MagickPI+MagickEpsilon)))));
6458 for (i=0; i < (ssize_t) arc_segments; i++)
6460 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6461 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6462 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6463 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6464 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6465 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6466 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6467 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6468 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6469 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6470 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) (i+1)*
6471 theta/arc_segments),DegreesToRadians(360.0))));
6472 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) (i+1)*
6473 theta/arc_segments),DegreesToRadians(360.0))));
6474 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(
double)
6475 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6476 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(
double)
6477 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6478 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6479 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6480 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
6482 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
6484 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
6486 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
6488 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
6490 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
6492 if (i == (ssize_t) (arc_segments-1))
6494 status&=(MagickStatusType) TraceBezier(mvg_info,4);
6497 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
6498 mvg_info->offset+=(ssize_t) p->coordinates;
6499 p+=(ptrdiff_t) p->coordinates;
6502 return(MagickFalse);
6503 mvg_info->offset=offset;
6504 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6505 primitive_info->coordinates=(size_t) (p-primitive_info);
6506 primitive_info->closed_subpath=MagickFalse;
6507 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6509 p->primitive=primitive_info->primitive;
6515static MagickBooleanType TraceBezier(MVGInfo *mvg_info,
6516 const size_t number_coordinates)
6545 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6546 quantum=number_coordinates;
6547 for (i=0; i < (ssize_t) number_coordinates; i++)
6549 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6551 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6552 if (alpha > (
double) GetMaxMemoryRequest())
6554 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6555 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6556 return(MagickFalse);
6558 if (alpha > (
double) quantum)
6559 quantum=(size_t) alpha;
6560 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6561 if (alpha > (
double) quantum)
6562 quantum=(size_t) alpha;
6565 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6566 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6567 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6568 sizeof(*coefficients));
6569 points=(PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6571 if ((coefficients == (
double *) NULL) || (points == (PointInfo *) NULL))
6573 if (points != (PointInfo *) NULL)
6574 points=(PointInfo *) RelinquishMagickMemory(points);
6575 if (coefficients != (
double *) NULL)
6576 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6577 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6578 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6579 return(MagickFalse);
6581 control_points=quantum*number_coordinates;
6582 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6584 points=(PointInfo *) RelinquishMagickMemory(points);
6585 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6586 return(MagickFalse);
6588 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6592 end=primitive_info[number_coordinates-1].point;
6593 for (i=0; i < (ssize_t) number_coordinates; i++)
6594 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6596 for (i=0; i < (ssize_t) control_points; i++)
6601 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6602 for (j=0; j < (ssize_t) number_coordinates; j++)
6604 point.x+=alpha*coefficients[j]*p->point.x;
6605 point.y+=alpha*coefficients[j]*p->point.y;
6606 alpha*=weight/(1.0-weight);
6610 weight+=1.0/control_points;
6616 for (i=0; i < (ssize_t) control_points; i++)
6618 if (TracePoint(p,points[i]) == MagickFalse)
6620 points=(PointInfo *) RelinquishMagickMemory(points);
6621 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6622 return(MagickFalse);
6624 p+=(ptrdiff_t) p->coordinates;
6626 if (TracePoint(p,end) == MagickFalse)
6628 points=(PointInfo *) RelinquishMagickMemory(points);
6629 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6630 return(MagickFalse);
6632 p+=(ptrdiff_t) p->coordinates;
6633 primitive_info->coordinates=(size_t) (p-primitive_info);
6634 primitive_info->closed_subpath=MagickFalse;
6635 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6637 p->primitive=primitive_info->primitive;
6640 points=(PointInfo *) RelinquishMagickMemory(points);
6641 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6645static MagickBooleanType TraceCircle(MVGInfo *mvg_info,
const PointInfo start,
6646 const PointInfo end)
6657 alpha=end.x-start.x;
6659 radius=hypot((
double) alpha,(
double) beta);
6660 offset.x=(double) radius;
6661 offset.y=(double) radius;
6664 return(TraceEllipse(mvg_info,start,offset,degrees));
6667static MagickBooleanType TraceEllipse(MVGInfo *mvg_info,
const PointInfo center,
6668 const PointInfo radii,
const PointInfo arc)
6693 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6694 primitive_info->coordinates=0;
6695 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6697 delta=MagickSafeReciprocal(MagickMax(radii.x,radii.y));
6698 step=MagickPI/(MagickPI*MagickSafeReciprocal(delta))/8.0;
6699 angle.x=DegreesToRadians(arc.x);
6703 angle.y=DegreesToRadians(y);
6704 coordinates=ceil((angle.y-angle.x)/step+1.0);
6705 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6706 return(MagickFalse);
6708 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6709 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6711 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6712 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6713 if (i++ >= (ssize_t) coordinates)
6715 if (TracePoint(p,point) == MagickFalse)
6716 return(MagickFalse);
6717 p+=(ptrdiff_t) p->coordinates;
6719 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6720 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6721 if (TracePoint(p,point) == MagickFalse)
6722 return(MagickFalse);
6723 p+=(ptrdiff_t) p->coordinates;
6724 primitive_info->coordinates=(size_t) (p-primitive_info);
6725 primitive_info->closed_subpath=MagickFalse;
6726 x=fabs(primitive_info[0].point.x-
6727 primitive_info[primitive_info->coordinates-1].point.x);
6728 y=fabs(primitive_info[0].point.y-
6729 primitive_info[primitive_info->coordinates-1].point.y);
6730 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6731 primitive_info->closed_subpath=MagickTrue;
6732 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6734 p->primitive=primitive_info->primitive;
6740static MagickBooleanType TraceLine(PrimitiveInfo *primitive_info,
6741 const PointInfo start,
const PointInfo end)
6743 if (TracePoint(primitive_info,start) == MagickFalse)
6744 return(MagickFalse);
6745 if (TracePoint(primitive_info+1,end) == MagickFalse)
6746 return(MagickFalse);
6747 (primitive_info+1)->primitive=primitive_info->primitive;
6748 primitive_info->coordinates=2;
6749 primitive_info->closed_subpath=MagickFalse;
6753static ssize_t TracePath(MVGInfo *mvg_info,
const char *path,
6754 ExceptionInfo *exception)
6758 token[MagickPathExtent] =
"";
6776 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6799 subpath_offset=mvg_info->offset;
6800 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6803 number_coordinates=0;
6805 primitive_type=primitive_info->primitive;
6807 for (p=path; *p !=
'\0'; )
6809 if (status == MagickFalse)
6811 while (isspace((
int) ((
unsigned char) *p)) != 0)
6815 last_attribute=attribute;
6816 attribute=(int) (*p++);
6826 large_arc = MagickFalse,
6827 sweep = MagickFalse;
6837 (void) GetNextToken(p,&p,MagickPathExtent,token);
6838 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6839 ThrowPointExpectedException(token,exception);
6841 (void) GetNextToken(p,&p,MagickPathExtent,token);
6842 arc.x=GetDrawValue(token,&next_token);
6843 if (token == next_token)
6844 ThrowPointExpectedException(token,exception);
6845 (void) GetNextToken(p,&p,MagickPathExtent,token);
6846 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6847 ThrowPointExpectedException(token,exception);
6849 (void) GetNextToken(p,&p,MagickPathExtent,token);
6850 arc.y=GetDrawValue(token,&next_token);
6851 if (token == next_token)
6852 ThrowPointExpectedException(token,exception);
6853 (void) GetNextToken(p,&p,MagickPathExtent,token);
6854 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6855 ThrowPointExpectedException(token,exception);
6857 (void) GetNextToken(p,&p,MagickPathExtent,token);
6858 angle=GetDrawValue(token,&next_token);
6859 if (token == next_token)
6860 ThrowPointExpectedException(token,exception);
6861 (void) GetNextToken(p,&p,MagickPathExtent,token);
6862 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6863 ThrowPointExpectedException(token,exception);
6865 (void) GetNextToken(p,&p,MagickPathExtent,token);
6866 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6867 (void) GetNextToken(p,&p,MagickPathExtent,token);
6868 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6869 ThrowPointExpectedException(token,exception);
6871 (void) GetNextToken(p,&p,MagickPathExtent,token);
6872 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6873 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6874 ThrowPointExpectedException(token,exception);
6876 (void) GetNextToken(p,&p,MagickPathExtent,token);
6877 (void) GetNextToken(p,&p,MagickPathExtent,token);
6878 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6879 ThrowPointExpectedException(token,exception);
6881 (void) GetNextToken(p,&p,MagickPathExtent,token);
6882 x=GetDrawValue(token,&next_token);
6883 if (token == next_token)
6884 ThrowPointExpectedException(token,exception);
6885 (void) GetNextToken(p,&p,MagickPathExtent,token);
6886 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6887 ThrowPointExpectedException(token,exception);
6889 (void) GetNextToken(p,&p,MagickPathExtent,token);
6890 y=GetDrawValue(token,&next_token);
6891 if (token == next_token)
6892 ThrowPointExpectedException(token,exception);
6893 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6894 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6895 if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
6897 q=(*mvg_info->primitive_info)+mvg_info->offset;
6898 mvg_info->offset+=(ssize_t) q->coordinates;
6899 q+=(ptrdiff_t) q->coordinates;
6901 while (isspace((
int) ((
unsigned char) *p)) != 0)
6905 }
while (IsValidPoint(p) != MagickFalse);
6917 for (i=1; i < 4; i++)
6919 (void) GetNextToken(p,&p,MagickPathExtent,token);
6920 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6921 ThrowPointExpectedException(token,exception);
6923 (void) GetNextToken(p,&p,MagickPathExtent,token);
6924 x=GetDrawValue(token,&next_token);
6925 if (token == next_token)
6926 ThrowPointExpectedException(token,exception);
6927 (void) GetNextToken(p,&p,MagickPathExtent,token);
6928 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6929 ThrowPointExpectedException(token,exception);
6931 (void) GetNextToken(p,&p,MagickPathExtent,token);
6932 y=GetDrawValue(token,&next_token);
6933 if (token == next_token)
6934 ThrowPointExpectedException(token,exception);
6935 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6936 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6939 for (i=0; i < 4; i++)
6940 (q+i)->point=points[i];
6941 if (TraceBezier(mvg_info,4) == MagickFalse)
6943 q=(*mvg_info->primitive_info)+mvg_info->offset;
6944 mvg_info->offset+=(ssize_t) q->coordinates;
6945 q+=(ptrdiff_t) q->coordinates;
6947 while (isspace((
int) ((
unsigned char) *p)) != 0)
6951 }
while (IsValidPoint(p) != MagickFalse);
6959 (void) GetNextToken(p,&p,MagickPathExtent,token);
6960 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6961 ThrowPointExpectedException(token,exception);
6963 (void) GetNextToken(p,&p,MagickPathExtent,token);
6964 x=GetDrawValue(token,&next_token);
6965 if (token == next_token)
6966 ThrowPointExpectedException(token,exception);
6967 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6968 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6970 q=(*mvg_info->primitive_info)+mvg_info->offset;
6971 if (TracePoint(q,point) == MagickFalse)
6973 mvg_info->offset+=(ssize_t) q->coordinates;
6974 q+=(ptrdiff_t) q->coordinates;
6975 while (isspace((
int) ((
unsigned char) *p)) != 0)
6979 }
while (IsValidPoint(p) != MagickFalse);
6990 (void) GetNextToken(p,&p,MagickPathExtent,token);
6991 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6992 ThrowPointExpectedException(token,exception);
6994 (void) GetNextToken(p,&p,MagickPathExtent,token);
6995 x=GetDrawValue(token,&next_token);
6996 if (token == next_token)
6997 ThrowPointExpectedException(token,exception);
6998 (void) GetNextToken(p,&p,MagickPathExtent,token);
6999 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7000 ThrowPointExpectedException(token,exception);
7002 (void) GetNextToken(p,&p,MagickPathExtent,token);
7003 y=GetDrawValue(token,&next_token);
7004 if (token == next_token)
7005 ThrowPointExpectedException(token,exception);
7006 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
7007 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
7008 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7010 q=(*mvg_info->primitive_info)+mvg_info->offset;
7011 if (TracePoint(q,point) == MagickFalse)
7013 mvg_info->offset+=(ssize_t) q->coordinates;
7014 q+=(ptrdiff_t) q->coordinates;
7015 while (isspace((
int) ((
unsigned char) *p)) != 0)
7019 }
while (IsValidPoint(p) != MagickFalse);
7028 if (mvg_info->offset != subpath_offset)
7030 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7031 primitive_info->coordinates=(size_t) (q-primitive_info);
7032 number_coordinates+=primitive_info->coordinates;
7034 subpath_offset=mvg_info->offset;
7039 (void) GetNextToken(p,&p,MagickPathExtent,token);
7040 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7041 ThrowPointExpectedException(token,exception);
7043 (void) GetNextToken(p,&p,MagickPathExtent,token);
7044 x=GetDrawValue(token,&next_token);
7045 if (token == next_token)
7046 ThrowPointExpectedException(token,exception);
7047 (void) GetNextToken(p,&p,MagickPathExtent,token);
7048 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7049 ThrowPointExpectedException(token,exception);
7051 (void) GetNextToken(p,&p,MagickPathExtent,token);
7052 y=GetDrawValue(token,&next_token);
7053 if (token == next_token)
7054 ThrowPointExpectedException(token,exception);
7055 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
7056 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
7060 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7062 q=(*mvg_info->primitive_info)+mvg_info->offset;
7063 if (TracePoint(q,point) == MagickFalse)
7065 mvg_info->offset+=(ssize_t) q->coordinates;
7066 q+=(ptrdiff_t) q->coordinates;
7067 while (isspace((
int) ((
unsigned char) *p)) != 0)
7071 }
while (IsValidPoint(p) != MagickFalse);
7083 for (i=1; i < 3; i++)
7085 (void) GetNextToken(p,&p,MagickPathExtent,token);
7086 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7087 ThrowPointExpectedException(token,exception);
7089 (void) GetNextToken(p,&p,MagickPathExtent,token);
7090 x=GetDrawValue(token,&next_token);
7091 if (token == next_token)
7092 ThrowPointExpectedException(token,exception);
7093 (void) GetNextToken(p,&p,MagickPathExtent,token);
7094 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7095 ThrowPointExpectedException(token,exception);
7097 (void) GetNextToken(p,&p,MagickPathExtent,token);
7098 y=GetDrawValue(token,&next_token);
7099 if (token == next_token)
7100 ThrowPointExpectedException(token,exception);
7103 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
7104 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
7107 for (i=0; i < 3; i++)
7108 (q+i)->point=points[i];
7109 if (TraceBezier(mvg_info,3) == MagickFalse)
7111 q=(*mvg_info->primitive_info)+mvg_info->offset;
7112 mvg_info->offset+=(ssize_t) q->coordinates;
7113 q+=(ptrdiff_t) q->coordinates;
7115 while (isspace((
int) ((
unsigned char) *p)) != 0)
7119 }
while (IsValidPoint(p) != MagickFalse);
7130 points[0]=points[3];
7131 points[1].x=2.0*points[3].x-points[2].x;
7132 points[1].y=2.0*points[3].y-points[2].y;
7133 for (i=2; i < 4; i++)
7135 (void) GetNextToken(p,&p,MagickPathExtent,token);
7136 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7137 ThrowPointExpectedException(token,exception);
7139 (void) GetNextToken(p,&p,MagickPathExtent,token);
7140 x=GetDrawValue(token,&next_token);
7141 if (token == next_token)
7142 ThrowPointExpectedException(token,exception);
7143 (void) GetNextToken(p,&p,MagickPathExtent,token);
7144 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7145 ThrowPointExpectedException(token,exception);
7147 (void) GetNextToken(p,&p,MagickPathExtent,token);
7148 y=GetDrawValue(token,&next_token);
7149 if (token == next_token)
7150 ThrowPointExpectedException(token,exception);
7153 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
7154 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
7157 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
7162 for (i=0; i < 4; i++)
7163 (q+i)->point=points[i];
7164 if (TraceBezier(mvg_info,4) == MagickFalse)
7166 q=(*mvg_info->primitive_info)+mvg_info->offset;
7167 mvg_info->offset+=(ssize_t) q->coordinates;
7168 q+=(ptrdiff_t) q->coordinates;
7170 last_attribute=attribute;
7171 while (isspace((
int) ((
unsigned char) *p)) != 0)
7175 }
while (IsValidPoint(p) != MagickFalse);
7186 points[0]=points[2];
7187 points[1].x=2.0*points[2].x-points[1].x;
7188 points[1].y=2.0*points[2].y-points[1].y;
7189 for (i=2; i < 3; i++)
7191 (void) GetNextToken(p,&p,MagickPathExtent,token);
7192 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7193 ThrowPointExpectedException(token,exception);
7195 (void) GetNextToken(p,&p,MagickPathExtent,token);
7196 x=GetDrawValue(token,&next_token);
7197 if (token == next_token)
7198 ThrowPointExpectedException(token,exception);
7199 (void) GetNextToken(p,&p,MagickPathExtent,token);
7200 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7201 ThrowPointExpectedException(token,exception);
7203 (void) GetNextToken(p,&p,MagickPathExtent,token);
7204 y=GetDrawValue(token,&next_token);
7205 if (token == next_token)
7206 ThrowPointExpectedException(token,exception);
7207 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7208 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7211 if (status == MagickFalse)
7213 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7218 for (i=0; i < 3; i++)
7219 (q+i)->point=points[i];
7220 if (TraceBezier(mvg_info,3) == MagickFalse)
7222 q=(*mvg_info->primitive_info)+mvg_info->offset;
7223 mvg_info->offset+=(ssize_t) q->coordinates;
7224 q+=(ptrdiff_t) q->coordinates;
7226 last_attribute=attribute;
7227 while (isspace((
int) ((
unsigned char) *p)) != 0)
7231 }
while (IsValidPoint(p) != MagickFalse);
7242 (void) GetNextToken(p,&p,MagickPathExtent,token);
7243 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7244 ThrowPointExpectedException(token,exception);
7246 (void) GetNextToken(p,&p,MagickPathExtent,token);
7247 y=GetDrawValue(token,&next_token);
7248 if (token == next_token)
7249 ThrowPointExpectedException(token,exception);
7250 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
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 while (isspace((
int) ((
unsigned char) *p)) != 0)
7262 }
while (IsValidPoint(p) != MagickFalse);
7272 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7274 q=(*mvg_info->primitive_info)+mvg_info->offset;
7275 if (TracePoint(q,point) == MagickFalse)
7277 mvg_info->offset+=(ssize_t) q->coordinates;
7278 q+=(ptrdiff_t) q->coordinates;
7279 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7280 primitive_info->coordinates=(size_t) (q-primitive_info);
7281 primitive_info->closed_subpath=MagickTrue;
7282 number_coordinates+=primitive_info->coordinates;
7284 subpath_offset=mvg_info->offset;
7290 ThrowPointExpectedException(token,exception);
7295 if (status == MagickFalse)
7297 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7298 primitive_info->coordinates=(size_t) (q-primitive_info);
7299 number_coordinates+=primitive_info->coordinates;
7300 for (i=0; i < (ssize_t) number_coordinates; i++)
7303 q->primitive=primitive_type;
7305 q->method=FillToBorderMethod;
7308 return((ssize_t) number_coordinates);
7311static MagickBooleanType TraceRectangle(PrimitiveInfo *primitive_info,
7312 const PointInfo start,
const PointInfo end)
7324 if (TracePoint(p,start) == MagickFalse)
7325 return(MagickFalse);
7326 p+=(ptrdiff_t) p->coordinates;
7329 if (TracePoint(p,point) == MagickFalse)
7330 return(MagickFalse);
7331 p+=(ptrdiff_t) p->coordinates;
7332 if (TracePoint(p,end) == MagickFalse)
7333 return(MagickFalse);
7334 p+=(ptrdiff_t) p->coordinates;
7337 if (TracePoint(p,point) == MagickFalse)
7338 return(MagickFalse);
7339 p+=(ptrdiff_t) p->coordinates;
7340 if (TracePoint(p,start) == MagickFalse)
7341 return(MagickFalse);
7342 p+=(ptrdiff_t) p->coordinates;
7343 primitive_info->coordinates=(size_t) (p-primitive_info);
7344 primitive_info->closed_subpath=MagickTrue;
7345 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7347 p->primitive=primitive_info->primitive;
7353static MagickBooleanType TraceRoundRectangle(MVGInfo *mvg_info,
7354 const PointInfo start,
const PointInfo end,PointInfo arc)
7373 offset=mvg_info->offset;
7374 segment.x=fabs(end.x-start.x);
7375 segment.y=fabs(end.y-start.y);
7376 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7378 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7381 if (arc.x > (0.5*segment.x))
7382 arc.x=0.5*segment.x;
7383 if (arc.y > (0.5*segment.y))
7384 arc.y=0.5*segment.y;
7385 point.x=start.x+segment.x-arc.x;
7386 point.y=start.y+arc.y;
7389 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7390 return(MagickFalse);
7391 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7392 mvg_info->offset+=(ssize_t) p->coordinates;
7393 point.x=start.x+segment.x-arc.x;
7394 point.y=start.y+segment.y-arc.y;
7397 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7398 return(MagickFalse);
7399 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7400 mvg_info->offset+=(ssize_t) p->coordinates;
7401 point.x=start.x+arc.x;
7402 point.y=start.y+segment.y-arc.y;
7405 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7406 return(MagickFalse);
7407 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7408 mvg_info->offset+=(ssize_t) p->coordinates;
7409 point.x=start.x+arc.x;
7410 point.y=start.y+arc.y;
7413 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7414 return(MagickFalse);
7415 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7416 mvg_info->offset+=(ssize_t) p->coordinates;
7417 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7418 return(MagickFalse);
7419 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7420 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7421 return(MagickFalse);
7422 p+=(ptrdiff_t) p->coordinates;
7423 mvg_info->offset=offset;
7424 primitive_info=(*mvg_info->primitive_info)+offset;
7425 primitive_info->coordinates=(size_t) (p-primitive_info);
7426 primitive_info->closed_subpath=MagickTrue;
7427 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7429 p->primitive=primitive_info->primitive;
7435static MagickBooleanType TraceSquareLinecap(PrimitiveInfo *primitive_info,
7436 const size_t number_vertices,
const double offset)
7453 for (i=1; i < (ssize_t) number_vertices; i++)
7455 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7456 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7457 if ((fabs((
double) dx) >= MagickEpsilon) ||
7458 (fabs((
double) dy) >= MagickEpsilon))
7461 if (i == (ssize_t) number_vertices)
7462 i=(ssize_t) number_vertices-1L;
7463 distance=hypot((
double) dx,(
double) dy);
7464 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7465 dx*(distance+offset)/distance);
7466 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7467 dy*(distance+offset)/distance);
7468 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7470 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7471 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7472 if ((fabs((
double) dx) >= MagickEpsilon) ||
7473 (fabs((
double) dy) >= MagickEpsilon))
7476 distance=hypot((
double) dx,(
double) dy);
7477 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7478 dx*(distance+offset)/distance);
7479 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7480 dy*(distance+offset)/distance);
7484static PrimitiveInfo *TraceStrokePolygon(
const DrawInfo *draw_info,
7485 const PrimitiveInfo *primitive_info,ExceptionInfo *exception)
7487#define MaxStrokePad (6*BezierQuantum+360)
7488#define CheckPathExtent(pad_p,pad_q) \
7490 if ((pad_p) > MaxBezierCoordinates) \
7491 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7493 if ((p+(ptrdiff_t) (pad_p)) >= (ssize_t) extent_p) \
7495 if (~extent_p < (pad_p)) \
7496 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7499 extent_p+=(pad_p); \
7500 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \
7501 MaxStrokePad,sizeof(*stroke_p)); \
7504 if ((pad_q) > MaxBezierCoordinates) \
7505 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7507 if ((q+(ptrdiff_t) (pad_q)) >= (ssize_t) extent_q) \
7509 if (~extent_q < (pad_q)) \
7510 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7513 extent_q+=(pad_q); \
7514 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \
7515 MaxStrokePad,sizeof(*stroke_q)); \
7518 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \
7520 if (stroke_p != (PointInfo *) NULL) \
7521 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7522 if (stroke_q != (PointInfo *) NULL) \
7523 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7524 polygon_primitive=(PrimitiveInfo *) \
7525 RelinquishMagickMemory(polygon_primitive); \
7526 (void) ThrowMagickException(exception,GetMagickModule(), \
7527 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \
7528 return((PrimitiveInfo *) NULL); \
7532 typedef struct _StrokeSegment
7578 inverse_slope = {0.0, 0.0},
7585 number_vertices=primitive_info->coordinates;
7586 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7587 number_vertices+2UL,
sizeof(*polygon_primitive));
7588 if (polygon_primitive == (PrimitiveInfo *) NULL)
7590 (void) ThrowMagickException(exception,GetMagickModule(),
7591 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7592 return((PrimitiveInfo *) NULL);
7594 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7595 sizeof(*polygon_primitive));
7596 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7597 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7598 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7599 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7600 if ((draw_info->linejoin == RoundJoin) ||
7601 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
7603 polygon_primitive[number_vertices]=primitive_info[1];
7606 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7610 closed_path=primitive_info[0].closed_subpath;
7613 for (n=1; n < (ssize_t) number_vertices; n++)
7615 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7616 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7617 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7620 if (n == (ssize_t) number_vertices)
7622 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7627 stroke_polygon=(PrimitiveInfo *) AcquireCriticalMemory(
7628 sizeof(*stroke_polygon));
7629 stroke_polygon[0]=polygon_primitive[0];
7630 stroke_polygon[0].coordinates=0;
7631 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7633 return(stroke_polygon);
7635 n=(ssize_t) number_vertices-1L;
7637 extent_p=2*number_vertices;
7638 extent_q=2*number_vertices;
7639 stroke_p=(PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7641 stroke_q=(PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7643 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL))
7645 if (stroke_p != (PointInfo *) NULL)
7646 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7647 if (stroke_q != (PointInfo *) NULL)
7648 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7649 polygon_primitive=(PrimitiveInfo *)
7650 RelinquishMagickMemory(polygon_primitive);
7651 (void) ThrowMagickException(exception,GetMagickModule(),
7652 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7653 return((PrimitiveInfo *) NULL);
7656 inverse_slope.p=0.0;
7657 if (fabs(dx.p) < MagickEpsilon)
7660 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7662 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7665 if (fabs(dy.p) < MagickEpsilon)
7668 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7670 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7675 inverse_slope.p=(-1.0*MagickSafeReciprocal(slope.p));
7677 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7678 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7679 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7680 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7681 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7682 offset.y=(double) (offset.x*inverse_slope.p);
7683 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7685 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7686 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7687 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7688 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7689 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7690 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7691 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7692 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7696 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7697 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7698 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7699 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7700 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7701 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7702 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7703 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7710 stroke_q[p++]=box_q[0];
7711 stroke_p[q++]=box_p[0];
7712 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7717 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7718 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7719 dot_product=dx.q*dx.q+dy.q*dy.q;
7720 if (dot_product < 0.25)
7723 inverse_slope.q=0.0;
7724 if (fabs(dx.q) < MagickEpsilon)
7727 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7729 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7732 if (fabs(dy.q) < MagickEpsilon)
7735 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7737 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7742 inverse_slope.q=(-1.0*MagickSafeReciprocal(slope.q));
7744 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7745 offset.y=(double) (offset.x*inverse_slope.q);
7746 dot_product=dy.q*offset.x-dx.q*offset.y;
7747 if (dot_product > 0.0)
7749 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7750 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7751 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7752 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7753 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7754 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7755 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7756 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7760 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7761 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7762 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7763 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7764 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7765 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7766 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7767 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7769 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7776 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7777 box_p[3].y)/(slope.p-slope.q));
7778 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7779 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7780 box_q[3].y)/(slope.p-slope.q));
7781 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7783 DisableMSCWarning(4127)
7784 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7786 dot_product=dx.q*dy.p-dx.p*dy.q;
7787 if (dot_product <= 0.0)
7788 switch (draw_info->linejoin)
7792 stroke_q[q++]=box_q[1];
7793 stroke_q[q++]=box_q[2];
7794 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7795 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7796 if (dot_product <= miterlimit)
7797 stroke_p[p++]=box_p[4];
7800 stroke_p[p++]=box_p[1];
7801 stroke_p[p++]=box_p[2];
7807 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7808 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7809 if (dot_product <= miterlimit)
7811 stroke_q[q++]=box_q[4];
7812 stroke_p[p++]=box_p[4];
7816 stroke_q[q++]=box_q[1];
7817 stroke_q[q++]=box_q[2];
7818 stroke_p[p++]=box_p[1];
7819 stroke_p[p++]=box_p[2];
7825 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7826 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7827 if (dot_product <= miterlimit)
7828 stroke_p[p++]=box_p[4];
7831 stroke_p[p++]=box_p[1];
7832 stroke_p[p++]=box_p[2];
7834 center=polygon_primitive[n].point;
7835 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7836 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7837 if (theta.q < theta.p)
7838 theta.q+=2.0*MagickPI;
7839 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.q-
7840 theta.p)/(2.0*sqrt(MagickSafeReciprocal(mid))))));
7841 DisableMSCWarning(4127)
7842 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7844 stroke_q[q].x=box_q[1].x;
7845 stroke_q[q].y=box_q[1].y;
7847 for (j=1; j < (ssize_t) arc_segments; j++)
7849 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7850 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7851 (theta.p+delta_theta),DegreesToRadians(360.0))));
7852 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7853 (theta.p+delta_theta),DegreesToRadians(360.0))));
7856 stroke_q[q++]=box_q[2];
7863 switch (draw_info->linejoin)
7867 stroke_p[p++]=box_p[1];
7868 stroke_p[p++]=box_p[2];
7869 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7870 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7871 if (dot_product <= miterlimit)
7872 stroke_q[q++]=box_q[4];
7875 stroke_q[q++]=box_q[1];
7876 stroke_q[q++]=box_q[2];
7882 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7883 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7884 if (dot_product <= miterlimit)
7886 stroke_q[q++]=box_q[4];
7887 stroke_p[p++]=box_p[4];
7891 stroke_q[q++]=box_q[1];
7892 stroke_q[q++]=box_q[2];
7893 stroke_p[p++]=box_p[1];
7894 stroke_p[p++]=box_p[2];
7900 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7901 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7902 if (dot_product <= miterlimit)
7903 stroke_q[q++]=box_q[4];
7906 stroke_q[q++]=box_q[1];
7907 stroke_q[q++]=box_q[2];
7909 center=polygon_primitive[n].point;
7910 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7911 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7912 if (theta.p < theta.q)
7913 theta.p+=2.0*MagickPI;
7914 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.p-
7915 theta.q)/(2.0*sqrt((
double) (MagickSafeReciprocal(mid)))))));
7916 DisableMSCWarning(4127)
7917 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7919 stroke_p[p++]=box_p[1];
7920 for (j=1; j < (ssize_t) arc_segments; j++)
7922 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7923 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7924 (theta.p+delta_theta),DegreesToRadians(360.0))));
7925 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7926 (theta.p+delta_theta),DegreesToRadians(360.0))));
7929 stroke_p[p++]=box_p[2];
7936 inverse_slope.p=inverse_slope.q;
7945 stroke_p[p++]=box_p[1];
7946 stroke_q[q++]=box_q[1];
7950 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7951 (p+q+2L),(
size_t) (closed_path+2L)*
sizeof(*stroke_polygon));
7952 if (stroke_polygon == (PrimitiveInfo *) NULL)
7954 (void) ThrowMagickException(exception,GetMagickModule(),
7955 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7956 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7957 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7958 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(
7960 return(stroke_polygon);
7962 for (i=0; i < (ssize_t) p; i++)
7964 stroke_polygon[i]=polygon_primitive[0];
7965 stroke_polygon[i].point=stroke_p[i];
7967 if (closed_path != MagickFalse)
7969 stroke_polygon[i]=polygon_primitive[0];
7970 stroke_polygon[i].point=stroke_polygon[0].point;
7973 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7975 stroke_polygon[i]=polygon_primitive[0];
7976 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7978 if (closed_path != MagickFalse)
7980 stroke_polygon[i]=polygon_primitive[0];
7981 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7984 stroke_polygon[i]=polygon_primitive[0];
7985 stroke_polygon[i].point=stroke_polygon[0].point;
7987 stroke_polygon[i].primitive=UndefinedPrimitive;
7988 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
7989 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p);
7990 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q);
7991 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
7992 return(stroke_polygon);