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; \
109static inline float MagickSafeReciprocal(
const float x) {
110 return PerceptibleReciprocal(x);
199 *DrawClippingMask(
Image *,
const DrawInfo *,
const char *,
const char *,
202static MagickBooleanType
208 const double,
const MagickBooleanType,
const MagickBooleanType),
209 TraceBezier(
MVGInfo *,
const size_t),
215 TraceSquareLinecap(
PrimitiveInfo *,
const size_t,
const double);
241MagickExport
DrawInfo *AcquireDrawInfo(
void)
246 draw_info=(
DrawInfo *) AcquireCriticalMemory(
sizeof(*draw_info));
247 GetDrawInfo((
ImageInfo *) NULL,draw_info);
287 clone_info=(
DrawInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
288 GetDrawInfo(image_info,clone_info);
291 exception=AcquireExceptionInfo();
292 if (draw_info->id != (
char *) NULL)
293 (void) CloneString(&clone_info->id,draw_info->id);
294 if (draw_info->primitive != (
char *) NULL)
295 (
void) CloneString(&clone_info->primitive,draw_info->primitive);
296 if (draw_info->geometry != (
char *) NULL)
297 (void) CloneString(&clone_info->geometry,draw_info->geometry);
298 clone_info->compliance=draw_info->compliance;
299 clone_info->viewbox=draw_info->viewbox;
300 clone_info->affine=draw_info->affine;
301 clone_info->gravity=draw_info->gravity;
302 clone_info->fill=draw_info->fill;
303 clone_info->stroke=draw_info->stroke;
304 clone_info->stroke_width=draw_info->stroke_width;
305 if (draw_info->fill_pattern != (
Image *) NULL)
306 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
308 if (draw_info->stroke_pattern != (
Image *) NULL)
309 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
310 MagickTrue,exception);
311 clone_info->stroke_antialias=draw_info->stroke_antialias;
312 clone_info->text_antialias=draw_info->text_antialias;
313 clone_info->fill_rule=draw_info->fill_rule;
314 clone_info->linecap=draw_info->linecap;
315 clone_info->linejoin=draw_info->linejoin;
316 clone_info->miterlimit=draw_info->miterlimit;
317 clone_info->dash_offset=draw_info->dash_offset;
318 clone_info->decorate=draw_info->decorate;
319 clone_info->compose=draw_info->compose;
320 if (draw_info->text != (
char *) NULL)
321 (
void) CloneString(&clone_info->text,draw_info->text);
322 if (draw_info->font != (
char *) NULL)
323 (void) CloneString(&clone_info->font,draw_info->font);
324 if (draw_info->metrics != (
char *) NULL)
325 (
void) CloneString(&clone_info->metrics,draw_info->metrics);
326 if (draw_info->family != (
char *) NULL)
327 (void) CloneString(&clone_info->family,draw_info->family);
328 clone_info->style=draw_info->style;
329 clone_info->stretch=draw_info->stretch;
330 clone_info->weight=draw_info->weight;
331 if (draw_info->encoding != (
char *) NULL)
332 (
void) CloneString(&clone_info->encoding,draw_info->encoding);
333 clone_info->pointsize=draw_info->pointsize;
334 clone_info->kerning=draw_info->kerning;
335 clone_info->interline_spacing=draw_info->interline_spacing;
336 clone_info->interword_spacing=draw_info->interword_spacing;
337 clone_info->direction=draw_info->direction;
338 clone_info->word_break=draw_info->word_break;
339 if (draw_info->density != (
char *) NULL)
340 (void) CloneString(&clone_info->density,draw_info->density);
341 clone_info->align=draw_info->align;
342 clone_info->undercolor=draw_info->undercolor;
343 clone_info->border_color=draw_info->border_color;
344 if (draw_info->server_name != (
char *) NULL)
345 (
void) CloneString(&clone_info->server_name,draw_info->server_name);
346 if (draw_info->dash_pattern != (
double *) NULL)
351 for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
352 clone_info->dash_pattern=(
double *) AcquireQuantumMemory((
size_t) (x+1),
353 sizeof(*clone_info->dash_pattern));
354 if (clone_info->dash_pattern == (
double *) NULL)
355 ThrowFatalException(ResourceLimitFatalError,
356 "UnableToAllocateDashPattern");
357 (void) memset(clone_info->dash_pattern,0,(
size_t) (x+1)*
358 sizeof(*clone_info->dash_pattern));
359 (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(
size_t)
360 x*
sizeof(*clone_info->dash_pattern));
362 clone_info->gradient=draw_info->gradient;
363 if (draw_info->gradient.stops != (
StopInfo *) NULL)
368 number_stops=clone_info->gradient.number_stops;
369 clone_info->gradient.stops=(
StopInfo *) AcquireQuantumMemory((
size_t)
370 number_stops,
sizeof(*clone_info->gradient.stops));
371 if (clone_info->gradient.stops == (
StopInfo *) NULL)
372 ThrowFatalException(ResourceLimitFatalError,
373 "UnableToAllocateDashPattern");
374 (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
375 (
size_t) number_stops*
sizeof(*clone_info->gradient.stops));
377 clone_info->bounds=draw_info->bounds;
378 clone_info->fill_alpha=draw_info->fill_alpha;
379 clone_info->stroke_alpha=draw_info->stroke_alpha;
380 clone_info->element_reference=draw_info->element_reference;
381 clone_info->clip_path=draw_info->clip_path;
382 clone_info->clip_units=draw_info->clip_units;
383 if (draw_info->clip_mask != (
char *) NULL)
384 (
void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
385 if (draw_info->clipping_mask != (
Image *) NULL)
386 clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
387 MagickTrue,exception);
388 if (draw_info->composite_mask != (
Image *) NULL)
389 clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
390 MagickTrue,exception);
391 clone_info->render=draw_info->render;
392 clone_info->debug=draw_info->debug;
393 clone_info->macro_expansion=draw_info->macro_expansion;
394 exception=DestroyExceptionInfo(exception);
434 if (polygon_info->edges != (
EdgeInfo *) NULL)
436 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
437 if (polygon_info->edges[i].points != (
PointInfo *) NULL)
438 polygon_info->edges[i].points=(
PointInfo *)
439 RelinquishMagickMemory(polygon_info->edges[i].points);
440 polygon_info->edges=(
EdgeInfo *) RelinquishMagickMemory(
441 polygon_info->edges);
443 return((
PolygonInfo *) RelinquishMagickMemory(polygon_info));
445#if defined(__cplusplus) || defined(c_plusplus)
449static int DrawCompareEdges(
const void *p_edge,
const void *q_edge)
451#define DrawCompareEdge(p,q) \
453 if (((p)-(q)) < 0.0) \
455 if (((p)-(q)) > 0.0) \
466 p=((
const EdgeInfo *) p_edge)->points;
467 q=((
const EdgeInfo *) q_edge)->points;
468 DrawCompareEdge(p[0].y,q[0].y);
469 DrawCompareEdge(p[0].x,q[0].x);
470 DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
472 DrawCompareEdge(p[1].y,q[1].y);
473 DrawCompareEdge(p[1].x,q[1].x);
477#if defined(__cplusplus) || defined(c_plusplus)
481static void LogPolygonInfo(
const PolygonInfo *polygon_info)
490 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin active-edge");
491 p=polygon_info->edges;
492 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
494 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" edge %.20g:",
496 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" direction: %s",
497 p->direction != MagickFalse ?
"down" :
"up");
498 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" ghostline: %s",
499 p->ghostline != MagickFalse ?
"transparent" :
"opaque");
500 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
501 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
502 p->bounds.x2,p->bounds.y2);
503 for (j=0; j < (ssize_t) p->number_points; j++)
504 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %g,%g",
505 p->points[j].x,p->points[j].y);
508 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end active-edge");
511static void ReversePoints(
PointInfo *points,
const size_t number_points)
519 for (i=0; i < (number_points >> 1); i++)
522 points[i]=points[number_points-(i+1)];
523 points[number_points-(i+1)]=point;
559 polygon_info=(
PolygonInfo *) AcquireMagickMemory(
sizeof(*polygon_info));
562 (void) ThrowMagickException(exception,GetMagickModule(),
563 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
567 polygon_info->edges=(
EdgeInfo *) AcquireQuantumMemory(number_edges,
568 sizeof(*polygon_info->edges));
569 if (polygon_info->edges == (
EdgeInfo *) NULL)
571 (void) ThrowMagickException(exception,GetMagickModule(),
572 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
573 return(DestroyPolygonInfo(polygon_info));
575 (void) memset(polygon_info->edges,0,number_edges*
576 sizeof(*polygon_info->edges));
579 ghostline=MagickFalse;
583 (void) memset(&point,0,
sizeof(point));
584 (void) memset(&bounds,0,
sizeof(bounds));
585 polygon_info->edges[edge].number_points=(size_t) n;
586 polygon_info->edges[edge].scanline=0.0;
587 polygon_info->edges[edge].highwater=0;
588 polygon_info->edges[edge].ghostline=ghostline;
589 polygon_info->edges[edge].direction=(ssize_t) direction;
590 polygon_info->edges[edge].points=points;
591 polygon_info->edges[edge].bounds=bounds;
592 polygon_info->number_edges=0;
593 for (i=0; path_info[i].code != EndCode; i++)
595 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
596 (path_info[i].code == GhostlineCode))
601 if ((points != (
PointInfo *) NULL) && (n >= 2))
603 if (edge == number_edges)
606 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
607 polygon_info->edges,(
size_t) number_edges,
608 sizeof(*polygon_info->edges));
609 if (polygon_info->edges == (
EdgeInfo *) NULL)
611 (void) ThrowMagickException(exception,GetMagickModule(),
612 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
613 points=(
PointInfo *) RelinquishMagickMemory(points);
614 return(DestroyPolygonInfo(polygon_info));
617 polygon_info->edges[edge].number_points=(size_t) n;
618 polygon_info->edges[edge].scanline=(-1.0);
619 polygon_info->edges[edge].highwater=0;
620 polygon_info->edges[edge].ghostline=ghostline;
621 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
623 ReversePoints(points,(
size_t) n);
624 polygon_info->edges[edge].points=points;
625 polygon_info->edges[edge].bounds=bounds;
626 polygon_info->edges[edge].bounds.y1=points[0].y;
627 polygon_info->edges[edge].bounds.y2=points[n-1].y;
629 ghostline=MagickFalse;
631 polygon_info->number_edges=edge;
636 points=(
PointInfo *) AcquireQuantumMemory((
size_t) number_points,
640 (void) ThrowMagickException(exception,GetMagickModule(),
641 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
642 return(DestroyPolygonInfo(polygon_info));
645 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
646 point=path_info[i].point;
657 next_direction=((path_info[i].point.y > point.y) ||
658 ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
659 (path_info[i].point.x > point.x))) ? 1 : -1;
660 if ((points != (
PointInfo *) NULL) && (direction != 0) &&
661 (direction != next_direction))
667 if (edge == number_edges)
670 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
671 polygon_info->edges,(
size_t) number_edges,
672 sizeof(*polygon_info->edges));
673 if (polygon_info->edges == (
EdgeInfo *) NULL)
675 (void) ThrowMagickException(exception,GetMagickModule(),
676 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
677 points=(
PointInfo *) RelinquishMagickMemory(points);
678 return(DestroyPolygonInfo(polygon_info));
681 polygon_info->edges[edge].number_points=(size_t) n;
682 polygon_info->edges[edge].scanline=(-1.0);
683 polygon_info->edges[edge].highwater=0;
684 polygon_info->edges[edge].ghostline=ghostline;
685 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
687 ReversePoints(points,(
size_t) n);
688 polygon_info->edges[edge].points=points;
689 polygon_info->edges[edge].bounds=bounds;
690 polygon_info->edges[edge].bounds.y1=points[0].y;
691 polygon_info->edges[edge].bounds.y2=points[n-1].y;
692 polygon_info->number_edges=edge+1;
695 points=(
PointInfo *) AcquireQuantumMemory((
size_t) number_points,
699 (void) ThrowMagickException(exception,GetMagickModule(),
700 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
701 return(DestroyPolygonInfo(polygon_info));
704 ghostline=MagickFalse;
710 direction=next_direction;
713 if (n == (ssize_t) number_points)
716 points=(
PointInfo *) ResizeQuantumMemory(points,(
size_t) number_points,
720 (void) ThrowMagickException(exception,GetMagickModule(),
721 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
722 return(DestroyPolygonInfo(polygon_info));
725 point=path_info[i].point;
727 if (point.x < bounds.x1)
729 if (point.x > bounds.x2)
736 points=(
PointInfo *) RelinquishMagickMemory(points);
739 if (edge == number_edges)
742 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
743 polygon_info->edges,(
size_t) number_edges,
744 sizeof(*polygon_info->edges));
745 if (polygon_info->edges == (
EdgeInfo *) NULL)
747 (void) ThrowMagickException(exception,GetMagickModule(),
748 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
749 return(DestroyPolygonInfo(polygon_info));
752 polygon_info->edges[edge].number_points=(size_t) n;
753 polygon_info->edges[edge].scanline=(-1.0);
754 polygon_info->edges[edge].highwater=0;
755 polygon_info->edges[edge].ghostline=ghostline;
756 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
758 ReversePoints(points,(
size_t) n);
759 polygon_info->edges[edge].points=points;
760 polygon_info->edges[edge].bounds=bounds;
761 polygon_info->edges[edge].bounds.y1=points[0].y;
762 polygon_info->edges[edge].bounds.y2=points[n-1].y;
764 ghostline=MagickFalse;
766 polygon_info->number_edges=edge;
769 polygon_info->number_edges=edge;
770 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(polygon_info->edges,
771 polygon_info->number_edges,
sizeof(*polygon_info->edges));
772 if (polygon_info->edges == (
EdgeInfo *) NULL)
774 (void) ThrowMagickException(exception,GetMagickModule(),
775 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
776 return(DestroyPolygonInfo(polygon_info));
778 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
783 edge_info=polygon_info->edges+i;
784 edge_info->points=(
PointInfo *) ResizeQuantumMemory(edge_info->points,
785 edge_info->number_points,
sizeof(*edge_info->points));
786 if (edge_info->points == (
PointInfo *) NULL)
788 (void) ThrowMagickException(exception,GetMagickModule(),
789 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
790 return(DestroyPolygonInfo(polygon_info));
793 qsort(polygon_info->edges,(
size_t) polygon_info->number_edges,
794 sizeof(*polygon_info->edges),DrawCompareEdges);
795 if ((GetLogEventMask() & DrawEvent) != 0)
796 LogPolygonInfo(polygon_info);
797 return(polygon_info);
830static void LogPathInfo(
const PathInfo *path_info)
835 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin vector-path");
836 for (p=path_info; p->code != EndCode; p++)
837 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
838 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
839 "moveto ghostline" : p->code == OpenCode ?
"moveto open" :
840 p->code == MoveToCode ?
"moveto" : p->code == LineToCode ?
"lineto" :
842 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end vector-path");
872 switch (primitive_info->primitive)
883 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
884 path_info=(
PathInfo *) AcquireQuantumMemory((
size_t) (3UL*i+1UL),
888 (void) ThrowMagickException(exception,GetMagickModule(),
889 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
893 closed_subpath=MagickFalse;
900 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
903 if (coordinates <= 0)
908 coordinates=primitive_info[i].coordinates;
909 p=primitive_info[i].point;
912 closed_subpath=primitive_info[i].closed_subpath;
915 if ((code == MoveToCode) || (coordinates <= 0) ||
916 (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
917 (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
922 path_info[n].code=code;
923 path_info[n].point=primitive_info[i].point;
924 q=primitive_info[i].point;
929 if (closed_subpath != MagickFalse)
931 closed_subpath=MagickFalse;
937 path_info[start].code=OpenCode;
938 path_info[n].code=GhostlineCode;
939 path_info[n].point=primitive_info[i].point;
941 path_info[n].code=LineToCode;
942 path_info[n].point=p;
945 path_info[n].code=EndCode;
946 path_info[n].point.x=0.0;
947 path_info[n].point.y=0.0;
948 if (IsEventLogging() != MagickFalse)
949 LogPathInfo(path_info);
950 path_info=(
PathInfo *) ResizeQuantumMemory(path_info,(
size_t) (n+1),
979 assert(draw_info != (
DrawInfo *) NULL);
980 assert(draw_info->signature == MagickCoreSignature);
981 if (IsEventLogging() != MagickFalse)
982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
983 if (draw_info->id != (
char *) NULL)
984 draw_info->id=DestroyString(draw_info->id);
985 if (draw_info->primitive != (
char *) NULL)
986 draw_info->primitive=DestroyString(draw_info->primitive);
987 if (draw_info->text != (
char *) NULL)
988 draw_info->text=DestroyString(draw_info->text);
989 if (draw_info->geometry != (
char *) NULL)
990 draw_info->geometry=DestroyString(draw_info->geometry);
991 if (draw_info->fill_pattern != (
Image *) NULL)
992 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
993 if (draw_info->stroke_pattern != (
Image *) NULL)
994 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
995 if (draw_info->font != (
char *) NULL)
996 draw_info->font=DestroyString(draw_info->font);
997 if (draw_info->metrics != (
char *) NULL)
998 draw_info->metrics=DestroyString(draw_info->metrics);
999 if (draw_info->family != (
char *) NULL)
1000 draw_info->family=DestroyString(draw_info->family);
1001 if (draw_info->encoding != (
char *) NULL)
1002 draw_info->encoding=DestroyString(draw_info->encoding);
1003 if (draw_info->density != (
char *) NULL)
1004 draw_info->density=DestroyString(draw_info->density);
1005 if (draw_info->server_name != (
char *) NULL)
1006 draw_info->server_name=(
char *)
1007 RelinquishMagickMemory(draw_info->server_name);
1008 if (draw_info->dash_pattern != (
double *) NULL)
1009 draw_info->dash_pattern=(
double *) RelinquishMagickMemory(
1010 draw_info->dash_pattern);
1011 if (draw_info->gradient.stops != (
StopInfo *) NULL)
1012 draw_info->gradient.stops=(
StopInfo *) RelinquishMagickMemory(
1013 draw_info->gradient.stops);
1014 if (draw_info->clip_mask != (
char *) NULL)
1015 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
1016 if (draw_info->clipping_mask != (
Image *) NULL)
1017 draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
1018 if (draw_info->composite_mask != (
Image *) NULL)
1019 draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
1020 if (draw_info->image_info != (
ImageInfo *) NULL)
1021 draw_info->image_info=DestroyImageInfo(draw_info->image_info);
1022 draw_info->signature=(~MagickCoreSignature);
1023 draw_info=(
DrawInfo *) RelinquishMagickMemory(draw_info);
1074 inverse_edge.x1=edge->x1;
1075 inverse_edge.y1=edge->y1;
1076 inverse_edge.x2=edge->x2;
1077 inverse_edge.y2=edge->y2;
1078 z=affine->ry*y+affine->tx;
1079 if (affine->sx >= MagickEpsilon)
1081 intercept=(-z/affine->sx);
1083 if (x > inverse_edge.x1)
1085 intercept=(-z+(double) image->columns)/affine->sx;
1087 if (x < inverse_edge.x2)
1091 if (affine->sx < -MagickEpsilon)
1093 intercept=(-z+(double) image->columns)/affine->sx;
1095 if (x > inverse_edge.x1)
1097 intercept=(-z/affine->sx);
1099 if (x < inverse_edge.x2)
1103 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
1105 inverse_edge.x2=edge->x1;
1106 return(inverse_edge);
1111 z=affine->sy*y+affine->ty;
1112 if (affine->rx >= MagickEpsilon)
1114 intercept=(-z/affine->rx);
1116 if (x > inverse_edge.x1)
1118 intercept=(-z+(double) image->rows)/affine->rx;
1120 if (x < inverse_edge.x2)
1124 if (affine->rx < -MagickEpsilon)
1126 intercept=(-z+(double) image->rows)/affine->rx;
1128 if (x > inverse_edge.x1)
1130 intercept=(-z/affine->rx);
1132 if (x < inverse_edge.x2)
1136 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
1138 inverse_edge.x2=edge->x2;
1139 return(inverse_edge);
1141 return(inverse_edge);
1152 determinant=MagickSafeReciprocal(affine->sx*affine->sy-affine->rx*
1154 inverse_affine.sx=determinant*affine->sy;
1155 inverse_affine.rx=determinant*(-affine->rx);
1156 inverse_affine.ry=determinant*(-affine->ry);
1157 inverse_affine.sy=determinant*affine->sx;
1158 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1160 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1162 return(inverse_affine);
1165MagickExport MagickBooleanType DrawAffineImage(
Image *image,
1200 assert(image != (
Image *) NULL);
1201 assert(image->signature == MagickCoreSignature);
1202 if (IsEventLogging() != MagickFalse)
1203 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1204 assert(source != (
const Image *) NULL);
1205 assert(source->signature == MagickCoreSignature);
1209 extent[1].x=(double) source->columns;
1211 extent[2].x=(double) source->columns;
1212 extent[2].y=(double) source->rows;
1214 extent[3].y=(double) source->rows;
1215 for (i=0; i < 4; i++)
1221 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1222 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1226 for (i=1; i < 4; i++)
1228 if (min.x > extent[i].x)
1230 if (min.y > extent[i].y)
1232 if (max.x < extent[i].x)
1234 if (max.y < extent[i].y)
1240 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1241 return(MagickFalse);
1247 inverse_affine=InverseAffineMatrix(affine);
1250 if (edge.y2 > ((
double) image->rows-1.0))
1251 edge.y2=(double) image->rows-1.0;
1252 GetPixelInfo(image,&zero);
1253 start=CastDoubleToSsizeT(ceil(edge.y1-0.5));
1254 stop=CastDoubleToSsizeT(floor(edge.y2+0.5));
1255 source_view=AcquireVirtualCacheView(source,exception);
1256 image_view=AcquireAuthenticCacheView(image,exception);
1257#if defined(MAGICKCORE_OPENMP_SUPPORT)
1258 #pragma omp parallel for schedule(static) shared(status) \
1259 magick_number_threads(source,image,(size_t) (stop-start),2)
1261 for (y=start; y <= stop; y++)
1279 if (status == MagickFalse)
1281 inverse_edge=AffineEdge(source,&inverse_affine,(
double) y,&edge);
1282 if (inverse_edge.x2 < inverse_edge.x1)
1284 if (inverse_edge.x1 < 0.0)
1285 inverse_edge.x1=0.0;
1286 if (inverse_edge.x2 > ((
double) image->columns-1.0))
1287 inverse_edge.x2=(double) image->columns-1.0;
1288 q=GetCacheViewAuthenticPixels(image_view,CastDoubleToSsizeT(
1289 ceil(inverse_edge.x1-0.5)),y,(
size_t) CastDoubleToSsizeT(floor(
1290 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
1291 if (q == (Quantum *) NULL)
1295 for (x=CastDoubleToSsizeT(ceil(inverse_edge.x1-0.5));
1296 x <= CastDoubleToSsizeT(floor(inverse_edge.x2+0.5)); x++)
1298 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1300 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1302 status=InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
1303 point.x,point.y,&pixel,exception);
1304 if (status == MagickFalse)
1306 GetPixelInfoPixel(image,q,&composite);
1307 CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
1309 SetPixelViaPixelInfo(image,&composite,q);
1310 q+=(ptrdiff_t) GetPixelChannels(image);
1312 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1315 source_view=DestroyCacheView(source_view);
1316 image_view=DestroyCacheView(image_view);
1352static MagickBooleanType DrawBoundingRectangles(
Image *image,
1382 (void) memset(primitive_info,0,
sizeof(primitive_info));
1383 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1384 status=QueryColorCompliance(
"#000F",AllCompliance,&clone_info->fill,
1386 if (status == MagickFalse)
1388 clone_info=DestroyDrawInfo(clone_info);
1389 return(MagickFalse);
1393 if (clone_info->density != (
char *) NULL)
1401 flags=ParseGeometry(clone_info->density,&geometry_info);
1402 if ((flags & RhoValue) != 0)
1403 resolution.x=geometry_info.rho;
1404 resolution.y=resolution.x;
1405 if ((flags & SigmaValue) != 0)
1406 resolution.y=geometry_info.sigma;
1408 mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
1409 clone_info->stroke_width/2.0;
1416 bounds=polygon_info->edges[0].bounds;
1417 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1419 if (polygon_info->edges[i].bounds.x1 < (
double) bounds.x1)
1420 bounds.x1=polygon_info->edges[i].bounds.x1;
1421 if (polygon_info->edges[i].bounds.y1 < (
double) bounds.y1)
1422 bounds.y1=polygon_info->edges[i].bounds.y1;
1423 if (polygon_info->edges[i].bounds.x2 > (
double) bounds.x2)
1424 bounds.x2=polygon_info->edges[i].bounds.x2;
1425 if (polygon_info->edges[i].bounds.y2 > (
double) bounds.y2)
1426 bounds.y2=polygon_info->edges[i].bounds.y2;
1429 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1430 image->columns ? (
double) image->columns-1 : bounds.x1;
1432 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1433 image->rows ? (
double) image->rows-1 : bounds.y1;
1435 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1436 image->columns ? (
double) image->columns-1 : bounds.x2;
1438 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1439 image->rows ? (
double) image->rows-1 : bounds.y2;
1440 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1442 if (polygon_info->edges[i].direction != 0)
1443 status=QueryColorCompliance(
"#f00",AllCompliance,&clone_info->stroke,
1446 status=QueryColorCompliance(
"#0f0",AllCompliance,&clone_info->stroke,
1448 if (status == MagickFalse)
1450 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1451 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1452 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1453 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1454 primitive_info[0].primitive=RectanglePrimitive;
1455 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1456 primitive_info[0].method=ReplaceMethod;
1457 coordinates=(ssize_t) primitive_info[0].coordinates;
1458 primitive_info[coordinates].primitive=UndefinedPrimitive;
1459 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1460 if (status == MagickFalse)
1463 if (i < (ssize_t) polygon_info->number_edges)
1465 clone_info=DestroyDrawInfo(clone_info);
1466 return(status == 0 ? MagickFalse : MagickTrue);
1469 status=QueryColorCompliance(
"#00f",AllCompliance,&clone_info->stroke,
1471 if (status == MagickFalse)
1473 clone_info=DestroyDrawInfo(clone_info);
1474 return(MagickFalse);
1476 start.x=(double) (bounds.x1-mid);
1477 start.y=(double) (bounds.y1-mid);
1478 end.x=(double) (bounds.x2+mid);
1479 end.y=(double) (bounds.y2+mid);
1480 primitive_info[0].primitive=RectanglePrimitive;
1481 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1482 primitive_info[0].method=ReplaceMethod;
1483 coordinates=(ssize_t) primitive_info[0].coordinates;
1484 primitive_info[coordinates].primitive=UndefinedPrimitive;
1485 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1486 clone_info=DestroyDrawInfo(clone_info);
1487 return(status == 0 ? MagickFalse : MagickTrue);
1520static MagickBooleanType DrawClipPath_(
Image *image,
1521 const DrawInfo *draw_info,
const char *
id,
const size_t depth,
1533 clip_path=GetImageArtifact(image,
id);
1534 if (clip_path == (
const char *) NULL)
1535 return(MagickFalse);
1536 clipping_mask=DrawClippingMask(image,draw_info,draw_info->clip_mask,clip_path,
1538 if (clipping_mask == (
Image *) NULL)
1539 return(MagickFalse);
1540 status=SetImageMask(image,WritePixelMask,clipping_mask,exception);
1541 clipping_mask=DestroyImage(clipping_mask);
1545MagickExport MagickBooleanType DrawClipPath(
Image *image,
1548 return(DrawClipPath_(image,draw_info,
id,0,exception));
1587 const char *
id,
const char *clip_path,
const size_t depth,
1603 assert(image != (
Image *) NULL);
1604 assert(image->signature == MagickCoreSignature);
1605 assert(draw_info != (
const DrawInfo *) NULL);
1606 if (IsEventLogging() != MagickFalse)
1607 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1608 clip_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1609 status=SetImageExtent(clip_mask,image->columns,image->rows,exception);
1610 if (status == MagickFalse)
1611 return(DestroyImage(clip_mask));
1612 status=SetImageMask(clip_mask,WritePixelMask,(
Image *) NULL,exception);
1613 status=QueryColorCompliance(
"#0000",AllCompliance,
1614 &clip_mask->background_color,exception);
1615 clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1616 clip_mask->background_color.alpha_trait=BlendPixelTrait;
1617 status=SetImageBackgroundColor(clip_mask,exception);
1618 if (draw_info->debug != MagickFalse)
1619 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin clip-path %s",
1621 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1622 (void) CloneString(&clone_info->primitive,clip_path);
1623 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1625 if (clone_info->clip_mask != (
char *) NULL)
1626 clone_info->clip_mask=DestroyString(clone_info->clip_mask);
1627 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1629 clone_info->stroke_width=0.0;
1630 clone_info->alpha=OpaqueAlpha;
1631 clone_info->clip_path=MagickTrue;
1632 status=RenderMVGContent(clip_mask,clone_info,depth+1,exception);
1633 clone_info=DestroyDrawInfo(clone_info);
1634 separate_mask=SeparateImage(clip_mask,AlphaChannel,exception);
1635 if (separate_mask == (
Image *) NULL)
1639 clip_mask=DestroyImage(clip_mask);
1640 clip_mask=separate_mask;
1641 status&=(MagickStatusType) NegateImage(clip_mask,MagickFalse,exception);
1643 if (status == MagickFalse)
1644 clip_mask=DestroyImage(clip_mask);
1645 if (draw_info->debug != MagickFalse)
1646 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end clip-path");
1685 const char *
id,
const char *mask_path,
const size_t depth,
1701 assert(image != (
Image *) NULL);
1702 assert(image->signature == MagickCoreSignature);
1703 assert(draw_info != (
const DrawInfo *) NULL);
1704 if (IsEventLogging() != MagickFalse)
1705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1706 composite_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1707 status=SetImageExtent(composite_mask,image->columns,image->rows,exception);
1708 if (status == MagickFalse)
1709 return(DestroyImage(composite_mask));
1710 status=SetImageMask(composite_mask,CompositePixelMask,(
Image *) NULL,
1712 status=QueryColorCompliance(
"#0000",AllCompliance,
1713 &composite_mask->background_color,exception);
1714 composite_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1715 composite_mask->background_color.alpha_trait=BlendPixelTrait;
1716 (void) SetImageBackgroundColor(composite_mask,exception);
1717 if (draw_info->debug != MagickFalse)
1718 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin mask-path %s",
1720 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1721 (void) CloneString(&clone_info->primitive,mask_path);
1722 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1724 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1726 clone_info->stroke_width=0.0;
1727 clone_info->alpha=OpaqueAlpha;
1728 status=RenderMVGContent(composite_mask,clone_info,depth+1,exception);
1729 clone_info=DestroyDrawInfo(clone_info);
1730 separate_mask=SeparateImage(composite_mask,AlphaChannel,exception);
1731 if (separate_mask != (
Image *) NULL)
1733 composite_mask=DestroyImage(composite_mask);
1734 composite_mask=separate_mask;
1735 status=NegateImage(composite_mask,MagickFalse,exception);
1736 if (status == MagickFalse)
1737 composite_mask=DestroyImage(composite_mask);
1739 if (status == MagickFalse)
1740 composite_mask=DestroyImage(composite_mask);
1741 if (draw_info->debug != MagickFalse)
1742 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end mask-path");
1743 return(composite_mask);
1777static MagickBooleanType DrawDashPolygon(
const DrawInfo *draw_info,
1808 assert(draw_info != (
const DrawInfo *) NULL);
1809 if (draw_info->debug != MagickFalse)
1810 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-dash");
1811 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1812 number_vertices=(size_t) i;
1813 dash_polygon=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
1814 (2UL*number_vertices+32UL),
sizeof(*dash_polygon));
1817 (void) ThrowMagickException(exception,GetMagickModule(),
1818 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1819 return(MagickFalse);
1821 (void) memset(dash_polygon,0,(2UL*number_vertices+32UL)*
1822 sizeof(*dash_polygon));
1823 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1824 clone_info->miterlimit=0;
1825 dash_polygon[0]=primitive_info[0];
1826 dash_polygon[0].closed_subpath=MagickFalse;
1827 scale=ExpandAffine(&draw_info->affine);
1828 length=scale*draw_info->dash_pattern[0];
1829 offset=fabs(draw_info->dash_offset) >= MagickEpsilon ?
1830 scale*draw_info->dash_offset : 0.0;
1832 for (n=0; offset > 0.0; j=0)
1834 if (draw_info->dash_pattern[n] <= 0.0)
1836 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1837 if (offset > length)
1841 length=scale*draw_info->dash_pattern[n];
1844 if (offset < length)
1856 for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
1858 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1859 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1860 maximum_length=hypot(dx,dy);
1861 if (maximum_length > (
double) (MaxBezierCoordinates >> 2))
1863 if (fabs(length) < MagickEpsilon)
1865 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1867 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1869 length=scale*draw_info->dash_pattern[n];
1871 for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); )
1873 total_length+=length;
1874 if ((n & 0x01) != 0)
1876 dash_polygon[0]=primitive_info[0];
1877 dash_polygon[0].closed_subpath=MagickFalse;
1878 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1879 total_length*MagickSafeReciprocal(maximum_length));
1880 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1881 total_length*MagickSafeReciprocal(maximum_length));
1886 if ((j+1) > (ssize_t) number_vertices)
1888 dash_polygon[j]=primitive_info[i-1];
1889 dash_polygon[j].closed_subpath=MagickFalse;
1890 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1891 total_length*MagickSafeReciprocal(maximum_length));
1892 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1893 total_length*MagickSafeReciprocal(maximum_length));
1894 dash_polygon[j].coordinates=1;
1896 dash_polygon[0].coordinates=(size_t) j;
1897 dash_polygon[j].primitive=UndefinedPrimitive;
1898 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1899 dash_polygon,exception);
1900 if (status == MagickFalse)
1903 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1905 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1907 length=scale*draw_info->dash_pattern[n];
1909 length-=(maximum_length-total_length);
1910 if ((n & 0x01) != 0)
1912 dash_polygon[j]=primitive_info[i];
1913 dash_polygon[j].coordinates=1;
1916 if ((status != MagickFalse) && (total_length < maximum_length) &&
1917 ((n & 0x01) == 0) && (j > 1))
1919 dash_polygon[j]=primitive_info[i-1];
1920 dash_polygon[j].closed_subpath=MagickFalse;
1921 dash_polygon[j].point.x+=MagickEpsilon;
1922 dash_polygon[j].point.y+=MagickEpsilon;
1923 dash_polygon[j].coordinates=1;
1925 dash_polygon[0].coordinates=(size_t) j;
1926 dash_polygon[j].primitive=UndefinedPrimitive;
1927 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1928 dash_polygon,exception);
1930 dash_polygon=(
PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1931 clone_info=DestroyDrawInfo(clone_info);
1932 if (draw_info->debug != MagickFalse)
1933 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-dash");
1934 return(status != 0 ? MagickTrue : MagickFalse);
1965static inline double GetStopColorOffset(
const GradientInfo *gradient,
1966 const ssize_t x,
const ssize_t y)
1968 switch (gradient->type)
1970 case UndefinedGradient:
1971 case LinearGradient:
1986 gradient_vector=(&gradient->gradient_vector);
1987 p.x=gradient_vector->x2-gradient_vector->x1;
1988 p.y=gradient_vector->y2-gradient_vector->y1;
1989 q.x=(double) x-gradient_vector->x1;
1990 q.y=(double) y-gradient_vector->y1;
1991 length=sqrt(q.x*q.x+q.y*q.y);
1992 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
1993 gamma=MagickSafeReciprocal(gamma);
1994 scale=p.x*q.x+p.y*q.y;
1995 offset=gamma*scale*length;
1998 case RadialGradient:
2003 if (gradient->spread == RepeatSpread)
2005 v.x=(double) x-gradient->center.x;
2006 v.y=(double) y-gradient->center.y;
2007 return(sqrt(v.x*v.x+v.y*v.y));
2009 v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians(
2010 gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians(
2011 gradient->angle))))*MagickSafeReciprocal(gradient->radii.x);
2012 v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians(
2013 gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians(
2014 gradient->angle))))*MagickSafeReciprocal(gradient->radii.y);
2015 return(sqrt(v.x*v.x+v.y*v.y));
2021static int StopInfoCompare(
const void *x,
const void *y)
2029 if (stop_1->offset > stop_2->offset)
2031 if (fabs(stop_1->offset-stop_2->offset) <= MagickEpsilon)
2036MagickExport MagickBooleanType DrawGradientImage(
Image *image,
2072 assert(image != (
Image *) NULL);
2073 assert(image->signature == MagickCoreSignature);
2074 assert(draw_info != (
const DrawInfo *) NULL);
2075 if (IsEventLogging() != MagickFalse)
2076 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2077 gradient=(&draw_info->gradient);
2078 qsort(gradient->stops,gradient->number_stops,
sizeof(
StopInfo),
2080 gradient_vector=(&gradient->gradient_vector);
2081 point.x=gradient_vector->x2-gradient_vector->x1;
2082 point.y=gradient_vector->y2-gradient_vector->y1;
2083 length=sqrt(point.x*point.x+point.y*point.y);
2084 bounding_box=gradient->bounding_box;
2086 GetPixelInfo(image,&zero);
2087 image_view=AcquireAuthenticCacheView(image,exception);
2088 height=(size_t) (bounding_box.y+(ssize_t) bounding_box.height);
2089#if defined(MAGICKCORE_OPENMP_SUPPORT)
2090 #pragma omp parallel for schedule(static) shared(status) \
2091 magick_number_threads(image,image,height,1)
2093 for (y=bounding_box.y; y < (ssize_t) height; y++)
2114 if (status == MagickFalse)
2116 q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,y,(
size_t)
2117 bounding_box.width,1,exception);
2118 if (q == (Quantum *) NULL)
2125 offset=GetStopColorOffset(gradient,0,y);
2126 if (gradient->type != RadialGradient)
2127 offset*=MagickSafeReciprocal(length);
2128 width=(size_t) (bounding_box.x+(ssize_t) bounding_box.width);
2129 for (x=bounding_box.x; x < (ssize_t) width; x++)
2131 GetPixelInfoPixel(image,q,&pixel);
2132 switch (gradient->spread)
2134 case UndefinedSpread:
2137 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2138 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2140 offset=GetStopColorOffset(gradient,x,y);
2141 if (gradient->type != RadialGradient)
2142 offset*=MagickSafeReciprocal(length);
2144 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2145 if (offset < gradient->stops[i].offset)
2147 if ((offset < 0.0) || (i == 0))
2148 composite=gradient->stops[0].color;
2150 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
2151 composite=gradient->stops[gradient->number_stops-1].color;
2156 alpha=(offset-gradient->stops[i].offset)/
2157 (gradient->stops[j].offset-gradient->stops[i].offset);
2158 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2159 &gradient->stops[j].color,alpha,&composite);
2165 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2166 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2168 offset=GetStopColorOffset(gradient,x,y);
2169 if (gradient->type != RadialGradient)
2170 offset*=MagickSafeReciprocal(length);
2174 if ((ssize_t) fmod(offset,2.0) == 0)
2175 offset=fmod(offset,1.0);
2177 offset=1.0-fmod(offset,1.0);
2178 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2179 if (offset < gradient->stops[i].offset)
2182 composite=gradient->stops[0].color;
2184 if (i == (ssize_t) gradient->number_stops)
2185 composite=gradient->stops[gradient->number_stops-1].color;
2190 alpha=(offset-gradient->stops[i].offset)/
2191 (gradient->stops[j].offset-gradient->stops[i].offset);
2192 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2193 &gradient->stops[j].color,alpha,&composite);
2205 antialias=MagickFalse;
2207 if ((x != CastDoubleToSsizeT(ceil(gradient_vector->x1-0.5))) ||
2208 (y != CastDoubleToSsizeT(ceil(gradient_vector->y1-0.5))))
2210 offset=GetStopColorOffset(gradient,x,y);
2211 if (gradient->type == LinearGradient)
2213 repeat=fmod(offset,length);
2215 repeat=length-fmod(-repeat,length);
2217 repeat=fmod(offset,length);
2218 antialias=(repeat < length) && ((repeat+1.0) > length) ?
2219 MagickTrue : MagickFalse;
2220 offset=MagickSafeReciprocal(length)*repeat;
2224 repeat=fmod(offset,gradient->radius);
2226 repeat=gradient->radius-fmod(-repeat,gradient->radius);
2228 repeat=fmod(offset,gradient->radius);
2229 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
2231 offset=repeat*MagickSafeReciprocal(gradient->radius);
2234 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2235 if (offset < gradient->stops[i].offset)
2238 composite=gradient->stops[0].color;
2240 if (i == (ssize_t) gradient->number_stops)
2241 composite=gradient->stops[gradient->number_stops-1].color;
2246 alpha=(offset-gradient->stops[i].offset)/
2247 (gradient->stops[j].offset-gradient->stops[i].offset);
2248 if (antialias != MagickFalse)
2250 if (gradient->type == LinearGradient)
2251 alpha=length-repeat;
2253 alpha=gradient->radius-repeat;
2255 j=(ssize_t) gradient->number_stops-1L;
2257 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2258 &gradient->stops[j].color,alpha,&composite);
2263 CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha,
2265 SetPixelViaPixelInfo(image,&pixel,q);
2266 q+=(ptrdiff_t) GetPixelChannels(image);
2268 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2271 image_view=DestroyCacheView(image_view);
2307static inline MagickBooleanType CheckPrimitiveExtent(
MVGInfo *mvg_info,
2322 if ((mvg_info == (
MVGInfo *) NULL) ||
2325 (mvg_info->extent == (
size_t *) NULL))
2326 return(MagickFalse);
2327 proposed_extent=mvg_info->offset+pad+PrimitiveExtentPad+1.0;
2328 if ((proposed_extent <= 0.0) || (proposed_extent > (
double) MAGICK_SIZE_MAX))
2329 return(MagickFalse);
2330 extent=CastDoubleToSizeT(ceil(proposed_extent));
2331 if (extent <= *mvg_info->extent)
2334 return(MagickFalse);
2342 extent=(size_t) PrimitiveExtentPad;
2343 primitive_info=(
PrimitiveInfo *) AcquireCriticalMemory(extent*
2344 sizeof(*primitive_info));
2345 (void) memset(primitive_info,0,extent*
sizeof(*primitive_info));
2346 *mvg_info->primitive_info=primitive_info;
2347 *mvg_info->extent=extent;
2349 ThrowMagickException(mvg_info->exception,GetMagickModule(),
2350 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2351 return(MagickFalse);
2353 primitive_info[extent].primitive=UndefinedPrimitive;
2354 primitive_info[extent].text=(
char *) NULL;
2358 for (i=(ssize_t) *mvg_info->extent; i < (ssize_t) extent; i++)
2360 primitive_info[i].primitive=UndefinedPrimitive;
2361 primitive_info[i].text=(
char *) NULL;
2363 *mvg_info->primitive_info=primitive_info;
2364 *mvg_info->extent=extent;
2368static inline double GetDrawValue(
const char *magick_restrict
string,
2369 char **magick_restrict sentinel)
2372 **magick_restrict q;
2378 value=InterpretLocaleValue(
string,q);
2383static int MVGMacroCompare(
const void *target,
const void *source)
2389 p=(
const char *) target;
2390 q=(
const char *) source;
2391 return(strcmp(p,q));
2413 if (primitive == (
const char *) NULL)
2415 macros=NewSplayTree(MVGMacroCompare,RelinquishMagickMemory,
2416 RelinquishMagickMemory);
2417 macro=AcquireString(primitive);
2418 token=AcquireString(primitive);
2419 extent=strlen(token)+MagickPathExtent;
2420 for (q=primitive; *q !=
'\0'; )
2422 if (GetNextToken(q,&q,extent,token) < 1)
2426 if (LocaleCompare(
"push",token) == 0)
2432 (void) GetNextToken(q,&q,extent,token);
2436 name[MagickPathExtent];
2447 (void) GetNextToken(q,&q,extent,token);
2450 (void) CopyMagickString(name,token,MagickPathExtent);
2452 for (p=q; *p !=
'\0'; )
2454 if (GetNextToken(p,&p,extent,token) < 1)
2458 if (LocaleCompare(token,
"pop") == 0)
2460 end=p-strlen(token)-1;
2463 if (LocaleCompare(token,
"push") == 0)
2465 if (n++ >= MaxVectorRecursionDepth)
2467 (void) ThrowMagickException(exception,GetMagickModule(),
2468 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2472 if ((n == 0) && (end >= start))
2475 length=(size_t) (end-start);
2480 (void) GetNextToken(p,&p,extent,token);
2483 (void) CopyMagickString(macro,start,length);
2484 (void) AddValueToSplayTree(macros,ConstantString(name),
2485 ConstantString(macro));
2493 token=DestroyString(token);
2494 macro=DestroyString(macro);
2498static inline MagickBooleanType IsValidListChar(
int c)
2500 if ((c >=
'0') && (c <=
'9'))
2514 return(MagickFalse);
2519static inline MagickBooleanType IsValidPoint(
const char *point)
2527 value=GetDrawValue(point,&p);
2528 return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
2532static inline MagickBooleanType TracePoint(
PrimitiveInfo *primitive_info,
2535 primitive_info->point=point;
2536 primitive_info->coordinates=1;
2537 primitive_info->closed_subpath=MagickFalse;
2538 primitive_info->text=(
char *) NULL;
2542static MagickBooleanType RenderMVGContent(
Image *image,
2545#define RenderImageTag "Render/Image"
2552 keyword[MagickPathExtent],
2553 geometry[MagickPathExtent],
2555 pattern[MagickPathExtent],
2619 assert(image != (
Image *) NULL);
2620 assert(image->signature == MagickCoreSignature);
2621 assert(draw_info != (
DrawInfo *) NULL);
2622 assert(draw_info->signature == MagickCoreSignature);
2623 if (IsEventLogging() != MagickFalse)
2624 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2625 if (depth >= MaxVectorRecursionDepth)
2626 ThrowBinaryException(DrawError,
"VectorGraphicsNestedTooDeeply",
2628 if ((draw_info->primitive == (
char *) NULL) ||
2629 (*draw_info->primitive ==
'\0'))
2630 return(MagickFalse);
2631 if (draw_info->debug != MagickFalse)
2632 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"begin draw-image");
2633 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2634 return(MagickFalse);
2635 if ((image->alpha_trait & BlendPixelTrait) == 0)
2637 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2638 if (status == MagickFalse)
2639 return(MagickFalse);
2641 if ((*draw_info->primitive ==
'@') && (strlen(draw_info->primitive) > 1) &&
2642 (*(draw_info->primitive+1) !=
'-') && (depth == 0))
2643 primitive=FileToString(draw_info->primitive,~0UL,exception);
2645 primitive=AcquireString(draw_info->primitive);
2646 if (primitive == (
char *) NULL)
2647 return(MagickFalse);
2648 primitive_extent=(double) strlen(primitive);
2649 (void) SetImageArtifact(image,
"mvg:vector-graphics",primitive);
2656 graphic_context=(
DrawInfo **) AcquireMagickMemory(
sizeof(*graphic_context));
2657 if (graphic_context == (
DrawInfo **) NULL)
2659 primitive=DestroyString(primitive);
2660 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2663 number_points=(size_t) PrimitiveExtentPad;
2664 primitive_info=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
2665 (number_points+1),
sizeof(*primitive_info));
2668 primitive=DestroyString(primitive);
2669 for ( ; n >= 0; n--)
2670 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2671 graphic_context=(
DrawInfo **) RelinquishMagickMemory(graphic_context);
2672 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2675 (void) memset(primitive_info,0,(
size_t) (number_points+1)*
2676 sizeof(*primitive_info));
2677 (void) memset(&mvg_info,0,
sizeof(mvg_info));
2678 mvg_info.primitive_info=(&primitive_info);
2679 mvg_info.extent=(&number_points);
2680 mvg_info.exception=exception;
2681 graphic_context[n]=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
2682 graphic_context[n]->viewbox=image->page;
2683 if ((image->page.width == 0) || (image->page.height == 0))
2685 graphic_context[n]->viewbox.width=image->columns;
2686 graphic_context[n]->viewbox.height=image->rows;
2688 token=AcquireString(primitive);
2689 extent=strlen(token)+MagickPathExtent;
2693 macros=GetMVGMacros(primitive,exception);
2695 for (q=primitive; *q !=
'\0'; )
2700 if (GetNextToken(q,&q,MagickPathExtent,keyword) < 1)
2702 if (*keyword ==
'\0')
2704 if (*keyword ==
'#')
2709 while ((*q !=
'\n') && (*q !=
'\0'))
2713 p=q-strlen(keyword)-1;
2714 primitive_type=UndefinedPrimitive;
2715 current=graphic_context[n]->affine;
2716 GetAffineMatrix(&affine);
2725 if (LocaleCompare(
"affine",keyword) == 0)
2727 (void) GetNextToken(q,&q,extent,token);
2728 affine.sx=GetDrawValue(token,&next_token);
2729 if (token == next_token)
2730 ThrowPointExpectedException(token,exception);
2731 (void) GetNextToken(q,&q,extent,token);
2732 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2733 ThrowPointExpectedException(token,exception);
2735 (void) GetNextToken(q,&q,extent,token);
2736 affine.ry=GetDrawValue(token,&next_token);
2737 if (token == next_token)
2738 ThrowPointExpectedException(token,exception);
2739 (void) GetNextToken(q,&q,extent,token);
2740 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2741 ThrowPointExpectedException(token,exception);
2743 (void) GetNextToken(q,&q,extent,token);
2744 affine.rx=GetDrawValue(token,&next_token);
2745 if (token == next_token)
2746 ThrowPointExpectedException(token,exception);
2747 (void) GetNextToken(q,&q,extent,token);
2748 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2749 ThrowPointExpectedException(token,exception);
2751 (void) GetNextToken(q,&q,extent,token);
2752 affine.sy=GetDrawValue(token,&next_token);
2753 if (token == next_token)
2754 ThrowPointExpectedException(token,exception);
2755 (void) GetNextToken(q,&q,extent,token);
2756 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2757 ThrowPointExpectedException(token,exception);
2759 (void) GetNextToken(q,&q,extent,token);
2760 affine.tx=GetDrawValue(token,&next_token);
2761 if (token == next_token)
2762 ThrowPointExpectedException(token,exception);
2763 (void) GetNextToken(q,&q,extent,token);
2764 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2765 ThrowPointExpectedException(token,exception);
2767 (void) GetNextToken(q,&q,extent,token);
2768 affine.ty=GetDrawValue(token,&next_token);
2769 if (token == next_token)
2770 ThrowPointExpectedException(token,exception);
2773 if (LocaleCompare(
"alpha",keyword) == 0)
2775 primitive_type=AlphaPrimitive;
2778 if (LocaleCompare(
"arc",keyword) == 0)
2780 primitive_type=ArcPrimitive;
2789 if (LocaleCompare(
"bezier",keyword) == 0)
2791 primitive_type=BezierPrimitive;
2794 if (LocaleCompare(
"border-color",keyword) == 0)
2796 (void) GetNextToken(q,&q,extent,token);
2797 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2798 &graphic_context[n]->border_color,exception);
2807 if (LocaleCompare(
"class",keyword) == 0)
2812 (void) GetNextToken(q,&q,extent,token);
2813 if ((*token ==
'\0') || (*token ==
';'))
2821 for (i=0; i <= n; i++)
2822 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2826 if (classDepth++ >= MaxVectorRecursionDepth)
2828 (void) ThrowMagickException(exception,GetMagickModule(),
2829 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2833 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2834 if ((graphic_context[n]->render != MagickFalse) &&
2835 (mvg_class != (
const char *) NULL) && (p > primitive))
2846 (void) CloneString(&graphic_context[n]->
id,token);
2847 offset=(ssize_t) (p-primitive);
2848 elements=AcquireString(primitive);
2849 elements[offset]=
'\0';
2850 (void) ConcatenateString(&elements,mvg_class);
2851 (void) ConcatenateString(&elements,
"\n");
2852 (void) ConcatenateString(&elements,q);
2853 primitive=DestroyString(primitive);
2859 if (LocaleCompare(
"clip-path",keyword) == 0)
2867 (void) GetNextToken(q,&q,extent,token);
2873 (void) CloneString(&graphic_context[n]->clip_mask,token);
2874 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2875 if (clip_path != (
const char *) NULL)
2877 if (graphic_context[n]->clipping_mask != (
Image *) NULL)
2878 graphic_context[n]->clipping_mask=
2879 DestroyImage(graphic_context[n]->clipping_mask);
2880 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2881 graphic_context[n],token,clip_path,depth+1,exception);
2882 if (graphic_context[n]->compliance != SVGCompliance)
2884 clip_path=(
const char *) GetValueFromSplayTree(macros,
2885 graphic_context[n]->clip_mask);
2886 if (clip_path != (
const char *) NULL)
2887 (
void) SetImageArtifact(image,
2888 graphic_context[n]->clip_mask,clip_path);
2889 status&=(MagickStatusType) DrawClipPath_(image,
2890 graphic_context[n],graphic_context[n]->clip_mask,
2896 if (LocaleCompare(
"clip-rule",keyword) == 0)
2901 (void) GetNextToken(q,&q,extent,token);
2902 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2904 if (fill_rule == -1)
2909 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2912 if (LocaleCompare(
"clip-units",keyword) == 0)
2917 (void) GetNextToken(q,&q,extent,token);
2918 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2920 if (clip_units == -1)
2925 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2926 if (clip_units == ObjectBoundingBox)
2928 GetAffineMatrix(¤t);
2929 affine.sx=draw_info->bounds.x2;
2930 affine.sy=draw_info->bounds.y2;
2931 affine.tx=draw_info->bounds.x1;
2932 affine.ty=draw_info->bounds.y1;
2937 if (LocaleCompare(
"circle",keyword) == 0)
2939 primitive_type=CirclePrimitive;
2942 if (LocaleCompare(
"color",keyword) == 0)
2944 primitive_type=ColorPrimitive;
2947 if (LocaleCompare(
"compliance",keyword) == 0)
2953 (void) GetNextToken(q,&q,extent,token);
2954 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2955 MagickComplianceOptions,MagickFalse,token);
2958 if (LocaleCompare(
"currentColor",keyword) == 0)
2960 (void) GetNextToken(q,&q,extent,token);
2969 if (LocaleCompare(
"decorate",keyword) == 0)
2974 (void) GetNextToken(q,&q,extent,token);
2975 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2982 graphic_context[n]->decorate=(DecorationType) decorate;
2985 if (LocaleCompare(
"density",keyword) == 0)
2987 (void) GetNextToken(q,&q,extent,token);
2988 (void) CloneString(&graphic_context[n]->density,token);
2991 if (LocaleCompare(
"direction",keyword) == 0)
2996 (void) GetNextToken(q,&q,extent,token);
2997 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2999 if (direction == -1)
3002 graphic_context[n]->direction=(DirectionType) direction;
3011 if (LocaleCompare(
"ellipse",keyword) == 0)
3013 primitive_type=EllipsePrimitive;
3016 if (LocaleCompare(
"encoding",keyword) == 0)
3018 (void) GetNextToken(q,&q,extent,token);
3019 (void) CloneString(&graphic_context[n]->encoding,token);
3028 if (LocaleCompare(
"fill",keyword) == 0)
3033 (void) GetNextToken(q,&q,extent,token);
3034 if (graphic_context[n]->clip_path != MagickFalse)
3036 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3037 if (mvg_class != (
const char *) NULL)
3039 (void) DrawPatternPath(image,draw_info,mvg_class,
3040 &graphic_context[n]->fill_pattern,exception);
3043 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3044 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3046 (void) DrawPatternPath(image,draw_info,token,
3047 &graphic_context[n]->fill_pattern,exception);
3050 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3051 &graphic_context[n]->fill,exception);
3052 if (graphic_context[n]->fill_alpha != (
double) OpaqueAlpha)
3053 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3056 if (LocaleCompare(
"fill-opacity",keyword) == 0)
3061 (void) GetNextToken(q,&q,extent,token);
3062 if (graphic_context[n]->clip_path != MagickFalse)
3064 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3065 opacity=MagickMin(MagickMax(factor*
3066 GetDrawValue(token,&next_token),0.0),1.0);
3067 if (token == next_token)
3068 ThrowPointExpectedException(token,exception);
3069 if (graphic_context[n]->compliance == SVGCompliance)
3070 graphic_context[n]->fill_alpha*=opacity;
3072 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3073 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3074 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3076 graphic_context[n]->fill.alpha=(MagickRealType)
3077 ClampToQuantum((
double) QuantumRange*opacity);
3078 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3081 if (LocaleCompare(
"fill-rule",keyword) == 0)
3086 (void) GetNextToken(q,&q,extent,token);
3087 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3089 if (fill_rule == -1)
3094 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3097 if (LocaleCompare(
"font",keyword) == 0)
3099 (void) GetNextToken(q,&q,extent,token);
3100 (void) CloneString(&graphic_context[n]->font,token);
3101 if (LocaleCompare(
"none",token) == 0)
3102 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3103 graphic_context[n]->font);
3106 if (LocaleCompare(
"font-family",keyword) == 0)
3108 (void) GetNextToken(q,&q,extent,token);
3109 (void) CloneString(&graphic_context[n]->family,token);
3112 if (LocaleCompare(
"font-size",keyword) == 0)
3114 (void) GetNextToken(q,&q,extent,token);
3115 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3116 if (token == next_token)
3117 ThrowPointExpectedException(token,exception);
3120 if (LocaleCompare(
"font-stretch",keyword) == 0)
3125 (void) GetNextToken(q,&q,extent,token);
3126 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3132 graphic_context[n]->stretch=(StretchType) stretch;
3135 if (LocaleCompare(
"font-style",keyword) == 0)
3140 (void) GetNextToken(q,&q,extent,token);
3141 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3147 graphic_context[n]->style=(StyleType) style;
3150 if (LocaleCompare(
"font-weight",keyword) == 0)
3155 (void) GetNextToken(q,&q,extent,token);
3156 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3158 weight=(ssize_t) StringToUnsignedLong(token);
3159 graphic_context[n]->weight=(size_t) weight;
3168 if (LocaleCompare(
"gradient-units",keyword) == 0)
3170 (void) GetNextToken(q,&q,extent,token);
3173 if (LocaleCompare(
"gravity",keyword) == 0)
3178 (void) GetNextToken(q,&q,extent,token);
3179 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3185 graphic_context[n]->gravity=(GravityType) gravity;
3194 if (LocaleCompare(
"image",keyword) == 0)
3199 primitive_type=ImagePrimitive;
3200 (void) GetNextToken(q,&q,extent,token);
3201 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3207 graphic_context[n]->compose=(CompositeOperator) compose;
3210 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3212 (void) GetNextToken(q,&q,extent,token);
3213 graphic_context[n]->interline_spacing=GetDrawValue(token,
3215 if (token == next_token)
3216 ThrowPointExpectedException(token,exception);
3219 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3221 (void) GetNextToken(q,&q,extent,token);
3222 graphic_context[n]->interword_spacing=GetDrawValue(token,
3224 if (token == next_token)
3225 ThrowPointExpectedException(token,exception);
3234 if (LocaleCompare(
"kerning",keyword) == 0)
3236 (void) GetNextToken(q,&q,extent,token);
3237 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3238 if (token == next_token)
3239 ThrowPointExpectedException(token,exception);
3248 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3250 (void) GetNextToken(q,&q,extent,token);
3251 if (IsValidPoint(token) == MagickFalse)
3253 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
3254 clone_info->text=AcquireString(
" ");
3255 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,&metrics,
3257 graphic_context[n]->kerning=metrics.width*
3258 GetDrawValue(token,&next_token);
3259 clone_info=DestroyDrawInfo(clone_info);
3260 if (token == next_token)
3261 ThrowPointExpectedException(token,exception);
3264 if (LocaleCompare(
"line",keyword) == 0)
3266 primitive_type=LinePrimitive;
3275 if (LocaleCompare(
"mask",keyword) == 0)
3283 (void) GetNextToken(q,&q,extent,token);
3284 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3285 if (mask_path != (
const char *) NULL)
3287 if (graphic_context[n]->composite_mask != (
Image *) NULL)
3288 graphic_context[n]->composite_mask=
3289 DestroyImage(graphic_context[n]->composite_mask);
3290 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3291 graphic_context[n],token,mask_path,depth+1,exception);
3292 if (graphic_context[n]->compliance != SVGCompliance)
3293 status=SetImageMask(image,CompositePixelMask,
3294 graphic_context[n]->composite_mask,exception);
3304 if (LocaleCompare(
"offset",keyword) == 0)
3306 (void) GetNextToken(q,&q,extent,token);
3309 if (LocaleCompare(
"opacity",keyword) == 0)
3314 (void) GetNextToken(q,&q,extent,token);
3315 if (graphic_context[n]->clip_path != MagickFalse)
3317 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3318 opacity=MagickMin(MagickMax(factor*
3319 GetDrawValue(token,&next_token),0.0),1.0);
3320 if (token == next_token)
3321 ThrowPointExpectedException(token,exception);
3322 if (graphic_context[n]->compliance == SVGCompliance)
3324 graphic_context[n]->fill_alpha*=opacity;
3325 graphic_context[n]->stroke_alpha*=opacity;
3329 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3330 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3332 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3334 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3335 graphic_context[n]->stroke.alpha=
3336 graphic_context[n]->stroke_alpha;
3340 graphic_context[n]->fill.alpha=(MagickRealType)
3341 ClampToQuantum((
double) QuantumRange*opacity);
3342 graphic_context[n]->stroke.alpha=(MagickRealType)
3343 ClampToQuantum((
double) QuantumRange*opacity);
3345 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3346 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3355 if (LocaleCompare(
"path",keyword) == 0)
3357 primitive_type=PathPrimitive;
3360 if (LocaleCompare(
"point",keyword) == 0)
3362 primitive_type=PointPrimitive;
3365 if (LocaleCompare(
"polyline",keyword) == 0)
3367 primitive_type=PolylinePrimitive;
3370 if (LocaleCompare(
"polygon",keyword) == 0)
3372 primitive_type=PolygonPrimitive;
3375 if (LocaleCompare(
"pop",keyword) == 0)
3377 if (GetNextToken(q,&q,extent,token) < 1)
3379 if (LocaleCompare(
"class",token) == 0)
3381 if (LocaleCompare(
"clip-path",token) == 0)
3383 if (LocaleCompare(
"defs",token) == 0)
3386 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3390 if (LocaleCompare(
"gradient",token) == 0)
3392 if (LocaleCompare(
"graphic-context",token) == 0)
3396 (void) ThrowMagickException(exception,GetMagickModule(),
3397 DrawError,
"UnbalancedGraphicContextPushPop",
"`%s'",token);
3402 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3403 (graphic_context[n]->compliance != SVGCompliance))
3404 if (LocaleCompare(graphic_context[n]->clip_mask,
3405 graphic_context[n-1]->clip_mask) != 0)
3406 status=SetImageMask(image,WritePixelMask,(
Image *) NULL,
3408 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3412 if (LocaleCompare(
"mask",token) == 0)
3414 if (LocaleCompare(
"pattern",token) == 0)
3416 if (LocaleCompare(
"symbol",token) == 0)
3419 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3426 if (LocaleCompare(
"push",keyword) == 0)
3428 if (GetNextToken(q,&q,extent,token) < 1)
3430 if (LocaleCompare(
"class",token) == 0)
3435 for (p=q; *q !=
'\0'; )
3437 if (GetNextToken(q,&q,extent,token) < 1)
3439 if (LocaleCompare(token,
"pop") != 0)
3441 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3442 if (LocaleCompare(token,
"class") != 0)
3446 (void) GetNextToken(q,&q,extent,token);
3449 if (LocaleCompare(
"clip-path",token) == 0)
3451 (void) GetNextToken(q,&q,extent,token);
3452 for (p=q; *q !=
'\0'; )
3454 if (GetNextToken(q,&q,extent,token) < 1)
3456 if (LocaleCompare(token,
"pop") != 0)
3458 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3459 if (LocaleCompare(token,
"clip-path") != 0)
3463 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3468 (void) GetNextToken(q,&q,extent,token);
3471 if (LocaleCompare(
"defs",token) == 0)
3474 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3478 if (LocaleCompare(
"gradient",token) == 0)
3481 key[2*MagickPathExtent],
3482 name[MagickPathExtent],
3483 type[MagickPathExtent];
3488 (void) GetNextToken(q,&q,extent,token);
3489 (void) CopyMagickString(name,token,MagickPathExtent);
3490 (void) GetNextToken(q,&q,extent,token);
3491 (void) CopyMagickString(type,token,MagickPathExtent);
3492 (void) GetNextToken(q,&q,extent,token);
3493 segment.x1=GetDrawValue(token,&next_token);
3494 if (token == next_token)
3495 ThrowPointExpectedException(token,exception);
3496 (void) GetNextToken(q,&q,extent,token);
3497 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3498 ThrowPointExpectedException(token,exception);
3500 (void) GetNextToken(q,&q,extent,token);
3501 segment.y1=GetDrawValue(token,&next_token);
3502 if (token == next_token)
3503 ThrowPointExpectedException(token,exception);
3504 (void) GetNextToken(q,&q,extent,token);
3505 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3506 ThrowPointExpectedException(token,exception);
3508 (void) GetNextToken(q,&q,extent,token);
3509 segment.x2=GetDrawValue(token,&next_token);
3510 if (token == next_token)
3511 ThrowPointExpectedException(token,exception);
3512 (void) GetNextToken(q,&q,extent,token);
3513 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3514 ThrowPointExpectedException(token,exception);
3516 (void) GetNextToken(q,&q,extent,token);
3517 segment.y2=GetDrawValue(token,&next_token);
3518 if (token == next_token)
3519 ThrowPointExpectedException(token,exception);
3520 if (LocaleCompare(type,
"radial") == 0)
3522 (void) GetNextToken(q,&q,extent,token);
3523 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3524 ThrowPointExpectedException(token,exception);
3526 (void) GetNextToken(q,&q,extent,token);
3528 for (p=q; *q !=
'\0'; )
3530 if (GetNextToken(q,&q,extent,token) < 1)
3532 if (LocaleCompare(token,
"pop") != 0)
3534 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3535 if (LocaleCompare(token,
"gradient") != 0)
3539 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3540 (p == (
char *) NULL) || ((q-4) < p) ||
3541 ((size_t) (q-p+4+1) > extent))
3546 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3547 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3548 graphic_context[n]->affine.ry*segment.y1+
3549 graphic_context[n]->affine.tx;
3550 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3551 graphic_context[n]->affine.sy*segment.y1+
3552 graphic_context[n]->affine.ty;
3553 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3554 graphic_context[n]->affine.ry*segment.y2+
3555 graphic_context[n]->affine.tx;
3556 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3557 graphic_context[n]->affine.sy*segment.y2+
3558 graphic_context[n]->affine.ty;
3559 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3560 (void) SetImageArtifact(image,key,token);
3561 (void) FormatLocaleString(key,MagickPathExtent,
"%s-type",name);
3562 (void) SetImageArtifact(image,key,type);
3563 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3565 (void) FormatLocaleString(geometry,MagickPathExtent,
3566 "%gx%g%+.15g%+.15g",
3567 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3568 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3569 bounds.x1,bounds.y1);
3570 (void) SetImageArtifact(image,key,geometry);
3571 (void) GetNextToken(q,&q,extent,token);
3574 if (LocaleCompare(
"graphic-context",token) == 0)
3577 graphic_context=(
DrawInfo **) ResizeQuantumMemory(
3578 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3579 if (graphic_context == (
DrawInfo **) NULL)
3581 (void) ThrowMagickException(exception,GetMagickModule(),
3582 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3587 graphic_context[n]=CloneDrawInfo((
ImageInfo *) NULL,
3588 graphic_context[n-1]);
3591 (void) GetNextToken(q,&q,extent,token);
3592 (void) CloneString(&graphic_context[n]->
id,token);
3594 if (n >= MaxVectorRecursionDepth)
3596 (void) ThrowMagickException(exception,GetMagickModule(),
3597 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",
3603 if (LocaleCompare(
"mask",token) == 0)
3605 (void) GetNextToken(q,&q,extent,token);
3608 if (LocaleCompare(
"pattern",token) == 0)
3611 key[2*MagickPathExtent],
3612 name[MagickPathExtent];
3617 (void) GetNextToken(q,&q,extent,token);
3618 (void) CopyMagickString(name,token,MagickPathExtent);
3619 (void) GetNextToken(q,&q,extent,token);
3620 region.x=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3622 if (token == next_token)
3623 ThrowPointExpectedException(token,exception);
3624 (void) GetNextToken(q,&q,extent,token);
3625 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3626 ThrowPointExpectedException(token,exception);
3628 (void) GetNextToken(q,&q,extent,token);
3629 region.y=CastDoubleToSsizeT(ceil(GetDrawValue(token,
3631 if (token == next_token)
3632 ThrowPointExpectedException(token,exception);
3633 (void) GetNextToken(q,&q,extent,token);
3634 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3635 ThrowPointExpectedException(token,exception);
3637 (void) GetNextToken(q,&q,extent,token);
3638 region.width=CastDoubleToSizeT(floor(GetDrawValue(token,
3640 if (token == next_token)
3641 ThrowPointExpectedException(token,exception);
3642 (void) GetNextToken(q,&q,extent,token);
3643 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3644 ThrowPointExpectedException(token,exception);
3646 (void) GetNextToken(q,&q,extent,token);
3647 region.height=CastDoubleToSizeT(GetDrawValue(token,
3649 if (token == next_token)
3650 ThrowPointExpectedException(token,exception);
3651 for (p=q; *q !=
'\0'; )
3653 if (GetNextToken(q,&q,extent,token) < 1)
3655 if (LocaleCompare(token,
"pop") != 0)
3657 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3658 if (LocaleCompare(token,
"pattern") != 0)
3662 if ((q == (
char *) NULL) || (p == (
char *) NULL) ||
3663 ((q-4) < p) || ((size_t) (q-p+4+1) > extent))
3668 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3669 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3670 (void) SetImageArtifact(image,key,token);
3671 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3673 (void) FormatLocaleString(geometry,MagickPathExtent,
3674 "%.20gx%.20g%+.20g%+.20g",(
double) region.width,(double)
3675 region.height,(
double) region.x,(double) region.y);
3676 (void) SetImageArtifact(image,key,geometry);
3677 (void) GetNextToken(q,&q,extent,token);
3680 if (LocaleCompare(
"symbol",token) == 0)
3683 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3696 if (LocaleCompare(
"rectangle",keyword) == 0)
3698 primitive_type=RectanglePrimitive;
3701 if (LocaleCompare(
"rotate",keyword) == 0)
3703 (void) GetNextToken(q,&q,extent,token);
3704 angle=GetDrawValue(token,&next_token);
3705 if (token == next_token)
3706 ThrowPointExpectedException(token,exception);
3707 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3708 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3709 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3710 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3713 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3715 primitive_type=RoundRectanglePrimitive;
3724 if (LocaleCompare(
"scale",keyword) == 0)
3726 (void) GetNextToken(q,&q,extent,token);
3727 affine.sx=GetDrawValue(token,&next_token);
3728 if (token == next_token)
3729 ThrowPointExpectedException(token,exception);
3730 (void) GetNextToken(q,&q,extent,token);
3731 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3732 ThrowPointExpectedException(token,exception);
3734 (void) GetNextToken(q,&q,extent,token);
3735 affine.sy=GetDrawValue(token,&next_token);
3736 if (token == next_token)
3737 ThrowPointExpectedException(token,exception);
3740 if (LocaleCompare(
"skewX",keyword) == 0)
3742 (void) GetNextToken(q,&q,extent,token);
3743 angle=GetDrawValue(token,&next_token);
3744 if (token == next_token)
3745 ThrowPointExpectedException(token,exception);
3746 affine.ry=sin(DegreesToRadians(angle));
3749 if (LocaleCompare(
"skewY",keyword) == 0)
3751 (void) GetNextToken(q,&q,extent,token);
3752 angle=GetDrawValue(token,&next_token);
3753 if (token == next_token)
3754 ThrowPointExpectedException(token,exception);
3755 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3758 if (LocaleCompare(
"stop-color",keyword) == 0)
3764 if (number_stops == 1)
3765 stops=(
StopInfo *) AcquireQuantumMemory(2,
sizeof(*stops));
3767 if (number_stops > 2)
3768 stops=(
StopInfo *) ResizeQuantumMemory(stops,number_stops,
3772 (void) ThrowMagickException(exception,GetMagickModule(),
3773 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3778 (void) GetNextToken(q,&q,extent,token);
3779 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3780 &stop_color,exception);
3781 stops[number_stops-1].color=stop_color;
3782 (void) GetNextToken(q,&q,extent,token);
3783 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3784 stops[number_stops-1].offset=factor*GetDrawValue(token,
3786 if (token == next_token)
3787 ThrowPointExpectedException(token,exception);
3790 if (LocaleCompare(
"stroke",keyword) == 0)
3795 (void) GetNextToken(q,&q,extent,token);
3796 if (graphic_context[n]->clip_path != MagickFalse)
3798 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3799 if (mvg_class != (
const char *) NULL)
3801 (void) DrawPatternPath(image,draw_info,mvg_class,
3802 &graphic_context[n]->stroke_pattern,exception);
3805 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3806 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3808 (void) DrawPatternPath(image,draw_info,token,
3809 &graphic_context[n]->stroke_pattern,exception);
3812 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3813 &graphic_context[n]->stroke,exception);
3814 if (graphic_context[n]->stroke_alpha != (
double) OpaqueAlpha)
3815 graphic_context[n]->stroke.alpha=
3816 graphic_context[n]->stroke_alpha;
3819 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3821 (void) GetNextToken(q,&q,extent,token);
3822 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3823 MagickTrue : MagickFalse;
3826 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3828 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3829 graphic_context[n]->dash_pattern=(
double *)
3830 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3831 if (IsValidPoint(q) != MagickFalse)
3837 (void) GetNextToken(r,&r,extent,token);
3838 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3839 ThrowPointExpectedException(token,exception);
3841 (void) GetNextToken(r,&r,extent,token);
3842 for (x=0; IsValidPoint(token) != MagickFalse; x++)
3844 (void) GetNextToken(r,&r,extent,token);
3846 (void) GetNextToken(r,&r,extent,token);
3848 graphic_context[n]->dash_pattern=(
double *)
3849 AcquireQuantumMemory((
size_t) (2*x+2),
3850 sizeof(*graphic_context[n]->dash_pattern));
3851 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3853 (void) ThrowMagickException(exception,GetMagickModule(),
3854 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3859 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3860 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3861 for (j=0; j < x; j++)
3863 (void) GetNextToken(q,&q,extent,token);
3864 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3865 ThrowPointExpectedException(token,exception);
3867 (void) GetNextToken(q,&q,extent,token);
3868 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3870 if (token == next_token)
3871 ThrowPointExpectedException(token,exception);
3872 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3875 if (((x & 0x01) != 0) && (j == x))
3876 for ( ; j < (2*x); j++)
3877 graphic_context[n]->dash_pattern[j]=
3878 graphic_context[n]->dash_pattern[j-x];
3879 graphic_context[n]->dash_pattern[j]=0.0;
3882 (void) GetNextToken(q,&q,extent,token);
3885 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3887 (void) GetNextToken(q,&q,extent,token);
3888 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3889 if (token == next_token)
3890 ThrowPointExpectedException(token,exception);
3893 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3898 (void) GetNextToken(q,&q,extent,token);
3899 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3905 graphic_context[n]->linecap=(LineCap) linecap;
3908 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3913 (void) GetNextToken(q,&q,extent,token);
3914 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3921 graphic_context[n]->linejoin=(LineJoin) linejoin;
3924 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3926 (void) GetNextToken(q,&q,extent,token);
3927 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3930 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3935 (void) GetNextToken(q,&q,extent,token);
3936 if (graphic_context[n]->clip_path != MagickFalse)
3938 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3939 opacity=MagickMin(MagickMax(factor*GetDrawValue(token,&next_token),
3941 if (token == next_token)
3942 ThrowPointExpectedException(token,exception);
3943 if (graphic_context[n]->compliance == SVGCompliance)
3944 graphic_context[n]->stroke_alpha*=opacity;
3946 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3947 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3948 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3950 graphic_context[n]->stroke.alpha=(MagickRealType)
3951 ClampToQuantum((
double) QuantumRange*opacity);
3952 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3955 if (LocaleCompare(
"stroke-width",keyword) == 0)
3957 (void) GetNextToken(q,&q,extent,token);
3958 if (graphic_context[n]->clip_path != MagickFalse)
3960 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3961 if ((token == next_token) ||
3962 (graphic_context[n]->stroke_width < 0.0))
3963 ThrowPointExpectedException(token,exception);
3972 if (LocaleCompare(
"text",keyword) == 0)
3974 primitive_type=TextPrimitive;
3978 if (LocaleCompare(
"text-align",keyword) == 0)
3983 (void) GetNextToken(q,&q,extent,token);
3984 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3990 graphic_context[n]->align=(AlignType) align;
3993 if (LocaleCompare(
"text-anchor",keyword) == 0)
3998 (void) GetNextToken(q,&q,extent,token);
3999 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
4005 graphic_context[n]->align=(AlignType) align;
4008 if (LocaleCompare(
"text-antialias",keyword) == 0)
4010 (void) GetNextToken(q,&q,extent,token);
4011 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
4012 MagickTrue : MagickFalse;
4015 if (LocaleCompare(
"text-undercolor",keyword) == 0)
4017 (void) GetNextToken(q,&q,extent,token);
4018 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
4019 &graphic_context[n]->undercolor,exception);
4022 if (LocaleCompare(
"translate",keyword) == 0)
4024 (void) GetNextToken(q,&q,extent,token);
4025 affine.tx=GetDrawValue(token,&next_token);
4026 if (token == next_token)
4027 ThrowPointExpectedException(token,exception);
4028 (void) GetNextToken(q,&q,extent,token);
4029 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4030 ThrowPointExpectedException(token,exception);
4032 (void) GetNextToken(q,&q,extent,token);
4033 affine.ty=GetDrawValue(token,&next_token);
4034 if (token == next_token)
4035 ThrowPointExpectedException(token,exception);
4045 if (LocaleCompare(
"use",keyword) == 0)
4053 (void) GetNextToken(q,&q,extent,token);
4054 use=(
const char *) GetValueFromSplayTree(macros,token);
4055 if (use != (
const char *) NULL)
4057 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
4058 if (draw_info->macro_expansion != (
size_t *) NULL)
4060 if (*draw_info->macro_expansion >= MacroExpansionLimit)
4062 (void) ThrowMagickException(exception,GetMagickModule(),
4063 DrawError,
"NonconformingDrawingPrimitiveDefinition",
4065 clone_info=DestroyDrawInfo(clone_info);
4066 return(MagickFalse);
4068 (*draw_info->macro_expansion)++;
4070 (void) CloneString(&clone_info->primitive,use);
4071 status=RenderMVGContent(image,clone_info,depth+1,exception);
4072 clone_info=DestroyDrawInfo(clone_info);
4082 if (LocaleCompare(
"viewbox",keyword) == 0)
4084 (void) GetNextToken(q,&q,extent,token);
4085 graphic_context[n]->viewbox.x=CastDoubleToSsizeT(ceil(
4086 GetDrawValue(token,&next_token)-0.5));
4087 if (token == next_token)
4088 ThrowPointExpectedException(token,exception);
4089 (void) GetNextToken(q,&q,extent,token);
4090 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4091 ThrowPointExpectedException(token,exception);
4093 (void) GetNextToken(q,&q,extent,token);
4094 graphic_context[n]->viewbox.y=CastDoubleToSsizeT(
4095 ceil(GetDrawValue(token,&next_token)-0.5));
4096 if (token == next_token)
4097 ThrowPointExpectedException(token,exception);
4098 (void) GetNextToken(q,&q,extent,token);
4099 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4100 ThrowPointExpectedException(token,exception);
4102 (void) GetNextToken(q,&q,extent,token);
4103 graphic_context[n]->viewbox.width=CastDoubleToSizeT(floor(
4104 GetDrawValue(token,&next_token)+0.5));
4105 if (token == next_token)
4106 ThrowPointExpectedException(token,exception);
4107 (void) GetNextToken(q,&q,extent,token);
4108 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4109 ThrowPointExpectedException(token,exception);
4111 (void) GetNextToken(q,&q,extent,token);
4112 graphic_context[n]->viewbox.height=CastDoubleToSizeT(floor(
4113 GetDrawValue(token,&next_token)+0.5));
4114 if (token == next_token)
4115 ThrowPointExpectedException(token,exception);
4124 if (LocaleCompare(
"word-spacing",keyword) == 0)
4126 (void) GetNextToken(q,&q,extent,token);
4127 graphic_context[n]->interword_spacing=GetDrawValue(token,
4129 if (token == next_token)
4130 ThrowPointExpectedException(token,exception);
4142 if (status == MagickFalse)
4144 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4145 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4146 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4147 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4149 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4150 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4151 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4152 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4153 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4155 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4158 if (primitive_type == UndefinedPrimitive)
4162 if (number_stops > 1)
4167 type=LinearGradient;
4168 if (draw_info->gradient.type == RadialGradient)
4169 type=RadialGradient;
4170 (void) GradientImage(image,type,PadSpread,stops,number_stops,
4173 if (number_stops > 0)
4174 stops=(
StopInfo *) RelinquishMagickMemory(stops);
4176 if ((draw_info->debug != MagickFalse) && (q > p))
4177 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(int)
4184 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4185 if (primitive_info[i].text != (
char *) NULL)
4186 primitive_info[i].text=DestroyString(primitive_info[i].text);
4190 primitive_info[0].primitive=primitive_type;
4191 primitive_info[0].point.x=0.0;
4192 primitive_info[0].point.y=0.0;
4193 primitive_info[0].coordinates=0;
4194 primitive_info[0].method=FloodfillMethod;
4195 primitive_info[0].closed_subpath=MagickFalse;
4196 for (x=0; *q !=
'\0'; x++)
4201 if (IsValidPoint(q) == MagickFalse)
4203 (void) GetNextToken(q,&q,extent,token);
4204 point.x=GetDrawValue(token,&next_token);
4205 if (token == next_token)
4206 ThrowPointExpectedException(token,exception);
4207 (void) GetNextToken(q,&q,extent,token);
4208 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4209 ThrowPointExpectedException(token,exception);
4211 (void) GetNextToken(q,&q,extent,token);
4212 point.y=GetDrawValue(token,&next_token);
4213 if (token == next_token)
4214 ThrowPointExpectedException(token,exception);
4215 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4217 (void) GetNextToken(q,&q,extent,token);
4218 primitive_info[i].primitive=primitive_type;
4219 primitive_info[i].point=point;
4220 primitive_info[i].coordinates=0;
4221 primitive_info[i].method=FloodfillMethod;
4222 primitive_info[i].closed_subpath=MagickFalse;
4225 if (i < (ssize_t) number_points)
4227 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4229 primitive_info=(*mvg_info.primitive_info);
4230 if (status == MagickFalse)
4233 if (status == MagickFalse)
4235 if (primitive_info[j].text != (
char *) NULL)
4236 primitive_info[j].text=DestroyString(primitive_info[j].text);
4237 primitive_info[j].primitive=primitive_type;
4238 primitive_info[j].coordinates=(size_t) x;
4239 primitive_info[j].method=FloodfillMethod;
4240 primitive_info[j].closed_subpath=MagickFalse;
4244 bounds.x1=primitive_info[j].point.x;
4245 bounds.y1=primitive_info[j].point.y;
4246 bounds.x2=primitive_info[j].point.x;
4247 bounds.y2=primitive_info[j].point.y;
4248 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4250 point=primitive_info[j+k].point;
4251 if (point.x < bounds.x1)
4253 if (point.y < bounds.y1)
4255 if (point.x > bounds.x2)
4257 if (point.y > bounds.y2)
4263 coordinates=(double) primitive_info[j].coordinates;
4264 switch (primitive_type)
4266 case RectanglePrimitive:
4271 case RoundRectanglePrimitive:
4278 alpha=bounds.x2-bounds.x1;
4279 beta=bounds.y2-bounds.y1;
4280 radius=hypot(alpha,beta);
4282 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4283 BezierQuantum+360.0;
4286 case BezierPrimitive:
4288 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4297 (void) GetNextToken(q,&q,extent,token);
4300 for (s=token; *s !=
'\0'; s=t)
4305 value=GetDrawValue(s,&t);
4314 for (s=token; *s !=
'\0'; s++)
4315 if (strspn(s,
"AaCcQqSsTt") != 0)
4316 coordinates+=(20.0*BezierQuantum)+360.0;
4322 if (status == MagickFalse)
4324 if (((
size_t) (i+coordinates)) >= number_points)
4329 number_points+=(size_t) coordinates+1;
4330 if (number_points < (
size_t) coordinates)
4332 (void) ThrowMagickException(exception,GetMagickModule(),
4333 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4339 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points+
4340 (
double) coordinates+1.0);
4341 primitive_info=(*mvg_info.primitive_info);
4342 if (status == MagickFalse)
4345 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,
4346 PrimitiveExtentPad);
4347 primitive_info=(*mvg_info.primitive_info);
4348 if (status == MagickFalse)
4351 switch (primitive_type)
4353 case PointPrimitive:
4356 if (primitive_info[j].coordinates != 1)
4361 status&=(MagickStatusType) TracePoint(primitive_info+j,
4362 primitive_info[j].point);
4363 primitive_info=(*mvg_info.primitive_info);
4364 if (status == MagickFalse)
4366 i=j+(ssize_t) primitive_info[j].coordinates;
4371 if (primitive_info[j].coordinates != 2)
4376 status&=(MagickStatusType) TraceLine(primitive_info+j,
4377 primitive_info[j].point,primitive_info[j+1].point);
4378 primitive_info=(*mvg_info.primitive_info);
4379 if (status == MagickFalse)
4381 i=j+(ssize_t) primitive_info[j].coordinates;
4384 case RectanglePrimitive:
4386 if (primitive_info[j].coordinates != 2)
4391 status&=(MagickStatusType) TraceRectangle(primitive_info+j,
4392 primitive_info[j].point,primitive_info[j+1].point);
4393 primitive_info=(*mvg_info.primitive_info);
4394 if (status == MagickFalse)
4396 i=j+(ssize_t) primitive_info[j].coordinates;
4399 case RoundRectanglePrimitive:
4401 if (primitive_info[j].coordinates != 3)
4406 if ((primitive_info[j+2].point.x < 0.0) ||
4407 (primitive_info[j+2].point.y < 0.0))
4412 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4417 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4422 status&=(MagickStatusType) TraceRoundRectangle(&mvg_info,
4423 primitive_info[j].point,primitive_info[j+1].point,
4424 primitive_info[j+2].point);
4425 primitive_info=(*mvg_info.primitive_info);
4426 if (status == MagickFalse)
4428 i=j+(ssize_t) primitive_info[j].coordinates;
4433 if (primitive_info[j].coordinates != 3)
4438 status&=(MagickStatusType) TraceArc(&mvg_info,primitive_info[j].point,
4439 primitive_info[j+1].point,primitive_info[j+2].point);
4440 primitive_info=(*mvg_info.primitive_info);
4441 if (status == MagickFalse)
4443 i=j+(ssize_t) primitive_info[j].coordinates;
4446 case EllipsePrimitive:
4448 if (primitive_info[j].coordinates != 3)
4453 if ((primitive_info[j+1].point.x < 0.0) ||
4454 (primitive_info[j+1].point.y < 0.0))
4459 status&=(MagickStatusType) TraceEllipse(&mvg_info,
4460 primitive_info[j].point,primitive_info[j+1].point,
4461 primitive_info[j+2].point);
4462 primitive_info=(*mvg_info.primitive_info);
4463 if (status == MagickFalse)
4465 i=j+(ssize_t) primitive_info[j].coordinates;
4468 case CirclePrimitive:
4470 if (primitive_info[j].coordinates != 2)
4475 status&=(MagickStatusType) TraceCircle(&mvg_info,
4476 primitive_info[j].point,primitive_info[j+1].point);
4477 primitive_info=(*mvg_info.primitive_info);
4478 if (status == MagickFalse)
4480 i=j+(ssize_t) primitive_info[j].coordinates;
4483 case PolylinePrimitive:
4485 if (primitive_info[j].coordinates < 1)
4492 case PolygonPrimitive:
4494 if (primitive_info[j].coordinates < 3)
4499 primitive_info[i]=primitive_info[j];
4500 primitive_info[i].coordinates=0;
4501 primitive_info[j].coordinates++;
4502 primitive_info[j].closed_subpath=MagickTrue;
4506 case BezierPrimitive:
4508 if (primitive_info[j].coordinates < 3)
4513 status&=(MagickStatusType) TraceBezier(&mvg_info,
4514 primitive_info[j].coordinates);
4515 primitive_info=(*mvg_info.primitive_info);
4516 if (status == MagickFalse)
4518 i=j+(ssize_t) primitive_info[j].coordinates;
4523 coordinates=(double) TracePath(&mvg_info,token,exception);
4524 primitive_info=(*mvg_info.primitive_info);
4525 if (status == MagickFalse)
4527 if (coordinates < 0.0)
4532 i=(ssize_t) (j+coordinates);
4535 case AlphaPrimitive:
4536 case ColorPrimitive:
4541 if (primitive_info[j].coordinates != 1)
4546 (void) GetNextToken(q,&q,extent,token);
4547 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4553 primitive_info[j].method=(PaintMethod) method;
4558 if (primitive_info[j].coordinates != 1)
4564 (void) GetNextToken(q,&q,extent,token);
4565 (void) CloneString(&primitive_info[j].text,token);
4569 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
4570 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4571 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4573 mvg_info.point=primitive_info->point;
4574 primitive_info->point.x+=cursor;
4578 mvg_info.point=primitive_info->point;
4581 clone_info->render=MagickFalse;
4582 clone_info->text=AcquireString(token);
4583 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,
4584 &metrics,exception);
4585 clone_info=DestroyDrawInfo(clone_info);
4586 cursor+=metrics.width;
4587 if (graphic_context[n]->compliance != SVGCompliance)
4591 case ImagePrimitive:
4593 if (primitive_info[j].coordinates != 2)
4598 (void) GetNextToken(q,&q,extent,token);
4599 (void) CloneString(&primitive_info[j].text,token);
4606 primitive_info[i].primitive=UndefinedPrimitive;
4607 if ((draw_info->debug != MagickFalse) && (q > p))
4608 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(int) (q-p),p);
4612 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4613 &graphic_context[n]->affine));
4614 primitive_info=(*mvg_info.primitive_info);
4617 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4618 graphic_context[n]->stroke_width);
4619 primitive_info=(*mvg_info.primitive_info);
4627 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4629 point=primitive_info[i].point;
4630 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4631 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4632 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4633 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4634 point=primitive_info[i].point;
4635 if (point.x < graphic_context[n]->bounds.x1)
4636 graphic_context[n]->bounds.x1=point.x;
4637 if (point.y < graphic_context[n]->bounds.y1)
4638 graphic_context[n]->bounds.y1=point.y;
4639 if (point.x > graphic_context[n]->bounds.x2)
4640 graphic_context[n]->bounds.x2=point.x;
4641 if (point.y > graphic_context[n]->bounds.y2)
4642 graphic_context[n]->bounds.y2=point.y;
4643 if (primitive_info[i].primitive == ImagePrimitive)
4645 if (i >= (ssize_t) number_points)
4646 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4648 if (graphic_context[n]->render != MagickFalse)
4650 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4651 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4652 (LocaleCompare(graphic_context[n]->clip_mask,
4653 graphic_context[n-1]->clip_mask) != 0))
4658 clip_path=(
const char *) GetValueFromSplayTree(macros,
4659 graphic_context[n]->clip_mask);
4660 if (clip_path != (
const char *) NULL)
4661 (
void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4663 status&=(MagickStatusType) DrawClipPath_(image,graphic_context[n],
4664 graphic_context[n]->clip_mask,depth+1,exception);
4666 status&=(MagickStatusType) DrawPrimitive(image,graphic_context[n],
4667 primitive_info,exception);
4669 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4671 if (proceed == MagickFalse)
4676 if (draw_info->debug != MagickFalse)
4677 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4681 macros=DestroySplayTree(macros);
4682 token=DestroyString(token);
4685 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4686 if (primitive_info[i].text != (
char *) NULL)
4687 primitive_info[i].text=DestroyString(primitive_info[i].text);
4688 primitive_info=(
PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4690 primitive=DestroyString(primitive);
4692 stops=(
StopInfo *) RelinquishMagickMemory(stops);
4693 for ( ; n >= 0; n--)
4694 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4695 graphic_context=(
DrawInfo **) RelinquishMagickMemory(graphic_context);
4696 if ((status == MagickFalse) && (exception->severity < ErrorException))
4697 ThrowBinaryException(DrawError,
"NonconformingDrawingPrimitiveDefinition",
4699 return(status != 0 ? MagickTrue : MagickFalse);
4702MagickExport MagickBooleanType DrawImage(
Image *image,
const DrawInfo *draw_info,
4709 macro_expansion = 0;
4711 ((
DrawInfo *) draw_info)->macro_expansion=(¯o_expansion);
4712 status=RenderMVGContent(image,draw_info,0,exception);
4713 ((
DrawInfo *) draw_info)->macro_expansion=(
size_t *) NULL;
4748MagickExport MagickBooleanType DrawPatternPath(
Image *image,
4753 property[MagickPathExtent];
4769 assert(image != (
Image *) NULL);
4770 assert(image->signature == MagickCoreSignature);
4771 assert(draw_info != (
const DrawInfo *) NULL);
4772 assert(name != (
const char *) NULL);
4773 if (IsEventLogging() != MagickFalse)
4774 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4775 (void) FormatLocaleString(property,MagickPathExtent,
"%s",name);
4776 path=GetImageArtifact(image,property);
4777 if (path == (
const char *) NULL)
4778 return(MagickFalse);
4779 (void) FormatLocaleString(property,MagickPathExtent,
"%s-geometry",name);
4780 geometry=GetImageArtifact(image,property);
4781 if (geometry == (
const char *) NULL)
4782 return(MagickFalse);
4783 if ((*pattern) != (
Image *) NULL)
4784 *pattern=DestroyImage(*pattern);
4785 image_info=AcquireImageInfo();
4786 image_info->size=AcquireString(geometry);
4787 *pattern=AcquireImage(image_info,exception);
4788 image_info=DestroyImageInfo(image_info);
4789 (void) QueryColorCompliance(
"#00000000",AllCompliance,
4790 &(*pattern)->background_color,exception);
4791 (void) SetImageBackgroundColor(*pattern,exception);
4792 if (draw_info->debug != MagickFalse)
4793 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4794 "begin pattern-path %s %s",name,geometry);
4795 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
4796 if (clone_info->fill_pattern != (
Image *) NULL)
4797 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4798 if (clone_info->stroke_pattern != (
Image *) NULL)
4799 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4800 (void) FormatLocaleString(property,MagickPathExtent,
"%s-type",name);
4801 type=GetImageArtifact(image,property);
4802 if (type != (
const char *) NULL)
4803 clone_info->gradient.type=(GradientType) ParseCommandOption(
4804 MagickGradientOptions,MagickFalse,type);
4805 (void) CloneString(&clone_info->primitive,path);
4806 status=RenderMVGContent(*pattern,clone_info,0,exception);
4807 clone_info=DestroyDrawInfo(clone_info);
4808 if (draw_info->debug != MagickFalse)
4809 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4850 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4852 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4853 polygon_info=(
PolygonInfo **) RelinquishMagickMemory(polygon_info);
4854 return(polygon_info);
4861 *magick_restrict path_info;
4869 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4870 polygon_info=(
PolygonInfo **) AcquireQuantumMemory(number_threads,
4871 sizeof(*polygon_info));
4874 (void) ThrowMagickException(exception,GetMagickModule(),
4875 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4878 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4879 path_info=ConvertPrimitiveToPath(primitive_info,exception);
4880 if (path_info == (
PathInfo *) NULL)
4881 return(DestroyPolygonTLS(polygon_info));
4882 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4885 (void) ThrowMagickException(exception,GetMagickModule(),
4886 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4887 return(DestroyPolygonTLS(polygon_info));
4889 path_info=(
PathInfo *) RelinquishMagickMemory(path_info);
4890 return(polygon_info);
4893static MagickBooleanType ClonePolygonEdgesTLS(
PolygonInfo **polygon_info,
4899 for (i=1; i < (ssize_t) number_threads; i++)
4907 polygon_info[i]=(
PolygonInfo *) AcquireMagickMemory(
4908 sizeof(*polygon_info[i]));
4911 (void) ThrowMagickException(exception,GetMagickModule(),
4912 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4913 return(MagickFalse);
4915 polygon_info[i]->number_edges=0;
4916 edge_info=polygon_info[0]->edges;
4917 polygon_info[i]->edges=(
EdgeInfo *) AcquireQuantumMemory(
4918 polygon_info[0]->number_edges,
sizeof(*edge_info));
4919 if (polygon_info[i]->edges == (
EdgeInfo *) NULL)
4921 (void) ThrowMagickException(exception,GetMagickModule(),
4922 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4923 return(MagickFalse);
4925 (void) memcpy(polygon_info[i]->edges,edge_info,
4926 polygon_info[0]->number_edges*
sizeof(*edge_info));
4927 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4928 polygon_info[i]->edges[j].points=(
PointInfo *) NULL;
4929 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4930 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4932 edge_info=polygon_info[0]->edges+j;
4933 polygon_info[i]->edges[j].points=(
PointInfo *) AcquireQuantumMemory(
4934 edge_info->number_points,
sizeof(*edge_info));
4935 if (polygon_info[i]->edges[j].points == (
PointInfo *) NULL)
4937 (void) ThrowMagickException(exception,GetMagickModule(),
4938 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4939 return(MagickFalse);
4941 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4942 edge_info->number_points*
sizeof(*edge_info->points));
4948static size_t DestroyEdge(
PolygonInfo *polygon_info,
const ssize_t edge)
4950 assert(edge < (ssize_t) polygon_info->number_edges);
4951 polygon_info->edges[edge].points=(
PointInfo *) RelinquishMagickMemory(
4952 polygon_info->edges[edge].points);
4953 polygon_info->number_edges--;
4954 if (edge < (ssize_t) polygon_info->number_edges)
4955 (
void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4956 (polygon_info->number_edges-(
size_t) edge)*
sizeof(*polygon_info->edges));
4957 return(polygon_info->number_edges);
4960static double GetFillAlpha(
PolygonInfo *polygon_info,
const double mid,
4961 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4962 const ssize_t y,
double *stroke_alpha)
4989 p=polygon_info->edges;
4990 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4992 if ((
double) y <= (p->bounds.y1-mid-0.5))
4994 if ((
double) y > (p->bounds.y2+mid+0.5))
4997 (void) DestroyEdge(polygon_info,j--);
5000 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
5001 ((double) x > (p->bounds.x2+mid+0.5)))
5003 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5004 for ( ; i < (ssize_t) p->number_points; i++)
5006 if ((
double) y <= (p->points[i-1].y-mid-0.5))
5008 if ((
double) y > (p->points[i].y+mid+0.5))
5010 if (p->scanline != (
double) y)
5012 p->scanline=(double) y;
5013 p->highwater=(size_t) i;
5019 delta.x=(q+1)->x-q->x;
5020 delta.y=(q+1)->y-q->y;
5021 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
5027 delta.x=(double) x-q->x;
5028 delta.y=(double) y-q->y;
5029 distance=delta.x*delta.x+delta.y*delta.y;
5033 alpha=delta.x*delta.x+delta.y*delta.y;
5039 delta.x=(double) x-(q+1)->x;
5040 delta.y=(double) y-(q+1)->y;
5041 distance=delta.x*delta.x+delta.y*delta.y;
5048 alpha=MagickSafeReciprocal(alpha);
5049 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
5050 distance=alpha*beta*beta;
5057 if (p->ghostline == MagickFalse)
5060 if ((*stroke_alpha < 1.0) &&
5061 (distance <= ((alpha+0.25)*(alpha+0.25))))
5064 if (distance <= ((alpha+0.25)*(alpha+0.25)))
5069 if (fabs(distance-1.0) >= MagickEpsilon)
5070 beta=sqrt((
double) distance);
5072 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
5073 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
5077 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
5079 if (distance <= 0.0)
5086 if (fabs(beta) < MagickEpsilon)
5089 if (fabs(distance-1.0) >= MagickEpsilon)
5090 beta=sqrt(distance);
5093 if (subpath_alpha < (alpha*alpha))
5094 subpath_alpha=alpha*alpha;
5100 if (fill == MagickFalse)
5102 if (subpath_alpha >= 1.0)
5108 p=polygon_info->edges;
5109 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
5111 if ((
double) y <= p->bounds.y1)
5113 if (((
double) y > p->bounds.y2) || ((double) x <= p->bounds.x1))
5115 if ((
double) x > p->bounds.x2)
5117 winding_number+=p->direction != 0 ? 1 : -1;
5120 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
5121 for ( ; i < (ssize_t) (p->number_points-1); i++)
5122 if ((
double) y <= p->points[i].y)
5125 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
5126 winding_number+=p->direction != 0 ? 1 : -1;
5128 if (fill_rule != NonZeroRule)
5130 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
5134 if (MagickAbsoluteValue(winding_number) != 0)
5136 return(subpath_alpha);
5139static MagickBooleanType DrawPolygonPrimitive(
Image *image,
5143 typedef struct _ExtentInfo
5172 **magick_restrict polygon_info;
5184 assert(image != (
Image *) NULL);
5185 assert(image->signature == MagickCoreSignature);
5186 assert(draw_info != (
DrawInfo *) NULL);
5187 assert(draw_info->signature == MagickCoreSignature);
5189 if (IsEventLogging() != MagickFalse)
5190 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5191 if (primitive_info->coordinates <= 1)
5196 polygon_info=AcquirePolygonTLS(primitive_info,exception);
5198 return(MagickFalse);
5199 if (draw_info->debug != MagickFalse)
5200 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5201 fill=(primitive_info->method == FillToBorderMethod) ||
5202 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5203 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5204 bounds=polygon_info[0]->edges[0].bounds;
5205 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5206 if (IsStringTrue(artifact) != MagickFalse)
5207 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
5208 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5210 p=polygon_info[0]->edges+i;
5211 if (p->bounds.x1 < bounds.x1)
5212 bounds.x1=p->bounds.x1;
5213 if (p->bounds.y1 < bounds.y1)
5214 bounds.y1=p->bounds.y1;
5215 if (p->bounds.x2 > bounds.x2)
5216 bounds.x2=p->bounds.x2;
5217 if (p->bounds.y2 > bounds.y2)
5218 bounds.y2=p->bounds.y2;
5220 bounds.x1-=(mid+1.0);
5221 bounds.y1-=(mid+1.0);
5222 bounds.x2+=(mid+1.0);
5223 bounds.y2+=(mid+1.0);
5224 if ((bounds.x1 >= (
double) image->columns) ||
5225 (bounds.y1 >= (
double) image->rows) ||
5226 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5228 polygon_info=DestroyPolygonTLS(polygon_info);
5231 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5232 (
double) image->columns-1.0 : bounds.x1;
5233 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5234 (
double) image->rows-1.0 : bounds.y1;
5235 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5236 (
double) image->columns-1.0 : bounds.x2;
5237 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5238 (
double) image->rows-1.0 : bounds.y2;
5239 poly_extent.x1=CastDoubleToSsizeT(ceil(bounds.x1-0.5));
5240 poly_extent.y1=CastDoubleToSsizeT(ceil(bounds.y1-0.5));
5241 poly_extent.x2=CastDoubleToSsizeT(floor(bounds.x2+0.5));
5242 poly_extent.y2=CastDoubleToSsizeT(floor(bounds.y2+0.5));
5243 number_threads=(size_t) GetMagickNumberThreads(image,image,(
size_t)
5244 (poly_extent.y2-poly_extent.y1+1),1);
5245 status=ClonePolygonEdgesTLS(polygon_info,number_threads,exception);
5246 if (status == MagickFalse)
5248 polygon_info=DestroyPolygonTLS(polygon_info);
5251 image_view=AcquireAuthenticCacheView(image,exception);
5252 if ((primitive_info->coordinates == 1) ||
5253 (polygon_info[0]->number_edges == 0))
5258#if defined(MAGICKCORE_OPENMP_SUPPORT)
5259 #pragma omp parallel for schedule(static) shared(status) \
5260 num_threads((int) number_threads)
5262 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5273 if (status == MagickFalse)
5276 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5278 if (q == (Quantum *) NULL)
5283 GetPixelInfo(image,&pixel);
5284 for ( ; x <= poly_extent.x2; x++)
5286 if ((x == CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5))) &&
5287 (y == CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5))))
5289 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&pixel,
5291 SetPixelViaPixelInfo(image,&pixel,q);
5293 q+=(ptrdiff_t) GetPixelChannels(image);
5295 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5298 image_view=DestroyCacheView(image_view);
5299 polygon_info=DestroyPolygonTLS(polygon_info);
5300 if (draw_info->debug != MagickFalse)
5301 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5302 " end draw-polygon");
5308#if defined(MAGICKCORE_OPENMP_SUPPORT)
5309 #pragma omp parallel for schedule(static) shared(status) \
5310 num_threads((int) number_threads)
5312 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5315 id = GetOpenMPThreadId();
5323 if (status == MagickFalse)
5325 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5326 (poly_extent.x2-poly_extent.x1+1),1,exception);
5327 if (q == (Quantum *) NULL)
5332 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5345 fill_alpha=GetFillAlpha(polygon_info[
id],mid,fill,draw_info->fill_rule,
5347 if (draw_info->stroke_antialias == MagickFalse)
5349 fill_alpha=fill_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5350 stroke_alpha=stroke_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5352 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&fill_color,
5354 CompositePixelOver(image,&fill_color,fill_alpha*fill_color.alpha,q,
5355 (
double) GetPixelAlpha(image,q),q);
5356 GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&stroke_color,
5358 CompositePixelOver(image,&stroke_color,stroke_alpha*stroke_color.alpha,q,
5359 (
double) GetPixelAlpha(image,q),q);
5360 q+=(ptrdiff_t) GetPixelChannels(image);
5362 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5365 image_view=DestroyCacheView(image_view);
5366 polygon_info=DestroyPolygonTLS(polygon_info);
5367 if (draw_info->debug != MagickFalse)
5368 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5401static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5427 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5428 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5429 switch (primitive_info->primitive)
5431 case AlphaPrimitive:
5433 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5434 "AlphaPrimitive %.20g,%.20g %s",(double) x,(
double) y,
5435 methods[primitive_info->method]);
5438 case ColorPrimitive:
5440 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5441 "ColorPrimitive %.20g,%.20g %s",(double) x,(
double) y,
5442 methods[primitive_info->method]);
5445 case ImagePrimitive:
5447 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5448 "ImagePrimitive %.20g,%.20g",(double) x,(
double) y);
5451 case PointPrimitive:
5453 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5454 "PointPrimitive %.20g,%.20g %s",(double) x,(
double) y,
5455 methods[primitive_info->method]);
5460 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5461 "TextPrimitive %.20g,%.20g",(double) x,(
double) y);
5468 p=primitive_info[0].point;
5471 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5473 point=primitive_info[i].point;
5474 if (coordinates <= 0)
5476 coordinates=(ssize_t) primitive_info[i].coordinates;
5477 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5478 " begin open (%.20g)",(double) coordinates);
5481 point=primitive_info[i].point;
5482 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5483 (fabs(q.y-point.y) >= MagickEpsilon))
5484 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5485 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
5487 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5488 " %.20g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5491 if (coordinates > 0)
5493 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5494 (fabs(p.y-point.y) >= MagickEpsilon))
5495 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.20g)",
5496 (double) coordinates);
5498 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.20g)",
5499 (
double) coordinates);
5503MagickExport MagickBooleanType DrawPrimitive(
Image *image,
5520 if (draw_info->debug != MagickFalse)
5522 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5523 " begin draw-primitive");
5524 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5525 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5526 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5527 draw_info->affine.tx,draw_info->affine.ty);
5530 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5531 ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
5532 (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
5533 status&=(MagickStatusType) SetImageColorspace(image,sRGBColorspace,
5535 if (draw_info->compliance == SVGCompliance)
5537 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5538 draw_info->clipping_mask,exception);
5539 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5540 draw_info->composite_mask,exception);
5542 x=CastDoubleToSsizeT(ceil(primitive_info->point.x-0.5));
5543 y=CastDoubleToSsizeT(ceil(primitive_info->point.y-0.5));
5544 image_view=AcquireAuthenticCacheView(image,exception);
5545 switch (primitive_info->primitive)
5547 case AlphaPrimitive:
5549 if ((image->alpha_trait & BlendPixelTrait) == 0)
5550 status&=(MagickStatusType) SetImageAlphaChannel(image,
5551 OpaqueAlphaChannel,exception);
5552 switch (primitive_info->method)
5563 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5564 if (q == (Quantum *) NULL)
5566 GetFillColor(draw_info,x,y,&pixel,exception);
5567 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5568 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5578 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5579 x,y,&target,exception);
5580 GetPixelInfo(image,&pixel);
5581 for (y=0; y < (ssize_t) image->rows; y++)
5586 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5588 if (q == (Quantum *) NULL)
5590 for (x=0; x < (ssize_t) image->columns; x++)
5592 GetPixelInfoPixel(image,q,&pixel);
5593 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5595 q+=(ptrdiff_t) GetPixelChannels(image);
5598 GetFillColor(draw_info,x,y,&pixel,exception);
5599 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5600 q+=(ptrdiff_t) GetPixelChannels(image);
5602 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5604 if (status == MagickFalse)
5609 case FloodfillMethod:
5610 case FillToBorderMethod:
5618 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5619 TileVirtualPixelMethod,x,y,&target,exception);
5620 if (primitive_info->method == FillToBorderMethod)
5622 target.red=(double) draw_info->border_color.red;
5623 target.green=(double) draw_info->border_color.green;
5624 target.blue=(double) draw_info->border_color.blue;
5626 channel_mask=SetImageChannelMask(image,AlphaChannel);
5627 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5628 &target,x,y,primitive_info->method == FloodfillMethod ?
5629 MagickFalse : MagickTrue,exception);
5630 (void) SetImageChannelMask(image,channel_mask);
5638 for (y=0; y < (ssize_t) image->rows; y++)
5643 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5645 if (q == (Quantum *) NULL)
5647 for (x=0; x < (ssize_t) image->columns; x++)
5649 GetFillColor(draw_info,x,y,&pixel,exception);
5650 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5651 q+=(ptrdiff_t) GetPixelChannels(image);
5653 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5655 if (status == MagickFalse)
5663 case ColorPrimitive:
5665 switch (primitive_info->method)
5676 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5677 if (q == (Quantum *) NULL)
5679 GetPixelInfo(image,&pixel);
5680 GetFillColor(draw_info,x,y,&pixel,exception);
5681 SetPixelViaPixelInfo(image,&pixel,q);
5682 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5692 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5693 x,y,&target,exception);
5694 for (y=0; y < (ssize_t) image->rows; y++)
5699 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5701 if (q == (Quantum *) NULL)
5703 for (x=0; x < (ssize_t) image->columns; x++)
5705 GetPixelInfoPixel(image,q,&pixel);
5706 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5708 q+=(ptrdiff_t) GetPixelChannels(image);
5711 GetFillColor(draw_info,x,y,&pixel,exception);
5712 SetPixelViaPixelInfo(image,&pixel,q);
5713 q+=(ptrdiff_t) GetPixelChannels(image);
5715 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5717 if (status == MagickFalse)
5722 case FloodfillMethod:
5723 case FillToBorderMethod:
5728 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5729 TileVirtualPixelMethod,x,y,&target,exception);
5730 if (primitive_info->method == FillToBorderMethod)
5732 target.red=(double) draw_info->border_color.red;
5733 target.green=(double) draw_info->border_color.green;
5734 target.blue=(double) draw_info->border_color.blue;
5736 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5737 &target,x,y,primitive_info->method == FloodfillMethod ?
5738 MagickFalse : MagickTrue,exception);
5746 GetPixelInfo(image,&pixel);
5747 for (y=0; y < (ssize_t) image->rows; y++)
5752 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5754 if (q == (Quantum *) NULL)
5756 for (x=0; x < (ssize_t) image->columns; x++)
5758 GetFillColor(draw_info,x,y,&pixel,exception);
5759 SetPixelViaPixelInfo(image,&pixel,q);
5760 q+=(ptrdiff_t) GetPixelChannels(image);
5762 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5764 if (status == MagickFalse)
5772 case ImagePrimitive:
5778 composite_geometry[MagickPathExtent];
5794 if (primitive_info->text == (
char *) NULL)
5796 clone_info=AcquireImageInfo();
5797 composite_images=(
Image *) NULL;
5798 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5799 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5802 if (*primitive_info->text !=
'\0')
5807 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5809 (void) SetImageInfo(clone_info,1,exception);
5810 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5812 if (clone_info->size != (
char *) NULL)
5813 clone_info->size=DestroyString(clone_info->size);
5814 if (clone_info->extract != (
char *) NULL)
5815 clone_info->extract=DestroyString(clone_info->extract);
5816 clone_info->coder_depth=draw_info->image_info->coder_depth;
5817 composite_images=StrictReadImage(clone_info,exception);
5819 clone_info=DestroyImageInfo(clone_info);
5820 if (composite_images == (
Image *) NULL)
5825 composite_image=RemoveFirstImageFromList(&composite_images);
5826 composite_images=DestroyImageList(composite_images);
5827 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5828 NULL,(
void *) NULL);
5829 x1=CastDoubleToSsizeT(ceil(primitive_info[1].point.x-0.5));
5830 y1=CastDoubleToSsizeT(ceil(primitive_info[1].point.y-0.5));
5831 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5832 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5837 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5838 "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y);
5839 composite_image->filter=image->filter;
5840 status&=(MagickStatusType) TransformImage(&composite_image,
5841 (
char *) NULL,composite_geometry,exception);
5843 if (composite_image->alpha_trait == UndefinedPixelTrait)
5844 status&=(MagickStatusType) SetImageAlphaChannel(composite_image,
5845 OpaqueAlphaChannel,exception);
5846 if (draw_info->alpha != OpaqueAlpha)
5847 status&=(MagickStatusType) SetImageAlpha(composite_image,
5848 draw_info->alpha,exception);
5849 SetGeometry(image,&geometry);
5850 image->gravity=draw_info->gravity;
5853 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5854 "%.20gx%.20g%+.20g%+.20g",(
double) composite_image->columns,(double)
5855 composite_image->rows,(
double) geometry.x,(double) geometry.y);
5856 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
5857 affine=draw_info->affine;
5858 affine.tx=(double) geometry.x;
5859 affine.ty=(double) geometry.y;
5860 composite_image->interpolate=image->interpolate;
5861 if ((draw_info->compose == OverCompositeOp) ||
5862 (draw_info->compose == SrcOverCompositeOp))
5863 status&=(MagickStatusType) DrawAffineImage(image,composite_image,
5866 status&=(MagickStatusType) CompositeImage(image,composite_image,
5867 draw_info->compose,MagickTrue,geometry.x,geometry.y,exception);
5868 composite_image=DestroyImage(composite_image);
5871 case PointPrimitive:
5879 if ((y < 0) || (y >= (ssize_t) image->rows))
5881 if ((x < 0) || (x >= (ssize_t) image->columns))
5883 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5884 if (q == (Quantum *) NULL)
5886 GetFillColor(draw_info,x,y,&fill_color,exception);
5887 CompositePixelOver(image,&fill_color,(
double) fill_color.alpha,q,(
double)
5888 GetPixelAlpha(image,q),q);
5889 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5896 geometry[MagickPathExtent];
5901 if (primitive_info->text == (
char *) NULL)
5903 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5904 (void) CloneString(&clone_info->text,primitive_info->text);
5905 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
5906 primitive_info->point.x,primitive_info->point.y);
5907 (void) CloneString(&clone_info->geometry,geometry);
5908 status&=(MagickStatusType) AnnotateImage(image,clone_info,exception);
5909 clone_info=DestroyDrawInfo(clone_info);
5921 if (IsEventLogging() != MagickFalse)
5922 LogPrimitiveInfo(primitive_info);
5923 scale=ExpandAffine(&draw_info->affine);
5924 if ((draw_info->dash_pattern != (
double *) NULL) &&
5925 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5926 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5927 (draw_info->stroke.alpha != (
double) TransparentAlpha))
5932 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5933 clone_info->stroke_width=0.0;
5934 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5935 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5936 primitive_info,exception);
5937 clone_info=DestroyDrawInfo(clone_info);
5938 if (status != MagickFalse)
5939 status&=(MagickStatusType) DrawDashPolygon(draw_info,primitive_info,
5943 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5945 ((draw_info->stroke.alpha != (
double) TransparentAlpha) ||
5946 (draw_info->stroke_pattern != (
Image *) NULL)))
5958 closed_path=primitive_info[0].closed_subpath;
5959 i=(ssize_t) primitive_info[0].coordinates;
5960 point_x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5961 point_y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5962 if ((point_x < MagickEpsilon) && (point_y < MagickEpsilon))
5963 closed_path=MagickTrue;
5964 if ((((draw_info->linecap == RoundCap) ||
5965 (closed_path != MagickFalse)) &&
5966 (draw_info->linejoin == RoundJoin)) ||
5967 (primitive_info[i].primitive != UndefinedPrimitive))
5969 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5970 primitive_info,exception);
5973 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5974 clone_info->stroke_width=0.0;
5975 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5976 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5977 primitive_info,exception);
5978 clone_info=DestroyDrawInfo(clone_info);
5979 if (status != MagickFalse)
5980 status&=(MagickStatusType) DrawStrokePolygon(image,draw_info,
5981 primitive_info,exception);
5984 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5985 primitive_info,exception);
5989 image_view=DestroyCacheView(image_view);
5990 if (draw_info->compliance == SVGCompliance)
5992 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5993 (
Image *) NULL,exception);
5994 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5995 (
Image *) NULL,exception);
5997 if (draw_info->debug != MagickFalse)
5998 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
5999 return(status != 0 ? MagickTrue : MagickFalse);
6032static MagickBooleanType DrawRoundLinecap(
Image *image,
6042 if (primitive_info->coordinates < 1)
6043 return(MagickFalse);
6044 for (i=0; i < 4; i++)
6045 linecap[i]=(*primitive_info);
6046 linecap[0].coordinates=4;
6047 linecap[1].point.x+=2.0*MagickEpsilon;
6048 linecap[2].point.x+=2.0*MagickEpsilon;
6049 linecap[2].point.y+=2.0*MagickEpsilon;
6050 linecap[3].point.y+=2.0*MagickEpsilon;
6051 linecap[4].primitive=UndefinedPrimitive;
6052 return(DrawPolygonPrimitive(image,draw_info,linecap,exception));
6055static MagickBooleanType DrawStrokePolygon(
Image *image,
6078 if (draw_info->debug != MagickFalse)
6079 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6080 " begin draw-stroke-polygon");
6081 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
6082 clone_info->fill=draw_info->stroke;
6083 if (clone_info->fill_pattern != (
Image *) NULL)
6084 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
6085 if (clone_info->stroke_pattern != (
Image *) NULL)
6086 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
6087 MagickTrue,exception);
6088 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
6089 clone_info->stroke_width=0.0;
6090 clone_info->fill_rule=NonZeroRule;
6092 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ptrdiff_t) p->coordinates)
6094 if (p->coordinates == 1)
6096 stroke_polygon=TraceStrokePolygon(draw_info,p,exception);
6102 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
6103 stroke_polygon,exception);
6104 stroke_polygon=(
PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
6107 q=p+p->coordinates-1;
6108 closed_path=p->closed_subpath;
6109 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
6111 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,p,
6113 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,q,
6117 clone_info=DestroyDrawInfo(clone_info);
6118 if (draw_info->debug != MagickFalse)
6119 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
6120 " end draw-stroke-polygon");
6121 return(status != 0 ? MagickTrue : MagickFalse);
6147MagickExport
void GetAffineMatrix(
AffineMatrix *affine_matrix)
6149 if (IsEventLogging() != MagickFalse)
6150 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6152 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
6153 affine_matrix->sx=1.0;
6154 affine_matrix->sy=1.0;
6195 assert(draw_info != (
DrawInfo *) NULL);
6196 if (IsEventLogging() != MagickFalse)
6197 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6198 (void) memset(draw_info,0,
sizeof(*draw_info));
6199 draw_info->image_info=CloneImageInfo(image_info);
6200 GetAffineMatrix(&draw_info->affine);
6201 exception=AcquireExceptionInfo();
6202 (void) QueryColorCompliance(
"#000F",AllCompliance,&draw_info->fill,
6204 (void) QueryColorCompliance(
"#FFF0",AllCompliance,&draw_info->stroke,
6206 draw_info->stroke_antialias=draw_info->image_info->antialias;
6207 draw_info->stroke_width=1.0;
6208 draw_info->fill_rule=EvenOddRule;
6209 draw_info->alpha=OpaqueAlpha;
6210 draw_info->fill_alpha=OpaqueAlpha;
6211 draw_info->stroke_alpha=OpaqueAlpha;
6212 draw_info->linecap=ButtCap;
6213 draw_info->linejoin=MiterJoin;
6214 draw_info->miterlimit=10;
6215 draw_info->decorate=NoDecoration;
6216 draw_info->pointsize=12.0;
6217 draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
6218 draw_info->compose=OverCompositeOp;
6219 draw_info->render=MagickTrue;
6220 draw_info->clip_path=MagickFalse;
6221 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6222 MagickTrue : MagickFalse;
6223 draw_info->macro_expansion=(
size_t *) NULL;
6224 if (draw_info->image_info->font != (
char *) NULL)
6225 draw_info->font=AcquireString(draw_info->image_info->font);
6226 if (draw_info->image_info->density != (
char *) NULL)
6227 draw_info->density=AcquireString(draw_info->image_info->density);
6228 draw_info->text_antialias=draw_info->image_info->antialias;
6229 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6230 draw_info->pointsize=draw_info->image_info->pointsize;
6231 draw_info->border_color=draw_info->image_info->border_color;
6232 if (draw_info->image_info->server_name != (
char *) NULL)
6233 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6234 option=GetImageOption(draw_info->image_info,
"direction");
6235 if (option != (
const char *) NULL)
6236 draw_info->direction=(DirectionType) ParseCommandOption(
6237 MagickDirectionOptions,MagickFalse,option);
6239 draw_info->direction=UndefinedDirection;
6240 option=GetImageOption(draw_info->image_info,
"encoding");
6241 if (option != (
const char *) NULL)
6242 (void) CloneString(&draw_info->encoding,option);
6243 option=GetImageOption(draw_info->image_info,
"family");
6244 if (option != (
const char *) NULL)
6245 (void) CloneString(&draw_info->family,option);
6246 option=GetImageOption(draw_info->image_info,
"fill");
6247 if (option != (
const char *) NULL)
6248 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
6250 option=GetImageOption(draw_info->image_info,
"gravity");
6251 if (option != (
const char *) NULL)
6252 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6253 MagickFalse,option);
6254 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6255 if (option != (
const char *) NULL)
6256 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6257 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6258 if (option != (
const char *) NULL)
6259 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6260 option=GetImageOption(draw_info->image_info,
"kerning");
6261 if (option != (
const char *) NULL)
6262 draw_info->kerning=GetDrawValue(option,&next_token);
6263 option=GetImageOption(draw_info->image_info,
"stroke");
6264 if (option != (
const char *) NULL)
6265 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
6267 option=GetImageOption(draw_info->image_info,
"strokewidth");
6268 if (option != (
const char *) NULL)
6269 draw_info->stroke_width=GetDrawValue(option,&next_token);
6270 option=GetImageOption(draw_info->image_info,
"style");
6271 if (option != (
const char *) NULL)
6272 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6273 MagickFalse,option);
6274 option=GetImageOption(draw_info->image_info,
"undercolor");
6275 if (option != (
const char *) NULL)
6276 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
6278 option=GetImageOption(draw_info->image_info,
"weight");
6279 if (option != (
const char *) NULL)
6284 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6286 weight=(ssize_t) StringToUnsignedLong(option);
6287 draw_info->weight=(size_t) weight;
6289 option=GetImageOption(draw_info->image_info,
"word-break");
6290 if (option != (
const char *) NULL)
6291 draw_info->word_break=(WordBreakType) ParseCommandOption(
6292 MagickWordBreakOptions,MagickFalse,option);
6293 exception=DestroyExceptionInfo(exception);
6294 draw_info->signature=MagickCoreSignature;
6322static inline double Permutate(
const ssize_t n,
const ssize_t k)
6331 for (i=k+1; i <= n; i++)
6333 for (i=1; i <= (n-k); i++)
6361 center.x=0.5*(end.x+start.x);
6362 center.y=0.5*(end.y+start.y);
6363 radius.x=fabs(center.x-start.x);
6364 radius.y=fabs(center.y-start.y);
6365 return(TraceEllipse(mvg_info,center,radius,degrees));
6368static MagickBooleanType TraceArcPath(
MVGInfo *mvg_info,
const PointInfo start,
6370 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6407 offset=mvg_info->offset;
6408 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6409 primitive_info->coordinates=0;
6410 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6411 (fabs(start.y-end.y) < MagickEpsilon))
6412 return(TracePoint(primitive_info,end));
6413 radii.x=fabs(arc.x);
6414 radii.y=fabs(arc.y);
6415 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6416 return(TraceLine(primitive_info,start,end));
6417 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6418 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6419 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6420 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6421 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6423 if (delta < MagickEpsilon)
6424 return(TraceLine(primitive_info,start,end));
6427 radii.x*=sqrt((
double) delta);
6428 radii.y*=sqrt((
double) delta);
6430 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6431 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6432 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6433 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6434 alpha=points[1].x-points[0].x;
6435 beta=points[1].y-points[0].y;
6436 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6437 return(TraceLine(primitive_info,start,end));
6438 factor=MagickSafeReciprocal(alpha*alpha+beta*beta)-0.25;
6443 factor=sqrt((
double) factor);
6444 if (sweep == large_arc)
6447 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6448 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6449 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6450 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6451 if ((theta < 0.0) && (sweep != MagickFalse))
6452 theta+=2.0*MagickPI;
6454 if ((theta > 0.0) && (sweep == MagickFalse))
6455 theta-=2.0*MagickPI;
6456 arc_segments=(size_t) CastDoubleToSsizeT(ceil(fabs((
double) (theta/(0.5*
6457 MagickPI+MagickEpsilon)))));
6460 for (i=0; i < (ssize_t) arc_segments; i++)
6462 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6463 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6464 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6465 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6466 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6467 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6468 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6469 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6470 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6471 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6472 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(double) (i+1)*
6473 theta/arc_segments),DegreesToRadians(360.0))));
6474 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(double) (i+1)*
6475 theta/arc_segments),DegreesToRadians(360.0))));
6476 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(double)
6477 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6478 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(double)
6479 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6480 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6481 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6482 (p+1)->point.x=(
double) (cosine*radii.x*points[0].x-sine*radii.y*
6484 (p+1)->point.y=(
double) (sine*radii.x*points[0].x+cosine*radii.y*
6486 (p+2)->point.x=(
double) (cosine*radii.x*points[1].x-sine*radii.y*
6488 (p+2)->point.y=(
double) (sine*radii.x*points[1].x+cosine*radii.y*
6490 (p+3)->point.x=(
double) (cosine*radii.x*points[2].x-sine*radii.y*
6492 (p+3)->point.y=(
double) (sine*radii.x*points[2].x+cosine*radii.y*
6494 if (i == (ssize_t) (arc_segments-1))
6496 status&=(MagickStatusType) TraceBezier(mvg_info,4);
6499 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
6500 mvg_info->offset+=(ssize_t) p->coordinates;
6501 p+=(ptrdiff_t) p->coordinates;
6504 return(MagickFalse);
6505 mvg_info->offset=offset;
6506 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6507 primitive_info->coordinates=(size_t) (p-primitive_info);
6508 primitive_info->closed_subpath=MagickFalse;
6509 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6511 p->primitive=primitive_info->primitive;
6517static MagickBooleanType TraceBezier(
MVGInfo *mvg_info,
6518 const size_t number_coordinates)
6547 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6548 quantum=number_coordinates;
6549 for (i=0; i < (ssize_t) number_coordinates; i++)
6551 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6553 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6554 if (alpha > (
double) GetMaxMemoryRequest())
6556 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6557 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6558 return(MagickFalse);
6560 if (alpha > (
double) quantum)
6561 quantum=(
size_t) alpha;
6562 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6563 if (alpha > (
double) quantum)
6564 quantum=(size_t) alpha;
6567 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6568 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6569 if (quantum > (
double) GetMaxMemoryRequest())
6571 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6572 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6573 return(MagickFalse);
6575 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6576 sizeof(*coefficients));
6577 points=(
PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6579 if ((coefficients == (
double *) NULL) || (points == (
PointInfo *) NULL))
6582 points=(
PointInfo *) RelinquishMagickMemory(points);
6583 if (coefficients != (
double *) NULL)
6584 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6585 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6586 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6587 return(MagickFalse);
6589 control_points=quantum*number_coordinates;
6590 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6592 points=(
PointInfo *) RelinquishMagickMemory(points);
6593 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6594 return(MagickFalse);
6596 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6600 end=primitive_info[number_coordinates-1].point;
6601 for (i=0; i < (ssize_t) number_coordinates; i++)
6602 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6604 for (i=0; i < (ssize_t) control_points; i++)
6609 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6610 for (j=0; j < (ssize_t) number_coordinates; j++)
6612 point.x+=alpha*coefficients[j]*p->point.x;
6613 point.y+=alpha*coefficients[j]*p->point.y;
6614 alpha*=weight/(1.0-weight);
6618 weight+=1.0/control_points;
6624 for (i=0; i < (ssize_t) control_points; i++)
6626 if (TracePoint(p,points[i]) == MagickFalse)
6628 points=(
PointInfo *) RelinquishMagickMemory(points);
6629 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6630 return(MagickFalse);
6632 p+=(ptrdiff_t) p->coordinates;
6634 if (TracePoint(p,end) == MagickFalse)
6636 points=(
PointInfo *) RelinquishMagickMemory(points);
6637 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6638 return(MagickFalse);
6640 p+=(ptrdiff_t) p->coordinates;
6641 primitive_info->coordinates=(size_t) (p-primitive_info);
6642 primitive_info->closed_subpath=MagickFalse;
6643 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6645 p->primitive=primitive_info->primitive;
6648 points=(
PointInfo *) RelinquishMagickMemory(points);
6649 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6653static MagickBooleanType TraceCircle(
MVGInfo *mvg_info,
const PointInfo start,
6665 alpha=end.x-start.x;
6667 radius=hypot((
double) alpha,(
double) beta);
6668 offset.x=(double) radius;
6669 offset.y=(double) radius;
6672 return(TraceEllipse(mvg_info,start,offset,degrees));
6675static MagickBooleanType TraceEllipse(
MVGInfo *mvg_info,
const PointInfo center,
6701 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6702 primitive_info->coordinates=0;
6703 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6705 delta=MagickSafeReciprocal(MagickMax(radii.x,radii.y));
6706 step=MagickPI/(MagickPI*MagickSafeReciprocal(delta))/8.0;
6707 angle.x=DegreesToRadians(arc.x);
6711 angle.y=DegreesToRadians(y);
6712 coordinates=ceil((angle.y-angle.x)/step+1.0);
6713 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6714 return(MagickFalse);
6716 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6717 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6719 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6720 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6721 if (i++ >= (ssize_t) coordinates)
6723 if (TracePoint(p,point) == MagickFalse)
6724 return(MagickFalse);
6725 p+=(ptrdiff_t) p->coordinates;
6727 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6728 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6729 if (TracePoint(p,point) == MagickFalse)
6730 return(MagickFalse);
6731 p+=(ptrdiff_t) p->coordinates;
6732 primitive_info->coordinates=(size_t) (p-primitive_info);
6733 primitive_info->closed_subpath=MagickFalse;
6734 x=fabs(primitive_info[0].point.x-
6735 primitive_info[primitive_info->coordinates-1].point.x);
6736 y=fabs(primitive_info[0].point.y-
6737 primitive_info[primitive_info->coordinates-1].point.y);
6738 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6739 primitive_info->closed_subpath=MagickTrue;
6740 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6742 p->primitive=primitive_info->primitive;
6748static MagickBooleanType TraceLine(
PrimitiveInfo *primitive_info,
6751 if (TracePoint(primitive_info,start) == MagickFalse)
6752 return(MagickFalse);
6753 if (TracePoint(primitive_info+1,end) == MagickFalse)
6754 return(MagickFalse);
6755 (primitive_info+1)->primitive=primitive_info->primitive;
6756 primitive_info->coordinates=2;
6757 primitive_info->closed_subpath=MagickFalse;
6761static ssize_t TracePath(
MVGInfo *mvg_info,
const char *path,
6766 token[MagickPathExtent] =
"";
6784 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6807 subpath_offset=mvg_info->offset;
6808 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6811 number_coordinates=0;
6813 primitive_type=primitive_info->primitive;
6815 for (p=path; *p !=
'\0'; )
6817 if (status == MagickFalse)
6819 while (isspace((
int) ((
unsigned char) *p)) != 0)
6823 last_attribute=attribute;
6824 attribute=(int) (*p++);
6834 large_arc = MagickFalse,
6835 sweep = MagickFalse;
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.x=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 arc.y=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 angle=GetDrawValue(token,&next_token);
6867 if (token == next_token)
6868 ThrowPointExpectedException(token,exception);
6869 (void) GetNextToken(p,&p,MagickPathExtent,token);
6870 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6871 ThrowPointExpectedException(token,exception);
6873 (void) GetNextToken(p,&p,MagickPathExtent,token);
6874 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6875 (void) GetNextToken(p,&p,MagickPathExtent,token);
6876 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6877 ThrowPointExpectedException(token,exception);
6879 (void) GetNextToken(p,&p,MagickPathExtent,token);
6880 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6881 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6882 ThrowPointExpectedException(token,exception);
6884 (void) GetNextToken(p,&p,MagickPathExtent,token);
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 x=GetDrawValue(token,&next_token);
6891 if (token == next_token)
6892 ThrowPointExpectedException(token,exception);
6893 (void) GetNextToken(p,&p,MagickPathExtent,token);
6894 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6895 ThrowPointExpectedException(token,exception);
6897 (void) GetNextToken(p,&p,MagickPathExtent,token);
6898 y=GetDrawValue(token,&next_token);
6899 if (token == next_token)
6900 ThrowPointExpectedException(token,exception);
6901 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6902 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6903 if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
6905 q=(*mvg_info->primitive_info)+mvg_info->offset;
6906 mvg_info->offset+=(ssize_t) q->coordinates;
6907 q+=(ptrdiff_t) q->coordinates;
6909 while (isspace((
int) ((
unsigned char) *p)) != 0)
6913 }
while (IsValidPoint(p) != MagickFalse);
6925 for (i=1; i < 4; i++)
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 x=GetDrawValue(token,&next_token);
6933 if (token == next_token)
6934 ThrowPointExpectedException(token,exception);
6935 (void) GetNextToken(p,&p,MagickPathExtent,token);
6936 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6937 ThrowPointExpectedException(token,exception);
6939 (void) GetNextToken(p,&p,MagickPathExtent,token);
6940 y=GetDrawValue(token,&next_token);
6941 if (token == next_token)
6942 ThrowPointExpectedException(token,exception);
6943 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6944 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6947 for (i=0; i < 4; i++)
6948 (q+i)->point=points[i];
6949 if (TraceBezier(mvg_info,4) == MagickFalse)
6951 q=(*mvg_info->primitive_info)+mvg_info->offset;
6952 mvg_info->offset+=(ssize_t) q->coordinates;
6953 q+=(ptrdiff_t) q->coordinates;
6955 while (isspace((
int) ((
unsigned char) *p)) != 0)
6959 }
while (IsValidPoint(p) != MagickFalse);
6967 (void) GetNextToken(p,&p,MagickPathExtent,token);
6968 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6969 ThrowPointExpectedException(token,exception);
6971 (void) GetNextToken(p,&p,MagickPathExtent,token);
6972 x=GetDrawValue(token,&next_token);
6973 if (token == next_token)
6974 ThrowPointExpectedException(token,exception);
6975 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6976 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6978 q=(*mvg_info->primitive_info)+mvg_info->offset;
6979 if (TracePoint(q,point) == MagickFalse)
6981 mvg_info->offset+=(ssize_t) q->coordinates;
6982 q+=(ptrdiff_t) q->coordinates;
6983 while (isspace((
int) ((
unsigned char) *p)) != 0)
6987 }
while (IsValidPoint(p) != MagickFalse);
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 x=GetDrawValue(token,&next_token);
7004 if (token == next_token)
7005 ThrowPointExpectedException(token,exception);
7006 (void) GetNextToken(p,&p,MagickPathExtent,token);
7007 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7008 ThrowPointExpectedException(token,exception);
7010 (void) GetNextToken(p,&p,MagickPathExtent,token);
7011 y=GetDrawValue(token,&next_token);
7012 if (token == next_token)
7013 ThrowPointExpectedException(token,exception);
7014 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
7015 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
7016 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7018 q=(*mvg_info->primitive_info)+mvg_info->offset;
7019 if (TracePoint(q,point) == MagickFalse)
7021 mvg_info->offset+=(ssize_t) q->coordinates;
7022 q+=(ptrdiff_t) q->coordinates;
7023 while (isspace((
int) ((
unsigned char) *p)) != 0)
7027 }
while (IsValidPoint(p) != MagickFalse);
7036 if (mvg_info->offset != subpath_offset)
7038 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7039 primitive_info->coordinates=(size_t) (q-primitive_info);
7040 number_coordinates+=primitive_info->coordinates;
7042 subpath_offset=mvg_info->offset;
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 x=GetDrawValue(token,&next_token);
7053 if (token == next_token)
7054 ThrowPointExpectedException(token,exception);
7055 (void) GetNextToken(p,&p,MagickPathExtent,token);
7056 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7057 ThrowPointExpectedException(token,exception);
7059 (void) GetNextToken(p,&p,MagickPathExtent,token);
7060 y=GetDrawValue(token,&next_token);
7061 if (token == next_token)
7062 ThrowPointExpectedException(token,exception);
7063 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
7064 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
7068 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7070 q=(*mvg_info->primitive_info)+mvg_info->offset;
7071 if (TracePoint(q,point) == MagickFalse)
7073 mvg_info->offset+=(ssize_t) q->coordinates;
7074 q+=(ptrdiff_t) q->coordinates;
7075 while (isspace((
int) ((
unsigned char) *p)) != 0)
7079 }
while (IsValidPoint(p) != MagickFalse);
7091 for (i=1; i < 3; i++)
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 x=GetDrawValue(token,&next_token);
7099 if (token == next_token)
7100 ThrowPointExpectedException(token,exception);
7101 (void) GetNextToken(p,&p,MagickPathExtent,token);
7102 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7103 ThrowPointExpectedException(token,exception);
7105 (void) GetNextToken(p,&p,MagickPathExtent,token);
7106 y=GetDrawValue(token,&next_token);
7107 if (token == next_token)
7108 ThrowPointExpectedException(token,exception);
7111 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
7112 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
7115 for (i=0; i < 3; i++)
7116 (q+i)->point=points[i];
7117 if (TraceBezier(mvg_info,3) == MagickFalse)
7119 q=(*mvg_info->primitive_info)+mvg_info->offset;
7120 mvg_info->offset+=(ssize_t) q->coordinates;
7121 q+=(ptrdiff_t) q->coordinates;
7123 while (isspace((
int) ((
unsigned char) *p)) != 0)
7127 }
while (IsValidPoint(p) != MagickFalse);
7138 points[0]=points[3];
7139 points[1].x=2.0*points[3].x-points[2].x;
7140 points[1].y=2.0*points[3].y-points[2].y;
7141 for (i=2; i < 4; i++)
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 x=GetDrawValue(token,&next_token);
7149 if (token == next_token)
7150 ThrowPointExpectedException(token,exception);
7151 (void) GetNextToken(p,&p,MagickPathExtent,token);
7152 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7153 ThrowPointExpectedException(token,exception);
7155 (void) GetNextToken(p,&p,MagickPathExtent,token);
7156 y=GetDrawValue(token,&next_token);
7157 if (token == next_token)
7158 ThrowPointExpectedException(token,exception);
7161 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
7162 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
7165 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
7170 for (i=0; i < 4; i++)
7171 (q+i)->point=points[i];
7172 if (TraceBezier(mvg_info,4) == MagickFalse)
7174 q=(*mvg_info->primitive_info)+mvg_info->offset;
7175 mvg_info->offset+=(ssize_t) q->coordinates;
7176 q+=(ptrdiff_t) q->coordinates;
7178 last_attribute=attribute;
7179 while (isspace((
int) ((
unsigned char) *p)) != 0)
7183 }
while (IsValidPoint(p) != MagickFalse);
7194 points[0]=points[2];
7195 points[1].x=2.0*points[2].x-points[1].x;
7196 points[1].y=2.0*points[2].y-points[1].y;
7197 for (i=2; i < 3; i++)
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 x=GetDrawValue(token,&next_token);
7205 if (token == next_token)
7206 ThrowPointExpectedException(token,exception);
7207 (void) GetNextToken(p,&p,MagickPathExtent,token);
7208 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7209 ThrowPointExpectedException(token,exception);
7211 (void) GetNextToken(p,&p,MagickPathExtent,token);
7212 y=GetDrawValue(token,&next_token);
7213 if (token == next_token)
7214 ThrowPointExpectedException(token,exception);
7215 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7216 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7219 if (status == MagickFalse)
7221 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7226 for (i=0; i < 3; i++)
7227 (q+i)->point=points[i];
7228 if (TraceBezier(mvg_info,3) == MagickFalse)
7230 q=(*mvg_info->primitive_info)+mvg_info->offset;
7231 mvg_info->offset+=(ssize_t) q->coordinates;
7232 q+=(ptrdiff_t) q->coordinates;
7234 last_attribute=attribute;
7235 while (isspace((
int) ((
unsigned char) *p)) != 0)
7239 }
while (IsValidPoint(p) != MagickFalse);
7250 (void) GetNextToken(p,&p,MagickPathExtent,token);
7251 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7252 ThrowPointExpectedException(token,exception);
7254 (void) GetNextToken(p,&p,MagickPathExtent,token);
7255 y=GetDrawValue(token,&next_token);
7256 if (token == next_token)
7257 ThrowPointExpectedException(token,exception);
7258 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
7259 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7261 q=(*mvg_info->primitive_info)+mvg_info->offset;
7262 if (TracePoint(q,point) == MagickFalse)
7264 mvg_info->offset+=(ssize_t) q->coordinates;
7265 q+=(ptrdiff_t) q->coordinates;
7266 while (isspace((
int) ((
unsigned char) *p)) != 0)
7270 }
while (IsValidPoint(p) != MagickFalse);
7280 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7282 q=(*mvg_info->primitive_info)+mvg_info->offset;
7283 if (TracePoint(q,point) == MagickFalse)
7285 mvg_info->offset+=(ssize_t) q->coordinates;
7286 q+=(ptrdiff_t) q->coordinates;
7287 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7288 primitive_info->coordinates=(size_t) (q-primitive_info);
7289 primitive_info->closed_subpath=MagickTrue;
7290 number_coordinates+=primitive_info->coordinates;
7292 subpath_offset=mvg_info->offset;
7298 ThrowPointExpectedException(token,exception);
7303 if (status == MagickFalse)
7305 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7306 primitive_info->coordinates=(size_t) (q-primitive_info);
7307 number_coordinates+=primitive_info->coordinates;
7308 for (i=0; i < (ssize_t) number_coordinates; i++)
7311 q->primitive=primitive_type;
7313 q->method=FillToBorderMethod;
7316 return((ssize_t) number_coordinates);
7319static MagickBooleanType TraceRectangle(
PrimitiveInfo *primitive_info,
7332 if (TracePoint(p,start) == 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,end) == MagickFalse)
7341 return(MagickFalse);
7342 p+=(ptrdiff_t) p->coordinates;
7345 if (TracePoint(p,point) == MagickFalse)
7346 return(MagickFalse);
7347 p+=(ptrdiff_t) p->coordinates;
7348 if (TracePoint(p,start) == MagickFalse)
7349 return(MagickFalse);
7350 p+=(ptrdiff_t) p->coordinates;
7351 primitive_info->coordinates=(size_t) (p-primitive_info);
7352 primitive_info->closed_subpath=MagickTrue;
7353 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7355 p->primitive=primitive_info->primitive;
7361static MagickBooleanType TraceRoundRectangle(
MVGInfo *mvg_info,
7381 offset=mvg_info->offset;
7382 segment.x=fabs(end.x-start.x);
7383 segment.y=fabs(end.y-start.y);
7384 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7386 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7389 if (arc.x > (0.5*segment.x))
7390 arc.x=0.5*segment.x;
7391 if (arc.y > (0.5*segment.y))
7392 arc.y=0.5*segment.y;
7393 point.x=start.x+segment.x-arc.x;
7394 point.y=start.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+segment.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+segment.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 point.x=start.x+arc.x;
7418 point.y=start.y+arc.y;
7421 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7422 return(MagickFalse);
7423 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7424 mvg_info->offset+=(ssize_t) p->coordinates;
7425 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7426 return(MagickFalse);
7427 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7428 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7429 return(MagickFalse);
7430 p+=(ptrdiff_t) p->coordinates;
7431 mvg_info->offset=offset;
7432 primitive_info=(*mvg_info->primitive_info)+offset;
7433 primitive_info->coordinates=(size_t) (p-primitive_info);
7434 primitive_info->closed_subpath=MagickTrue;
7435 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7437 p->primitive=primitive_info->primitive;
7443static MagickBooleanType TraceSquareLinecap(
PrimitiveInfo *primitive_info,
7444 const size_t number_vertices,
const double offset)
7461 for (i=1; i < (ssize_t) number_vertices; i++)
7463 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7464 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7465 if ((fabs((
double) dx) >= MagickEpsilon) ||
7466 (fabs((
double) dy) >= MagickEpsilon))
7469 if (i == (ssize_t) number_vertices)
7470 i=(ssize_t) number_vertices-1L;
7471 distance=hypot((
double) dx,(
double) dy);
7472 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7473 dx*(distance+offset)/distance);
7474 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7475 dy*(distance+offset)/distance);
7476 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7478 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7479 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7480 if ((fabs((
double) dx) >= MagickEpsilon) ||
7481 (fabs((
double) dy) >= MagickEpsilon))
7484 distance=hypot((
double) dx,(
double) dy);
7485 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7486 dx*(distance+offset)/distance);
7487 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7488 dy*(distance+offset)/distance);
7495#define MaxStrokePad (6*BezierQuantum+360)
7496#define CheckPathExtent(pad_p,pad_q) \
7498 if ((pad_p) > MaxBezierCoordinates) \
7499 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7501 if ((p+(ptrdiff_t) (pad_p)) >= (ssize_t) extent_p) \
7503 if (~extent_p < (pad_p)) \
7504 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7507 extent_p+=(pad_p); \
7508 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \
7509 MaxStrokePad,sizeof(*stroke_p)); \
7512 if ((pad_q) > MaxBezierCoordinates) \
7513 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7515 if ((q+(ptrdiff_t) (pad_q)) >= (ssize_t) extent_q) \
7517 if (~extent_q < (pad_q)) \
7518 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7521 extent_q+=(pad_q); \
7522 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \
7523 MaxStrokePad,sizeof(*stroke_q)); \
7526 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \
7528 if (stroke_p != (PointInfo *) NULL) \
7529 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7530 if (stroke_q != (PointInfo *) NULL) \
7531 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7532 polygon_primitive=(PrimitiveInfo *) \
7533 RelinquishMagickMemory(polygon_primitive); \
7534 (void) ThrowMagickException(exception,GetMagickModule(), \
7535 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \
7536 return((PrimitiveInfo *) NULL); \
7540 typedef struct _StrokeSegment
7586 inverse_slope = {0.0, 0.0},
7593 number_vertices=primitive_info->coordinates;
7594 polygon_primitive=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7595 number_vertices+2UL,
sizeof(*polygon_primitive));
7598 (void) ThrowMagickException(exception,GetMagickModule(),
7599 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7602 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7603 sizeof(*polygon_primitive));
7604 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7605 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7606 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7607 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7608 if ((draw_info->linejoin == RoundJoin) ||
7609 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
7611 polygon_primitive[number_vertices]=primitive_info[1];
7614 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7618 closed_path=primitive_info[0].closed_subpath;
7621 for (n=1; n < (ssize_t) number_vertices; n++)
7623 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7624 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7625 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7628 if (n == (ssize_t) number_vertices)
7630 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7636 sizeof(*stroke_polygon));
7637 stroke_polygon[0]=polygon_primitive[0];
7638 stroke_polygon[0].coordinates=0;
7641 return(stroke_polygon);
7643 n=(ssize_t) number_vertices-1L;
7645 extent_p=2*number_vertices;
7646 extent_q=2*number_vertices;
7647 stroke_p=(
PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7649 stroke_q=(
PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7654 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7656 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7658 RelinquishMagickMemory(polygon_primitive);
7659 (void) ThrowMagickException(exception,GetMagickModule(),
7660 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7664 inverse_slope.p=0.0;
7665 if (fabs(dx.p) < MagickEpsilon)
7668 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7670 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7673 if (fabs(dy.p) < MagickEpsilon)
7676 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7678 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7683 inverse_slope.p=(-1.0*MagickSafeReciprocal(slope.p));
7685 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7686 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7687 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7688 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7689 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7690 offset.y=(double) (offset.x*inverse_slope.p);
7691 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7693 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7694 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7695 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7696 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7697 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7698 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7699 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7700 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7704 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7705 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7706 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7707 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7708 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7709 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7710 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7711 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7718 stroke_q[p++]=box_q[0];
7719 stroke_p[q++]=box_p[0];
7720 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7725 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7726 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7727 dot_product=dx.q*dx.q+dy.q*dy.q;
7728 if (dot_product < 0.25)
7731 inverse_slope.q=0.0;
7732 if (fabs(dx.q) < MagickEpsilon)
7735 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7737 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7740 if (fabs(dy.q) < MagickEpsilon)
7743 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7745 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7750 inverse_slope.q=(-1.0*MagickSafeReciprocal(slope.q));
7752 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7753 offset.y=(double) (offset.x*inverse_slope.q);
7754 dot_product=dy.q*offset.x-dx.q*offset.y;
7755 if (dot_product > 0.0)
7757 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7758 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7759 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7760 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7761 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7762 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7763 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7764 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7768 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7769 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7770 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7771 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7772 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7773 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7774 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7775 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7777 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7784 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7785 box_p[3].y)/(slope.p-slope.q));
7786 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7787 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7788 box_q[3].y)/(slope.p-slope.q));
7789 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7791 DisableMSCWarning(4127)
7792 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7794 dot_product=dx.q*dy.p-dx.p*dy.q;
7795 if (dot_product <= 0.0)
7796 switch (draw_info->linejoin)
7800 stroke_q[q++]=box_q[1];
7801 stroke_q[q++]=box_q[2];
7802 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7803 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7804 if (dot_product <= miterlimit)
7805 stroke_p[p++]=box_p[4];
7808 stroke_p[p++]=box_p[1];
7809 stroke_p[p++]=box_p[2];
7815 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7816 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7817 if (dot_product <= miterlimit)
7819 stroke_q[q++]=box_q[4];
7820 stroke_p[p++]=box_p[4];
7824 stroke_q[q++]=box_q[1];
7825 stroke_q[q++]=box_q[2];
7826 stroke_p[p++]=box_p[1];
7827 stroke_p[p++]=box_p[2];
7833 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7834 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7835 if (dot_product <= miterlimit)
7836 stroke_p[p++]=box_p[4];
7839 stroke_p[p++]=box_p[1];
7840 stroke_p[p++]=box_p[2];
7842 center=polygon_primitive[n].point;
7843 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7844 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7845 if (theta.q < theta.p)
7846 theta.q+=2.0*MagickPI;
7847 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.q-
7848 theta.p)/(2.0*sqrt(MagickSafeReciprocal(mid))))));
7849 DisableMSCWarning(4127)
7850 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7852 stroke_q[q].x=box_q[1].x;
7853 stroke_q[q].y=box_q[1].y;
7855 for (j=1; j < (ssize_t) arc_segments; j++)
7857 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7858 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7859 (theta.p+delta_theta),DegreesToRadians(360.0))));
7860 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7861 (theta.p+delta_theta),DegreesToRadians(360.0))));
7864 stroke_q[q++]=box_q[2];
7871 switch (draw_info->linejoin)
7875 stroke_p[p++]=box_p[1];
7876 stroke_p[p++]=box_p[2];
7877 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7878 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7879 if (dot_product <= miterlimit)
7880 stroke_q[q++]=box_q[4];
7883 stroke_q[q++]=box_q[1];
7884 stroke_q[q++]=box_q[2];
7890 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7891 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7892 if (dot_product <= miterlimit)
7894 stroke_q[q++]=box_q[4];
7895 stroke_p[p++]=box_p[4];
7899 stroke_q[q++]=box_q[1];
7900 stroke_q[q++]=box_q[2];
7901 stroke_p[p++]=box_p[1];
7902 stroke_p[p++]=box_p[2];
7908 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7909 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7910 if (dot_product <= miterlimit)
7911 stroke_q[q++]=box_q[4];
7914 stroke_q[q++]=box_q[1];
7915 stroke_q[q++]=box_q[2];
7917 center=polygon_primitive[n].point;
7918 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7919 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7920 if (theta.p < theta.q)
7921 theta.p+=2.0*MagickPI;
7922 arc_segments=(size_t) CastDoubleToSsizeT(ceil((
double) ((theta.p-
7923 theta.q)/(2.0*sqrt((
double) (MagickSafeReciprocal(mid)))))));
7924 DisableMSCWarning(4127)
7925 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7927 stroke_p[p++]=box_p[1];
7928 for (j=1; j < (ssize_t) arc_segments; j++)
7930 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7931 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7932 (theta.p+delta_theta),DegreesToRadians(360.0))));
7933 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7934 (theta.p+delta_theta),DegreesToRadians(360.0))));
7937 stroke_p[p++]=box_p[2];
7944 inverse_slope.p=inverse_slope.q;
7953 stroke_p[p++]=box_p[1];
7954 stroke_q[q++]=box_q[1];
7958 stroke_polygon=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7959 (p+q+2L),(
size_t) (closed_path+2L)*
sizeof(*stroke_polygon));
7962 (void) ThrowMagickException(exception,GetMagickModule(),
7963 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7964 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7965 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7968 return(stroke_polygon);
7970 for (i=0; i < (ssize_t) p; i++)
7972 stroke_polygon[i]=polygon_primitive[0];
7973 stroke_polygon[i].point=stroke_p[i];
7975 if (closed_path != MagickFalse)
7977 stroke_polygon[i]=polygon_primitive[0];
7978 stroke_polygon[i].point=stroke_polygon[0].point;
7981 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7983 stroke_polygon[i]=polygon_primitive[0];
7984 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7986 if (closed_path != MagickFalse)
7988 stroke_polygon[i]=polygon_primitive[0];
7989 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7992 stroke_polygon[i]=polygon_primitive[0];
7993 stroke_polygon[i].point=stroke_polygon[0].point;
7995 stroke_polygon[i].primitive=UndefinedPrimitive;
7996 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
7997 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7998 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7999 polygon_primitive=(
PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
8000 return(stroke_polygon);