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/draw.h"
62#include "MagickCore/draw-private.h"
63#include "MagickCore/enhance.h"
64#include "MagickCore/exception.h"
65#include "MagickCore/exception-private.h"
66#include "MagickCore/gem.h"
67#include "MagickCore/geometry.h"
68#include "MagickCore/image-private.h"
69#include "MagickCore/list.h"
70#include "MagickCore/log.h"
71#include "MagickCore/magick.h"
72#include "MagickCore/memory-private.h"
73#include "MagickCore/monitor.h"
74#include "MagickCore/monitor-private.h"
75#include "MagickCore/option.h"
76#include "MagickCore/paint.h"
77#include "MagickCore/pixel-accessor.h"
78#include "MagickCore/property.h"
79#include "MagickCore/resample.h"
80#include "MagickCore/resample-private.h"
81#include "MagickCore/resource_.h"
82#include "MagickCore/splay-tree.h"
83#include "MagickCore/string_.h"
84#include "MagickCore/string-private.h"
85#include "MagickCore/thread-private.h"
86#include "MagickCore/token.h"
87#include "MagickCore/transform-private.h"
88#include "MagickCore/utility.h"
93#define AntialiasThreshold (1.0/3.0)
94#define BezierQuantum 200
95#define PrimitiveExtentPad 4296.0
96#define MaxBezierCoordinates 67108864
97#define ThrowPointExpectedException(token,exception) \
99 (void) ThrowMagickException(exception,GetMagickModule(),DrawError, \
100 "NonconformingDrawingPrimitiveDefinition","`%s'",token); \
101 status=MagickFalse; \
191 *DrawClippingMask(
Image *,
const DrawInfo *,
const char *,
const char *,
194static MagickBooleanType
200 const double,
const MagickBooleanType,
const MagickBooleanType),
201 TraceBezier(
MVGInfo *,
const size_t),
207 TraceSquareLinecap(
PrimitiveInfo *,
const size_t,
const double);
233MagickExport
DrawInfo *AcquireDrawInfo(
void)
238 draw_info=(
DrawInfo *) AcquireCriticalMemory(
sizeof(*draw_info));
239 GetDrawInfo((
ImageInfo *) NULL,draw_info);
279 clone_info=(
DrawInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
280 GetDrawInfo(image_info,clone_info);
283 exception=AcquireExceptionInfo();
284 if (draw_info->id != (
char *) NULL)
285 (void) CloneString(&clone_info->id,draw_info->id);
286 if (draw_info->primitive != (
char *) NULL)
287 (void) CloneString(&clone_info->primitive,draw_info->primitive);
288 if (draw_info->geometry != (
char *) NULL)
289 (void) CloneString(&clone_info->geometry,draw_info->geometry);
290 clone_info->compliance=draw_info->compliance;
291 clone_info->viewbox=draw_info->viewbox;
292 clone_info->affine=draw_info->affine;
293 clone_info->gravity=draw_info->gravity;
294 clone_info->fill=draw_info->fill;
295 clone_info->stroke=draw_info->stroke;
296 clone_info->stroke_width=draw_info->stroke_width;
297 if (draw_info->fill_pattern != (
Image *) NULL)
298 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
300 if (draw_info->stroke_pattern != (
Image *) NULL)
301 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
302 MagickTrue,exception);
303 clone_info->stroke_antialias=draw_info->stroke_antialias;
304 clone_info->text_antialias=draw_info->text_antialias;
305 clone_info->fill_rule=draw_info->fill_rule;
306 clone_info->linecap=draw_info->linecap;
307 clone_info->linejoin=draw_info->linejoin;
308 clone_info->miterlimit=draw_info->miterlimit;
309 clone_info->dash_offset=draw_info->dash_offset;
310 clone_info->decorate=draw_info->decorate;
311 clone_info->compose=draw_info->compose;
312 if (draw_info->text != (
char *) NULL)
313 (void) CloneString(&clone_info->text,draw_info->text);
314 if (draw_info->font != (
char *) NULL)
315 (void) CloneString(&clone_info->font,draw_info->font);
316 if (draw_info->metrics != (
char *) NULL)
317 (void) CloneString(&clone_info->metrics,draw_info->metrics);
318 if (draw_info->family != (
char *) NULL)
319 (void) CloneString(&clone_info->family,draw_info->family);
320 clone_info->style=draw_info->style;
321 clone_info->stretch=draw_info->stretch;
322 clone_info->weight=draw_info->weight;
323 if (draw_info->encoding != (
char *) NULL)
324 (void) CloneString(&clone_info->encoding,draw_info->encoding);
325 clone_info->pointsize=draw_info->pointsize;
326 clone_info->kerning=draw_info->kerning;
327 clone_info->interline_spacing=draw_info->interline_spacing;
328 clone_info->interword_spacing=draw_info->interword_spacing;
329 clone_info->direction=draw_info->direction;
330 clone_info->word_break=draw_info->word_break;
331 if (draw_info->density != (
char *) NULL)
332 (void) CloneString(&clone_info->density,draw_info->density);
333 clone_info->align=draw_info->align;
334 clone_info->undercolor=draw_info->undercolor;
335 clone_info->border_color=draw_info->border_color;
336 if (draw_info->server_name != (
char *) NULL)
337 (void) CloneString(&clone_info->server_name,draw_info->server_name);
338 if (draw_info->dash_pattern != (
double *) NULL)
343 for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
344 clone_info->dash_pattern=(
double *) AcquireQuantumMemory((
size_t) (2*x+2),
345 sizeof(*clone_info->dash_pattern));
346 if (clone_info->dash_pattern == (
double *) NULL)
347 ThrowFatalException(ResourceLimitFatalError,
348 "UnableToAllocateDashPattern");
349 (void) memset(clone_info->dash_pattern,0,(
size_t) (2*x+2)*
350 sizeof(*clone_info->dash_pattern));
351 (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(
size_t)
352 (x+1)*
sizeof(*clone_info->dash_pattern));
354 clone_info->gradient=draw_info->gradient;
355 if (draw_info->gradient.stops != (
StopInfo *) NULL)
360 number_stops=clone_info->gradient.number_stops;
361 clone_info->gradient.stops=(
StopInfo *) AcquireQuantumMemory((
size_t)
362 number_stops,
sizeof(*clone_info->gradient.stops));
363 if (clone_info->gradient.stops == (
StopInfo *) NULL)
364 ThrowFatalException(ResourceLimitFatalError,
365 "UnableToAllocateDashPattern");
366 (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
367 (
size_t) number_stops*
sizeof(*clone_info->gradient.stops));
369 clone_info->bounds=draw_info->bounds;
370 clone_info->fill_alpha=draw_info->fill_alpha;
371 clone_info->stroke_alpha=draw_info->stroke_alpha;
372 clone_info->element_reference=draw_info->element_reference;
373 clone_info->clip_path=draw_info->clip_path;
374 clone_info->clip_units=draw_info->clip_units;
375 if (draw_info->clip_mask != (
char *) NULL)
376 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
377 if (draw_info->clipping_mask != (
Image *) NULL)
378 clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
379 MagickTrue,exception);
380 if (draw_info->composite_mask != (
Image *) NULL)
381 clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
382 MagickTrue,exception);
383 clone_info->render=draw_info->render;
384 clone_info->debug=draw_info->debug;
385 exception=DestroyExceptionInfo(exception);
425 if (polygon_info->edges != (
EdgeInfo *) NULL)
427 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
428 if (polygon_info->edges[i].points != (
PointInfo *) NULL)
429 polygon_info->edges[i].points=(
PointInfo *)
430 RelinquishMagickMemory(polygon_info->edges[i].points);
431 polygon_info->edges=(
EdgeInfo *) RelinquishMagickMemory(
432 polygon_info->edges);
434 return((
PolygonInfo *) RelinquishMagickMemory(polygon_info));
436#if defined(__cplusplus) || defined(c_plusplus)
440static int DrawCompareEdges(
const void *p_edge,
const void *q_edge)
442#define DrawCompareEdge(p,q) \
444 if (((p)-(q)) < 0.0) \
446 if (((p)-(q)) > 0.0) \
457 p=((
const EdgeInfo *) p_edge)->points;
458 q=((
const EdgeInfo *) q_edge)->points;
459 DrawCompareEdge(p[0].y,q[0].y);
460 DrawCompareEdge(p[0].x,q[0].x);
461 DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
463 DrawCompareEdge(p[1].y,q[1].y);
464 DrawCompareEdge(p[1].x,q[1].x);
468#if defined(__cplusplus) || defined(c_plusplus)
472static void LogPolygonInfo(
const PolygonInfo *polygon_info)
481 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin active-edge");
482 p=polygon_info->edges;
483 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
485 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" edge %.20g:",
487 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" direction: %s",
488 p->direction != MagickFalse ?
"down" :
"up");
489 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" ghostline: %s",
490 p->ghostline != MagickFalse ?
"transparent" :
"opaque");
491 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
492 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
493 p->bounds.x2,p->bounds.y2);
494 for (j=0; j < (ssize_t) p->number_points; j++)
495 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %g,%g",
496 p->points[j].x,p->points[j].y);
499 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end active-edge");
502static void ReversePoints(
PointInfo *points,
const size_t number_points)
510 for (i=0; i < (number_points >> 1); i++)
513 points[i]=points[number_points-(i+1)];
514 points[number_points-(i+1)]=point;
550 polygon_info=(
PolygonInfo *) AcquireMagickMemory(
sizeof(*polygon_info));
553 (void) ThrowMagickException(exception,GetMagickModule(),
554 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
558 polygon_info->edges=(
EdgeInfo *) AcquireQuantumMemory(number_edges,
559 sizeof(*polygon_info->edges));
560 if (polygon_info->edges == (
EdgeInfo *) NULL)
562 (void) ThrowMagickException(exception,GetMagickModule(),
563 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
564 return(DestroyPolygonInfo(polygon_info));
566 (void) memset(polygon_info->edges,0,number_edges*
567 sizeof(*polygon_info->edges));
570 ghostline=MagickFalse;
574 (void) memset(&point,0,
sizeof(point));
575 (void) memset(&bounds,0,
sizeof(bounds));
576 polygon_info->edges[edge].number_points=(size_t) n;
577 polygon_info->edges[edge].scanline=0.0;
578 polygon_info->edges[edge].highwater=0;
579 polygon_info->edges[edge].ghostline=ghostline;
580 polygon_info->edges[edge].direction=(ssize_t) direction;
581 polygon_info->edges[edge].points=points;
582 polygon_info->edges[edge].bounds=bounds;
583 polygon_info->number_edges=0;
584 for (i=0; path_info[i].code != EndCode; i++)
586 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
587 (path_info[i].code == GhostlineCode))
592 if ((points != (
PointInfo *) NULL) && (n >= 2))
594 if (edge == number_edges)
597 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
598 polygon_info->edges,(
size_t) number_edges,
599 sizeof(*polygon_info->edges));
600 if (polygon_info->edges == (
EdgeInfo *) NULL)
602 (void) ThrowMagickException(exception,GetMagickModule(),
603 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
604 points=(
PointInfo *) RelinquishMagickMemory(points);
605 return(DestroyPolygonInfo(polygon_info));
608 polygon_info->edges[edge].number_points=(size_t) n;
609 polygon_info->edges[edge].scanline=(-1.0);
610 polygon_info->edges[edge].highwater=0;
611 polygon_info->edges[edge].ghostline=ghostline;
612 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
614 ReversePoints(points,(
size_t) n);
615 polygon_info->edges[edge].points=points;
616 polygon_info->edges[edge].bounds=bounds;
617 polygon_info->edges[edge].bounds.y1=points[0].y;
618 polygon_info->edges[edge].bounds.y2=points[n-1].y;
620 ghostline=MagickFalse;
622 polygon_info->number_edges=edge;
627 points=(
PointInfo *) AcquireQuantumMemory((
size_t) number_points,
631 (void) ThrowMagickException(exception,GetMagickModule(),
632 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
633 return(DestroyPolygonInfo(polygon_info));
636 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
637 point=path_info[i].point;
648 next_direction=((path_info[i].point.y > point.y) ||
649 ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
650 (path_info[i].point.x > point.x))) ? 1 : -1;
651 if ((points != (
PointInfo *) NULL) && (direction != 0) &&
652 (direction != next_direction))
658 if (edge == number_edges)
661 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
662 polygon_info->edges,(
size_t) number_edges,
663 sizeof(*polygon_info->edges));
664 if (polygon_info->edges == (
EdgeInfo *) NULL)
666 (void) ThrowMagickException(exception,GetMagickModule(),
667 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
668 points=(
PointInfo *) RelinquishMagickMemory(points);
669 return(DestroyPolygonInfo(polygon_info));
672 polygon_info->edges[edge].number_points=(size_t) n;
673 polygon_info->edges[edge].scanline=(-1.0);
674 polygon_info->edges[edge].highwater=0;
675 polygon_info->edges[edge].ghostline=ghostline;
676 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
678 ReversePoints(points,(
size_t) n);
679 polygon_info->edges[edge].points=points;
680 polygon_info->edges[edge].bounds=bounds;
681 polygon_info->edges[edge].bounds.y1=points[0].y;
682 polygon_info->edges[edge].bounds.y2=points[n-1].y;
683 polygon_info->number_edges=edge+1;
686 points=(
PointInfo *) AcquireQuantumMemory((
size_t) number_points,
690 (void) ThrowMagickException(exception,GetMagickModule(),
691 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
692 return(DestroyPolygonInfo(polygon_info));
695 ghostline=MagickFalse;
701 direction=next_direction;
704 if (n == (ssize_t) number_points)
707 points=(
PointInfo *) ResizeQuantumMemory(points,(
size_t) number_points,
711 (void) ThrowMagickException(exception,GetMagickModule(),
712 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
713 return(DestroyPolygonInfo(polygon_info));
716 point=path_info[i].point;
718 if (point.x < bounds.x1)
720 if (point.x > bounds.x2)
727 points=(
PointInfo *) RelinquishMagickMemory(points);
730 if (edge == number_edges)
733 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
734 polygon_info->edges,(
size_t) number_edges,
735 sizeof(*polygon_info->edges));
736 if (polygon_info->edges == (
EdgeInfo *) NULL)
738 (void) ThrowMagickException(exception,GetMagickModule(),
739 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
740 return(DestroyPolygonInfo(polygon_info));
743 polygon_info->edges[edge].number_points=(size_t) n;
744 polygon_info->edges[edge].scanline=(-1.0);
745 polygon_info->edges[edge].highwater=0;
746 polygon_info->edges[edge].ghostline=ghostline;
747 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
749 ReversePoints(points,(
size_t) n);
750 polygon_info->edges[edge].points=points;
751 polygon_info->edges[edge].bounds=bounds;
752 polygon_info->edges[edge].bounds.y1=points[0].y;
753 polygon_info->edges[edge].bounds.y2=points[n-1].y;
755 ghostline=MagickFalse;
757 polygon_info->number_edges=edge;
760 polygon_info->number_edges=edge;
761 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(polygon_info->edges,
762 polygon_info->number_edges,
sizeof(*polygon_info->edges));
763 if (polygon_info->edges == (
EdgeInfo *) NULL)
765 (void) ThrowMagickException(exception,GetMagickModule(),
766 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
767 return(DestroyPolygonInfo(polygon_info));
769 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
774 edge_info=polygon_info->edges+i;
775 edge_info->points=(
PointInfo *) ResizeQuantumMemory(edge_info->points,
776 edge_info->number_points,
sizeof(*edge_info->points));
777 if (edge_info->points == (
PointInfo *) NULL)
779 (void) ThrowMagickException(exception,GetMagickModule(),
780 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
781 return(DestroyPolygonInfo(polygon_info));
784 qsort(polygon_info->edges,(
size_t) polygon_info->number_edges,
785 sizeof(*polygon_info->edges),DrawCompareEdges);
786 if ((GetLogEventMask() & DrawEvent) != 0)
787 LogPolygonInfo(polygon_info);
788 return(polygon_info);
821static void LogPathInfo(
const PathInfo *path_info)
826 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin vector-path");
827 for (p=path_info; p->code != EndCode; p++)
828 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
829 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
830 "moveto ghostline" : p->code == OpenCode ?
"moveto open" :
831 p->code == MoveToCode ?
"moveto" : p->code == LineToCode ?
"lineto" :
833 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end vector-path");
863 switch (primitive_info->primitive)
874 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
875 path_info=(
PathInfo *) AcquireQuantumMemory((
size_t) (3UL*i+1UL),
879 (void) ThrowMagickException(exception,GetMagickModule(),
880 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
884 closed_subpath=MagickFalse;
891 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
894 if (coordinates <= 0)
899 coordinates=primitive_info[i].coordinates;
900 p=primitive_info[i].point;
903 closed_subpath=primitive_info[i].closed_subpath;
906 if ((code == MoveToCode) || (coordinates <= 0) ||
907 (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
908 (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
913 path_info[n].code=code;
914 path_info[n].point=primitive_info[i].point;
915 q=primitive_info[i].point;
920 if (closed_subpath != MagickFalse)
922 closed_subpath=MagickFalse;
928 path_info[start].code=OpenCode;
929 path_info[n].code=GhostlineCode;
930 path_info[n].point=primitive_info[i].point;
932 path_info[n].code=LineToCode;
933 path_info[n].point=p;
936 path_info[n].code=EndCode;
937 path_info[n].point.x=0.0;
938 path_info[n].point.y=0.0;
939 if (IsEventLogging() != MagickFalse)
940 LogPathInfo(path_info);
941 path_info=(
PathInfo *) ResizeQuantumMemory(path_info,(
size_t) (n+1),
970 assert(draw_info != (
DrawInfo *) NULL);
971 assert(draw_info->signature == MagickCoreSignature);
972 if (IsEventLogging() != MagickFalse)
973 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
974 if (draw_info->id != (
char *) NULL)
975 draw_info->id=DestroyString(draw_info->id);
976 if (draw_info->primitive != (
char *) NULL)
977 draw_info->primitive=DestroyString(draw_info->primitive);
978 if (draw_info->text != (
char *) NULL)
979 draw_info->text=DestroyString(draw_info->text);
980 if (draw_info->geometry != (
char *) NULL)
981 draw_info->geometry=DestroyString(draw_info->geometry);
982 if (draw_info->fill_pattern != (
Image *) NULL)
983 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
984 if (draw_info->stroke_pattern != (
Image *) NULL)
985 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
986 if (draw_info->font != (
char *) NULL)
987 draw_info->font=DestroyString(draw_info->font);
988 if (draw_info->metrics != (
char *) NULL)
989 draw_info->metrics=DestroyString(draw_info->metrics);
990 if (draw_info->family != (
char *) NULL)
991 draw_info->family=DestroyString(draw_info->family);
992 if (draw_info->encoding != (
char *) NULL)
993 draw_info->encoding=DestroyString(draw_info->encoding);
994 if (draw_info->density != (
char *) NULL)
995 draw_info->density=DestroyString(draw_info->density);
996 if (draw_info->server_name != (
char *) NULL)
997 draw_info->server_name=(
char *)
998 RelinquishMagickMemory(draw_info->server_name);
999 if (draw_info->dash_pattern != (
double *) NULL)
1000 draw_info->dash_pattern=(
double *) RelinquishMagickMemory(
1001 draw_info->dash_pattern);
1002 if (draw_info->gradient.stops != (
StopInfo *) NULL)
1003 draw_info->gradient.stops=(
StopInfo *) RelinquishMagickMemory(
1004 draw_info->gradient.stops);
1005 if (draw_info->clip_mask != (
char *) NULL)
1006 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
1007 if (draw_info->clipping_mask != (
Image *) NULL)
1008 draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
1009 if (draw_info->composite_mask != (
Image *) NULL)
1010 draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
1011 if (draw_info->image_info != (
ImageInfo *) NULL)
1012 draw_info->image_info=DestroyImageInfo(draw_info->image_info);
1013 draw_info->signature=(~MagickCoreSignature);
1014 draw_info=(
DrawInfo *) RelinquishMagickMemory(draw_info);
1065 inverse_edge.x1=edge->x1;
1066 inverse_edge.y1=edge->y1;
1067 inverse_edge.x2=edge->x2;
1068 inverse_edge.y2=edge->y2;
1069 z=affine->ry*y+affine->tx;
1070 if (affine->sx >= MagickEpsilon)
1072 intercept=(-z/affine->sx);
1074 if (x > inverse_edge.x1)
1076 intercept=(-z+(double) image->columns)/affine->sx;
1078 if (x < inverse_edge.x2)
1082 if (affine->sx < -MagickEpsilon)
1084 intercept=(-z+(double) image->columns)/affine->sx;
1086 if (x > inverse_edge.x1)
1088 intercept=(-z/affine->sx);
1090 if (x < inverse_edge.x2)
1094 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->columns))
1096 inverse_edge.x2=edge->x1;
1097 return(inverse_edge);
1102 z=affine->sy*y+affine->ty;
1103 if (affine->rx >= MagickEpsilon)
1105 intercept=(-z/affine->rx);
1107 if (x > inverse_edge.x1)
1109 intercept=(-z+(double) image->rows)/affine->rx;
1111 if (x < inverse_edge.x2)
1115 if (affine->rx < -MagickEpsilon)
1117 intercept=(-z+(double) image->rows)/affine->rx;
1119 if (x > inverse_edge.x1)
1121 intercept=(-z/affine->rx);
1123 if (x < inverse_edge.x2)
1127 if ((z < 0.0) || ((
size_t) floor(z+0.5) >= image->rows))
1129 inverse_edge.x2=edge->x2;
1130 return(inverse_edge);
1132 return(inverse_edge);
1143 determinant=PerceptibleReciprocal(affine->sx*affine->sy-affine->rx*
1145 inverse_affine.sx=determinant*affine->sy;
1146 inverse_affine.rx=determinant*(-affine->rx);
1147 inverse_affine.ry=determinant*(-affine->ry);
1148 inverse_affine.sy=determinant*affine->sx;
1149 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1151 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1153 return(inverse_affine);
1156MagickExport MagickBooleanType DrawAffineImage(
Image *image,
1191 assert(image != (
Image *) NULL);
1192 assert(image->signature == MagickCoreSignature);
1193 if (IsEventLogging() != MagickFalse)
1194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1195 assert(source != (
const Image *) NULL);
1196 assert(source->signature == MagickCoreSignature);
1200 extent[1].x=(double) source->columns;
1202 extent[2].x=(double) source->columns;
1203 extent[2].y=(double) source->rows;
1205 extent[3].y=(double) source->rows;
1206 for (i=0; i < 4; i++)
1212 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1213 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1217 for (i=1; i < 4; i++)
1219 if (min.x > extent[i].x)
1221 if (min.y > extent[i].y)
1223 if (max.x < extent[i].x)
1225 if (max.y < extent[i].y)
1231 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1232 return(MagickFalse);
1238 inverse_affine=InverseAffineMatrix(affine);
1241 if (edge.y2 > (image->rows-1.0))
1242 edge.y2=image->rows-1.0;
1243 GetPixelInfo(image,&zero);
1244 start=CastDoubleToLong(ceil(edge.y1-0.5));
1245 stop=CastDoubleToLong(floor(edge.y2+0.5));
1246 source_view=AcquireVirtualCacheView(source,exception);
1247 image_view=AcquireAuthenticCacheView(image,exception);
1248#if defined(MAGICKCORE_OPENMP_SUPPORT)
1249 #pragma omp parallel for schedule(static) shared(status) \
1250 magick_number_threads(source,image,(size_t) (stop-start),2)
1252 for (y=start; y <= stop; y++)
1270 if (status == MagickFalse)
1272 inverse_edge=AffineEdge(source,&inverse_affine,(
double) y,&edge);
1273 if (inverse_edge.x2 < inverse_edge.x1)
1275 if (inverse_edge.x1 < 0.0)
1276 inverse_edge.x1=0.0;
1277 if (inverse_edge.x2 > image->columns-1.0)
1278 inverse_edge.x2=image->columns-1.0;
1279 q=GetCacheViewAuthenticPixels(image_view,CastDoubleToLong(
1280 ceil(inverse_edge.x1-0.5)),y,(
size_t) CastDoubleToLong(floor(
1281 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
1282 if (q == (Quantum *) NULL)
1286 for (x=CastDoubleToLong(ceil(inverse_edge.x1-0.5));
1287 x <= CastDoubleToLong(floor(inverse_edge.x2+0.5)); x++)
1289 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1291 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1293 status=InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
1294 point.x,point.y,&pixel,exception);
1295 if (status == MagickFalse)
1297 GetPixelInfoPixel(image,q,&composite);
1298 CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
1300 SetPixelViaPixelInfo(image,&composite,q);
1301 q+=GetPixelChannels(image);
1303 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1306 source_view=DestroyCacheView(source_view);
1307 image_view=DestroyCacheView(image_view);
1343static MagickBooleanType DrawBoundingRectangles(
Image *image,
1373 (void) memset(primitive_info,0,
sizeof(primitive_info));
1374 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1375 status=QueryColorCompliance(
"#000F",AllCompliance,&clone_info->fill,
1377 if (status == MagickFalse)
1379 clone_info=DestroyDrawInfo(clone_info);
1380 return(MagickFalse);
1384 if (clone_info->density != (
char *) NULL)
1392 flags=ParseGeometry(clone_info->density,&geometry_info);
1393 if ((flags & RhoValue) != 0)
1394 resolution.x=geometry_info.rho;
1395 resolution.y=resolution.x;
1396 if ((flags & SigmaValue) != 0)
1397 resolution.y=geometry_info.sigma;
1399 mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
1400 clone_info->stroke_width/2.0;
1407 bounds=polygon_info->edges[0].bounds;
1408 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1410 if (polygon_info->edges[i].bounds.x1 < (
double) bounds.x1)
1411 bounds.x1=polygon_info->edges[i].bounds.x1;
1412 if (polygon_info->edges[i].bounds.y1 < (
double) bounds.y1)
1413 bounds.y1=polygon_info->edges[i].bounds.y1;
1414 if (polygon_info->edges[i].bounds.x2 > (
double) bounds.x2)
1415 bounds.x2=polygon_info->edges[i].bounds.x2;
1416 if (polygon_info->edges[i].bounds.y2 > (
double) bounds.y2)
1417 bounds.y2=polygon_info->edges[i].bounds.y2;
1420 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1421 image->columns ? (
double) image->columns-1 : bounds.x1;
1423 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1424 image->rows ? (
double) image->rows-1 : bounds.y1;
1426 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1427 image->columns ? (
double) image->columns-1 : bounds.x2;
1429 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1430 image->rows ? (
double) image->rows-1 : bounds.y2;
1431 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1433 if (polygon_info->edges[i].direction != 0)
1434 status=QueryColorCompliance(
"#f00",AllCompliance,&clone_info->stroke,
1437 status=QueryColorCompliance(
"#0f0",AllCompliance,&clone_info->stroke,
1439 if (status == MagickFalse)
1441 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1442 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1443 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1444 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1445 primitive_info[0].primitive=RectanglePrimitive;
1446 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1447 primitive_info[0].method=ReplaceMethod;
1448 coordinates=(ssize_t) primitive_info[0].coordinates;
1449 primitive_info[coordinates].primitive=UndefinedPrimitive;
1450 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1451 if (status == MagickFalse)
1454 if (i < (ssize_t) polygon_info->number_edges)
1456 clone_info=DestroyDrawInfo(clone_info);
1457 return(status == 0 ? MagickFalse : MagickTrue);
1460 status=QueryColorCompliance(
"#00f",AllCompliance,&clone_info->stroke,
1462 if (status == MagickFalse)
1464 clone_info=DestroyDrawInfo(clone_info);
1465 return(MagickFalse);
1467 start.x=(double) (bounds.x1-mid);
1468 start.y=(double) (bounds.y1-mid);
1469 end.x=(double) (bounds.x2+mid);
1470 end.y=(double) (bounds.y2+mid);
1471 primitive_info[0].primitive=RectanglePrimitive;
1472 status&=(MagickStatusType) TraceRectangle(primitive_info,start,end);
1473 primitive_info[0].method=ReplaceMethod;
1474 coordinates=(ssize_t) primitive_info[0].coordinates;
1475 primitive_info[coordinates].primitive=UndefinedPrimitive;
1476 status=DrawPrimitive(image,clone_info,primitive_info,exception);
1477 clone_info=DestroyDrawInfo(clone_info);
1478 return(status == 0 ? MagickFalse : MagickTrue);
1510MagickExport MagickBooleanType DrawClipPath(
Image *image,
1522 clip_path=GetImageArtifact(image,
id);
1523 if (clip_path == (
const char *) NULL)
1524 return(MagickFalse);
1525 clipping_mask=DrawClippingMask(image,draw_info,draw_info->clip_mask,clip_path,
1527 if (clipping_mask == (
Image *) NULL)
1528 return(MagickFalse);
1529 status=SetImageMask(image,WritePixelMask,clipping_mask,exception);
1530 clipping_mask=DestroyImage(clipping_mask);
1567 const char *
id,
const char *clip_path,
ExceptionInfo *exception)
1582 assert(image != (
Image *) NULL);
1583 assert(image->signature == MagickCoreSignature);
1584 assert(draw_info != (
const DrawInfo *) NULL);
1585 if (IsEventLogging() != MagickFalse)
1586 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1587 clip_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1588 status=SetImageExtent(clip_mask,image->columns,image->rows,exception);
1589 if (status == MagickFalse)
1590 return(DestroyImage(clip_mask));
1591 status=SetImageMask(clip_mask,WritePixelMask,(
Image *) NULL,exception);
1592 status=QueryColorCompliance(
"#0000",AllCompliance,
1593 &clip_mask->background_color,exception);
1594 clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1595 clip_mask->background_color.alpha_trait=BlendPixelTrait;
1596 status=SetImageBackgroundColor(clip_mask,exception);
1597 if (draw_info->debug != MagickFalse)
1598 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin clip-path %s",
1600 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1601 (void) CloneString(&clone_info->primitive,clip_path);
1602 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1604 if (clone_info->clip_mask != (
char *) NULL)
1605 clone_info->clip_mask=DestroyString(clone_info->clip_mask);
1606 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1608 clone_info->stroke_width=0.0;
1609 clone_info->alpha=OpaqueAlpha;
1610 clone_info->clip_path=MagickTrue;
1611 status=RenderMVGContent(clip_mask,clone_info,0,exception);
1612 clone_info=DestroyDrawInfo(clone_info);
1613 separate_mask=SeparateImage(clip_mask,AlphaChannel,exception);
1614 if (separate_mask == (
Image *) NULL)
1618 clip_mask=DestroyImage(clip_mask);
1619 clip_mask=separate_mask;
1620 status&=(MagickStatusType) NegateImage(clip_mask,MagickFalse,exception);
1622 if (status == MagickFalse)
1623 clip_mask=DestroyImage(clip_mask);
1624 if (draw_info->debug != MagickFalse)
1625 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end clip-path");
1661 const char *
id,
const char *mask_path,
ExceptionInfo *exception)
1676 assert(image != (
Image *) NULL);
1677 assert(image->signature == MagickCoreSignature);
1678 assert(draw_info != (
const DrawInfo *) NULL);
1679 if (IsEventLogging() != MagickFalse)
1680 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1681 composite_mask=AcquireImage((
const ImageInfo *) NULL,exception);
1682 status=SetImageExtent(composite_mask,image->columns,image->rows,exception);
1683 if (status == MagickFalse)
1684 return(DestroyImage(composite_mask));
1685 status=SetImageMask(composite_mask,CompositePixelMask,(
Image *) NULL,
1687 status=QueryColorCompliance(
"#0000",AllCompliance,
1688 &composite_mask->background_color,exception);
1689 composite_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
1690 composite_mask->background_color.alpha_trait=BlendPixelTrait;
1691 (void) SetImageBackgroundColor(composite_mask,exception);
1692 if (draw_info->debug != MagickFalse)
1693 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin mask-path %s",
1695 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1696 (void) CloneString(&clone_info->primitive,mask_path);
1697 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1699 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1701 clone_info->stroke_width=0.0;
1702 clone_info->alpha=OpaqueAlpha;
1703 status=RenderMVGContent(composite_mask,clone_info,0,exception);
1704 clone_info=DestroyDrawInfo(clone_info);
1705 separate_mask=SeparateImage(composite_mask,AlphaChannel,exception);
1706 if (separate_mask != (
Image *) NULL)
1708 composite_mask=DestroyImage(composite_mask);
1709 composite_mask=separate_mask;
1710 status=NegateImage(composite_mask,MagickFalse,exception);
1711 if (status == MagickFalse)
1712 composite_mask=DestroyImage(composite_mask);
1714 if (status == MagickFalse)
1715 composite_mask=DestroyImage(composite_mask);
1716 if (draw_info->debug != MagickFalse)
1717 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end mask-path");
1718 return(composite_mask);
1752static MagickBooleanType DrawDashPolygon(
const DrawInfo *draw_info,
1783 assert(draw_info != (
const DrawInfo *) NULL);
1784 if (draw_info->debug != MagickFalse)
1785 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-dash");
1786 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1787 number_vertices=(size_t) i;
1788 dash_polygon=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
1789 (2UL*number_vertices+32UL),
sizeof(*dash_polygon));
1792 (void) ThrowMagickException(exception,GetMagickModule(),
1793 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1794 return(MagickFalse);
1796 (void) memset(dash_polygon,0,(2UL*number_vertices+32UL)*
1797 sizeof(*dash_polygon));
1798 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1799 clone_info->miterlimit=0;
1800 dash_polygon[0]=primitive_info[0];
1801 scale=ExpandAffine(&draw_info->affine);
1802 length=scale*draw_info->dash_pattern[0];
1803 offset=fabs(draw_info->dash_offset) >= MagickEpsilon ?
1804 scale*draw_info->dash_offset : 0.0;
1806 for (n=0; offset > 0.0; j=0)
1808 if (draw_info->dash_pattern[n] <= 0.0)
1810 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1811 if (offset > length)
1815 length=scale*draw_info->dash_pattern[n];
1818 if (offset < length)
1830 for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
1832 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1833 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1834 maximum_length=hypot(dx,dy);
1835 if (maximum_length > (
double) (MaxBezierCoordinates >> 2))
1837 if (fabs(length) < MagickEpsilon)
1839 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1841 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1843 length=scale*draw_info->dash_pattern[n];
1845 for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); )
1847 total_length+=length;
1848 if ((n & 0x01) != 0)
1850 dash_polygon[0]=primitive_info[0];
1851 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1852 total_length*PerceptibleReciprocal(maximum_length));
1853 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1854 total_length*PerceptibleReciprocal(maximum_length));
1859 if ((j+1) > (ssize_t) number_vertices)
1861 dash_polygon[j]=primitive_info[i-1];
1862 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1863 total_length*PerceptibleReciprocal(maximum_length));
1864 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1865 total_length*PerceptibleReciprocal(maximum_length));
1866 dash_polygon[j].coordinates=1;
1868 dash_polygon[0].coordinates=(size_t) j;
1869 dash_polygon[j].primitive=UndefinedPrimitive;
1870 status&=(MagickStatusType) DrawStrokePolygon(image,clone_info,
1871 dash_polygon,exception);
1872 if (status == MagickFalse)
1875 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1877 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1879 length=scale*draw_info->dash_pattern[n];
1881 length-=(maximum_length-total_length);
1882 if ((n & 0x01) != 0)
1884 dash_polygon[j]=primitive_info[i];
1885 dash_polygon[j].coordinates=1;
1888 if ((status != MagickFalse) && (total_length < maximum_length) &&
1889 ((n & 0x01) == 0) && (j > 1))
1891 dash_polygon[j]=primitive_info[i-1];
1892 dash_polygon[j].point.x+=MagickEpsilon;
1893 dash_polygon[j].point.y+=MagickEpsilon;
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);
1901 dash_polygon=(
PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1902 clone_info=DestroyDrawInfo(clone_info);
1903 if (draw_info->debug != MagickFalse)
1904 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-dash");
1905 return(status != 0 ? MagickTrue : MagickFalse);
1936static inline double GetStopColorOffset(
const GradientInfo *gradient,
1937 const ssize_t x,
const ssize_t y)
1939 switch (gradient->type)
1941 case UndefinedGradient:
1942 case LinearGradient:
1957 gradient_vector=(&gradient->gradient_vector);
1958 p.x=gradient_vector->x2-gradient_vector->x1;
1959 p.y=gradient_vector->y2-gradient_vector->y1;
1960 q.x=(double) x-gradient_vector->x1;
1961 q.y=(double) y-gradient_vector->y1;
1962 length=sqrt(q.x*q.x+q.y*q.y);
1963 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
1964 gamma=PerceptibleReciprocal(gamma);
1965 scale=p.x*q.x+p.y*q.y;
1966 offset=gamma*scale*length;
1969 case RadialGradient:
1974 if (gradient->spread == RepeatSpread)
1976 v.x=(double) x-gradient->center.x;
1977 v.y=(double) y-gradient->center.y;
1978 return(sqrt(v.x*v.x+v.y*v.y));
1980 v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians(
1981 gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians(
1982 gradient->angle))))*PerceptibleReciprocal(gradient->radii.x);
1983 v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians(
1984 gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians(
1985 gradient->angle))))*PerceptibleReciprocal(gradient->radii.y);
1986 return(sqrt(v.x*v.x+v.y*v.y));
1992static int StopInfoCompare(
const void *x,
const void *y)
2000 if (stop_1->offset > stop_2->offset)
2002 if (fabs(stop_1->offset-stop_2->offset) <= MagickEpsilon)
2007MagickExport MagickBooleanType DrawGradientImage(
Image *image,
2043 assert(image != (
Image *) NULL);
2044 assert(image->signature == MagickCoreSignature);
2045 assert(draw_info != (
const DrawInfo *) NULL);
2046 if (IsEventLogging() != MagickFalse)
2047 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2048 gradient=(&draw_info->gradient);
2049 qsort(gradient->stops,gradient->number_stops,
sizeof(
StopInfo),
2051 gradient_vector=(&gradient->gradient_vector);
2052 point.x=gradient_vector->x2-gradient_vector->x1;
2053 point.y=gradient_vector->y2-gradient_vector->y1;
2054 length=sqrt(point.x*point.x+point.y*point.y);
2055 bounding_box=gradient->bounding_box;
2057 GetPixelInfo(image,&zero);
2058 image_view=AcquireAuthenticCacheView(image,exception);
2059 height=(size_t) (bounding_box.y+(ssize_t) bounding_box.height);
2060#if defined(MAGICKCORE_OPENMP_SUPPORT)
2061 #pragma omp parallel for schedule(static) shared(status) \
2062 magick_number_threads(image,image,height,1)
2064 for (y=bounding_box.y; y < (ssize_t) height; y++)
2085 if (status == MagickFalse)
2087 q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,y,(
size_t)
2088 bounding_box.width,1,exception);
2089 if (q == (Quantum *) NULL)
2096 offset=GetStopColorOffset(gradient,0,y);
2097 if (gradient->type != RadialGradient)
2098 offset*=PerceptibleReciprocal(length);
2099 width=(size_t) (bounding_box.x+(ssize_t) bounding_box.width);
2100 for (x=bounding_box.x; x < (ssize_t) width; x++)
2102 GetPixelInfoPixel(image,q,&pixel);
2103 switch (gradient->spread)
2105 case UndefinedSpread:
2108 if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
2109 (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
2111 offset=GetStopColorOffset(gradient,x,y);
2112 if (gradient->type != RadialGradient)
2113 offset*=PerceptibleReciprocal(length);
2115 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2116 if (offset < gradient->stops[i].offset)
2118 if ((offset < 0.0) || (i == 0))
2119 composite=gradient->stops[0].color;
2121 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
2122 composite=gradient->stops[gradient->number_stops-1].color;
2127 alpha=(offset-gradient->stops[i].offset)/
2128 (gradient->stops[j].offset-gradient->stops[i].offset);
2129 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2130 &gradient->stops[j].color,alpha,&composite);
2136 if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
2137 (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
2139 offset=GetStopColorOffset(gradient,x,y);
2140 if (gradient->type != RadialGradient)
2141 offset*=PerceptibleReciprocal(length);
2145 if ((ssize_t) fmod(offset,2.0) == 0)
2146 offset=fmod(offset,1.0);
2148 offset=1.0-fmod(offset,1.0);
2149 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2150 if (offset < gradient->stops[i].offset)
2153 composite=gradient->stops[0].color;
2155 if (i == (ssize_t) gradient->number_stops)
2156 composite=gradient->stops[gradient->number_stops-1].color;
2161 alpha=(offset-gradient->stops[i].offset)/
2162 (gradient->stops[j].offset-gradient->stops[i].offset);
2163 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2164 &gradient->stops[j].color,alpha,&composite);
2176 antialias=MagickFalse;
2178 if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
2179 (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
2181 offset=GetStopColorOffset(gradient,x,y);
2182 if (gradient->type == LinearGradient)
2184 repeat=fmod(offset,length);
2186 repeat=length-fmod(-repeat,length);
2188 repeat=fmod(offset,length);
2189 antialias=(repeat < length) && ((repeat+1.0) > length) ?
2190 MagickTrue : MagickFalse;
2191 offset=PerceptibleReciprocal(length)*repeat;
2195 repeat=fmod(offset,gradient->radius);
2197 repeat=gradient->radius-fmod(-repeat,gradient->radius);
2199 repeat=fmod(offset,gradient->radius);
2200 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
2202 offset=repeat*PerceptibleReciprocal(gradient->radius);
2205 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2206 if (offset < gradient->stops[i].offset)
2209 composite=gradient->stops[0].color;
2211 if (i == (ssize_t) gradient->number_stops)
2212 composite=gradient->stops[gradient->number_stops-1].color;
2217 alpha=(offset-gradient->stops[i].offset)/
2218 (gradient->stops[j].offset-gradient->stops[i].offset);
2219 if (antialias != MagickFalse)
2221 if (gradient->type == LinearGradient)
2222 alpha=length-repeat;
2224 alpha=gradient->radius-repeat;
2226 j=(ssize_t) gradient->number_stops-1L;
2228 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
2229 &gradient->stops[j].color,alpha,&composite);
2234 CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha,
2236 SetPixelViaPixelInfo(image,&pixel,q);
2237 q+=GetPixelChannels(image);
2239 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2242 image_view=DestroyCacheView(image_view);
2278static MagickBooleanType CheckPrimitiveExtent(
MVGInfo *mvg_info,
2282 **text = (
char **) NULL;
2296 quantum=
sizeof(**mvg_info->primitive_info);
2297 extent=(double) mvg_info->offset+pad+(PrimitiveExtentPad+1)*(double) quantum;
2298 if (extent <= (
double) *mvg_info->extent)
2300 if ((extent >= (
double) MAGICK_SSIZE_MAX) || (IsNaN(extent) != 0))
2301 return(MagickFalse);
2302 if (mvg_info->offset > 0)
2304 text=(
char **) AcquireQuantumMemory((
size_t) mvg_info->offset,
2306 if (text == (
char **) NULL)
2307 return(MagickFalse);
2308 for (i=0; i < mvg_info->offset; i++)
2309 text[i]=(*mvg_info->primitive_info)[i].text;
2311 *mvg_info->primitive_info=(
PrimitiveInfo *) ResizeQuantumMemory(
2312 *mvg_info->primitive_info,(
size_t) (extent+1),quantum);
2315 if (text != (
char **) NULL)
2316 text=(
char **) RelinquishMagickMemory(text);
2317 *mvg_info->extent=(size_t) extent;
2318 for (i=mvg_info->offset+1; i <= (ssize_t) extent; i++)
2320 (*mvg_info->primitive_info)[i].primitive=UndefinedPrimitive;
2321 (*mvg_info->primitive_info)[i].text=(
char *) NULL;
2328 if (text != (
char **) NULL)
2330 for (i=0; i < mvg_info->offset; i++)
2331 if (text[i] != (
char *) NULL)
2332 text[i]=DestroyString(text[i]);
2333 text=(
char **) RelinquishMagickMemory(text);
2335 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
2336 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2337 *mvg_info->primitive_info=(
PrimitiveInfo *) AcquireCriticalMemory((
size_t)
2338 (PrimitiveExtentPad+1)*quantum);
2339 (void) memset(*mvg_info->primitive_info,0,(
size_t) ((PrimitiveExtentPad+1)*
2341 *mvg_info->extent=1;
2343 return(MagickFalse);
2346static inline double GetDrawValue(
const char *magick_restrict
string,
2347 char **magick_restrict sentinel)
2350 **magick_restrict q;
2356 value=InterpretLocaleValue(
string,q);
2361static int MVGMacroCompare(
const void *target,
const void *source)
2367 p=(
const char *) target;
2368 q=(
const char *) source;
2369 return(strcmp(p,q));
2390 if (primitive == (
const char *) NULL)
2392 macros=NewSplayTree(MVGMacroCompare,RelinquishMagickMemory,
2393 RelinquishMagickMemory);
2394 macro=AcquireString(primitive);
2395 token=AcquireString(primitive);
2396 extent=strlen(token)+MagickPathExtent;
2397 for (q=primitive; *q !=
'\0'; )
2399 if (GetNextToken(q,&q,extent,token) < 1)
2403 if (LocaleCompare(
"push",token) == 0)
2409 (void) GetNextToken(q,&q,extent,token);
2413 name[MagickPathExtent];
2424 (void) GetNextToken(q,&q,extent,token);
2427 (void) CopyMagickString(name,token,MagickPathExtent);
2429 for (p=q; *p !=
'\0'; )
2431 if (GetNextToken(p,&p,extent,token) < 1)
2435 if (LocaleCompare(token,
"pop") == 0)
2437 end=p-strlen(token)-1;
2440 if (LocaleCompare(token,
"push") == 0)
2442 if ((n == 0) && (end >= start))
2445 length=(size_t) (end-start);
2450 (void) GetNextToken(p,&p,extent,token);
2453 (void) CopyMagickString(macro,start,length);
2454 (void) AddValueToSplayTree(macros,ConstantString(name),
2455 ConstantString(macro));
2463 token=DestroyString(token);
2464 macro=DestroyString(macro);
2468static inline MagickBooleanType IsPoint(
const char *point)
2476 value=GetDrawValue(point,&p);
2477 return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
2481static inline MagickBooleanType TracePoint(
PrimitiveInfo *primitive_info,
2484 primitive_info->coordinates=1;
2485 primitive_info->closed_subpath=MagickFalse;
2486 primitive_info->point=point;
2490static MagickBooleanType RenderMVGContent(
Image *image,
2493#define RenderImageTag "Render/Image"
2500 keyword[MagickPathExtent],
2501 geometry[MagickPathExtent],
2503 pattern[MagickPathExtent],
2566 assert(image != (
Image *) NULL);
2567 assert(image->signature == MagickCoreSignature);
2568 assert(draw_info != (
DrawInfo *) NULL);
2569 assert(draw_info->signature == MagickCoreSignature);
2570 if (IsEventLogging() != MagickFalse)
2571 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2572 if (depth > MagickMaxRecursionDepth)
2573 ThrowBinaryException(DrawError,
"VectorGraphicsNestedTooDeeply",
2575 if ((draw_info->primitive == (
char *) NULL) ||
2576 (*draw_info->primitive ==
'\0'))
2577 return(MagickFalse);
2578 if (draw_info->debug != MagickFalse)
2579 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"begin draw-image");
2580 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2581 return(MagickFalse);
2582 if ((image->alpha_trait & BlendPixelTrait) == 0)
2584 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
2585 if (status == MagickFalse)
2586 return(MagickFalse);
2588 if ((*draw_info->primitive ==
'@') && (strlen(draw_info->primitive) > 1) &&
2589 (*(draw_info->primitive+1) !=
'-') && (depth == 0))
2590 primitive=FileToString(draw_info->primitive,~0UL,exception);
2592 primitive=AcquireString(draw_info->primitive);
2593 if (primitive == (
char *) NULL)
2594 return(MagickFalse);
2595 primitive_extent=(double) strlen(primitive);
2596 (void) SetImageArtifact(image,
"mvg:vector-graphics",primitive);
2603 graphic_context=(
DrawInfo **) AcquireMagickMemory(
sizeof(*graphic_context));
2604 if (graphic_context == (
DrawInfo **) NULL)
2606 primitive=DestroyString(primitive);
2607 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2610 number_points=(size_t) PrimitiveExtentPad;
2611 primitive_info=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
2612 (number_points+1),
sizeof(*primitive_info));
2615 primitive=DestroyString(primitive);
2616 for ( ; n >= 0; n--)
2617 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2618 graphic_context=(
DrawInfo **) RelinquishMagickMemory(graphic_context);
2619 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2622 (void) memset(primitive_info,0,(
size_t) (number_points+1)*
2623 sizeof(*primitive_info));
2624 (void) memset(&mvg_info,0,
sizeof(mvg_info));
2625 mvg_info.primitive_info=(&primitive_info);
2626 mvg_info.extent=(&number_points);
2627 mvg_info.exception=exception;
2628 graphic_context[n]=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
2629 graphic_context[n]->viewbox=image->page;
2630 if ((image->page.width == 0) || (image->page.height == 0))
2632 graphic_context[n]->viewbox.width=image->columns;
2633 graphic_context[n]->viewbox.height=image->rows;
2635 token=AcquireString(primitive);
2636 extent=strlen(token)+MagickPathExtent;
2640 macros=GetMVGMacros(primitive);
2642 for (q=primitive; *q !=
'\0'; )
2647 if (GetNextToken(q,&q,MagickPathExtent,keyword) < 1)
2649 if (*keyword ==
'\0')
2651 if (*keyword ==
'#')
2656 while ((*q !=
'\n') && (*q !=
'\0'))
2660 p=q-strlen(keyword)-1;
2661 primitive_type=UndefinedPrimitive;
2662 current=graphic_context[n]->affine;
2663 GetAffineMatrix(&affine);
2672 if (LocaleCompare(
"affine",keyword) == 0)
2674 (void) GetNextToken(q,&q,extent,token);
2675 affine.sx=GetDrawValue(token,&next_token);
2676 if (token == next_token)
2677 ThrowPointExpectedException(token,exception);
2678 (void) GetNextToken(q,&q,extent,token);
2680 (void) GetNextToken(q,&q,extent,token);
2681 affine.rx=GetDrawValue(token,&next_token);
2682 if (token == next_token)
2683 ThrowPointExpectedException(token,exception);
2684 (void) GetNextToken(q,&q,extent,token);
2686 (void) GetNextToken(q,&q,extent,token);
2687 affine.ry=GetDrawValue(token,&next_token);
2688 if (token == next_token)
2689 ThrowPointExpectedException(token,exception);
2690 (void) GetNextToken(q,&q,extent,token);
2692 (void) GetNextToken(q,&q,extent,token);
2693 affine.sy=GetDrawValue(token,&next_token);
2694 if (token == next_token)
2695 ThrowPointExpectedException(token,exception);
2696 (void) GetNextToken(q,&q,extent,token);
2698 (void) GetNextToken(q,&q,extent,token);
2699 affine.tx=GetDrawValue(token,&next_token);
2700 if (token == next_token)
2701 ThrowPointExpectedException(token,exception);
2702 (void) GetNextToken(q,&q,extent,token);
2704 (void) GetNextToken(q,&q,extent,token);
2705 affine.ty=GetDrawValue(token,&next_token);
2706 if (token == next_token)
2707 ThrowPointExpectedException(token,exception);
2710 if (LocaleCompare(
"alpha",keyword) == 0)
2712 primitive_type=AlphaPrimitive;
2715 if (LocaleCompare(
"arc",keyword) == 0)
2717 primitive_type=ArcPrimitive;
2726 if (LocaleCompare(
"bezier",keyword) == 0)
2728 primitive_type=BezierPrimitive;
2731 if (LocaleCompare(
"border-color",keyword) == 0)
2733 (void) GetNextToken(q,&q,extent,token);
2734 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2735 &graphic_context[n]->border_color,exception);
2744 if (LocaleCompare(
"class",keyword) == 0)
2749 (void) GetNextToken(q,&q,extent,token);
2750 if ((*token ==
'\0') || (*token ==
';'))
2758 for (i=0; i < n; i++)
2759 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2763 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2764 if ((graphic_context[n]->render != MagickFalse) &&
2765 (mvg_class != (
const char *) NULL) && (p > primitive))
2776 offset=(ssize_t) (p-primitive);
2777 elements=AcquireString(primitive);
2778 elements[offset]=
'\0';
2779 (void) ConcatenateString(&elements,mvg_class);
2780 (void) ConcatenateString(&elements,
"\n");
2781 (void) ConcatenateString(&elements,q);
2782 primitive=DestroyString(primitive);
2788 if (LocaleCompare(
"clip-path",keyword) == 0)
2796 (void) GetNextToken(q,&q,extent,token);
2802 (void) CloneString(&graphic_context[n]->clip_mask,token);
2803 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2804 if (clip_path != (
const char *) NULL)
2806 if (graphic_context[n]->clipping_mask != (
Image *) NULL)
2807 graphic_context[n]->clipping_mask=
2808 DestroyImage(graphic_context[n]->clipping_mask);
2809 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2810 graphic_context[n],token,clip_path,exception);
2811 if (graphic_context[n]->compliance != SVGCompliance)
2813 clip_path=(
const char *) GetValueFromSplayTree(macros,
2814 graphic_context[n]->clip_mask);
2815 if (clip_path != (
const char *) NULL)
2816 (void) SetImageArtifact(image,
2817 graphic_context[n]->clip_mask,clip_path);
2818 status&=(MagickStatusType) DrawClipPath(image,
2819 graphic_context[n],graphic_context[n]->clip_mask,
2825 if (LocaleCompare(
"clip-rule",keyword) == 0)
2830 (void) GetNextToken(q,&q,extent,token);
2831 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2833 if (fill_rule == -1)
2838 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2841 if (LocaleCompare(
"clip-units",keyword) == 0)
2846 (void) GetNextToken(q,&q,extent,token);
2847 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2849 if (clip_units == -1)
2854 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2855 if (clip_units == ObjectBoundingBox)
2857 GetAffineMatrix(¤t);
2858 affine.sx=draw_info->bounds.x2;
2859 affine.sy=draw_info->bounds.y2;
2860 affine.tx=draw_info->bounds.x1;
2861 affine.ty=draw_info->bounds.y1;
2866 if (LocaleCompare(
"circle",keyword) == 0)
2868 primitive_type=CirclePrimitive;
2871 if (LocaleCompare(
"color",keyword) == 0)
2873 primitive_type=ColorPrimitive;
2876 if (LocaleCompare(
"compliance",keyword) == 0)
2882 (void) GetNextToken(q,&q,extent,token);
2883 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2884 MagickComplianceOptions,MagickFalse,token);
2887 if (LocaleCompare(
"currentColor",keyword) == 0)
2889 (void) GetNextToken(q,&q,extent,token);
2898 if (LocaleCompare(
"decorate",keyword) == 0)
2903 (void) GetNextToken(q,&q,extent,token);
2904 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2911 graphic_context[n]->decorate=(DecorationType) decorate;
2914 if (LocaleCompare(
"density",keyword) == 0)
2916 (void) GetNextToken(q,&q,extent,token);
2917 (void) CloneString(&graphic_context[n]->density,token);
2920 if (LocaleCompare(
"direction",keyword) == 0)
2925 (void) GetNextToken(q,&q,extent,token);
2926 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2928 if (direction == -1)
2931 graphic_context[n]->direction=(DirectionType) direction;
2940 if (LocaleCompare(
"ellipse",keyword) == 0)
2942 primitive_type=EllipsePrimitive;
2945 if (LocaleCompare(
"encoding",keyword) == 0)
2947 (void) GetNextToken(q,&q,extent,token);
2948 (void) CloneString(&graphic_context[n]->encoding,token);
2957 if (LocaleCompare(
"fill",keyword) == 0)
2962 (void) GetNextToken(q,&q,extent,token);
2963 if (graphic_context[n]->clip_path != MagickFalse)
2965 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2966 if (mvg_class != (
const char *) NULL)
2968 (void) DrawPatternPath(image,draw_info,mvg_class,
2969 &graphic_context[n]->fill_pattern,exception);
2972 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
2973 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
2975 (void) DrawPatternPath(image,draw_info,token,
2976 &graphic_context[n]->fill_pattern,exception);
2979 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
2980 &graphic_context[n]->fill,exception);
2981 if (graphic_context[n]->fill_alpha != (
double) OpaqueAlpha)
2982 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
2985 if (LocaleCompare(
"fill-opacity",keyword) == 0)
2990 (void) GetNextToken(q,&q,extent,token);
2991 if (graphic_context[n]->clip_path != MagickFalse)
2993 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
2994 opacity=MagickMin(MagickMax(factor*
2995 GetDrawValue(token,&next_token),0.0),1.0);
2996 if (token == next_token)
2997 ThrowPointExpectedException(token,exception);
2998 if (graphic_context[n]->compliance == SVGCompliance)
2999 graphic_context[n]->fill_alpha*=opacity;
3001 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3002 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3003 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3005 graphic_context[n]->fill.alpha=(MagickRealType)
3006 ClampToQuantum((
double) QuantumRange*opacity);
3007 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3010 if (LocaleCompare(
"fill-rule",keyword) == 0)
3015 (void) GetNextToken(q,&q,extent,token);
3016 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3018 if (fill_rule == -1)
3023 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3026 if (LocaleCompare(
"font",keyword) == 0)
3028 (void) GetNextToken(q,&q,extent,token);
3029 (void) CloneString(&graphic_context[n]->font,token);
3030 if (LocaleCompare(
"none",token) == 0)
3031 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3032 graphic_context[n]->font);
3035 if (LocaleCompare(
"font-family",keyword) == 0)
3037 (void) GetNextToken(q,&q,extent,token);
3038 (void) CloneString(&graphic_context[n]->family,token);
3041 if (LocaleCompare(
"font-size",keyword) == 0)
3043 (void) GetNextToken(q,&q,extent,token);
3044 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3045 if (token == next_token)
3046 ThrowPointExpectedException(token,exception);
3049 if (LocaleCompare(
"font-stretch",keyword) == 0)
3054 (void) GetNextToken(q,&q,extent,token);
3055 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3061 graphic_context[n]->stretch=(StretchType) stretch;
3064 if (LocaleCompare(
"font-style",keyword) == 0)
3069 (void) GetNextToken(q,&q,extent,token);
3070 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3076 graphic_context[n]->style=(StyleType) style;
3079 if (LocaleCompare(
"font-weight",keyword) == 0)
3084 (void) GetNextToken(q,&q,extent,token);
3085 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3087 weight=(ssize_t) StringToUnsignedLong(token);
3088 graphic_context[n]->weight=(size_t) weight;
3097 if (LocaleCompare(
"gradient-units",keyword) == 0)
3099 (void) GetNextToken(q,&q,extent,token);
3102 if (LocaleCompare(
"gravity",keyword) == 0)
3107 (void) GetNextToken(q,&q,extent,token);
3108 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3114 graphic_context[n]->gravity=(GravityType) gravity;
3123 if (LocaleCompare(
"image",keyword) == 0)
3128 primitive_type=ImagePrimitive;
3129 (void) GetNextToken(q,&q,extent,token);
3130 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3136 graphic_context[n]->compose=(CompositeOperator) compose;
3139 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3141 (void) GetNextToken(q,&q,extent,token);
3142 graphic_context[n]->interline_spacing=GetDrawValue(token,
3144 if (token == next_token)
3145 ThrowPointExpectedException(token,exception);
3148 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3150 (void) GetNextToken(q,&q,extent,token);
3151 graphic_context[n]->interword_spacing=GetDrawValue(token,
3153 if (token == next_token)
3154 ThrowPointExpectedException(token,exception);
3163 if (LocaleCompare(
"kerning",keyword) == 0)
3165 (void) GetNextToken(q,&q,extent,token);
3166 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3167 if (token == next_token)
3168 ThrowPointExpectedException(token,exception);
3177 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3179 (void) GetNextToken(q,&q,extent,token);
3180 if (IsPoint(token) == MagickFalse)
3182 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
3183 clone_info->text=AcquireString(
" ");
3184 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,&metrics,
3186 graphic_context[n]->kerning=metrics.width*
3187 GetDrawValue(token,&next_token);
3188 clone_info=DestroyDrawInfo(clone_info);
3189 if (token == next_token)
3190 ThrowPointExpectedException(token,exception);
3193 if (LocaleCompare(
"line",keyword) == 0)
3195 primitive_type=LinePrimitive;
3204 if (LocaleCompare(
"mask",keyword) == 0)
3212 (void) GetNextToken(q,&q,extent,token);
3213 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3214 if (mask_path != (
const char *) NULL)
3216 if (graphic_context[n]->composite_mask != (
Image *) NULL)
3217 graphic_context[n]->composite_mask=
3218 DestroyImage(graphic_context[n]->composite_mask);
3219 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3220 graphic_context[n],token,mask_path,exception);
3221 if (graphic_context[n]->compliance != SVGCompliance)
3222 status=SetImageMask(image,CompositePixelMask,
3223 graphic_context[n]->composite_mask,exception);
3233 if (LocaleCompare(
"offset",keyword) == 0)
3235 (void) GetNextToken(q,&q,extent,token);
3238 if (LocaleCompare(
"opacity",keyword) == 0)
3243 (void) GetNextToken(q,&q,extent,token);
3244 if (graphic_context[n]->clip_path != MagickFalse)
3246 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3247 opacity=MagickMin(MagickMax(factor*
3248 GetDrawValue(token,&next_token),0.0),1.0);
3249 if (token == next_token)
3250 ThrowPointExpectedException(token,exception);
3251 if (graphic_context[n]->compliance == SVGCompliance)
3253 graphic_context[n]->fill_alpha*=opacity;
3254 graphic_context[n]->stroke_alpha*=opacity;
3258 graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
3259 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3261 if (graphic_context[n]->fill.alpha != (
double) TransparentAlpha)
3263 graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha;
3264 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3268 graphic_context[n]->fill.alpha=(MagickRealType)
3269 ClampToQuantum((
double) QuantumRange*opacity);
3270 graphic_context[n]->stroke.alpha=(MagickRealType)
3271 ClampToQuantum((
double) QuantumRange*opacity);
3273 graphic_context[n]->fill.alpha_trait=BlendPixelTrait;
3274 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3283 if (LocaleCompare(
"path",keyword) == 0)
3285 primitive_type=PathPrimitive;
3288 if (LocaleCompare(
"point",keyword) == 0)
3290 primitive_type=PointPrimitive;
3293 if (LocaleCompare(
"polyline",keyword) == 0)
3295 primitive_type=PolylinePrimitive;
3298 if (LocaleCompare(
"polygon",keyword) == 0)
3300 primitive_type=PolygonPrimitive;
3303 if (LocaleCompare(
"pop",keyword) == 0)
3305 if (GetNextToken(q,&q,extent,token) < 1)
3307 if (LocaleCompare(
"class",token) == 0)
3309 if (LocaleCompare(
"clip-path",token) == 0)
3311 if (LocaleCompare(
"defs",token) == 0)
3314 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3318 if (LocaleCompare(
"gradient",token) == 0)
3320 if (LocaleCompare(
"graphic-context",token) == 0)
3324 (void) ThrowMagickException(exception,GetMagickModule(),
3325 DrawError,
"UnbalancedGraphicContextPushPop",
"`%s'",token);
3330 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3331 (graphic_context[n]->compliance != SVGCompliance))
3332 if (LocaleCompare(graphic_context[n]->clip_mask,
3333 graphic_context[n-1]->clip_mask) != 0)
3334 status=SetImageMask(image,WritePixelMask,(
Image *) NULL,
3336 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3340 if (LocaleCompare(
"mask",token) == 0)
3342 if (LocaleCompare(
"pattern",token) == 0)
3344 if (LocaleCompare(
"symbol",token) == 0)
3347 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3354 if (LocaleCompare(
"push",keyword) == 0)
3356 if (GetNextToken(q,&q,extent,token) < 1)
3358 if (LocaleCompare(
"class",token) == 0)
3363 for (p=q; *q !=
'\0'; )
3365 if (GetNextToken(q,&q,extent,token) < 1)
3367 if (LocaleCompare(token,
"pop") != 0)
3369 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3370 if (LocaleCompare(token,
"class") != 0)
3374 (void) GetNextToken(q,&q,extent,token);
3377 if (LocaleCompare(
"clip-path",token) == 0)
3379 (void) GetNextToken(q,&q,extent,token);
3380 for (p=q; *q !=
'\0'; )
3382 if (GetNextToken(q,&q,extent,token) < 1)
3384 if (LocaleCompare(token,
"pop") != 0)
3386 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3387 if (LocaleCompare(token,
"clip-path") != 0)
3391 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3396 (void) GetNextToken(q,&q,extent,token);
3399 if (LocaleCompare(
"defs",token) == 0)
3402 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3406 if (LocaleCompare(
"gradient",token) == 0)
3409 key[2*MagickPathExtent],
3410 name[MagickPathExtent],
3411 type[MagickPathExtent];
3416 (void) GetNextToken(q,&q,extent,token);
3417 (void) CopyMagickString(name,token,MagickPathExtent);
3418 (void) GetNextToken(q,&q,extent,token);
3419 (void) CopyMagickString(type,token,MagickPathExtent);
3420 (void) GetNextToken(q,&q,extent,token);
3421 segment.x1=GetDrawValue(token,&next_token);
3422 if (token == next_token)
3423 ThrowPointExpectedException(token,exception);
3424 (void) GetNextToken(q,&q,extent,token);
3426 (void) GetNextToken(q,&q,extent,token);
3427 segment.y1=GetDrawValue(token,&next_token);
3428 if (token == next_token)
3429 ThrowPointExpectedException(token,exception);
3430 (void) GetNextToken(q,&q,extent,token);
3432 (void) GetNextToken(q,&q,extent,token);
3433 segment.x2=GetDrawValue(token,&next_token);
3434 if (token == next_token)
3435 ThrowPointExpectedException(token,exception);
3436 (void) GetNextToken(q,&q,extent,token);
3438 (void) GetNextToken(q,&q,extent,token);
3439 segment.y2=GetDrawValue(token,&next_token);
3440 if (token == next_token)
3441 ThrowPointExpectedException(token,exception);
3442 if (LocaleCompare(type,
"radial") == 0)
3444 (void) GetNextToken(q,&q,extent,token);
3446 (void) GetNextToken(q,&q,extent,token);
3448 for (p=q; *q !=
'\0'; )
3450 if (GetNextToken(q,&q,extent,token) < 1)
3452 if (LocaleCompare(token,
"pop") != 0)
3454 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3455 if (LocaleCompare(token,
"gradient") != 0)
3459 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3460 (p == (
char *) NULL) || ((q-4) < p))
3465 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3466 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3467 graphic_context[n]->affine.ry*segment.y1+
3468 graphic_context[n]->affine.tx;
3469 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3470 graphic_context[n]->affine.sy*segment.y1+
3471 graphic_context[n]->affine.ty;
3472 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3473 graphic_context[n]->affine.ry*segment.y2+
3474 graphic_context[n]->affine.tx;
3475 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3476 graphic_context[n]->affine.sy*segment.y2+
3477 graphic_context[n]->affine.ty;
3478 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3479 (void) SetImageArtifact(image,key,token);
3480 (void) FormatLocaleString(key,MagickPathExtent,
"%s-type",name);
3481 (void) SetImageArtifact(image,key,type);
3482 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3484 (void) FormatLocaleString(geometry,MagickPathExtent,
3485 "%gx%g%+.15g%+.15g",
3486 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3487 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3488 bounds.x1,bounds.y1);
3489 (void) SetImageArtifact(image,key,geometry);
3490 (void) GetNextToken(q,&q,extent,token);
3493 if (LocaleCompare(
"graphic-context",token) == 0)
3496 graphic_context=(
DrawInfo **) ResizeQuantumMemory(
3497 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3498 if (graphic_context == (
DrawInfo **) NULL)
3500 (void) ThrowMagickException(exception,GetMagickModule(),
3501 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3505 graphic_context[n]=CloneDrawInfo((
ImageInfo *) NULL,
3506 graphic_context[n-1]);
3509 (void) GetNextToken(q,&q,extent,token);
3510 (void) CloneString(&graphic_context[n]->
id,token);
3514 if (LocaleCompare(
"mask",token) == 0)
3516 (void) GetNextToken(q,&q,extent,token);
3519 if (LocaleCompare(
"pattern",token) == 0)
3522 key[2*MagickPathExtent],
3523 name[MagickPathExtent];
3528 (void) GetNextToken(q,&q,extent,token);
3529 (void) CopyMagickString(name,token,MagickPathExtent);
3530 (void) GetNextToken(q,&q,extent,token);
3531 region.x=CastDoubleToLong(ceil(GetDrawValue(token,
3533 if (token == next_token)
3534 ThrowPointExpectedException(token,exception);
3535 (void) GetNextToken(q,&q,extent,token);
3537 (void) GetNextToken(q,&q,extent,token);
3538 region.y=CastDoubleToLong(ceil(GetDrawValue(token,
3540 if (token == next_token)
3541 ThrowPointExpectedException(token,exception);
3542 (void) GetNextToken(q,&q,extent,token);
3544 (void) GetNextToken(q,&q,extent,token);
3545 region.width=CastDoubleToUnsigned(floor(GetDrawValue(
3546 token,&next_token)+0.5));
3547 if (token == next_token)
3548 ThrowPointExpectedException(token,exception);
3549 (void) GetNextToken(q,&q,extent,token);
3551 (void) GetNextToken(q,&q,extent,token);
3552 region.height=CastDoubleToUnsigned(GetDrawValue(token,
3554 if (token == next_token)
3555 ThrowPointExpectedException(token,exception);
3556 for (p=q; *q !=
'\0'; )
3558 if (GetNextToken(q,&q,extent,token) < 1)
3560 if (LocaleCompare(token,
"pop") != 0)
3562 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3563 if (LocaleCompare(token,
"pattern") != 0)
3567 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3572 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3573 (void) FormatLocaleString(key,MagickPathExtent,
"%s",name);
3574 (void) SetImageArtifact(image,key,token);
3575 (void) FormatLocaleString(key,MagickPathExtent,
"%s-geometry",
3577 (void) FormatLocaleString(geometry,MagickPathExtent,
3578 "%.20gx%.20g%+.20g%+.20g",(
double) region.width,(
double)
3579 region.height,(
double) region.x,(
double) region.y);
3580 (void) SetImageArtifact(image,key,geometry);
3581 (void) GetNextToken(q,&q,extent,token);
3584 if (LocaleCompare(
"symbol",token) == 0)
3587 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3600 if (LocaleCompare(
"rectangle",keyword) == 0)
3602 primitive_type=RectanglePrimitive;
3605 if (LocaleCompare(
"rotate",keyword) == 0)
3607 (void) GetNextToken(q,&q,extent,token);
3608 angle=GetDrawValue(token,&next_token);
3609 if (token == next_token)
3610 ThrowPointExpectedException(token,exception);
3611 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3612 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3613 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3614 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3617 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3619 primitive_type=RoundRectanglePrimitive;
3628 if (LocaleCompare(
"scale",keyword) == 0)
3630 (void) GetNextToken(q,&q,extent,token);
3631 affine.sx=GetDrawValue(token,&next_token);
3632 if (token == next_token)
3633 ThrowPointExpectedException(token,exception);
3634 (void) GetNextToken(q,&q,extent,token);
3636 (void) GetNextToken(q,&q,extent,token);
3637 affine.sy=GetDrawValue(token,&next_token);
3638 if (token == next_token)
3639 ThrowPointExpectedException(token,exception);
3642 if (LocaleCompare(
"skewX",keyword) == 0)
3644 (void) GetNextToken(q,&q,extent,token);
3645 angle=GetDrawValue(token,&next_token);
3646 if (token == next_token)
3647 ThrowPointExpectedException(token,exception);
3648 affine.ry=sin(DegreesToRadians(angle));
3651 if (LocaleCompare(
"skewY",keyword) == 0)
3653 (void) GetNextToken(q,&q,extent,token);
3654 angle=GetDrawValue(token,&next_token);
3655 if (token == next_token)
3656 ThrowPointExpectedException(token,exception);
3657 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3660 if (LocaleCompare(
"stop-color",keyword) == 0)
3666 if (number_stops == 1)
3667 stops=(
StopInfo *) AcquireQuantumMemory(2,
sizeof(*stops));
3669 if (number_stops > 2)
3670 stops=(
StopInfo *) ResizeQuantumMemory(stops,number_stops,
3674 (void) ThrowMagickException(exception,GetMagickModule(),
3675 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3679 (void) GetNextToken(q,&q,extent,token);
3680 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3681 &stop_color,exception);
3682 stops[number_stops-1].color=stop_color;
3683 (void) GetNextToken(q,&q,extent,token);
3684 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3685 stops[number_stops-1].offset=factor*GetDrawValue(token,
3687 if (token == next_token)
3688 ThrowPointExpectedException(token,exception);
3691 if (LocaleCompare(
"stroke",keyword) == 0)
3696 (void) GetNextToken(q,&q,extent,token);
3697 if (graphic_context[n]->clip_path != MagickFalse)
3699 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3700 if (mvg_class != (
const char *) NULL)
3702 (void) DrawPatternPath(image,draw_info,mvg_class,
3703 &graphic_context[n]->stroke_pattern,exception);
3706 (void) FormatLocaleString(pattern,MagickPathExtent,
"%s",token);
3707 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3709 (void) DrawPatternPath(image,draw_info,token,
3710 &graphic_context[n]->stroke_pattern,exception);
3713 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3714 &graphic_context[n]->stroke,exception);
3715 if (graphic_context[n]->stroke_alpha != (
double) OpaqueAlpha)
3716 graphic_context[n]->stroke.alpha=
3717 graphic_context[n]->stroke_alpha;
3720 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3722 (void) GetNextToken(q,&q,extent,token);
3723 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3724 MagickTrue : MagickFalse;
3727 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3729 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3730 graphic_context[n]->dash_pattern=(
double *)
3731 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3732 if (IsPoint(q) != MagickFalse)
3738 (void) GetNextToken(r,&r,extent,token);
3740 (void) GetNextToken(r,&r,extent,token);
3741 for (x=0; IsPoint(token) != MagickFalse; x++)
3743 (void) GetNextToken(r,&r,extent,token);
3745 (void) GetNextToken(r,&r,extent,token);
3747 graphic_context[n]->dash_pattern=(
double *)
3748 AcquireQuantumMemory((
size_t) (2*x+2),
3749 sizeof(*graphic_context[n]->dash_pattern));
3750 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3752 (void) ThrowMagickException(exception,GetMagickModule(),
3753 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
3758 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3759 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3760 for (j=0; j < x; j++)
3762 (void) GetNextToken(q,&q,extent,token);
3764 (void) GetNextToken(q,&q,extent,token);
3765 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3767 if (token == next_token)
3768 ThrowPointExpectedException(token,exception);
3769 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3772 if ((x & 0x01) != 0)
3773 for ( ; j < (2*x); j++)
3774 graphic_context[n]->dash_pattern[j]=
3775 graphic_context[n]->dash_pattern[j-x];
3776 graphic_context[n]->dash_pattern[j]=0.0;
3779 (void) GetNextToken(q,&q,extent,token);
3782 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3784 (void) GetNextToken(q,&q,extent,token);
3785 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3786 if (token == next_token)
3787 ThrowPointExpectedException(token,exception);
3790 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3795 (void) GetNextToken(q,&q,extent,token);
3796 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3802 graphic_context[n]->linecap=(LineCap) linecap;
3805 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3810 (void) GetNextToken(q,&q,extent,token);
3811 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3818 graphic_context[n]->linejoin=(LineJoin) linejoin;
3821 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3823 (void) GetNextToken(q,&q,extent,token);
3824 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3827 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3832 (void) GetNextToken(q,&q,extent,token);
3833 if (graphic_context[n]->clip_path != MagickFalse)
3835 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3836 opacity=MagickMin(MagickMax(factor*GetDrawValue(token,&next_token),
3838 if (token == next_token)
3839 ThrowPointExpectedException(token,exception);
3840 if (graphic_context[n]->compliance == SVGCompliance)
3841 graphic_context[n]->stroke_alpha*=opacity;
3843 graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
3844 if (graphic_context[n]->stroke.alpha != (
double) TransparentAlpha)
3845 graphic_context[n]->stroke.alpha=graphic_context[n]->stroke_alpha;
3847 graphic_context[n]->stroke.alpha=(MagickRealType)
3848 ClampToQuantum((
double) QuantumRange*opacity);
3849 graphic_context[n]->stroke.alpha_trait=BlendPixelTrait;
3852 if (LocaleCompare(
"stroke-width",keyword) == 0)
3854 (void) GetNextToken(q,&q,extent,token);
3855 if (graphic_context[n]->clip_path != MagickFalse)
3857 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3858 if ((token == next_token) ||
3859 (graphic_context[n]->stroke_width < 0.0))
3860 ThrowPointExpectedException(token,exception);
3869 if (LocaleCompare(
"text",keyword) == 0)
3871 primitive_type=TextPrimitive;
3875 if (LocaleCompare(
"text-align",keyword) == 0)
3880 (void) GetNextToken(q,&q,extent,token);
3881 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3887 graphic_context[n]->align=(AlignType) align;
3890 if (LocaleCompare(
"text-anchor",keyword) == 0)
3895 (void) GetNextToken(q,&q,extent,token);
3896 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3902 graphic_context[n]->align=(AlignType) align;
3905 if (LocaleCompare(
"text-antialias",keyword) == 0)
3907 (void) GetNextToken(q,&q,extent,token);
3908 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
3909 MagickTrue : MagickFalse;
3912 if (LocaleCompare(
"text-undercolor",keyword) == 0)
3914 (void) GetNextToken(q,&q,extent,token);
3915 status&=(MagickStatusType) QueryColorCompliance(token,AllCompliance,
3916 &graphic_context[n]->undercolor,exception);
3919 if (LocaleCompare(
"translate",keyword) == 0)
3921 (void) GetNextToken(q,&q,extent,token);
3922 affine.tx=GetDrawValue(token,&next_token);
3923 if (token == next_token)
3924 ThrowPointExpectedException(token,exception);
3925 (void) GetNextToken(q,&q,extent,token);
3927 (void) GetNextToken(q,&q,extent,token);
3928 affine.ty=GetDrawValue(token,&next_token);
3929 if (token == next_token)
3930 ThrowPointExpectedException(token,exception);
3940 if (LocaleCompare(
"use",keyword) == 0)
3948 (void) GetNextToken(q,&q,extent,token);
3949 use=(
const char *) GetValueFromSplayTree(macros,token);
3950 if (use != (
const char *) NULL)
3952 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
3953 (void) CloneString(&clone_info->primitive,use);
3954 status=RenderMVGContent(image,clone_info,depth+1,exception);
3955 clone_info=DestroyDrawInfo(clone_info);
3965 if (LocaleCompare(
"viewbox",keyword) == 0)
3967 (void) GetNextToken(q,&q,extent,token);
3968 graphic_context[n]->viewbox.x=CastDoubleToLong(ceil(
3969 GetDrawValue(token,&next_token)-0.5));
3970 if (token == next_token)
3971 ThrowPointExpectedException(token,exception);
3972 (void) GetNextToken(q,&q,extent,token);
3974 (void) GetNextToken(q,&q,extent,token);
3975 graphic_context[n]->viewbox.y=CastDoubleToLong(
3976 ceil(GetDrawValue(token,&next_token)-0.5));
3977 if (token == next_token)
3978 ThrowPointExpectedException(token,exception);
3979 (void) GetNextToken(q,&q,extent,token);
3981 (void) GetNextToken(q,&q,extent,token);
3982 graphic_context[n]->viewbox.width=CastDoubleToUnsigned(
3983 floor(GetDrawValue(token,&next_token)+0.5));
3984 if (token == next_token)
3985 ThrowPointExpectedException(token,exception);
3986 (void) GetNextToken(q,&q,extent,token);
3988 (void) GetNextToken(q,&q,extent,token);
3989 graphic_context[n]->viewbox.height=(size_t) CastDoubleToUnsigned(
3990 floor(GetDrawValue(token,&next_token)+0.5));
3991 if (token == next_token)
3992 ThrowPointExpectedException(token,exception);
4001 if (LocaleCompare(
"word-spacing",keyword) == 0)
4003 (void) GetNextToken(q,&q,extent,token);
4004 graphic_context[n]->interword_spacing=GetDrawValue(token,
4006 if (token == next_token)
4007 ThrowPointExpectedException(token,exception);
4019 if (status == MagickFalse)
4021 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4022 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4023 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4024 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4026 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4027 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4028 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4029 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4030 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4032 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4035 if (primitive_type == UndefinedPrimitive)
4039 if (number_stops > 1)
4044 type=LinearGradient;
4045 if (draw_info->gradient.type == RadialGradient)
4046 type=RadialGradient;
4047 (void) GradientImage(image,type,PadSpread,stops,number_stops,
4050 if (number_stops > 0)
4051 stops=(
StopInfo *) RelinquishMagickMemory(stops);
4053 if ((draw_info->debug != MagickFalse) && (q > p))
4054 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int)
4061 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4062 if (primitive_info[i].text != (
char *) NULL)
4063 primitive_info[i].text=DestroyString(primitive_info[i].text);
4067 primitive_info[0].point.x=0.0;
4068 primitive_info[0].point.y=0.0;
4069 primitive_info[0].coordinates=0;
4070 primitive_info[0].method=FloodfillMethod;
4071 primitive_info[0].closed_subpath=MagickFalse;
4072 for (x=0; *q !=
'\0'; x++)
4077 if (IsPoint(q) == MagickFalse)
4079 (void) GetNextToken(q,&q,extent,token);
4080 point.x=GetDrawValue(token,&next_token);
4081 if (token == next_token)
4082 ThrowPointExpectedException(token,exception);
4083 (void) GetNextToken(q,&q,extent,token);
4085 (void) GetNextToken(q,&q,extent,token);
4086 point.y=GetDrawValue(token,&next_token);
4087 if (token == next_token)
4088 ThrowPointExpectedException(token,exception);
4089 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4091 (void) GetNextToken(q,&q,extent,token);
4092 primitive_info[i].primitive=primitive_type;
4093 primitive_info[i].point=point;
4094 primitive_info[i].coordinates=0;
4095 primitive_info[i].method=FloodfillMethod;
4096 primitive_info[i].closed_subpath=MagickFalse;
4099 if (i < (ssize_t) number_points)
4101 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4103 primitive_info=(*mvg_info.primitive_info);
4105 if (status == MagickFalse)
4107 if (primitive_info[j].text != (
char *) NULL)
4108 primitive_info[j].text=DestroyString(primitive_info[j].text);
4109 primitive_info[j].primitive=primitive_type;
4110 primitive_info[j].coordinates=(size_t) x;
4111 primitive_info[j].method=FloodfillMethod;
4112 primitive_info[j].closed_subpath=MagickFalse;
4116 bounds.x1=primitive_info[j].point.x;
4117 bounds.y1=primitive_info[j].point.y;
4118 bounds.x2=primitive_info[j].point.x;
4119 bounds.y2=primitive_info[j].point.y;
4120 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4122 point=primitive_info[j+k].point;
4123 if (point.x < bounds.x1)
4125 if (point.y < bounds.y1)
4127 if (point.x > bounds.x2)
4129 if (point.y > bounds.y2)
4135 coordinates=(double) primitive_info[j].coordinates;
4136 switch (primitive_type)
4138 case RectanglePrimitive:
4143 case RoundRectanglePrimitive:
4150 alpha=bounds.x2-bounds.x1;
4151 beta=bounds.y2-bounds.y1;
4152 radius=hypot(alpha,beta);
4154 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4155 BezierQuantum+360.0;
4158 case BezierPrimitive:
4160 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4169 (void) GetNextToken(q,&q,extent,token);
4172 for (s=token; *s !=
'\0'; s=t)
4177 value=GetDrawValue(s,&t);
4186 for (s=token; *s !=
'\0'; s++)
4187 if (strspn(s,
"AaCcQqSsTt") != 0)
4188 coordinates+=(20.0*BezierQuantum)+360.0;
4194 if (status == MagickFalse)
4196 if (((
size_t) (i+coordinates)) >= number_points)
4201 number_points+=coordinates+1;
4202 if (number_points < (
size_t) coordinates)
4204 (void) ThrowMagickException(exception,GetMagickModule(),
4205 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4210 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4212 primitive_info=(*mvg_info.primitive_info);
4214 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,
4215 PrimitiveExtentPad);
4216 primitive_info=(*mvg_info.primitive_info);
4217 if (status == MagickFalse)
4220 switch (primitive_type)
4222 case PointPrimitive:
4225 if (primitive_info[j].coordinates != 1)
4230 status&=(MagickStatusType) TracePoint(primitive_info+j,
4231 primitive_info[j].point);
4232 primitive_info=(*mvg_info.primitive_info);
4233 i=j+(ssize_t) primitive_info[j].coordinates;
4238 if (primitive_info[j].coordinates != 2)
4243 status&=(MagickStatusType) TraceLine(primitive_info+j,
4244 primitive_info[j].point,primitive_info[j+1].point);
4245 primitive_info=(*mvg_info.primitive_info);
4246 i=j+(ssize_t) primitive_info[j].coordinates;
4249 case RectanglePrimitive:
4251 if (primitive_info[j].coordinates != 2)
4256 status&=(MagickStatusType) TraceRectangle(primitive_info+j,
4257 primitive_info[j].point,primitive_info[j+1].point);
4258 primitive_info=(*mvg_info.primitive_info);
4259 i=j+(ssize_t) primitive_info[j].coordinates;
4262 case RoundRectanglePrimitive:
4264 if (primitive_info[j].coordinates != 3)
4269 if ((primitive_info[j+2].point.x < 0.0) ||
4270 (primitive_info[j+2].point.y < 0.0))
4275 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4280 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4285 status&=(MagickStatusType) TraceRoundRectangle(&mvg_info,
4286 primitive_info[j].point,primitive_info[j+1].point,
4287 primitive_info[j+2].point);
4288 primitive_info=(*mvg_info.primitive_info);
4289 i=j+(ssize_t) primitive_info[j].coordinates;
4294 if (primitive_info[j].coordinates != 3)
4299 status&=(MagickStatusType) TraceArc(&mvg_info,primitive_info[j].point,
4300 primitive_info[j+1].point,primitive_info[j+2].point);
4301 primitive_info=(*mvg_info.primitive_info);
4302 i=j+(ssize_t) primitive_info[j].coordinates;
4305 case EllipsePrimitive:
4307 if (primitive_info[j].coordinates != 3)
4312 if ((primitive_info[j+1].point.x < 0.0) ||
4313 (primitive_info[j+1].point.y < 0.0))
4318 status&=(MagickStatusType) TraceEllipse(&mvg_info,
4319 primitive_info[j].point,primitive_info[j+1].point,
4320 primitive_info[j+2].point);
4321 primitive_info=(*mvg_info.primitive_info);
4322 i=j+(ssize_t) primitive_info[j].coordinates;
4325 case CirclePrimitive:
4327 if (primitive_info[j].coordinates != 2)
4332 status&=(MagickStatusType) TraceCircle(&mvg_info,
4333 primitive_info[j].point,primitive_info[j+1].point);
4334 primitive_info=(*mvg_info.primitive_info);
4335 i=j+(ssize_t) primitive_info[j].coordinates;
4338 case PolylinePrimitive:
4340 if (primitive_info[j].coordinates < 1)
4347 case PolygonPrimitive:
4349 if (primitive_info[j].coordinates < 3)
4354 primitive_info[i]=primitive_info[j];
4355 primitive_info[i].coordinates=0;
4356 primitive_info[j].coordinates++;
4357 primitive_info[j].closed_subpath=MagickTrue;
4361 case BezierPrimitive:
4363 if (primitive_info[j].coordinates < 3)
4368 status&=(MagickStatusType) TraceBezier(&mvg_info,
4369 primitive_info[j].coordinates);
4370 primitive_info=(*mvg_info.primitive_info);
4371 i=j+(ssize_t) primitive_info[j].coordinates;
4376 coordinates=(double) TracePath(&mvg_info,token,exception);
4377 primitive_info=(*mvg_info.primitive_info);
4378 if (coordinates < 0.0)
4383 i=(ssize_t) (j+coordinates);
4386 case AlphaPrimitive:
4387 case ColorPrimitive:
4392 if (primitive_info[j].coordinates != 1)
4397 (void) GetNextToken(q,&q,extent,token);
4398 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4404 primitive_info[j].method=(PaintMethod) method;
4409 if (primitive_info[j].coordinates != 1)
4415 (void) GetNextToken(q,&q,extent,token);
4416 (void) CloneString(&primitive_info[j].text,token);
4420 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
4421 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4422 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4424 mvg_info.point=primitive_info->point;
4425 primitive_info->point.x+=cursor;
4429 mvg_info.point=primitive_info->point;
4432 clone_info->render=MagickFalse;
4433 clone_info->text=AcquireString(token);
4434 status&=(MagickStatusType) GetTypeMetrics(image,clone_info,
4435 &metrics,exception);
4436 clone_info=DestroyDrawInfo(clone_info);
4437 cursor+=metrics.width;
4438 if (graphic_context[n]->compliance != SVGCompliance)
4442 case ImagePrimitive:
4444 if (primitive_info[j].coordinates != 2)
4449 (void) GetNextToken(q,&q,extent,token);
4450 (void) CloneString(&primitive_info[j].text,token);
4457 primitive_info[i].primitive=UndefinedPrimitive;
4458 if ((draw_info->debug != MagickFalse) && (q > p))
4459 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(
int) (q-p),p);
4463 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4464 &graphic_context[n]->affine));
4465 primitive_info=(*mvg_info.primitive_info);
4468 status&=(MagickStatusType) CheckPrimitiveExtent(&mvg_info,(
double)
4469 graphic_context[n]->stroke_width);
4470 primitive_info=(*mvg_info.primitive_info);
4478 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4480 point=primitive_info[i].point;
4481 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4482 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4483 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4484 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4485 point=primitive_info[i].point;
4486 if (point.x < graphic_context[n]->bounds.x1)
4487 graphic_context[n]->bounds.x1=point.x;
4488 if (point.y < graphic_context[n]->bounds.y1)
4489 graphic_context[n]->bounds.y1=point.y;
4490 if (point.x > graphic_context[n]->bounds.x2)
4491 graphic_context[n]->bounds.x2=point.x;
4492 if (point.y > graphic_context[n]->bounds.y2)
4493 graphic_context[n]->bounds.y2=point.y;
4494 if (primitive_info[i].primitive == ImagePrimitive)
4496 if (i >= (ssize_t) number_points)
4497 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4499 if (graphic_context[n]->render != MagickFalse)
4501 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4502 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4503 (LocaleCompare(graphic_context[n]->clip_mask,
4504 graphic_context[n-1]->clip_mask) != 0))
4509 clip_path=(
const char *) GetValueFromSplayTree(macros,
4510 graphic_context[n]->clip_mask);
4511 if (clip_path != (
const char *) NULL)
4512 (void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4514 status&=(MagickStatusType) DrawClipPath(image,graphic_context[n],
4515 graphic_context[n]->clip_mask,exception);
4517 status&=(MagickStatusType) DrawPrimitive(image,graphic_context[n],
4518 primitive_info,exception);
4520 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4522 if (proceed == MagickFalse)
4527 if (draw_info->debug != MagickFalse)
4528 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4532 macros=DestroySplayTree(macros);
4533 token=DestroyString(token);
4536 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4537 if (primitive_info[i].text != (
char *) NULL)
4538 primitive_info[i].text=DestroyString(primitive_info[i].text);
4539 primitive_info=(
PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4541 primitive=DestroyString(primitive);
4543 stops=(
StopInfo *) RelinquishMagickMemory(stops);
4544 for ( ; n >= 0; n--)
4545 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4546 graphic_context=(
DrawInfo **) RelinquishMagickMemory(graphic_context);
4547 if ((status == MagickFalse) && (exception->severity < ErrorException))
4548 ThrowBinaryException(DrawError,
"NonconformingDrawingPrimitiveDefinition",
4550 return(status != 0 ? MagickTrue : MagickFalse);
4553MagickExport MagickBooleanType DrawImage(
Image *image,
const DrawInfo *draw_info,
4556 return(RenderMVGContent(image,draw_info,0,exception));
4590MagickExport MagickBooleanType DrawPatternPath(
Image *image,
4595 property[MagickPathExtent];
4611 assert(image != (
Image *) NULL);
4612 assert(image->signature == MagickCoreSignature);
4613 assert(draw_info != (
const DrawInfo *) NULL);
4614 assert(name != (
const char *) NULL);
4615 if (IsEventLogging() != MagickFalse)
4616 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4617 (void) FormatLocaleString(property,MagickPathExtent,
"%s",name);
4618 path=GetImageArtifact(image,property);
4619 if (path == (
const char *) NULL)
4620 return(MagickFalse);
4621 (void) FormatLocaleString(property,MagickPathExtent,
"%s-geometry",name);
4622 geometry=GetImageArtifact(image,property);
4623 if (geometry == (
const char *) NULL)
4624 return(MagickFalse);
4625 if ((*pattern) != (
Image *) NULL)
4626 *pattern=DestroyImage(*pattern);
4627 image_info=AcquireImageInfo();
4628 image_info->size=AcquireString(geometry);
4629 *pattern=AcquireImage(image_info,exception);
4630 image_info=DestroyImageInfo(image_info);
4631 (void) QueryColorCompliance(
"#00000000",AllCompliance,
4632 &(*pattern)->background_color,exception);
4633 (void) SetImageBackgroundColor(*pattern,exception);
4634 if (draw_info->debug != MagickFalse)
4635 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4636 "begin pattern-path %s %s",name,geometry);
4637 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
4638 if (clone_info->fill_pattern != (
Image *) NULL)
4639 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4640 if (clone_info->stroke_pattern != (
Image *) NULL)
4641 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4642 (void) FormatLocaleString(property,MagickPathExtent,
"%s-type",name);
4643 type=GetImageArtifact(image,property);
4644 if (type != (
const char *) NULL)
4645 clone_info->gradient.type=(GradientType) ParseCommandOption(
4646 MagickGradientOptions,MagickFalse,type);
4647 (void) CloneString(&clone_info->primitive,path);
4648 status=RenderMVGContent(*pattern,clone_info,0,exception);
4649 clone_info=DestroyDrawInfo(clone_info);
4650 if (draw_info->debug != MagickFalse)
4651 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4692 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4694 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4695 polygon_info=(
PolygonInfo **) RelinquishMagickMemory(polygon_info);
4696 return(polygon_info);
4703 *magick_restrict path_info;
4711 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4712 polygon_info=(
PolygonInfo **) AcquireQuantumMemory(number_threads,
4713 sizeof(*polygon_info));
4716 (void) ThrowMagickException(exception,GetMagickModule(),
4717 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4720 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4721 path_info=ConvertPrimitiveToPath(primitive_info,exception);
4722 if (path_info == (
PathInfo *) NULL)
4723 return(DestroyPolygonTLS(polygon_info));
4724 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4727 (void) ThrowMagickException(exception,GetMagickModule(),
4728 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4729 return(DestroyPolygonTLS(polygon_info));
4731 path_info=(
PathInfo *) RelinquishMagickMemory(path_info);
4732 return(polygon_info);
4735static MagickBooleanType ClonePolygonEdgesTLS(
PolygonInfo **polygon_info,
4741 for (i=1; i < (ssize_t) number_threads; i++)
4749 polygon_info[i]=(
PolygonInfo *) AcquireMagickMemory(
4750 sizeof(*polygon_info[i]));
4753 (void) ThrowMagickException(exception,GetMagickModule(),
4754 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4755 return(MagickFalse);
4757 polygon_info[i]->number_edges=0;
4758 edge_info=polygon_info[0]->edges;
4759 polygon_info[i]->edges=(
EdgeInfo *) AcquireQuantumMemory(
4760 polygon_info[0]->number_edges,
sizeof(*edge_info));
4761 if (polygon_info[i]->edges == (
EdgeInfo *) NULL)
4763 (void) ThrowMagickException(exception,GetMagickModule(),
4764 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4765 return(MagickFalse);
4767 (void) memcpy(polygon_info[i]->edges,edge_info,
4768 polygon_info[0]->number_edges*
sizeof(*edge_info));
4769 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4770 polygon_info[i]->edges[j].points=(
PointInfo *) NULL;
4771 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4772 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4774 edge_info=polygon_info[0]->edges+j;
4775 polygon_info[i]->edges[j].points=(
PointInfo *) AcquireQuantumMemory(
4776 edge_info->number_points,
sizeof(*edge_info));
4777 if (polygon_info[i]->edges[j].points == (
PointInfo *) NULL)
4779 (void) ThrowMagickException(exception,GetMagickModule(),
4780 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4781 return(MagickFalse);
4783 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4784 edge_info->number_points*
sizeof(*edge_info->points));
4790static size_t DestroyEdge(
PolygonInfo *polygon_info,
const ssize_t edge)
4792 assert(edge < (ssize_t) polygon_info->number_edges);
4793 polygon_info->edges[edge].points=(
PointInfo *) RelinquishMagickMemory(
4794 polygon_info->edges[edge].points);
4795 polygon_info->number_edges--;
4796 if (edge < (ssize_t) polygon_info->number_edges)
4797 (void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4798 (polygon_info->number_edges-(
size_t) edge)*
sizeof(*polygon_info->edges));
4799 return(polygon_info->number_edges);
4802static double GetFillAlpha(
PolygonInfo *polygon_info,
const double mid,
4803 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4804 const ssize_t y,
double *stroke_alpha)
4831 p=polygon_info->edges;
4832 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4834 if ((
double) y <= (p->bounds.y1-mid-0.5))
4836 if ((
double) y > (p->bounds.y2+mid+0.5))
4839 (void) DestroyEdge(polygon_info,j--);
4842 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
4843 ((
double) x > (p->bounds.x2+mid+0.5)))
4845 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
4846 for ( ; i < (ssize_t) p->number_points; i++)
4848 if ((
double) y <= (p->points[i-1].y-mid-0.5))
4850 if ((
double) y > (p->points[i].y+mid+0.5))
4852 if (p->scanline != (
double) y)
4854 p->scanline=(double) y;
4855 p->highwater=(size_t) i;
4861 delta.x=(q+1)->x-q->x;
4862 delta.y=(q+1)->y-q->y;
4863 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
4869 delta.x=(double) x-q->x;
4870 delta.y=(double) y-q->y;
4871 distance=delta.x*delta.x+delta.y*delta.y;
4875 alpha=delta.x*delta.x+delta.y*delta.y;
4881 delta.x=(double) x-(q+1)->x;
4882 delta.y=(double) y-(q+1)->y;
4883 distance=delta.x*delta.x+delta.y*delta.y;
4890 alpha=PerceptibleReciprocal(alpha);
4891 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
4892 distance=alpha*beta*beta;
4899 if (p->ghostline == MagickFalse)
4902 if ((*stroke_alpha < 1.0) &&
4903 (distance <= ((alpha+0.25)*(alpha+0.25))))
4906 if (distance <= ((alpha+0.25)*(alpha+0.25)))
4911 if (fabs(distance-1.0) >= MagickEpsilon)
4912 beta=sqrt((
double) distance);
4914 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
4915 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
4919 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
4921 if (distance <= 0.0)
4928 if (fabs(beta) < MagickEpsilon)
4931 if (fabs(distance-1.0) >= MagickEpsilon)
4932 beta=sqrt(distance);
4935 if (subpath_alpha < (alpha*alpha))
4936 subpath_alpha=alpha*alpha;
4942 if (fill == MagickFalse)
4944 if (subpath_alpha >= 1.0)
4950 p=polygon_info->edges;
4951 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4953 if ((
double) y <= p->bounds.y1)
4955 if (((
double) y > p->bounds.y2) || ((
double) x <= p->bounds.x1))
4957 if ((
double) x > p->bounds.x2)
4959 winding_number+=p->direction != 0 ? 1 : -1;
4962 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
4963 for ( ; i < (ssize_t) (p->number_points-1); i++)
4964 if ((
double) y <= p->points[i].y)
4967 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
4968 winding_number+=p->direction != 0 ? 1 : -1;
4970 if (fill_rule != NonZeroRule)
4972 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
4976 if (MagickAbsoluteValue(winding_number) != 0)
4978 return(subpath_alpha);
4981static MagickBooleanType DrawPolygonPrimitive(
Image *image,
4985 typedef struct _ExtentInfo
5014 **magick_restrict polygon_info;
5026 assert(image != (
Image *) NULL);
5027 assert(image->signature == MagickCoreSignature);
5028 assert(draw_info != (
DrawInfo *) NULL);
5029 assert(draw_info->signature == MagickCoreSignature);
5031 if (IsEventLogging() != MagickFalse)
5032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5033 if (primitive_info->coordinates <= 1)
5038 polygon_info=AcquirePolygonTLS(primitive_info,exception);
5040 return(MagickFalse);
5041 if (draw_info->debug != MagickFalse)
5042 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5043 fill=(primitive_info->method == FillToBorderMethod) ||
5044 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5045 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5046 bounds=polygon_info[0]->edges[0].bounds;
5047 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5048 if (IsStringTrue(artifact) != MagickFalse)
5049 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
5050 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5052 p=polygon_info[0]->edges+i;
5053 if (p->bounds.x1 < bounds.x1)
5054 bounds.x1=p->bounds.x1;
5055 if (p->bounds.y1 < bounds.y1)
5056 bounds.y1=p->bounds.y1;
5057 if (p->bounds.x2 > bounds.x2)
5058 bounds.x2=p->bounds.x2;
5059 if (p->bounds.y2 > bounds.y2)
5060 bounds.y2=p->bounds.y2;
5062 bounds.x1-=(mid+1.0);
5063 bounds.y1-=(mid+1.0);
5064 bounds.x2+=(mid+1.0);
5065 bounds.y2+=(mid+1.0);
5066 if ((bounds.x1 >= (
double) image->columns) ||
5067 (bounds.y1 >= (
double) image->rows) ||
5068 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5070 polygon_info=DestroyPolygonTLS(polygon_info);
5073 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5074 (
double) image->columns-1.0 : bounds.x1;
5075 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5076 (
double) image->rows-1.0 : bounds.y1;
5077 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5078 (
double) image->columns-1.0 : bounds.x2;
5079 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5080 (
double) image->rows-1.0 : bounds.y2;
5081 poly_extent.x1=CastDoubleToLong(ceil(bounds.x1-0.5));
5082 poly_extent.y1=CastDoubleToLong(ceil(bounds.y1-0.5));
5083 poly_extent.x2=CastDoubleToLong(floor(bounds.x2+0.5));
5084 poly_extent.y2=CastDoubleToLong(floor(bounds.y2+0.5));
5085 number_threads=(size_t) GetMagickNumberThreads(image,image,(
size_t)
5086 (poly_extent.y2-poly_extent.y1+1),1);
5087 status=ClonePolygonEdgesTLS(polygon_info,number_threads,exception);
5088 if (status == MagickFalse)
5090 polygon_info=DestroyPolygonTLS(polygon_info);
5093 image_view=AcquireAuthenticCacheView(image,exception);
5094 if ((primitive_info->coordinates == 1) ||
5095 (polygon_info[0]->number_edges == 0))
5100#if defined(MAGICKCORE_OPENMP_SUPPORT)
5101 #pragma omp parallel for schedule(static) shared(status) \
5102 num_threads((int) number_threads)
5104 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5115 if (status == MagickFalse)
5118 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5120 if (q == (Quantum *) NULL)
5125 GetPixelInfo(image,&pixel);
5126 for ( ; x <= poly_extent.x2; x++)
5128 if ((x == CastDoubleToLong(ceil(primitive_info->point.x-0.5))) &&
5129 (y == CastDoubleToLong(ceil(primitive_info->point.y-0.5))))
5131 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&pixel,
5133 SetPixelViaPixelInfo(image,&pixel,q);
5135 q+=GetPixelChannels(image);
5137 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5140 image_view=DestroyCacheView(image_view);
5141 polygon_info=DestroyPolygonTLS(polygon_info);
5142 if (draw_info->debug != MagickFalse)
5143 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5144 " end draw-polygon");
5150#if defined(MAGICKCORE_OPENMP_SUPPORT)
5151 #pragma omp parallel for schedule(static) shared(status) \
5152 num_threads((int) number_threads)
5154 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5157 id = GetOpenMPThreadId();
5165 if (status == MagickFalse)
5167 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5168 (poly_extent.x2-poly_extent.x1+1),1,exception);
5169 if (q == (Quantum *) NULL)
5174 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5187 fill_alpha=GetFillAlpha(polygon_info[
id],mid,fill,draw_info->fill_rule,
5189 if (draw_info->stroke_antialias == MagickFalse)
5191 fill_alpha=fill_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5192 stroke_alpha=stroke_alpha >= AntialiasThreshold ? 1.0 : 0.0;
5194 GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&fill_color,
5196 CompositePixelOver(image,&fill_color,fill_alpha*fill_color.alpha,q,
5197 (
double) GetPixelAlpha(image,q),q);
5198 GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,&stroke_color,
5200 CompositePixelOver(image,&stroke_color,stroke_alpha*stroke_color.alpha,q,
5201 (
double) GetPixelAlpha(image,q),q);
5202 q+=GetPixelChannels(image);
5204 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5207 image_view=DestroyCacheView(image_view);
5208 polygon_info=DestroyPolygonTLS(polygon_info);
5209 if (draw_info->debug != MagickFalse)
5210 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5243static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5269 x=CastDoubleToLong(ceil(primitive_info->point.x-0.5));
5270 y=CastDoubleToLong(ceil(primitive_info->point.y-0.5));
5271 switch (primitive_info->primitive)
5273 case AlphaPrimitive:
5275 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5276 "AlphaPrimitive %.20g,%.20g %s",(
double) x,(
double) y,
5277 methods[primitive_info->method]);
5280 case ColorPrimitive:
5282 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5283 "ColorPrimitive %.20g,%.20g %s",(
double) x,(
double) y,
5284 methods[primitive_info->method]);
5287 case ImagePrimitive:
5289 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5290 "ImagePrimitive %.20g,%.20g",(
double) x,(
double) y);
5293 case PointPrimitive:
5295 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5296 "PointPrimitive %.20g,%.20g %s",(
double) x,(
double) y,
5297 methods[primitive_info->method]);
5302 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5303 "TextPrimitive %.20g,%.20g",(
double) x,(
double) y);
5310 p=primitive_info[0].point;
5313 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5315 point=primitive_info[i].point;
5316 if (coordinates <= 0)
5318 coordinates=(ssize_t) primitive_info[i].coordinates;
5319 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5320 " begin open (%.20g)",(
double) coordinates);
5323 point=primitive_info[i].point;
5324 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5325 (fabs(q.y-point.y) >= MagickEpsilon))
5326 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5327 " %.20g: %.18g,%.18g",(
double) coordinates,point.x,point.y);
5329 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5330 " %.20g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5333 if (coordinates > 0)
5335 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5336 (fabs(p.y-point.y) >= MagickEpsilon))
5337 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.20g)",
5338 (
double) coordinates);
5340 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.20g)",
5341 (
double) coordinates);
5345MagickExport MagickBooleanType DrawPrimitive(
Image *image,
5362 if (draw_info->debug != MagickFalse)
5364 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5365 " begin draw-primitive");
5366 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5367 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5368 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5369 draw_info->affine.tx,draw_info->affine.ty);
5372 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5373 ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
5374 (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
5375 status&=(MagickStatusType) SetImageColorspace(image,sRGBColorspace,
5377 if (draw_info->compliance == SVGCompliance)
5379 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5380 draw_info->clipping_mask,exception);
5381 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5382 draw_info->composite_mask,exception);
5384 x=CastDoubleToLong(ceil(primitive_info->point.x-0.5));
5385 y=CastDoubleToLong(ceil(primitive_info->point.y-0.5));
5386 image_view=AcquireAuthenticCacheView(image,exception);
5387 switch (primitive_info->primitive)
5389 case AlphaPrimitive:
5391 if ((image->alpha_trait & BlendPixelTrait) == 0)
5392 status&=(MagickStatusType) SetImageAlphaChannel(image,
5393 OpaqueAlphaChannel,exception);
5394 switch (primitive_info->method)
5405 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5406 if (q == (Quantum *) NULL)
5408 GetFillColor(draw_info,x,y,&pixel,exception);
5409 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5410 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5420 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5421 x,y,&target,exception);
5422 GetPixelInfo(image,&pixel);
5423 for (y=0; y < (ssize_t) image->rows; y++)
5428 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5430 if (q == (Quantum *) NULL)
5432 for (x=0; x < (ssize_t) image->columns; x++)
5434 GetPixelInfoPixel(image,q,&pixel);
5435 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5437 q+=GetPixelChannels(image);
5440 GetFillColor(draw_info,x,y,&pixel,exception);
5441 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5442 q+=GetPixelChannels(image);
5444 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5446 if (status == MagickFalse)
5451 case FloodfillMethod:
5452 case FillToBorderMethod:
5460 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5461 TileVirtualPixelMethod,x,y,&target,exception);
5462 if (primitive_info->method == FillToBorderMethod)
5464 target.red=(double) draw_info->border_color.red;
5465 target.green=(double) draw_info->border_color.green;
5466 target.blue=(double) draw_info->border_color.blue;
5468 channel_mask=SetImageChannelMask(image,AlphaChannel);
5469 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5470 &target,x,y,primitive_info->method == FloodfillMethod ?
5471 MagickFalse : MagickTrue,exception);
5472 (void) SetImageChannelMask(image,channel_mask);
5480 for (y=0; y < (ssize_t) image->rows; y++)
5485 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5487 if (q == (Quantum *) NULL)
5489 for (x=0; x < (ssize_t) image->columns; x++)
5491 GetFillColor(draw_info,x,y,&pixel,exception);
5492 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
5493 q+=GetPixelChannels(image);
5495 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5497 if (status == MagickFalse)
5505 case ColorPrimitive:
5507 switch (primitive_info->method)
5518 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5519 if (q == (Quantum *) NULL)
5521 GetPixelInfo(image,&pixel);
5522 GetFillColor(draw_info,x,y,&pixel,exception);
5523 SetPixelViaPixelInfo(image,&pixel,q);
5524 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5534 status&=(MagickStatusType) GetOneCacheViewVirtualPixelInfo(image_view,
5535 x,y,&target,exception);
5536 for (y=0; y < (ssize_t) image->rows; y++)
5541 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5543 if (q == (Quantum *) NULL)
5545 for (x=0; x < (ssize_t) image->columns; x++)
5547 GetPixelInfoPixel(image,q,&pixel);
5548 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
5550 q+=GetPixelChannels(image);
5553 GetFillColor(draw_info,x,y,&pixel,exception);
5554 SetPixelViaPixelInfo(image,&pixel,q);
5555 q+=GetPixelChannels(image);
5557 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5559 if (status == MagickFalse)
5564 case FloodfillMethod:
5565 case FillToBorderMethod:
5570 status&=(MagickStatusType) GetOneVirtualPixelInfo(image,
5571 TileVirtualPixelMethod,x,y,&target,exception);
5572 if (primitive_info->method == FillToBorderMethod)
5574 target.red=(double) draw_info->border_color.red;
5575 target.green=(double) draw_info->border_color.green;
5576 target.blue=(double) draw_info->border_color.blue;
5578 status&=(MagickStatusType) FloodfillPaintImage(image,draw_info,
5579 &target,x,y,primitive_info->method == FloodfillMethod ?
5580 MagickFalse : MagickTrue,exception);
5588 GetPixelInfo(image,&pixel);
5589 for (y=0; y < (ssize_t) image->rows; y++)
5594 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5596 if (q == (Quantum *) NULL)
5598 for (x=0; x < (ssize_t) image->columns; x++)
5600 GetFillColor(draw_info,x,y,&pixel,exception);
5601 SetPixelViaPixelInfo(image,&pixel,q);
5602 q+=GetPixelChannels(image);
5604 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5606 if (status == MagickFalse)
5614 case ImagePrimitive:
5620 composite_geometry[MagickPathExtent];
5636 if (primitive_info->text == (
char *) NULL)
5638 clone_info=AcquireImageInfo();
5639 composite_images=(
Image *) NULL;
5640 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5641 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5644 if (*primitive_info->text !=
'\0')
5658 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5660 (void) SetImageInfo(clone_info,1,exception);
5661 magick_info=GetMagickInfo(clone_info->magick,exception);
5662 if ((magick_info != (
const MagickInfo*) NULL) &&
5663 (LocaleCompare(magick_info->magick_module,
"SVG") == 0))
5665 (void) ThrowMagickException(exception,GetMagickModule(),
5666 CorruptImageError,
"ImageTypeNotSupported",
"`%s'",
5667 clone_info->filename);
5668 clone_info=DestroyImageInfo(clone_info);
5671 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5673 if (clone_info->size != (
char *) NULL)
5674 clone_info->size=DestroyString(clone_info->size);
5675 if (clone_info->extract != (
char *) NULL)
5676 clone_info->extract=DestroyString(clone_info->extract);
5677 path_status=GetPathAttributes(clone_info->filename,&attributes);
5678 if (path_status != MagickFalse)
5680 if (S_ISCHR(attributes.st_mode) == 0)
5681 composite_images=ReadImage(clone_info,exception);
5683 (
void) ThrowMagickException(exception,GetMagickModule(),
5684 FileOpenError,
"UnableToOpenFile",
"`%s'",
5685 clone_info->filename);
5688 if ((LocaleCompare(clone_info->magick,
"ftp") != 0) &&
5689 (LocaleCompare(clone_info->magick,
"http") != 0) &&
5690 (LocaleCompare(clone_info->magick,
"https") != 0))
5691 composite_images=ReadImage(clone_info,exception);
5693 (
void) ThrowMagickException(exception,GetMagickModule(),
5694 FileOpenError,
"UnableToOpenFile",
"`%s'",clone_info->filename);
5696 clone_info=DestroyImageInfo(clone_info);
5697 if (composite_images == (
Image *) NULL)
5702 composite_image=RemoveFirstImageFromList(&composite_images);
5703 composite_images=DestroyImageList(composite_images);
5704 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5705 NULL,(
void *) NULL);
5706 x1=CastDoubleToLong(ceil(primitive_info[1].point.x-0.5));
5707 y1=CastDoubleToLong(ceil(primitive_info[1].point.y-0.5));
5708 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5709 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5714 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5715 "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y);
5716 composite_image->filter=image->filter;
5717 status&=(MagickStatusType) TransformImage(&composite_image,
5718 (
char *) NULL,composite_geometry,exception);
5720 if (composite_image->alpha_trait == UndefinedPixelTrait)
5721 status&=(MagickStatusType) SetImageAlphaChannel(composite_image,
5722 OpaqueAlphaChannel,exception);
5723 if (draw_info->alpha != OpaqueAlpha)
5724 status&=(MagickStatusType) SetImageAlpha(composite_image,
5725 draw_info->alpha,exception);
5726 SetGeometry(image,&geometry);
5727 image->gravity=draw_info->gravity;
5730 (void) FormatLocaleString(composite_geometry,MagickPathExtent,
5731 "%.20gx%.20g%+.20g%+.20g",(
double) composite_image->columns,(
double)
5732 composite_image->rows,(
double) geometry.x,(
double) geometry.y);
5733 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
5734 affine=draw_info->affine;
5735 affine.tx=(double) geometry.x;
5736 affine.ty=(double) geometry.y;
5737 composite_image->interpolate=image->interpolate;
5738 if ((draw_info->compose == OverCompositeOp) ||
5739 (draw_info->compose == SrcOverCompositeOp))
5740 status&=(MagickStatusType) DrawAffineImage(image,composite_image,
5743 status&=(MagickStatusType) CompositeImage(image,composite_image,
5744 draw_info->compose,MagickTrue,geometry.x,geometry.y,exception);
5745 composite_image=DestroyImage(composite_image);
5748 case PointPrimitive:
5756 if ((y < 0) || (y >= (ssize_t) image->rows))
5758 if ((x < 0) || (x >= (ssize_t) image->columns))
5760 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5761 if (q == (Quantum *) NULL)
5763 GetFillColor(draw_info,x,y,&fill_color,exception);
5764 CompositePixelOver(image,&fill_color,(
double) fill_color.alpha,q,(
double)
5765 GetPixelAlpha(image,q),q);
5766 status&=(MagickStatusType) SyncCacheViewAuthenticPixels(image_view,
5773 geometry[MagickPathExtent];
5778 if (primitive_info->text == (
char *) NULL)
5780 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5781 (void) CloneString(&clone_info->text,primitive_info->text);
5782 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
5783 primitive_info->point.x,primitive_info->point.y);
5784 (void) CloneString(&clone_info->geometry,geometry);
5785 status&=(MagickStatusType) AnnotateImage(image,clone_info,exception);
5786 clone_info=DestroyDrawInfo(clone_info);
5798 if (IsEventLogging() != MagickFalse)
5799 LogPrimitiveInfo(primitive_info);
5800 scale=ExpandAffine(&draw_info->affine);
5801 if ((draw_info->dash_pattern != (
double *) NULL) &&
5802 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5803 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5804 (draw_info->stroke.alpha != (
double) TransparentAlpha))
5809 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5810 clone_info->stroke_width=0.0;
5811 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5812 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5813 primitive_info,exception);
5814 clone_info=DestroyDrawInfo(clone_info);
5815 if (status != MagickFalse)
5816 status&=(MagickStatusType) DrawDashPolygon(draw_info,primitive_info,
5820 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5822 ((draw_info->stroke.alpha != (
double) TransparentAlpha) ||
5823 (draw_info->stroke_pattern != (
Image *) NULL)))
5835 closed_path=primitive_info[0].closed_subpath;
5836 i=(ssize_t) primitive_info[0].coordinates;
5837 point_x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5838 point_y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5839 if ((point_x < MagickEpsilon) && (point_y < MagickEpsilon))
5840 closed_path=MagickTrue;
5841 if ((((draw_info->linecap == RoundCap) ||
5842 (closed_path != MagickFalse)) &&
5843 (draw_info->linejoin == RoundJoin)) ||
5844 (primitive_info[i].primitive != UndefinedPrimitive))
5846 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5847 primitive_info,exception);
5850 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5851 clone_info->stroke_width=0.0;
5852 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5853 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5854 primitive_info,exception);
5855 clone_info=DestroyDrawInfo(clone_info);
5856 if (status != MagickFalse)
5857 status&=(MagickStatusType) DrawStrokePolygon(image,draw_info,
5858 primitive_info,exception);
5861 status&=(MagickStatusType) DrawPolygonPrimitive(image,draw_info,
5862 primitive_info,exception);
5866 image_view=DestroyCacheView(image_view);
5867 if (draw_info->compliance == SVGCompliance)
5869 status&=(MagickStatusType) SetImageMask(image,WritePixelMask,
5870 (
Image *) NULL,exception);
5871 status&=(MagickStatusType) SetImageMask(image,CompositePixelMask,
5872 (
Image *) NULL,exception);
5874 if (draw_info->debug != MagickFalse)
5875 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
5876 return(status != 0 ? MagickTrue : MagickFalse);
5909static MagickBooleanType DrawRoundLinecap(
Image *image,
5919 for (i=0; i < 4; i++)
5920 linecap[i]=(*primitive_info);
5921 linecap[0].coordinates=4;
5922 linecap[1].point.x+=2.0*MagickEpsilon;
5923 linecap[2].point.x+=2.0*MagickEpsilon;
5924 linecap[2].point.y+=2.0*MagickEpsilon;
5925 linecap[3].point.y+=2.0*MagickEpsilon;
5926 linecap[4].primitive=UndefinedPrimitive;
5927 return(DrawPolygonPrimitive(image,draw_info,linecap,exception));
5930static MagickBooleanType DrawStrokePolygon(
Image *image,
5953 if (draw_info->debug != MagickFalse)
5954 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5955 " begin draw-stroke-polygon");
5956 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5957 clone_info->fill=draw_info->stroke;
5958 if (clone_info->fill_pattern != (
Image *) NULL)
5959 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
5960 if (clone_info->stroke_pattern != (
Image *) NULL)
5961 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
5962 MagickTrue,exception);
5963 clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
5964 clone_info->stroke_width=0.0;
5965 clone_info->fill_rule=NonZeroRule;
5967 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ssize_t) p->coordinates)
5969 if (p->coordinates == 1)
5971 stroke_polygon=TraceStrokePolygon(draw_info,p,exception);
5977 status&=(MagickStatusType) DrawPolygonPrimitive(image,clone_info,
5978 stroke_polygon,exception);
5979 stroke_polygon=(
PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
5982 q=p+p->coordinates-1;
5983 closed_path=p->closed_subpath;
5984 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
5986 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,p,
5988 status&=(MagickStatusType) DrawRoundLinecap(image,draw_info,q,
5992 clone_info=DestroyDrawInfo(clone_info);
5993 if (draw_info->debug != MagickFalse)
5994 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5995 " end draw-stroke-polygon");
5996 return(status != 0 ? MagickTrue : MagickFalse);
6022MagickExport
void GetAffineMatrix(
AffineMatrix *affine_matrix)
6024 if (IsEventLogging() != MagickFalse)
6025 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6027 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
6028 affine_matrix->sx=1.0;
6029 affine_matrix->sy=1.0;
6070 assert(draw_info != (
DrawInfo *) NULL);
6071 if (IsEventLogging() != MagickFalse)
6072 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6073 (void) memset(draw_info,0,
sizeof(*draw_info));
6074 draw_info->image_info=CloneImageInfo(image_info);
6075 GetAffineMatrix(&draw_info->affine);
6076 exception=AcquireExceptionInfo();
6077 (void) QueryColorCompliance(
"#000F",AllCompliance,&draw_info->fill,
6079 (void) QueryColorCompliance(
"#FFF0",AllCompliance,&draw_info->stroke,
6081 draw_info->stroke_antialias=draw_info->image_info->antialias;
6082 draw_info->stroke_width=1.0;
6083 draw_info->fill_rule=EvenOddRule;
6084 draw_info->alpha=OpaqueAlpha;
6085 draw_info->fill_alpha=OpaqueAlpha;
6086 draw_info->stroke_alpha=OpaqueAlpha;
6087 draw_info->linecap=ButtCap;
6088 draw_info->linejoin=MiterJoin;
6089 draw_info->miterlimit=10;
6090 draw_info->decorate=NoDecoration;
6091 draw_info->pointsize=12.0;
6092 draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
6093 draw_info->compose=OverCompositeOp;
6094 draw_info->render=MagickTrue;
6095 draw_info->clip_path=MagickFalse;
6096 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6097 MagickTrue : MagickFalse;
6098 if (draw_info->image_info->font != (
char *) NULL)
6099 draw_info->font=AcquireString(draw_info->image_info->font);
6100 if (draw_info->image_info->density != (
char *) NULL)
6101 draw_info->density=AcquireString(draw_info->image_info->density);
6102 draw_info->text_antialias=draw_info->image_info->antialias;
6103 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6104 draw_info->pointsize=draw_info->image_info->pointsize;
6105 draw_info->border_color=draw_info->image_info->border_color;
6106 if (draw_info->image_info->server_name != (
char *) NULL)
6107 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6108 option=GetImageOption(draw_info->image_info,
"direction");
6109 if (option != (
const char *) NULL)
6110 draw_info->direction=(DirectionType) ParseCommandOption(
6111 MagickDirectionOptions,MagickFalse,option);
6113 draw_info->direction=UndefinedDirection;
6114 option=GetImageOption(draw_info->image_info,
"encoding");
6115 if (option != (
const char *) NULL)
6116 (void) CloneString(&draw_info->encoding,option);
6117 option=GetImageOption(draw_info->image_info,
"family");
6118 if (option != (
const char *) NULL)
6119 (void) CloneString(&draw_info->family,option);
6120 option=GetImageOption(draw_info->image_info,
"fill");
6121 if (option != (
const char *) NULL)
6122 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
6124 option=GetImageOption(draw_info->image_info,
"gravity");
6125 if (option != (
const char *) NULL)
6126 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6127 MagickFalse,option);
6128 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6129 if (option != (
const char *) NULL)
6130 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6131 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6132 if (option != (
const char *) NULL)
6133 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6134 option=GetImageOption(draw_info->image_info,
"kerning");
6135 if (option != (
const char *) NULL)
6136 draw_info->kerning=GetDrawValue(option,&next_token);
6137 option=GetImageOption(draw_info->image_info,
"stroke");
6138 if (option != (
const char *) NULL)
6139 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
6141 option=GetImageOption(draw_info->image_info,
"strokewidth");
6142 if (option != (
const char *) NULL)
6143 draw_info->stroke_width=GetDrawValue(option,&next_token);
6144 option=GetImageOption(draw_info->image_info,
"style");
6145 if (option != (
const char *) NULL)
6146 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6147 MagickFalse,option);
6148 option=GetImageOption(draw_info->image_info,
"undercolor");
6149 if (option != (
const char *) NULL)
6150 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
6152 option=GetImageOption(draw_info->image_info,
"weight");
6153 if (option != (
const char *) NULL)
6158 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6160 weight=(ssize_t) StringToUnsignedLong(option);
6161 draw_info->weight=(size_t) weight;
6163 option=GetImageOption(draw_info->image_info,
"word-break");
6164 if (option != (
const char *) NULL)
6165 draw_info->word_break=(WordBreakType) ParseCommandOption(
6166 MagickWordBreakOptions,MagickFalse,option);
6167 exception=DestroyExceptionInfo(exception);
6168 draw_info->signature=MagickCoreSignature;
6196static inline double Permutate(
const ssize_t n,
const ssize_t k)
6205 for (i=k+1; i <= n; i++)
6207 for (i=1; i <= (n-k); i++)
6235 center.x=0.5*(end.x+start.x);
6236 center.y=0.5*(end.y+start.y);
6237 radius.x=fabs(center.x-start.x);
6238 radius.y=fabs(center.y-start.y);
6239 return(TraceEllipse(mvg_info,center,radius,degrees));
6242static MagickBooleanType TraceArcPath(
MVGInfo *mvg_info,
const PointInfo start,
6244 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6281 offset=mvg_info->offset;
6282 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6283 primitive_info->coordinates=0;
6284 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6285 (fabs(start.y-end.y) < MagickEpsilon))
6286 return(TracePoint(primitive_info,end));
6287 radii.x=fabs(arc.x);
6288 radii.y=fabs(arc.y);
6289 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6290 return(TraceLine(primitive_info,start,end));
6291 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6292 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6293 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6294 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6295 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6297 if (delta < MagickEpsilon)
6298 return(TraceLine(primitive_info,start,end));
6301 radii.x*=sqrt((
double) delta);
6302 radii.y*=sqrt((
double) delta);
6304 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6305 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6306 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6307 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6308 alpha=points[1].x-points[0].x;
6309 beta=points[1].y-points[0].y;
6310 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6311 return(TraceLine(primitive_info,start,end));
6312 factor=PerceptibleReciprocal(alpha*alpha+beta*beta)-0.25;
6317 factor=sqrt((
double) factor);
6318 if (sweep == large_arc)
6321 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6322 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6323 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6324 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6325 if ((theta < 0.0) && (sweep != MagickFalse))
6326 theta+=2.0*MagickPI;
6328 if ((theta > 0.0) && (sweep == MagickFalse))
6329 theta-=2.0*MagickPI;
6330 arc_segments=(size_t) CastDoubleToLong(ceil(fabs((
double) (theta/(0.5*
6331 MagickPI+MagickEpsilon)))));
6334 for (i=0; i < (ssize_t) arc_segments; i++)
6336 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6337 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6338 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6339 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6340 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6341 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6342 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6343 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6344 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6345 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6346 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) (i+1)*
6347 theta/arc_segments),DegreesToRadians(360.0))));
6348 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) (i+1)*
6349 theta/arc_segments),DegreesToRadians(360.0))));
6350 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(
double)
6351 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6352 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(
double)
6353 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6354 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6355 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6356 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
6358 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
6360 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
6362 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
6364 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
6366 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
6368 if (i == (ssize_t) (arc_segments-1))
6370 status&=(MagickStatusType) TraceBezier(mvg_info,4);
6373 p=(*mvg_info->primitive_info)+mvg_info->offset;
6374 mvg_info->offset+=(ssize_t) p->coordinates;
6375 p+=(ssize_t) p->coordinates;
6378 return(MagickFalse);
6379 mvg_info->offset=offset;
6380 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6381 primitive_info->coordinates=(size_t) (p-primitive_info);
6382 primitive_info->closed_subpath=MagickFalse;
6383 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6385 p->primitive=primitive_info->primitive;
6391static MagickBooleanType TraceBezier(
MVGInfo *mvg_info,
6392 const size_t number_coordinates)
6421 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6422 quantum=number_coordinates;
6423 for (i=0; i < (ssize_t) number_coordinates; i++)
6425 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6427 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6428 if (alpha > (
double) MAGICK_SSIZE_MAX)
6430 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6431 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6432 return(MagickFalse);
6434 if (alpha > (
double) quantum)
6435 quantum=(size_t) alpha;
6436 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6437 if (alpha > (
double) MAGICK_SSIZE_MAX)
6439 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6440 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6441 return(MagickFalse);
6443 if (alpha > (
double) quantum)
6444 quantum=(size_t) alpha;
6447 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6448 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6449 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6450 sizeof(*coefficients));
6451 points=(
PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6453 if ((coefficients == (
double *) NULL) || (points == (
PointInfo *) NULL))
6456 points=(
PointInfo *) RelinquishMagickMemory(points);
6457 if (coefficients != (
double *) NULL)
6458 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6459 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6460 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6461 return(MagickFalse);
6463 control_points=quantum*number_coordinates;
6464 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6466 points=(
PointInfo *) RelinquishMagickMemory(points);
6467 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6468 return(MagickFalse);
6470 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6474 end=primitive_info[number_coordinates-1].point;
6475 for (i=0; i < (ssize_t) number_coordinates; i++)
6476 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6478 for (i=0; i < (ssize_t) control_points; i++)
6483 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6484 for (j=0; j < (ssize_t) number_coordinates; j++)
6486 point.x+=alpha*coefficients[j]*p->point.x;
6487 point.y+=alpha*coefficients[j]*p->point.y;
6488 alpha*=weight/(1.0-weight);
6492 weight+=1.0/control_points;
6498 for (i=0; i < (ssize_t) control_points; i++)
6500 if (TracePoint(p,points[i]) == MagickFalse)
6502 points=(
PointInfo *) RelinquishMagickMemory(points);
6503 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6504 return(MagickFalse);
6506 p+=(ssize_t) p->coordinates;
6508 if (TracePoint(p,end) == MagickFalse)
6510 points=(
PointInfo *) RelinquishMagickMemory(points);
6511 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6512 return(MagickFalse);
6514 p+=(ssize_t) p->coordinates;
6515 primitive_info->coordinates=(size_t) (p-primitive_info);
6516 primitive_info->closed_subpath=MagickFalse;
6517 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6519 p->primitive=primitive_info->primitive;
6522 points=(
PointInfo *) RelinquishMagickMemory(points);
6523 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6527static MagickBooleanType TraceCircle(
MVGInfo *mvg_info,
const PointInfo start,
6539 alpha=end.x-start.x;
6541 radius=hypot((
double) alpha,(
double) beta);
6542 offset.x=(double) radius;
6543 offset.y=(double) radius;
6546 return(TraceEllipse(mvg_info,start,offset,degrees));
6549static MagickBooleanType TraceEllipse(
MVGInfo *mvg_info,
const PointInfo center,
6575 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6576 primitive_info->coordinates=0;
6577 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6579 delta=PerceptibleReciprocal(MagickMax(radii.x,radii.y));
6580 step=MagickPI/(MagickPI*PerceptibleReciprocal(delta))/8.0;
6581 angle.x=DegreesToRadians(arc.x);
6585 angle.y=DegreesToRadians(y);
6586 coordinates=ceil((angle.y-angle.x)/step+1.0);
6587 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6588 return(MagickFalse);
6590 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6591 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6593 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6594 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6595 if (i++ >= (ssize_t) coordinates)
6597 if (TracePoint(p,point) == MagickFalse)
6598 return(MagickFalse);
6599 p+=(ssize_t) p->coordinates;
6601 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6602 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6603 if (TracePoint(p,point) == MagickFalse)
6604 return(MagickFalse);
6605 p+=(ssize_t) p->coordinates;
6606 primitive_info->coordinates=(size_t) (p-primitive_info);
6607 primitive_info->closed_subpath=MagickFalse;
6608 x=fabs(primitive_info[0].point.x-
6609 primitive_info[primitive_info->coordinates-1].point.x);
6610 y=fabs(primitive_info[0].point.y-
6611 primitive_info[primitive_info->coordinates-1].point.y);
6612 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6613 primitive_info->closed_subpath=MagickTrue;
6614 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6616 p->primitive=primitive_info->primitive;
6622static MagickBooleanType TraceLine(
PrimitiveInfo *primitive_info,
6625 if (TracePoint(primitive_info,start) == MagickFalse)
6626 return(MagickFalse);
6627 if (TracePoint(primitive_info+1,end) == MagickFalse)
6628 return(MagickFalse);
6629 (primitive_info+1)->primitive=primitive_info->primitive;
6630 primitive_info->coordinates=2;
6631 primitive_info->closed_subpath=MagickFalse;
6635static ssize_t TracePath(
MVGInfo *mvg_info,
const char *path,
6640 token[MagickPathExtent] =
"";
6658 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6681 subpath_offset=mvg_info->offset;
6682 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6685 number_coordinates=0;
6687 primitive_type=primitive_info->primitive;
6689 for (p=path; *p !=
'\0'; )
6691 if (status == MagickFalse)
6693 while (isspace((
int) ((
unsigned char) *p)) != 0)
6697 last_attribute=attribute;
6698 attribute=(int) (*p++);
6708 large_arc = MagickFalse,
6709 sweep = MagickFalse;
6719 (void) GetNextToken(p,&p,MagickPathExtent,token);
6721 (void) GetNextToken(p,&p,MagickPathExtent,token);
6722 arc.x=GetDrawValue(token,&next_token);
6723 if (token == next_token)
6724 ThrowPointExpectedException(token,exception);
6725 (void) GetNextToken(p,&p,MagickPathExtent,token);
6727 (void) GetNextToken(p,&p,MagickPathExtent,token);
6728 arc.y=GetDrawValue(token,&next_token);
6729 if (token == next_token)
6730 ThrowPointExpectedException(token,exception);
6731 (void) GetNextToken(p,&p,MagickPathExtent,token);
6733 (void) GetNextToken(p,&p,MagickPathExtent,token);
6734 angle=GetDrawValue(token,&next_token);
6735 if (token == next_token)
6736 ThrowPointExpectedException(token,exception);
6737 (void) GetNextToken(p,&p,MagickPathExtent,token);
6739 (void) GetNextToken(p,&p,MagickPathExtent,token);
6740 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6741 (void) GetNextToken(p,&p,MagickPathExtent,token);
6743 (void) GetNextToken(p,&p,MagickPathExtent,token);
6744 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6746 (void) GetNextToken(p,&p,MagickPathExtent,token);
6747 (void) GetNextToken(p,&p,MagickPathExtent,token);
6749 (void) GetNextToken(p,&p,MagickPathExtent,token);
6750 x=GetDrawValue(token,&next_token);
6751 if (token == next_token)
6752 ThrowPointExpectedException(token,exception);
6753 (void) GetNextToken(p,&p,MagickPathExtent,token);
6755 (void) GetNextToken(p,&p,MagickPathExtent,token);
6756 y=GetDrawValue(token,&next_token);
6757 if (token == next_token)
6758 ThrowPointExpectedException(token,exception);
6759 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6760 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6761 if (TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep) == MagickFalse)
6763 q=(*mvg_info->primitive_info)+mvg_info->offset;
6764 mvg_info->offset+=(ssize_t) q->coordinates;
6765 q+=(ssize_t) q->coordinates;
6767 while (isspace((
int) ((
unsigned char) *p)) != 0)
6771 }
while (IsPoint(p) != MagickFalse);
6783 for (i=1; i < 4; i++)
6785 (void) GetNextToken(p,&p,MagickPathExtent,token);
6787 (void) GetNextToken(p,&p,MagickPathExtent,token);
6788 x=GetDrawValue(token,&next_token);
6789 if (token == next_token)
6790 ThrowPointExpectedException(token,exception);
6791 (void) GetNextToken(p,&p,MagickPathExtent,token);
6793 (void) GetNextToken(p,&p,MagickPathExtent,token);
6794 y=GetDrawValue(token,&next_token);
6795 if (token == next_token)
6796 ThrowPointExpectedException(token,exception);
6797 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6798 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6801 for (i=0; i < 4; i++)
6802 (q+i)->point=points[i];
6803 if (TraceBezier(mvg_info,4) == MagickFalse)
6805 q=(*mvg_info->primitive_info)+mvg_info->offset;
6806 mvg_info->offset+=(ssize_t) q->coordinates;
6807 q+=(ssize_t) q->coordinates;
6809 while (isspace((
int) ((
unsigned char) *p)) != 0)
6813 }
while (IsPoint(p) != MagickFalse);
6821 (void) GetNextToken(p,&p,MagickPathExtent,token);
6823 (void) GetNextToken(p,&p,MagickPathExtent,token);
6824 x=GetDrawValue(token,&next_token);
6825 if (token == next_token)
6826 ThrowPointExpectedException(token,exception);
6827 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6828 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6830 q=(*mvg_info->primitive_info)+mvg_info->offset;
6831 if (TracePoint(q,point) == MagickFalse)
6833 mvg_info->offset+=(ssize_t) q->coordinates;
6834 q+=(ssize_t) q->coordinates;
6835 while (isspace((
int) ((
unsigned char) *p)) != 0)
6839 }
while (IsPoint(p) != MagickFalse);
6850 (void) GetNextToken(p,&p,MagickPathExtent,token);
6852 (void) GetNextToken(p,&p,MagickPathExtent,token);
6853 x=GetDrawValue(token,&next_token);
6854 if (token == next_token)
6855 ThrowPointExpectedException(token,exception);
6856 (void) GetNextToken(p,&p,MagickPathExtent,token);
6858 (void) GetNextToken(p,&p,MagickPathExtent,token);
6859 y=GetDrawValue(token,&next_token);
6860 if (token == next_token)
6861 ThrowPointExpectedException(token,exception);
6862 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
6863 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
6864 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6866 q=(*mvg_info->primitive_info)+mvg_info->offset;
6867 if (TracePoint(q,point) == MagickFalse)
6869 mvg_info->offset+=(ssize_t) q->coordinates;
6870 q+=(ssize_t) q->coordinates;
6871 while (isspace((
int) ((
unsigned char) *p)) != 0)
6875 }
while (IsPoint(p) != MagickFalse);
6884 if (mvg_info->offset != subpath_offset)
6886 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
6887 primitive_info->coordinates=(size_t) (q-primitive_info);
6888 number_coordinates+=primitive_info->coordinates;
6890 subpath_offset=mvg_info->offset;
6895 (void) GetNextToken(p,&p,MagickPathExtent,token);
6897 (void) GetNextToken(p,&p,MagickPathExtent,token);
6898 x=GetDrawValue(token,&next_token);
6899 if (token == next_token)
6900 ThrowPointExpectedException(token,exception);
6901 (void) GetNextToken(p,&p,MagickPathExtent,token);
6903 (void) GetNextToken(p,&p,MagickPathExtent,token);
6904 y=GetDrawValue(token,&next_token);
6905 if (token == next_token)
6906 ThrowPointExpectedException(token,exception);
6907 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
6908 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
6912 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6914 q=(*mvg_info->primitive_info)+mvg_info->offset;
6915 if (TracePoint(q,point) == MagickFalse)
6917 mvg_info->offset+=(ssize_t) q->coordinates;
6918 q+=(ssize_t) q->coordinates;
6919 while (isspace((
int) ((
unsigned char) *p)) != 0)
6923 }
while (IsPoint(p) != MagickFalse);
6935 for (i=1; i < 3; i++)
6937 (void) GetNextToken(p,&p,MagickPathExtent,token);
6939 (void) GetNextToken(p,&p,MagickPathExtent,token);
6940 x=GetDrawValue(token,&next_token);
6941 if (token == next_token)
6942 ThrowPointExpectedException(token,exception);
6943 (void) GetNextToken(p,&p,MagickPathExtent,token);
6945 (void) GetNextToken(p,&p,MagickPathExtent,token);
6946 y=GetDrawValue(token,&next_token);
6947 if (token == next_token)
6948 ThrowPointExpectedException(token,exception);
6951 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
6952 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
6955 for (i=0; i < 3; i++)
6956 (q+i)->point=points[i];
6957 if (TraceBezier(mvg_info,3) == MagickFalse)
6959 q=(*mvg_info->primitive_info)+mvg_info->offset;
6960 mvg_info->offset+=(ssize_t) q->coordinates;
6961 q+=(ssize_t) q->coordinates;
6963 while (isspace((
int) ((
unsigned char) *p)) != 0)
6967 }
while (IsPoint(p) != MagickFalse);
6978 points[0]=points[3];
6979 points[1].x=2.0*points[3].x-points[2].x;
6980 points[1].y=2.0*points[3].y-points[2].y;
6981 for (i=2; i < 4; i++)
6983 (void) GetNextToken(p,&p,MagickPathExtent,token);
6985 (void) GetNextToken(p,&p,MagickPathExtent,token);
6986 x=GetDrawValue(token,&next_token);
6987 if (token == next_token)
6988 ThrowPointExpectedException(token,exception);
6989 (void) GetNextToken(p,&p,MagickPathExtent,token);
6991 (void) GetNextToken(p,&p,MagickPathExtent,token);
6992 y=GetDrawValue(token,&next_token);
6993 if (token == next_token)
6994 ThrowPointExpectedException(token,exception);
6997 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
6998 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
7001 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
7006 for (i=0; i < 4; i++)
7007 (q+i)->point=points[i];
7008 if (TraceBezier(mvg_info,4) == MagickFalse)
7010 q=(*mvg_info->primitive_info)+mvg_info->offset;
7011 mvg_info->offset+=(ssize_t) q->coordinates;
7012 q+=(ssize_t) q->coordinates;
7014 last_attribute=attribute;
7015 while (isspace((
int) ((
unsigned char) *p)) != 0)
7019 }
while (IsPoint(p) != MagickFalse);
7030 points[0]=points[2];
7031 points[1].x=2.0*points[2].x-points[1].x;
7032 points[1].y=2.0*points[2].y-points[1].y;
7033 for (i=2; i < 3; i++)
7035 (void) GetNextToken(p,&p,MagickPathExtent,token);
7037 (void) GetNextToken(p,&p,MagickPathExtent,token);
7038 x=GetDrawValue(token,&next_token);
7039 if (token == next_token)
7040 ThrowPointExpectedException(token,exception);
7041 (void) GetNextToken(p,&p,MagickPathExtent,token);
7043 (void) GetNextToken(p,&p,MagickPathExtent,token);
7044 y=GetDrawValue(token,&next_token);
7045 if (token == next_token)
7046 ThrowPointExpectedException(token,exception);
7047 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7048 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7051 if (status == MagickFalse)
7053 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7058 for (i=0; i < 3; i++)
7059 (q+i)->point=points[i];
7060 if (TraceBezier(mvg_info,3) == MagickFalse)
7062 q=(*mvg_info->primitive_info)+mvg_info->offset;
7063 mvg_info->offset+=(ssize_t) q->coordinates;
7064 q+=(ssize_t) q->coordinates;
7066 last_attribute=attribute;
7067 while (isspace((
int) ((
unsigned char) *p)) != 0)
7071 }
while (IsPoint(p) != MagickFalse);
7082 (void) GetNextToken(p,&p,MagickPathExtent,token);
7084 (void) GetNextToken(p,&p,MagickPathExtent,token);
7085 y=GetDrawValue(token,&next_token);
7086 if (token == next_token)
7087 ThrowPointExpectedException(token,exception);
7088 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
7089 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7091 q=(*mvg_info->primitive_info)+mvg_info->offset;
7092 if (TracePoint(q,point) == MagickFalse)
7094 mvg_info->offset+=(ssize_t) q->coordinates;
7095 q+=(ssize_t) q->coordinates;
7096 while (isspace((
int) ((
unsigned char) *p)) != 0)
7100 }
while (IsPoint(p) != MagickFalse);
7110 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7112 q=(*mvg_info->primitive_info)+mvg_info->offset;
7113 if (TracePoint(q,point) == MagickFalse)
7115 mvg_info->offset+=(ssize_t) q->coordinates;
7116 q+=(ssize_t) q->coordinates;
7117 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7118 primitive_info->coordinates=(size_t) (q-primitive_info);
7119 primitive_info->closed_subpath=MagickTrue;
7120 number_coordinates+=primitive_info->coordinates;
7122 subpath_offset=mvg_info->offset;
7128 ThrowPointExpectedException(token,exception);
7133 if (status == MagickFalse)
7135 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7136 primitive_info->coordinates=(size_t) (q-primitive_info);
7137 number_coordinates+=primitive_info->coordinates;
7138 for (i=0; i < (ssize_t) number_coordinates; i++)
7141 q->primitive=primitive_type;
7143 q->method=FillToBorderMethod;
7146 return((ssize_t) number_coordinates);
7149static MagickBooleanType TraceRectangle(
PrimitiveInfo *primitive_info,
7162 if (TracePoint(p,start) == MagickFalse)
7163 return(MagickFalse);
7164 p+=(ssize_t) p->coordinates;
7167 if (TracePoint(p,point) == MagickFalse)
7168 return(MagickFalse);
7169 p+=(ssize_t) p->coordinates;
7170 if (TracePoint(p,end) == MagickFalse)
7171 return(MagickFalse);
7172 p+=(ssize_t) p->coordinates;
7175 if (TracePoint(p,point) == MagickFalse)
7176 return(MagickFalse);
7177 p+=(ssize_t) p->coordinates;
7178 if (TracePoint(p,start) == MagickFalse)
7179 return(MagickFalse);
7180 p+=(ssize_t) p->coordinates;
7181 primitive_info->coordinates=(size_t) (p-primitive_info);
7182 primitive_info->closed_subpath=MagickTrue;
7183 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7185 p->primitive=primitive_info->primitive;
7191static MagickBooleanType TraceRoundRectangle(
MVGInfo *mvg_info,
7211 offset=mvg_info->offset;
7212 segment.x=fabs(end.x-start.x);
7213 segment.y=fabs(end.y-start.y);
7214 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7216 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7219 if (arc.x > (0.5*segment.x))
7220 arc.x=0.5*segment.x;
7221 if (arc.y > (0.5*segment.y))
7222 arc.y=0.5*segment.y;
7223 point.x=start.x+segment.x-arc.x;
7224 point.y=start.y+arc.y;
7227 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7228 return(MagickFalse);
7229 p=(*mvg_info->primitive_info)+mvg_info->offset;
7230 mvg_info->offset+=(ssize_t) p->coordinates;
7231 point.x=start.x+segment.x-arc.x;
7232 point.y=start.y+segment.y-arc.y;
7235 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7236 return(MagickFalse);
7237 p=(*mvg_info->primitive_info)+mvg_info->offset;
7238 mvg_info->offset+=(ssize_t) p->coordinates;
7239 point.x=start.x+arc.x;
7240 point.y=start.y+segment.y-arc.y;
7243 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7244 return(MagickFalse);
7245 p=(*mvg_info->primitive_info)+mvg_info->offset;
7246 mvg_info->offset+=(ssize_t) p->coordinates;
7247 point.x=start.x+arc.x;
7248 point.y=start.y+arc.y;
7251 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7252 return(MagickFalse);
7253 p=(*mvg_info->primitive_info)+mvg_info->offset;
7254 mvg_info->offset+=(ssize_t) p->coordinates;
7255 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7256 return(MagickFalse);
7257 p=(*mvg_info->primitive_info)+mvg_info->offset;
7258 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7259 return(MagickFalse);
7260 p+=(ssize_t) p->coordinates;
7261 mvg_info->offset=offset;
7262 primitive_info=(*mvg_info->primitive_info)+offset;
7263 primitive_info->coordinates=(size_t) (p-primitive_info);
7264 primitive_info->closed_subpath=MagickTrue;
7265 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7267 p->primitive=primitive_info->primitive;
7273static MagickBooleanType TraceSquareLinecap(
PrimitiveInfo *primitive_info,
7274 const size_t number_vertices,
const double offset)
7291 for (i=1; i < (ssize_t) number_vertices; i++)
7293 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7294 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7295 if ((fabs((
double) dx) >= MagickEpsilon) ||
7296 (fabs((
double) dy) >= MagickEpsilon))
7299 if (i == (ssize_t) number_vertices)
7300 i=(ssize_t) number_vertices-1L;
7301 distance=hypot((
double) dx,(
double) dy);
7302 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7303 dx*(distance+offset)/distance);
7304 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7305 dy*(distance+offset)/distance);
7306 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7308 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7309 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7310 if ((fabs((
double) dx) >= MagickEpsilon) ||
7311 (fabs((
double) dy) >= MagickEpsilon))
7314 distance=hypot((
double) dx,(
double) dy);
7315 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7316 dx*(distance+offset)/distance);
7317 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7318 dy*(distance+offset)/distance);
7325#define MaxStrokePad (6*BezierQuantum+360)
7326#define CheckPathExtent(pad_p,pad_q) \
7328 if ((pad_p) > MaxBezierCoordinates) \
7329 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7331 if ((p+(ssize_t) (pad_p)) >= (ssize_t) extent_p) \
7333 if (~extent_p < (pad_p)) \
7334 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7337 extent_p+=(pad_p); \
7338 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \
7339 MaxStrokePad,sizeof(*stroke_p)); \
7342 if ((pad_q) > MaxBezierCoordinates) \
7343 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7345 if ((q+(ssize_t) (pad_q)) >= (ssize_t) extent_q) \
7347 if (~extent_q < (pad_q)) \
7348 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7351 extent_q+=(pad_q); \
7352 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \
7353 MaxStrokePad,sizeof(*stroke_q)); \
7356 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \
7358 if (stroke_p != (PointInfo *) NULL) \
7359 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \
7360 if (stroke_q != (PointInfo *) NULL) \
7361 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \
7362 polygon_primitive=(PrimitiveInfo *) \
7363 RelinquishMagickMemory(polygon_primitive); \
7364 (void) ThrowMagickException(exception,GetMagickModule(), \
7365 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \
7366 return((PrimitiveInfo *) NULL); \
7370 typedef struct _StrokeSegment
7416 inverse_slope = {0.0, 0.0},
7423 number_vertices=primitive_info->coordinates;
7424 polygon_primitive=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7425 number_vertices+2UL,
sizeof(*polygon_primitive));
7428 (void) ThrowMagickException(exception,GetMagickModule(),
7429 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7432 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7433 sizeof(*polygon_primitive));
7434 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7435 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7436 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7437 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7438 if (((draw_info->linejoin == RoundJoin) ||
7439 (draw_info->linejoin == MiterJoin)) && (closed_path != MagickFalse))
7441 polygon_primitive[number_vertices]=primitive_info[1];
7444 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7450 for (n=1; n < (ssize_t) number_vertices; n++)
7452 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7453 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7454 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7457 if (n == (ssize_t) number_vertices)
7459 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7465 sizeof(*stroke_polygon));
7466 stroke_polygon[0]=polygon_primitive[0];
7467 stroke_polygon[0].coordinates=0;
7470 return(stroke_polygon);
7472 n=(ssize_t) number_vertices-1L;
7474 extent_p=2*number_vertices;
7475 extent_q=2*number_vertices;
7476 stroke_p=(
PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7478 stroke_q=(
PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7483 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7485 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7487 RelinquishMagickMemory(polygon_primitive);
7488 (void) ThrowMagickException(exception,GetMagickModule(),
7489 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7493 inverse_slope.p=0.0;
7494 if (fabs(dx.p) < MagickEpsilon)
7497 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7499 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7502 if (fabs(dy.p) < MagickEpsilon)
7505 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7507 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7512 inverse_slope.p=(-1.0*PerceptibleReciprocal(slope.p));
7514 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7515 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7516 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7517 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7518 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7519 offset.y=(double) (offset.x*inverse_slope.p);
7520 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7522 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7523 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7524 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7525 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7526 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7527 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7528 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7529 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7533 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7534 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7535 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7536 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7537 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7538 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7539 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7540 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7547 stroke_q[p++]=box_q[0];
7548 stroke_p[q++]=box_p[0];
7549 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7554 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7555 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7556 dot_product=dx.q*dx.q+dy.q*dy.q;
7557 if (dot_product < 0.25)
7560 inverse_slope.q=0.0;
7561 if (fabs(dx.q) < MagickEpsilon)
7564 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7566 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7569 if (fabs(dy.q) < MagickEpsilon)
7572 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7574 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7579 inverse_slope.q=(-1.0*PerceptibleReciprocal(slope.q));
7581 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7582 offset.y=(double) (offset.x*inverse_slope.q);
7583 dot_product=dy.q*offset.x-dx.q*offset.y;
7584 if (dot_product > 0.0)
7586 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7587 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7588 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7589 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7590 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7591 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7592 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7593 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7597 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7598 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7599 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7600 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7601 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7602 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7603 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7604 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7606 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7613 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7614 box_p[3].y)/(slope.p-slope.q));
7615 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7616 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7617 box_q[3].y)/(slope.p-slope.q));
7618 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7620 DisableMSCWarning(4127)
7621 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7623 dot_product=dx.q*dy.p-dx.p*dy.q;
7624 if (dot_product <= 0.0)
7625 switch (draw_info->linejoin)
7629 stroke_q[q++]=box_q[1];
7630 stroke_q[q++]=box_q[2];
7631 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7632 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7633 if (dot_product <= miterlimit)
7634 stroke_p[p++]=box_p[4];
7637 stroke_p[p++]=box_p[1];
7638 stroke_p[p++]=box_p[2];
7644 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7645 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7646 if (dot_product <= miterlimit)
7648 stroke_q[q++]=box_q[4];
7649 stroke_p[p++]=box_p[4];
7653 stroke_q[q++]=box_q[1];
7654 stroke_q[q++]=box_q[2];
7655 stroke_p[p++]=box_p[1];
7656 stroke_p[p++]=box_p[2];
7662 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7663 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7664 if (dot_product <= miterlimit)
7665 stroke_p[p++]=box_p[4];
7668 stroke_p[p++]=box_p[1];
7669 stroke_p[p++]=box_p[2];
7671 center=polygon_primitive[n].point;
7672 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7673 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7674 if (theta.q < theta.p)
7675 theta.q+=2.0*MagickPI;
7676 arc_segments=(size_t) CastDoubleToLong(ceil((
double) ((theta.q-
7677 theta.p)/(2.0*sqrt(PerceptibleReciprocal(mid))))));
7678 DisableMSCWarning(4127)
7679 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7681 stroke_q[q].x=box_q[1].x;
7682 stroke_q[q].y=box_q[1].y;
7684 for (j=1; j < (ssize_t) arc_segments; j++)
7686 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7687 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7688 (theta.p+delta_theta),DegreesToRadians(360.0))));
7689 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7690 (theta.p+delta_theta),DegreesToRadians(360.0))));
7693 stroke_q[q++]=box_q[2];
7700 switch (draw_info->linejoin)
7704 stroke_p[p++]=box_p[1];
7705 stroke_p[p++]=box_p[2];
7706 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7707 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7708 if (dot_product <= miterlimit)
7709 stroke_q[q++]=box_q[4];
7712 stroke_q[q++]=box_q[1];
7713 stroke_q[q++]=box_q[2];
7719 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7720 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7721 if (dot_product <= miterlimit)
7723 stroke_q[q++]=box_q[4];
7724 stroke_p[p++]=box_p[4];
7728 stroke_q[q++]=box_q[1];
7729 stroke_q[q++]=box_q[2];
7730 stroke_p[p++]=box_p[1];
7731 stroke_p[p++]=box_p[2];
7737 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7738 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7739 if (dot_product <= miterlimit)
7740 stroke_q[q++]=box_q[4];
7743 stroke_q[q++]=box_q[1];
7744 stroke_q[q++]=box_q[2];
7746 center=polygon_primitive[n].point;
7747 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7748 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7749 if (theta.p < theta.q)
7750 theta.p+=2.0*MagickPI;
7751 arc_segments=(size_t) CastDoubleToLong(ceil((
double) ((theta.p-
7752 theta.q)/(2.0*sqrt((
double) (PerceptibleReciprocal(mid)))))));
7753 DisableMSCWarning(4127)
7754 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7756 stroke_p[p++]=box_p[1];
7757 for (j=1; j < (ssize_t) arc_segments; j++)
7759 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7760 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7761 (theta.p+delta_theta),DegreesToRadians(360.0))));
7762 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7763 (theta.p+delta_theta),DegreesToRadians(360.0))));
7766 stroke_p[p++]=box_p[2];
7773 inverse_slope.p=inverse_slope.q;
7782 stroke_p[p++]=box_p[1];
7783 stroke_q[q++]=box_q[1];
7787 stroke_polygon=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7788 (p+q+2L*closed_path+2L),
sizeof(*stroke_polygon));
7791 (void) ThrowMagickException(exception,GetMagickModule(),
7792 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7793 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7794 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7797 return(stroke_polygon);
7799 for (i=0; i < (ssize_t) p; i++)
7801 stroke_polygon[i]=polygon_primitive[0];
7802 stroke_polygon[i].point=stroke_p[i];
7804 if (closed_path != MagickFalse)
7806 stroke_polygon[i]=polygon_primitive[0];
7807 stroke_polygon[i].point=stroke_polygon[0].point;
7810 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7812 stroke_polygon[i]=polygon_primitive[0];
7813 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7815 if (closed_path != MagickFalse)
7817 stroke_polygon[i]=polygon_primitive[0];
7818 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7821 stroke_polygon[i]=polygon_primitive[0];
7822 stroke_polygon[i].point=stroke_polygon[0].point;
7824 stroke_polygon[i].primitive=UndefinedPrimitive;
7825 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
7826 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7827 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7828 polygon_primitive=(
PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
7829 return(stroke_polygon);