48 #include "magick/studio.h" 49 #include "magick/annotate.h" 50 #include "magick/artifact.h" 51 #include "magick/blob.h" 52 #include "magick/cache.h" 53 #include "magick/cache-private.h" 54 #include "magick/cache-view.h" 55 #include "magick/channel.h" 56 #include "magick/color.h" 57 #include "magick/color-private.h" 58 #include "magick/colorspace.h" 59 #include "magick/colorspace-private.h" 60 #include "magick/composite.h" 61 #include "magick/composite-private.h" 62 #include "magick/constitute.h" 63 #include "magick/constitute-private.h" 64 #include "magick/draw.h" 65 #include "magick/draw-private.h" 66 #include "magick/enhance.h" 67 #include "magick/exception.h" 68 #include "magick/exception-private.h" 69 #include "magick/gem.h" 70 #include "magick/geometry.h" 71 #include "magick/image-private.h" 72 #include "magick/list.h" 73 #include "magick/log.h" 74 #include "magick/magick.h" 75 #include "magick/memory-private.h" 76 #include "magick/monitor.h" 77 #include "magick/monitor-private.h" 78 #include "magick/option.h" 79 #include "magick/paint.h" 80 #include "magick/pixel-accessor.h" 81 #include "magick/pixel-private.h" 82 #include "magick/property.h" 83 #include "magick/resample.h" 84 #include "magick/resample-private.h" 85 #include "magick/resource_.h" 86 #include "magick/splay-tree.h" 87 #include "magick/string_.h" 88 #include "magick/string-private.h" 89 #include "magick/thread-private.h" 90 #include "magick/token.h" 91 #include "magick/transform.h" 92 #include "magick/utility.h" 97 #define AntialiasThreshold (1.0/3.0) 98 #define BezierQuantum 200 99 #define PrimitiveExtentPad 4296.0 100 #define MaxBezierCoordinates 67108864 101 #define ThrowPointExpectedException(image,token) \ 103 (void) ThrowMagickException(&(image)->exception,GetMagickModule(),DrawError, \ 104 "NonconformingDrawingPrimitiveDefinition","`%s'",token); \ 105 status=MagickFalse; \ 195 *DrawClippingMask(
Image *,
const DrawInfo *,
const char *,
const char *,
198 static MagickBooleanType
203 const double,
const MagickBooleanType,
const MagickBooleanType),
204 TraceBezier(
MVGInfo *,
const size_t),
210 TraceSquareLinecap(
PrimitiveInfo *,
const size_t,
const double);
236 MagickExport
DrawInfo *AcquireDrawInfo(
void)
241 draw_info=(
DrawInfo *) AcquireCriticalMemory(
sizeof(*draw_info));
242 GetDrawInfo((
ImageInfo *) NULL,draw_info);
279 clone_info=(
DrawInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
280 GetDrawInfo(image_info,clone_info);
283 if (draw_info->id != (
char *) NULL)
284 (void) CloneString(&clone_info->id,draw_info->id);
285 if (draw_info->primitive != (
char *) NULL)
286 (
void) CloneString(&clone_info->primitive,draw_info->primitive);
287 if (draw_info->geometry != (
char *) NULL)
288 (void) CloneString(&clone_info->geometry,draw_info->geometry);
289 clone_info->compliance=draw_info->compliance;
290 clone_info->viewbox=draw_info->viewbox;
291 clone_info->affine=draw_info->affine;
292 clone_info->gravity=draw_info->gravity;
293 clone_info->fill=draw_info->fill;
294 clone_info->stroke=draw_info->stroke;
295 clone_info->stroke_width=draw_info->stroke_width;
296 if (draw_info->fill_pattern != (
Image *) NULL)
297 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
298 &draw_info->fill_pattern->exception);
300 if (draw_info->tile != (
Image *) NULL)
301 clone_info->fill_pattern=CloneImage(draw_info->tile,0,0,MagickTrue,
302 &draw_info->tile->exception);
303 clone_info->tile=NewImageList();
304 if (draw_info->stroke_pattern != (
Image *) NULL)
305 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
306 MagickTrue,&draw_info->stroke_pattern->exception);
307 clone_info->stroke_antialias=draw_info->stroke_antialias;
308 clone_info->text_antialias=draw_info->text_antialias;
309 clone_info->fill_rule=draw_info->fill_rule;
310 clone_info->linecap=draw_info->linecap;
311 clone_info->linejoin=draw_info->linejoin;
312 clone_info->miterlimit=draw_info->miterlimit;
313 clone_info->dash_offset=draw_info->dash_offset;
314 clone_info->decorate=draw_info->decorate;
315 clone_info->compose=draw_info->compose;
316 if (draw_info->text != (
char *) NULL)
317 (void) CloneString(&clone_info->text,draw_info->text);
318 if (draw_info->font != (
char *) NULL)
319 (
void) CloneString(&clone_info->font,draw_info->font);
320 if (draw_info->metrics != (
char *) NULL)
321 (void) CloneString(&clone_info->metrics,draw_info->metrics);
322 if (draw_info->family != (
char *) NULL)
323 (
void) CloneString(&clone_info->family,draw_info->family);
324 clone_info->style=draw_info->style;
325 clone_info->stretch=draw_info->stretch;
326 clone_info->weight=draw_info->weight;
327 if (draw_info->encoding != (
char *) NULL)
328 (void) CloneString(&clone_info->encoding,draw_info->encoding);
329 clone_info->pointsize=draw_info->pointsize;
330 clone_info->kerning=draw_info->kerning;
331 clone_info->interline_spacing=draw_info->interline_spacing;
332 clone_info->interword_spacing=draw_info->interword_spacing;
333 clone_info->direction=draw_info->direction;
334 if (draw_info->density != (
char *) NULL)
335 (
void) CloneString(&clone_info->density,draw_info->density);
336 clone_info->align=draw_info->align;
337 clone_info->undercolor=draw_info->undercolor;
338 clone_info->border_color=draw_info->border_color;
339 if (draw_info->server_name != (
char *) NULL)
340 (void) CloneString(&clone_info->server_name,draw_info->server_name);
341 if (draw_info->dash_pattern != (
double *) NULL)
346 for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
347 clone_info->dash_pattern=(
double *) AcquireQuantumMemory((
size_t) (2*x+2),
348 sizeof(*clone_info->dash_pattern));
349 if (clone_info->dash_pattern == (
double *) NULL)
350 ThrowFatalException(ResourceLimitFatalError,
351 "UnableToAllocateDashPattern");
352 (void) memset(clone_info->dash_pattern,0,(
size_t) (2*x+2)*
353 sizeof(*clone_info->dash_pattern));
354 (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(
size_t)
355 (x+1)*
sizeof(*clone_info->dash_pattern));
357 clone_info->gradient=draw_info->gradient;
358 if (draw_info->gradient.stops != (
StopInfo *) NULL)
363 number_stops=clone_info->gradient.number_stops;
364 clone_info->gradient.stops=(
StopInfo *) AcquireQuantumMemory((
size_t)
365 number_stops,
sizeof(*clone_info->gradient.stops));
366 if (clone_info->gradient.stops == (
StopInfo *) NULL)
367 ThrowFatalException(ResourceLimitFatalError,
368 "UnableToAllocateDashPattern");
369 (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
370 (
size_t) number_stops*
sizeof(*clone_info->gradient.stops));
372 clone_info->bounds=draw_info->bounds;
373 clone_info->fill_opacity=draw_info->fill_opacity;
374 clone_info->stroke_opacity=draw_info->stroke_opacity;
375 clone_info->element_reference=draw_info->element_reference;
376 clone_info->clip_path=draw_info->clip_path;
377 clone_info->clip_units=draw_info->clip_units;
378 if (draw_info->clip_mask != (
char *) NULL)
379 (
void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
380 if (draw_info->clipping_mask != (
Image *) NULL)
381 clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
382 MagickTrue,&draw_info->clipping_mask->exception);
383 if (draw_info->composite_mask != (
Image *) NULL)
384 clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
385 MagickTrue,&draw_info->composite_mask->exception);
386 clone_info->render=draw_info->render;
387 clone_info->debug=draw_info->debug;
428 if (polygon_info->edges != (
EdgeInfo *) NULL)
430 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
431 if (polygon_info->edges[i].points != (
PointInfo *) NULL)
432 polygon_info->edges[i].points=(
PointInfo *)
433 RelinquishMagickMemory(polygon_info->edges[i].points);
434 polygon_info->edges=(
EdgeInfo *) RelinquishMagickMemory(
435 polygon_info->edges);
437 return((
PolygonInfo *) RelinquishMagickMemory(polygon_info));
440 #if defined(__cplusplus) || defined(c_plusplus) 444 static int DrawCompareEdges(
const void *p_edge,
const void *q_edge)
446 #define DrawCompareEdge(p,q) \ 448 if (((p)-(q)) < 0.0) \ 450 if (((p)-(q)) > 0.0) \ 461 p=((
const EdgeInfo *) p_edge)->points;
462 q=((
const EdgeInfo *) q_edge)->points;
463 DrawCompareEdge(p[0].y,q[0].y);
464 DrawCompareEdge(p[0].x,q[0].x);
465 DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
467 DrawCompareEdge(p[1].y,q[1].y);
468 DrawCompareEdge(p[1].x,q[1].x);
472 #if defined(__cplusplus) || defined(c_plusplus) 476 static void LogPolygonInfo(
const PolygonInfo *polygon_info)
485 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin active-edge");
486 p=polygon_info->edges;
487 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
489 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" edge %.20g:",
491 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" direction: %s",
492 p->direction != MagickFalse ?
"down" :
"up");
493 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" ghostline: %s",
494 p->ghostline != MagickFalse ?
"transparent" :
"opaque");
495 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
496 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
497 p->bounds.x2,p->bounds.y2);
498 for (j=0; j < (ssize_t) p->number_points; j++)
499 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %g,%g",
500 p->points[j].x,p->points[j].y);
503 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end active-edge");
506 static void ReversePoints(
PointInfo *points,
const size_t number_points)
514 for (i=0; i < (ssize_t) (number_points >> 1); i++)
517 points[i]=points[number_points-(i+1)];
518 points[number_points-(i+1)]=point;
554 polygon_info=(
PolygonInfo *) AcquireMagickMemory(
sizeof(*polygon_info));
557 (void) ThrowMagickException(exception,GetMagickModule(),
558 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
562 polygon_info->edges=(
EdgeInfo *) AcquireQuantumMemory(number_edges,
563 sizeof(*polygon_info->edges));
564 if (polygon_info->edges == (
EdgeInfo *) NULL)
566 (void) ThrowMagickException(exception,GetMagickModule(),
567 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
568 return(DestroyPolygonInfo(polygon_info));
570 (void) memset(polygon_info->edges,0,number_edges*
571 sizeof(*polygon_info->edges));
574 ghostline=MagickFalse;
578 (void) memset(&point,0,
sizeof(point));
579 (void) memset(&bounds,0,
sizeof(bounds));
580 polygon_info->edges[edge].number_points=(size_t) n;
581 polygon_info->edges[edge].scanline=0.0;
582 polygon_info->edges[edge].highwater=0;
583 polygon_info->edges[edge].ghostline=ghostline;
584 polygon_info->edges[edge].direction=(ssize_t) direction;
585 polygon_info->edges[edge].points=points;
586 polygon_info->edges[edge].bounds=bounds;
587 polygon_info->number_edges=0;
588 for (i=0; path_info[i].code != EndCode; i++)
590 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
591 (path_info[i].code == GhostlineCode))
596 if ((points != (
PointInfo *) NULL) && (n >= 2))
598 if (edge == number_edges)
601 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
602 polygon_info->edges,(
size_t) number_edges,
603 sizeof(*polygon_info->edges));
604 if (polygon_info->edges == (
EdgeInfo *) NULL)
606 (void) ThrowMagickException(exception,GetMagickModule(),
607 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
608 points=(
PointInfo *) RelinquishMagickMemory(points);
609 return(DestroyPolygonInfo(polygon_info));
612 polygon_info->edges[edge].number_points=(size_t) n;
613 polygon_info->edges[edge].scanline=(-1.0);
614 polygon_info->edges[edge].highwater=0;
615 polygon_info->edges[edge].ghostline=ghostline;
616 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
618 ReversePoints(points,(
size_t) n);
619 polygon_info->edges[edge].points=points;
620 polygon_info->edges[edge].bounds=bounds;
621 polygon_info->edges[edge].bounds.y1=points[0].y;
622 polygon_info->edges[edge].bounds.y2=points[n-1].y;
624 ghostline=MagickFalse;
626 polygon_info->number_edges=edge;
631 points=(
PointInfo *) AcquireQuantumMemory((
size_t) number_points,
635 (void) ThrowMagickException(exception,GetMagickModule(),
636 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
637 return(DestroyPolygonInfo(polygon_info));
640 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
641 point=path_info[i].point;
652 next_direction=((path_info[i].point.y > point.y) ||
653 ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
654 (path_info[i].point.x > point.x))) ? 1 : -1;
655 if ((points != (
PointInfo *) NULL) && (direction != 0) &&
656 (direction != next_direction))
662 if (edge == number_edges)
665 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
666 polygon_info->edges,(
size_t) number_edges,
667 sizeof(*polygon_info->edges));
668 if (polygon_info->edges == (
EdgeInfo *) NULL)
670 (void) ThrowMagickException(exception,GetMagickModule(),
671 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
672 points=(
PointInfo *) RelinquishMagickMemory(points);
673 return(DestroyPolygonInfo(polygon_info));
676 polygon_info->edges[edge].number_points=(size_t) n;
677 polygon_info->edges[edge].scanline=(-1.0);
678 polygon_info->edges[edge].highwater=0;
679 polygon_info->edges[edge].ghostline=ghostline;
680 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
682 ReversePoints(points,(
size_t) n);
683 polygon_info->edges[edge].points=points;
684 polygon_info->edges[edge].bounds=bounds;
685 polygon_info->edges[edge].bounds.y1=points[0].y;
686 polygon_info->edges[edge].bounds.y2=points[n-1].y;
687 polygon_info->number_edges=edge+1;
690 points=(
PointInfo *) AcquireQuantumMemory((
size_t) number_points,
694 (void) ThrowMagickException(exception,GetMagickModule(),
695 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
696 return(DestroyPolygonInfo(polygon_info));
699 ghostline=MagickFalse;
705 direction=next_direction;
708 if (n == (ssize_t) number_points)
711 points=(
PointInfo *) ResizeQuantumMemory(points,(
size_t) number_points,
715 (void) ThrowMagickException(exception,GetMagickModule(),
716 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
717 return(DestroyPolygonInfo(polygon_info));
720 point=path_info[i].point;
722 if (point.x < bounds.x1)
724 if (point.x > bounds.x2)
731 points=(
PointInfo *) RelinquishMagickMemory(points);
734 if (edge == number_edges)
737 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(
738 polygon_info->edges,(
size_t) number_edges,
739 sizeof(*polygon_info->edges));
740 if (polygon_info->edges == (
EdgeInfo *) NULL)
742 (void) ThrowMagickException(exception,GetMagickModule(),
743 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
744 return(DestroyPolygonInfo(polygon_info));
747 polygon_info->edges[edge].number_points=(size_t) n;
748 polygon_info->edges[edge].scanline=(-1.0);
749 polygon_info->edges[edge].highwater=0;
750 polygon_info->edges[edge].ghostline=ghostline;
751 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
753 ReversePoints(points,(
size_t) n);
754 polygon_info->edges[edge].points=points;
755 polygon_info->edges[edge].bounds=bounds;
756 polygon_info->edges[edge].bounds.y1=points[0].y;
757 polygon_info->edges[edge].bounds.y2=points[n-1].y;
759 ghostline=MagickFalse;
761 polygon_info->number_edges=edge;
764 polygon_info->number_edges=edge;
765 polygon_info->edges=(
EdgeInfo *) ResizeQuantumMemory(polygon_info->edges,
766 polygon_info->number_edges,
sizeof(*polygon_info->edges));
767 if (polygon_info->edges == (
EdgeInfo *) NULL)
769 (void) ThrowMagickException(exception,GetMagickModule(),
770 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
771 return(DestroyPolygonInfo(polygon_info));
773 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
778 edge_info=polygon_info->edges+i;
779 edge_info->points=(
PointInfo *) ResizeQuantumMemory(edge_info->points,
780 edge_info->number_points,
sizeof(*edge_info->points));
781 if (edge_info->points == (
PointInfo *) NULL)
783 (void) ThrowMagickException(exception,GetMagickModule(),
784 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
785 return(DestroyPolygonInfo(polygon_info));
788 qsort(polygon_info->edges,(
size_t) polygon_info->number_edges,
789 sizeof(*polygon_info->edges),DrawCompareEdges);
790 if ((GetLogEventMask() & DrawEvent) != 0)
791 LogPolygonInfo(polygon_info);
792 return(polygon_info);
826 static void LogPathInfo(
const PathInfo *path_info)
831 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin vector-path");
832 for (p=path_info; p->code != EndCode; p++)
833 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
834 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
835 "moveto ghostline" : p->code == OpenCode ?
"moveto open" :
836 p->code == MoveToCode ?
"moveto" : p->code == LineToCode ?
"lineto" :
838 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end vector-path");
841 static PathInfo *ConvertPrimitiveToPath(
866 magick_unreferenced(draw_info);
871 switch (primitive_info->primitive)
882 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
883 path_info=(
PathInfo *) AcquireQuantumMemory((
size_t) (3UL*i+1UL),
887 (void) ThrowMagickException(exception,GetMagickModule(),
888 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
892 closed_subpath=MagickFalse;
899 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
902 if (coordinates <= 0)
907 coordinates=(ssize_t) primitive_info[i].coordinates;
908 p=primitive_info[i].point;
911 closed_subpath=primitive_info[i].closed_subpath;
914 if ((code == MoveToCode) || (coordinates <= 0) ||
915 (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
916 (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
921 path_info[n].code=code;
922 path_info[n].point=primitive_info[i].point;
923 q=primitive_info[i].point;
928 if (closed_subpath != MagickFalse)
930 closed_subpath=MagickFalse;
936 path_info[start].code=OpenCode;
937 path_info[n].code=GhostlineCode;
938 path_info[n].point=primitive_info[i].point;
940 path_info[n].code=LineToCode;
941 path_info[n].point=p;
944 path_info[n].code=EndCode;
945 path_info[n].point.x=0.0;
946 path_info[n].point.y=0.0;
947 if (IsEventLogging() != MagickFalse)
948 LogPathInfo(path_info);
949 path_info=(
PathInfo *) ResizeQuantumMemory(path_info,(
size_t) (n+1),
978 assert(draw_info != (
DrawInfo *) NULL);
979 assert(draw_info->signature == MagickCoreSignature);
980 if (IsEventLogging() != MagickFalse)
981 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
982 if (draw_info->id != (
char *) NULL)
983 draw_info->id=DestroyString(draw_info->id);
984 if (draw_info->primitive != (
char *) NULL)
985 draw_info->primitive=DestroyString(draw_info->primitive);
986 if (draw_info->text != (
char *) NULL)
987 draw_info->text=DestroyString(draw_info->text);
988 if (draw_info->geometry != (
char *) NULL)
989 draw_info->geometry=DestroyString(draw_info->geometry);
990 if (draw_info->tile != (
Image *) NULL)
991 draw_info->tile=DestroyImage(draw_info->tile);
992 if (draw_info->fill_pattern != (
Image *) NULL)
993 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
994 if (draw_info->stroke_pattern != (
Image *) NULL)
995 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
996 if (draw_info->font != (
char *) NULL)
997 draw_info->font=DestroyString(draw_info->font);
998 if (draw_info->metrics != (
char *) NULL)
999 draw_info->metrics=DestroyString(draw_info->metrics);
1000 if (draw_info->family != (
char *) NULL)
1001 draw_info->family=DestroyString(draw_info->family);
1002 if (draw_info->encoding != (
char *) NULL)
1003 draw_info->encoding=DestroyString(draw_info->encoding);
1004 if (draw_info->density != (
char *) NULL)
1005 draw_info->density=DestroyString(draw_info->density);
1006 if (draw_info->server_name != (
char *) NULL)
1007 draw_info->server_name=(
char *)
1008 RelinquishMagickMemory(draw_info->server_name);
1009 if (draw_info->dash_pattern != (
double *) NULL)
1010 draw_info->dash_pattern=(
double *) RelinquishMagickMemory(
1011 draw_info->dash_pattern);
1012 if (draw_info->gradient.stops != (
StopInfo *) NULL)
1013 draw_info->gradient.stops=(
StopInfo *) RelinquishMagickMemory(
1014 draw_info->gradient.stops);
1015 if (draw_info->clip_mask != (
char *) NULL)
1016 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
1017 if (draw_info->clipping_mask != (
Image *) NULL)
1018 draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
1019 if (draw_info->composite_mask != (
Image *) NULL)
1020 draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
1021 if (draw_info->image_info != (
ImageInfo *) NULL)
1022 draw_info->image_info=DestroyImageInfo(draw_info->image_info);
1023 draw_info->signature=(~MagickCoreSignature);
1024 draw_info=(
DrawInfo *) RelinquishMagickMemory(draw_info);
1073 inverse_edge.x1=edge->x1;
1074 inverse_edge.y1=edge->y1;
1075 inverse_edge.x2=edge->x2;
1076 inverse_edge.y2=edge->y2;
1077 z=affine->ry*y+affine->tx;
1078 if (affine->sx >= MagickEpsilon)
1080 intercept=(-z/affine->sx);
1082 if (x > inverse_edge.x1)
1084 intercept=(-z+(double) image->columns)/affine->sx;
1086 if (x < inverse_edge.x2)
1090 if (affine->sx < -MagickEpsilon)
1092 intercept=(-z+(double) image->columns)/affine->sx;
1094 if (x > inverse_edge.x1)
1096 intercept=(-z/affine->sx);
1098 if (x < inverse_edge.x2)
1102 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
1104 inverse_edge.x2=edge->x1;
1105 return(inverse_edge);
1110 z=affine->sy*y+affine->ty;
1111 if (affine->rx >= MagickEpsilon)
1113 intercept=(-z/affine->rx);
1115 if (x > inverse_edge.x1)
1117 intercept=(-z+(double) image->rows)/affine->rx;
1119 if (x < inverse_edge.x2)
1123 if (affine->rx < -MagickEpsilon)
1125 intercept=(-z+(double) image->rows)/affine->rx;
1127 if (x > inverse_edge.x1)
1129 intercept=(-z/affine->rx);
1131 if (x < inverse_edge.x2)
1135 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
1137 inverse_edge.x2=edge->x2;
1138 return(inverse_edge);
1140 return(inverse_edge);
1151 determinant=MagickSafeReciprocal(affine->sx*affine->sy-affine->rx*
1153 inverse_affine.sx=determinant*affine->sy;
1154 inverse_affine.rx=determinant*(-affine->rx);
1155 inverse_affine.ry=determinant*(-affine->ry);
1156 inverse_affine.sy=determinant*affine->sx;
1157 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1159 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1161 return(inverse_affine);
1164 MagickExport MagickBooleanType DrawAffineImage(
Image *image,
1203 assert(image != (
Image *) NULL);
1204 assert(image->signature == MagickCoreSignature);
1205 assert(source != (
const Image *) NULL);
1206 assert(source->signature == MagickCoreSignature);
1207 if (IsEventLogging() != MagickFalse)
1208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1212 extent[1].x=(double) source->columns;
1214 extent[2].x=(
double) source->columns;
1215 extent[2].y=(double) source->rows;
1217 extent[3].y=(
double) source->rows;
1218 for (i=0; i < 4; i++)
1221 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1222 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1226 for (i=1; i < 4; i++)
1228 if (min.x > extent[i].x)
1230 if (min.y > extent[i].y)
1232 if (max.x < extent[i].x)
1234 if (max.y < extent[i].y)
1240 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1241 return(MagickFalse);
1247 inverse_affine=InverseAffineMatrix(affine);
1250 if (edge.y2 > (image->rows-1.0))
1251 edge.y2=image->rows-1.0;
1252 GetMagickPixelPacket(image,&zero);
1253 exception=(&image->exception);
1254 start=CastDoubleToLong(ceil(edge.y1-0.5));
1255 stop=CastDoubleToLong(floor(edge.y2+0.5));
1256 source_view=AcquireVirtualCacheView(source,exception);
1257 image_view=AcquireAuthenticCacheView(image,exception);
1258 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1259 #pragma omp parallel for schedule(static) shared(status) \ 1260 magick_number_threads(source,image,stop-start,1) 1262 for (y=start; y <= stop; y++)
1265 *magick_restrict indexes;
1284 if (status == MagickFalse)
1286 inverse_edge=AffineEdge(source,&inverse_affine,(
double) y,&edge);
1287 if (inverse_edge.x2 < inverse_edge.x1)
1289 if (inverse_edge.x1 < 0.0)
1290 inverse_edge.x1=0.0;
1291 if (inverse_edge.x2 > image->columns-1.0)
1292 inverse_edge.x2=image->columns-1.0;
1293 q=GetCacheViewAuthenticPixels(image_view,CastDoubleToLong(
1294 ceil(inverse_edge.x1-0.5)),y,(
size_t) CastDoubleToLong(floor(
1295 inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),1,exception);
1298 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1302 for (x=CastDoubleToLong(ceil(inverse_edge.x1-0.5));
1303 x <= CastDoubleToLong(floor(inverse_edge.x2+0.5)); x++)
1305 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1307 point.y=(
double) x*inverse_affine.rx+y*inverse_affine.sy+
1309 status=InterpolateMagickPixelPacket(source,source_view,
1310 UndefinedInterpolatePixel,point.x,point.y,&pixel,exception);
1311 if (status == MagickFalse)
1313 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1314 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1315 composite.opacity,&composite);
1316 SetPixelPacket(image,&composite,q,indexes+x_offset);
1320 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1323 source_view=DestroyCacheView(source_view);
1324 image_view=DestroyCacheView(image_view);
1357 static MagickBooleanType DrawBoundingRectangles(
Image *image,
1386 (void) memset(primitive_info,0,
sizeof(primitive_info));
1387 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1388 status=QueryColorDatabase(
"#0000",&clone_info->fill,&image->exception);
1389 if (status == MagickFalse)
1391 clone_info=DestroyDrawInfo(clone_info);
1392 return(MagickFalse);
1396 if (clone_info->density != (
char *) NULL)
1404 flags=ParseGeometry(clone_info->density,&geometry_info);
1405 if ((flags & RhoValue) != 0)
1406 resolution.x=geometry_info.rho;
1407 resolution.y=resolution.x;
1408 if ((flags & SigmaValue) != 0)
1409 resolution.y=geometry_info.sigma;
1411 mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
1412 clone_info->stroke_width/2.0;
1419 bounds=polygon_info->edges[0].bounds;
1420 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1422 if (polygon_info->edges[i].bounds.x1 < (
double) bounds.x1)
1423 bounds.x1=polygon_info->edges[i].bounds.x1;
1424 if (polygon_info->edges[i].bounds.y1 < (
double) bounds.y1)
1425 bounds.y1=polygon_info->edges[i].bounds.y1;
1426 if (polygon_info->edges[i].bounds.x2 > (
double) bounds.x2)
1427 bounds.x2=polygon_info->edges[i].bounds.x2;
1428 if (polygon_info->edges[i].bounds.y2 > (
double) bounds.y2)
1429 bounds.y2=polygon_info->edges[i].bounds.y2;
1432 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1433 image->columns ? (
double) image->columns-1 : bounds.x1;
1435 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1436 image->rows ? (
double) image->rows-1 : bounds.y1;
1438 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1439 image->columns ? (
double) image->columns-1 : bounds.x2;
1441 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1442 image->rows ? (
double) image->rows-1 : bounds.y2;
1443 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1445 if (polygon_info->edges[i].direction != 0)
1446 status=QueryColorDatabase(
"#f00",&clone_info->stroke,
1449 status=QueryColorDatabase(
"#0f0",&clone_info->stroke,
1451 if (status == MagickFalse)
1453 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1454 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1455 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1456 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1457 primitive_info[0].primitive=RectanglePrimitive;
1458 status&=TraceRectangle(primitive_info,start,end);
1459 primitive_info[0].method=ReplaceMethod;
1460 coordinates=(ssize_t) primitive_info[0].coordinates;
1461 primitive_info[coordinates].primitive=UndefinedPrimitive;
1462 status=DrawPrimitive(image,clone_info,primitive_info);
1463 if (status == MagickFalse)
1466 if (i < (ssize_t) polygon_info->number_edges)
1468 clone_info=DestroyDrawInfo(clone_info);
1469 return(status == 0 ? MagickFalse : MagickTrue);
1472 status=QueryColorDatabase(
"#00f",&clone_info->stroke,&image->exception);
1473 if (status == MagickFalse)
1475 clone_info=DestroyDrawInfo(clone_info);
1476 return(MagickFalse);
1478 start.x=(double) (bounds.x1-mid);
1479 start.y=(double) (bounds.y1-mid);
1480 end.x=(double) (bounds.x2+mid);
1481 end.y=(double) (bounds.y2+mid);
1482 primitive_info[0].primitive=RectanglePrimitive;
1483 status&=TraceRectangle(primitive_info,start,end);
1484 primitive_info[0].method=ReplaceMethod;
1485 coordinates=(ssize_t) primitive_info[0].coordinates;
1486 primitive_info[coordinates].primitive=UndefinedPrimitive;
1487 status=DrawPrimitive(image,clone_info,primitive_info);
1488 clone_info=DestroyDrawInfo(clone_info);
1489 return(status == 0 ? MagickFalse : MagickTrue);
1519 MagickExport MagickBooleanType DrawClipPath(
Image *image,
1520 const DrawInfo *draw_info,
const char *
id)
1531 clip_path=GetImageArtifact(image,
id);
1532 if (clip_path == (
const char *) NULL)
1533 return(MagickFalse);
1534 clipping_mask=DrawClippingMask(image,draw_info,draw_info->clip_mask,clip_path,
1536 if (clipping_mask == (
Image *) NULL)
1537 return(MagickFalse);
1538 status=SetImageClipMask(image,clipping_mask);
1539 clipping_mask=DestroyImage(clipping_mask);
1576 const char *
id,
const char *clip_path,
ExceptionInfo *exception)
1590 assert(image != (
Image *) NULL);
1591 assert(image->signature == MagickCoreSignature);
1592 assert(draw_info != (
const DrawInfo *) NULL);
1593 if (IsEventLogging() != MagickFalse)
1594 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1595 clip_mask=AcquireImage((
const ImageInfo *) NULL);
1596 status=SetImageExtent(clip_mask,image->columns,image->rows);
1597 if (status == MagickFalse)
1598 return(DestroyImage(clip_mask));
1599 status=SetImageClipMask(image,(
Image *) NULL);
1600 status=QueryColorCompliance(
"#0000",AllCompliance,
1601 &clip_mask->background_color,exception);
1602 clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1603 status=SetImageBackgroundColor(clip_mask);
1604 if (draw_info->debug != MagickFalse)
1605 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin clip-path %s",
1607 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1608 (void) CloneString(&clone_info->primitive,clip_path);
1609 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1611 if (clone_info->clip_mask != (
char *) NULL)
1612 clone_info->clip_mask=DestroyString(clone_info->clip_mask);
1613 (void) QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1615 clone_info->stroke_width=0.0;
1616 clone_info->opacity=OpaqueOpacity;
1617 clone_info->clip_path=MagickTrue;
1618 status=RenderMVGContent(clip_mask,clone_info,0);
1619 clone_info=DestroyDrawInfo(clone_info);
1620 status&=SeparateImageChannel(clip_mask,TrueAlphaChannel);
1621 if (draw_info->compliance != SVGCompliance)
1622 status&=NegateImage(clip_mask,MagickFalse);
1623 if (status == MagickFalse)
1624 clip_mask=DestroyImage(clip_mask);
1625 if (draw_info->debug != MagickFalse)
1626 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end clip-path");
1662 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);
1682 status=SetImageExtent(composite_mask,image->columns,image->rows);
1683 if (status == MagickFalse)
1684 return(DestroyImage(composite_mask));
1685 status=SetImageMask(image,(
Image *) NULL);
1686 status=QueryColorCompliance(
"#0000",AllCompliance,
1687 &composite_mask->background_color,exception);
1688 composite_mask->background_color.opacity=(Quantum) TransparentOpacity;
1689 (void) SetImageBackgroundColor(composite_mask);
1690 if (draw_info->debug != MagickFalse)
1691 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"\nbegin mask-path %s",
1693 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1694 (void) CloneString(&clone_info->primitive,mask_path);
1695 status=QueryColorCompliance(
"#ffffff",AllCompliance,&clone_info->fill,
1697 status=QueryColorCompliance(
"#00000000",AllCompliance,&clone_info->stroke,
1699 clone_info->stroke_width=0.0;
1700 clone_info->opacity=OpaqueOpacity;
1701 status=RenderMVGContent(composite_mask,clone_info,0);
1702 clone_info=DestroyDrawInfo(clone_info);
1703 status&=SeparateImageChannel(composite_mask,TrueAlphaChannel);
1704 status&=NegateImage(composite_mask,MagickFalse);
1705 if (status == MagickFalse)
1706 composite_mask=DestroyImage(composite_mask);
1707 if (draw_info->debug != MagickFalse)
1708 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end mask-path");
1709 return(composite_mask);
1741 static MagickBooleanType DrawDashPolygon(
const DrawInfo *draw_info,
1772 assert(draw_info != (
const DrawInfo *) NULL);
1773 if (draw_info->debug != MagickFalse)
1774 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-dash");
1775 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1776 number_vertices=(size_t) i;
1777 dash_polygon=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
1778 (2UL*number_vertices+32UL),
sizeof(*dash_polygon));
1781 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1782 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1783 return(MagickFalse);
1785 (void) memset(dash_polygon,0,(2UL*number_vertices+32UL)*
1786 sizeof(*dash_polygon));
1787 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
1788 clone_info->miterlimit=0;
1789 dash_polygon[0]=primitive_info[0];
1790 dash_polygon[0].closed_subpath=MagickFalse;
1791 scale=ExpandAffine(&draw_info->affine);
1792 length=scale*draw_info->dash_pattern[0];
1793 offset=fabs(draw_info->dash_offset) >= MagickEpsilon ?
1794 scale*draw_info->dash_offset : 0.0;
1796 for (n=0; offset > 0.0; j=0)
1798 if (draw_info->dash_pattern[n] <= 0.0)
1800 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1801 if (offset > length)
1805 length=scale*draw_info->dash_pattern[n];
1808 if (offset < length)
1820 for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
1822 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1823 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1824 maximum_length=hypot(dx,dy);
1825 if (maximum_length > (
double) (MaxBezierCoordinates >> 2))
1827 if (fabs(length) < MagickEpsilon)
1829 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1831 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1833 length=scale*draw_info->dash_pattern[n];
1835 for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); )
1837 total_length+=length;
1838 if ((n & 0x01) != 0)
1840 dash_polygon[0]=primitive_info[0];
1841 dash_polygon[0].closed_subpath=MagickFalse;
1842 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1843 total_length*MagickSafeReciprocal(maximum_length));
1844 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1845 total_length*MagickSafeReciprocal(maximum_length));
1850 if ((j+1) > (ssize_t) number_vertices)
1852 dash_polygon[j]=primitive_info[i-1];
1853 dash_polygon[j].closed_subpath=MagickFalse;
1854 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1855 total_length*MagickSafeReciprocal(maximum_length));
1856 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1857 total_length*MagickSafeReciprocal(maximum_length));
1858 dash_polygon[j].coordinates=1;
1860 dash_polygon[0].coordinates=(size_t) j;
1861 dash_polygon[j].primitive=UndefinedPrimitive;
1862 status&=DrawStrokePolygon(image,clone_info,dash_polygon);
1863 if (status == MagickFalse)
1866 if (fabs(draw_info->dash_pattern[n]) >= MagickEpsilon)
1868 if (fabs(draw_info->dash_pattern[n]) < MagickEpsilon)
1870 length=scale*draw_info->dash_pattern[n];
1872 length-=(maximum_length-total_length);
1873 if ((n & 0x01) != 0)
1875 dash_polygon[j]=primitive_info[i];
1876 dash_polygon[j].coordinates=1;
1879 if ((status != MagickFalse) && (total_length < maximum_length) &&
1880 ((n & 0x01) == 0) && (j > 1))
1882 dash_polygon[j]=primitive_info[i-1];
1883 dash_polygon[j].closed_subpath=MagickFalse;
1884 dash_polygon[j].point.x+=MagickEpsilon;
1885 dash_polygon[j].point.y+=MagickEpsilon;
1886 dash_polygon[j].coordinates=1;
1888 dash_polygon[0].coordinates=(size_t) j;
1889 dash_polygon[j].primitive=UndefinedPrimitive;
1890 status&=DrawStrokePolygon(image,clone_info,dash_polygon);
1892 dash_polygon=(
PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1893 clone_info=DestroyDrawInfo(clone_info);
1894 if (draw_info->debug != MagickFalse)
1895 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-dash");
1896 return(status != 0 ? MagickTrue : MagickFalse);
1925 static inline double GetStopColorOffset(
const GradientInfo *gradient,
1926 const ssize_t x,
const ssize_t y)
1928 switch (gradient->type)
1930 case UndefinedGradient:
1931 case LinearGradient:
1946 gradient_vector=(&gradient->gradient_vector);
1947 p.x=gradient_vector->x2-gradient_vector->x1;
1948 p.y=gradient_vector->y2-gradient_vector->y1;
1949 q.x=(double) x-gradient_vector->x1;
1950 q.y=(
double) y-gradient_vector->y1;
1951 length=sqrt(q.x*q.x+q.y*q.y);
1952 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
1953 gamma=MagickSafeReciprocal(gamma);
1954 scale=p.x*q.x+p.y*q.y;
1955 offset=gamma*scale*length;
1958 case RadialGradient:
1963 if (gradient->spread == RepeatSpread)
1965 v.x=(double) x-gradient->center.x;
1966 v.y=(
double) y-gradient->center.y;
1967 return(sqrt(v.x*v.x+v.y*v.y));
1969 v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians(
1970 gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians(
1971 gradient->angle))))*MagickSafeReciprocal(gradient->radii.x);
1972 v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians(
1973 gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians(
1974 gradient->angle))))*MagickSafeReciprocal(gradient->radii.y);
1975 return(sqrt(v.x*v.x+v.y*v.y));
1981 MagickExport MagickBooleanType DrawGradientImage(
Image *image,
2018 assert(image != (
Image *) NULL);
2019 assert(image->signature == MagickCoreSignature);
2020 assert(draw_info != (
const DrawInfo *) NULL);
2021 if (IsEventLogging() != MagickFalse)
2022 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2023 gradient=(&draw_info->gradient);
2024 gradient_vector=(&gradient->gradient_vector);
2025 point.x=gradient_vector->x2-gradient_vector->x1;
2026 point.y=gradient_vector->y2-gradient_vector->y1;
2027 length=sqrt(point.x*point.x+point.y*point.y);
2028 bounding_box=gradient->bounding_box;
2030 exception=(&image->exception);
2031 GetMagickPixelPacket(image,&zero);
2032 image_view=AcquireAuthenticCacheView(image,exception);
2033 height=(size_t) (bounding_box.y+bounding_box.height);
2034 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2035 #pragma omp parallel for schedule(static) shared(status) \ 2036 magick_number_threads(image,image,height,1) 2038 for (y=bounding_box.y; y < (ssize_t) height; y++)
2049 *magick_restrict indexes;
2060 if (status == MagickFalse)
2062 q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,y,(
size_t)
2063 bounding_box.width,1,exception);
2069 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2072 offset=GetStopColorOffset(gradient,0,y);
2073 if (gradient->type != RadialGradient)
2074 offset*=MagickSafeReciprocal(length);
2075 width=(size_t) (bounding_box.x+bounding_box.width);
2076 for (x=bounding_box.x; x < (ssize_t) width; x++)
2078 SetMagickPixelPacket(image,q,indexes+x,&pixel);
2079 switch (gradient->spread)
2081 case UndefinedSpread:
2084 if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
2085 (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
2087 offset=GetStopColorOffset(gradient,x,y);
2088 if (gradient->type != RadialGradient)
2089 offset*=MagickSafeReciprocal(length);
2091 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2092 if (offset < gradient->stops[i].offset)
2094 if ((offset < 0.0) || (i == 0))
2095 composite=gradient->stops[0].color;
2097 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
2098 composite=gradient->stops[gradient->number_stops-1].color;
2103 alpha=(offset-gradient->stops[i].offset)/
2104 (gradient->stops[j].offset-gradient->stops[i].offset);
2105 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
2106 &gradient->stops[j].color,alpha,&composite);
2112 if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
2113 (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
2115 offset=GetStopColorOffset(gradient,x,y);
2116 if (gradient->type != RadialGradient)
2117 offset*=MagickSafeReciprocal(length);
2121 if ((ssize_t) fmod(offset,2.0) == 0)
2122 offset=fmod(offset,1.0);
2124 offset=1.0-fmod(offset,1.0);
2125 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2126 if (offset < gradient->stops[i].offset)
2129 composite=gradient->stops[0].color;
2131 if (i == (ssize_t) gradient->number_stops)
2132 composite=gradient->stops[gradient->number_stops-1].color;
2137 alpha=(offset-gradient->stops[i].offset)/
2138 (gradient->stops[j].offset-gradient->stops[i].offset);
2139 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
2140 &gradient->stops[j].color,alpha,&composite);
2152 antialias=MagickFalse;
2154 if ((x != CastDoubleToLong(ceil(gradient_vector->x1-0.5))) ||
2155 (y != CastDoubleToLong(ceil(gradient_vector->y1-0.5))))
2157 offset=GetStopColorOffset(gradient,x,y);
2158 if (gradient->type == LinearGradient)
2160 repeat=fmod(offset,length);
2162 repeat=length-fmod(-repeat,length);
2164 repeat=fmod(offset,length);
2165 antialias=(repeat < length) && ((repeat+1.0) > length) ?
2166 MagickTrue : MagickFalse;
2167 offset=MagickSafeReciprocal(length)*repeat;
2171 repeat=fmod(offset,(
double) gradient->radius);
2173 repeat=gradient->radius-fmod(-repeat,
2174 (
double) gradient->radius);
2176 repeat=fmod(offset,(
double) gradient->radius);
2177 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
2179 offset=repeat*MagickSafeReciprocal(gradient->radius);
2182 for (i=0; i < (ssize_t) gradient->number_stops; i++)
2183 if (offset < gradient->stops[i].offset)
2186 composite=gradient->stops[0].color;
2188 if (i == (ssize_t) gradient->number_stops)
2189 composite=gradient->stops[gradient->number_stops-1].color;
2194 alpha=(offset-gradient->stops[i].offset)/
2195 (gradient->stops[j].offset-gradient->stops[i].offset);
2196 if (antialias != MagickFalse)
2198 if (gradient->type == LinearGradient)
2199 alpha=length-repeat;
2201 alpha=gradient->radius-repeat;
2203 j=(ssize_t) gradient->number_stops-1L;
2205 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
2206 &gradient->stops[j].color,alpha,&composite);
2211 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
2212 pixel.opacity,&pixel);
2213 SetPixelPacket(image,&pixel,q,indexes+x);
2216 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2219 image_view=DestroyCacheView(image_view);
2252 static inline MagickBooleanType CheckPrimitiveExtent(
MVGInfo *mvg_info,
2267 if ((mvg_info == (
MVGInfo *) NULL) ||
2270 (mvg_info->extent == (
size_t *) NULL))
2271 return(MagickFalse);
2272 proposed_extent=mvg_info->offset+pad+PrimitiveExtentPad+1.0;
2273 if ((proposed_extent <= 0.0) || (proposed_extent > (
double) MAGICK_SIZE_MAX))
2274 return(MagickFalse);
2275 extent=CastDoubleToSizeT(ceil(proposed_extent));
2276 if (extent <= *mvg_info->extent)
2279 return(MagickFalse);
2287 extent=(size_t) PrimitiveExtentPad;
2288 primitive_info=(
PrimitiveInfo *) AcquireCriticalMemory(extent*
2289 sizeof(*primitive_info));
2290 (void) memset(primitive_info,0,extent*
sizeof(*primitive_info));
2291 *mvg_info->primitive_info=primitive_info;
2292 *mvg_info->extent=extent;
2294 ThrowMagickException(mvg_info->exception,GetMagickModule(),
2295 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2296 return(MagickFalse);
2298 primitive_info[extent].primitive=UndefinedPrimitive;
2299 primitive_info[extent].text=(
char *) NULL;
2303 for (i=(ssize_t) *mvg_info->extent; i < (ssize_t) extent; i++)
2305 primitive_info[i].primitive=UndefinedPrimitive;
2306 primitive_info[i].text=(
char *) NULL;
2308 *mvg_info->primitive_info=primitive_info;
2309 *mvg_info->extent=extent;
2313 static inline double GetDrawValue(
const char *magick_restrict
string,
2314 char **magick_restrict sentinel)
2317 **magick_restrict q;
2323 value=InterpretLocaleValue(
string,q);
2328 static int MVGMacroCompare(
const void *target,
const void *source)
2334 p=(
const char *) target;
2335 q=(
const char *) source;
2336 return(strcmp(p,q));
2358 if (primitive == (
const char *) NULL)
2360 macros=NewSplayTree(MVGMacroCompare,RelinquishMagickMemory,
2361 RelinquishMagickMemory);
2362 macro=AcquireString(primitive);
2363 token=AcquireString(primitive);
2364 extent=strlen(token)+MagickPathExtent;
2365 for (q=primitive; *q !=
'\0'; )
2367 if (GetNextToken(q,&q,extent,token) < 1)
2371 if (LocaleCompare(
"push",token) == 0)
2377 (void) GetNextToken(q,&q,extent,token);
2381 name[MagickPathExtent];
2392 (void) GetNextToken(q,&q,extent,token);
2395 (void) CopyMagickString(name,token,MagickPathExtent);
2397 for (p=q; *p !=
'\0'; )
2399 if (GetNextToken(p,&p,extent,token) < 1)
2403 if (LocaleCompare(token,
"pop") == 0)
2405 end=p-strlen(token)-1;
2408 if (LocaleCompare(token,
"push") == 0)
2410 if (n++ > MagickMaxRecursionDepth)
2412 (void) ThrowMagickException(exception,GetMagickModule(),
2413 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2417 if ((n == 0) && (end >= start))
2420 length=(size_t) (end-start);
2425 (void) GetNextToken(p,&p,extent,token);
2428 (void) CopyMagickString(macro,start,length);
2429 (void) AddValueToSplayTree(macros,ConstantString(name),
2430 ConstantString(macro));
2438 token=DestroyString(token);
2439 macro=DestroyString(macro);
2443 static inline MagickBooleanType IsValidListChar(
int c)
2445 if ((c >=
'0') && (c <=
'9'))
2459 return(MagickFalse);
2464 static inline MagickBooleanType IsValidPoint(
const char *point)
2472 value=GetDrawValue(point,&p);
2473 return((fabs(value) < MagickEpsilon) && (p == point) ? MagickFalse :
2477 static inline MagickBooleanType TracePoint(
PrimitiveInfo *primitive_info,
2480 primitive_info->point=point;
2481 primitive_info->coordinates=1;
2482 primitive_info->closed_subpath=MagickFalse;
2483 primitive_info->text=(
char *) NULL;
2487 static MagickBooleanType RenderMVGContent(
Image *image,
2488 const DrawInfo *draw_info,
const size_t depth)
2490 #define RenderImageTag "Render/Image" 2497 key[2*MaxTextExtent],
2498 keyword[MaxTextExtent],
2499 geometry[MaxTextExtent],
2500 name[MaxTextExtent],
2502 pattern[MaxTextExtent],
2565 assert(image != (
Image *) NULL);
2566 assert(image->signature == MagickCoreSignature);
2567 assert(draw_info != (
DrawInfo *) NULL);
2568 assert(draw_info->signature == MagickCoreSignature);
2569 if (IsEventLogging() != MagickFalse)
2570 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2571 if (depth > MagickMaxRecursionDepth)
2572 ThrowBinaryImageException(DrawError,
"VectorGraphicsNestedTooDeeply",
2574 if ((draw_info->primitive == (
char *) NULL) ||
2575 (*draw_info->primitive ==
'\0'))
2576 return(MagickFalse);
2577 if (draw_info->debug != MagickFalse)
2578 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"begin draw-image");
2579 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2580 return(MagickFalse);
2581 if (image->matte == MagickFalse)
2583 status=SetImageAlphaChannel(image,OpaqueAlphaChannel);
2584 if (status == MagickFalse)
2585 return(MagickFalse);
2587 primitive=(
char *) NULL;
2588 if ((*draw_info->primitive ==
'@') && (strlen(draw_info->primitive) > 1) &&
2589 (*(draw_info->primitive+1) !=
'-') && (depth == 0))
2590 primitive=FileToString(draw_info->primitive,~0UL,&image->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);
2601 graphic_context=(
DrawInfo **) AcquireMagickMemory(
sizeof(*graphic_context));
2602 if (graphic_context == (
DrawInfo **) NULL)
2604 primitive=DestroyString(primitive);
2605 ThrowBinaryImageException(ResourceLimitError,
"MemoryAllocationFailed",
2608 number_points=(size_t) PrimitiveExtentPad;
2609 primitive_info=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
2610 (number_points+1),
sizeof(*primitive_info));
2613 primitive=DestroyString(primitive);
2614 for ( ; n >= 0; n--)
2615 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2616 graphic_context=(
DrawInfo **) RelinquishMagickMemory(graphic_context);
2617 ThrowBinaryImageException(ResourceLimitError,
"MemoryAllocationFailed",
2620 (void) memset(primitive_info,0,(
size_t) (number_points+1)*
2621 sizeof(*primitive_info));
2622 (void) memset(&mvg_info,0,
sizeof(mvg_info));
2623 mvg_info.primitive_info=(&primitive_info);
2624 mvg_info.extent=(&number_points);
2625 mvg_info.exception=(&image->exception);
2626 graphic_context[n]=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
2627 graphic_context[n]->viewbox=image->page;
2628 if ((image->page.width == 0) || (image->page.height == 0))
2630 graphic_context[n]->viewbox.width=image->columns;
2631 graphic_context[n]->viewbox.height=image->rows;
2633 token=AcquireString(primitive);
2634 extent=strlen(token)+MaxTextExtent;
2638 macros=GetMVGMacros(primitive,&image->exception);
2639 status=QueryColorDatabase(
"#000000",&start_color,&image->exception);
2640 for (q=primitive; *q !=
'\0'; )
2645 if (GetNextToken(q,&q,MaxTextExtent,keyword) < 1)
2647 if (*keyword ==
'\0')
2649 if (*keyword ==
'#')
2654 while ((*q !=
'\n') && (*q !=
'\0'))
2658 p=q-strlen(keyword)-1;
2659 primitive_type=UndefinedPrimitive;
2660 current=graphic_context[n]->affine;
2661 GetAffineMatrix(&affine);
2670 if (LocaleCompare(
"affine",keyword) == 0)
2672 (void) GetNextToken(q,&q,extent,token);
2673 affine.sx=GetDrawValue(token,&next_token);
2674 if (token == next_token)
2675 ThrowPointExpectedException(image,token);
2676 (void) GetNextToken(q,&q,extent,token);
2677 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2678 ThrowPointExpectedException(image,token);
2680 (void) GetNextToken(q,&q,extent,token);
2681 affine.ry=GetDrawValue(token,&next_token);
2682 if (token == next_token)
2683 ThrowPointExpectedException(image,token);
2684 (void) GetNextToken(q,&q,extent,token);
2685 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2686 ThrowPointExpectedException(image,token);
2688 (void) GetNextToken(q,&q,extent,token);
2689 affine.rx=GetDrawValue(token,&next_token);
2690 if (token == next_token)
2691 ThrowPointExpectedException(image,token);
2692 (void) GetNextToken(q,&q,extent,token);
2693 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2694 ThrowPointExpectedException(image,token);
2696 (void) GetNextToken(q,&q,extent,token);
2697 affine.sy=GetDrawValue(token,&next_token);
2698 if (token == next_token)
2699 ThrowPointExpectedException(image,token);
2700 (void) GetNextToken(q,&q,extent,token);
2701 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2702 ThrowPointExpectedException(image,token);
2704 (void) GetNextToken(q,&q,extent,token);
2705 affine.tx=GetDrawValue(token,&next_token);
2706 if (token == next_token)
2707 ThrowPointExpectedException(image,token);
2708 (void) GetNextToken(q,&q,extent,token);
2709 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
2710 ThrowPointExpectedException(image,token);
2712 (void) GetNextToken(q,&q,extent,token);
2713 affine.ty=GetDrawValue(token,&next_token);
2714 if (token == next_token)
2715 ThrowPointExpectedException(image,token);
2718 if (LocaleCompare(
"arc",keyword) == 0)
2720 primitive_type=ArcPrimitive;
2729 if (LocaleCompare(
"bezier",keyword) == 0)
2731 primitive_type=BezierPrimitive;
2734 if (LocaleCompare(
"border-color",keyword) == 0)
2736 (void) GetNextToken(q,&q,extent,token);
2737 status&=QueryColorDatabase(token,&graphic_context[n]->border_color,
2747 if (LocaleCompare(
"class",keyword) == 0)
2752 (void) GetNextToken(q,&q,extent,token);
2753 if ((*token ==
'\0') || (*token ==
';'))
2761 for (i=0; i <= n; i++)
2762 if (LocaleCompare(token,graphic_context[i]->
id) == 0)
2766 if (classDepth++ > MagickMaxRecursionDepth)
2768 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2769 DrawError,
"VectorGraphicsNestedTooDeeply",
"`%s'",token);
2773 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2774 if ((graphic_context[n]->render != MagickFalse) &&
2775 (mvg_class != (
const char *) NULL) && (p > primitive))
2786 (void) CloneString(&graphic_context[n]->
id,token);
2787 offset=(ssize_t) (p-primitive);
2788 elements=AcquireString(primitive);
2789 elements[offset]=
'\0';
2790 (void) ConcatenateString(&elements,mvg_class);
2791 (void) ConcatenateString(&elements,
"\n");
2792 (void) ConcatenateString(&elements,q);
2793 primitive=DestroyString(primitive);
2799 if (LocaleCompare(
"clip-path",keyword) == 0)
2807 (void) GetNextToken(q,&q,extent,token);
2813 (void) CloneString(&graphic_context[n]->clip_mask,token);
2814 clip_path=(
const char *) GetValueFromSplayTree(macros,token);
2815 if (clip_path != (
const char *) NULL)
2817 if (graphic_context[n]->clipping_mask != (
Image *) NULL)
2818 graphic_context[n]->clipping_mask=
2819 DestroyImage(graphic_context[n]->clipping_mask);
2820 graphic_context[n]->clipping_mask=DrawClippingMask(image,
2821 graphic_context[n],token,clip_path,&image->exception);
2822 if (graphic_context[n]->compliance != SVGCompliance)
2827 clip_path=(
const char *) GetValueFromSplayTree(macros,
2828 graphic_context[n]->clip_mask);
2829 if (clip_path != (
const char *) NULL)
2830 (
void) SetImageArtifact(image,
2831 graphic_context[n]->clip_mask,clip_path);
2832 status&=DrawClipPath(image,graphic_context[n],
2833 graphic_context[n]->clip_mask);
2838 if (LocaleCompare(
"clip-rule",keyword) == 0)
2843 (void) GetNextToken(q,&q,extent,token);
2844 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2846 if (fill_rule == -1)
2851 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2854 if (LocaleCompare(
"clip-units",keyword) == 0)
2859 (void) GetNextToken(q,&q,extent,token);
2860 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
2862 if (clip_units == -1)
2867 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
2868 if (clip_units == ObjectBoundingBox)
2870 GetAffineMatrix(¤t);
2871 affine.sx=draw_info->bounds.x2;
2872 affine.sy=draw_info->bounds.y2;
2873 affine.tx=draw_info->bounds.x1;
2874 affine.ty=draw_info->bounds.y1;
2879 if (LocaleCompare(
"circle",keyword) == 0)
2881 primitive_type=CirclePrimitive;
2884 if (LocaleCompare(
"color",keyword) == 0)
2886 primitive_type=ColorPrimitive;
2889 if (LocaleCompare(
"compliance",keyword) == 0)
2895 (void) GetNextToken(q,&q,extent,token);
2896 graphic_context[n]->compliance=(ComplianceType) ParseCommandOption(
2897 MagickComplianceOptions,MagickFalse,token);
2900 if (LocaleCompare(
"currentColor",keyword) == 0)
2902 (void) GetNextToken(q,&q,extent,token);
2911 if (LocaleCompare(
"decorate",keyword) == 0)
2916 (void) GetNextToken(q,&q,extent,token);
2917 decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse,
2924 graphic_context[n]->decorate=(DecorationType) decorate;
2927 if (LocaleCompare(
"density",keyword) == 0)
2929 (void) GetNextToken(q,&q,extent,token);
2930 (void) CloneString(&graphic_context[n]->density,token);
2933 if (LocaleCompare(
"direction",keyword) == 0)
2938 (void) GetNextToken(q,&q,extent,token);
2939 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
2941 if (direction == -1)
2944 graphic_context[n]->direction=(DirectionType) direction;
2953 if (LocaleCompare(
"ellipse",keyword) == 0)
2955 primitive_type=EllipsePrimitive;
2958 if (LocaleCompare(
"encoding",keyword) == 0)
2960 (void) GetNextToken(q,&q,extent,token);
2961 (void) CloneString(&graphic_context[n]->encoding,token);
2970 if (LocaleCompare(
"fill",keyword) == 0)
2975 (void) GetNextToken(q,&q,extent,token);
2976 if (graphic_context[n]->clip_path != MagickFalse)
2978 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
2979 if (mvg_class != (
const char *) NULL)
2981 (void) DrawPatternPath(image,draw_info,mvg_class,
2982 &graphic_context[n]->fill_pattern);
2985 (void) FormatLocaleString(pattern,MaxTextExtent,
"%s",token);
2986 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
2988 (void) DrawPatternPath(image,draw_info,token,
2989 &graphic_context[n]->fill_pattern);
2992 status&=QueryColorDatabase(token,&graphic_context[n]->fill,
2994 if (graphic_context[n]->fill_opacity != (
double) OpaqueOpacity)
2995 graphic_context[n]->fill.opacity=ClampToQuantum(
2996 graphic_context[n]->fill_opacity);
2999 if (LocaleCompare(
"fill-opacity",keyword) == 0)
3004 (void) GetNextToken(q,&q,extent,token);
3005 if (graphic_context[n]->clip_path != MagickFalse)
3007 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3008 opacity=MagickMin(MagickMax(factor*
3009 GetDrawValue(token,&next_token),0.0),1.0);
3010 if (token == next_token)
3011 ThrowPointExpectedException(image,token);
3012 if (graphic_context[n]->compliance == SVGCompliance)
3013 graphic_context[n]->fill_opacity*=(1.0-opacity);
3015 graphic_context[n]->fill_opacity=((MagickRealType) QuantumRange-
3016 graphic_context[n]->fill_opacity)*(1.0-opacity);
3017 if (graphic_context[n]->fill.opacity != TransparentOpacity)
3018 graphic_context[n]->fill.opacity=(Quantum)
3019 graphic_context[n]->fill_opacity;
3021 graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType)
3022 QuantumRange*(1.0-opacity));
3025 if (LocaleCompare(
"fill-rule",keyword) == 0)
3030 (void) GetNextToken(q,&q,extent,token);
3031 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
3033 if (fill_rule == -1)
3038 graphic_context[n]->fill_rule=(FillRule) fill_rule;
3041 if (LocaleCompare(
"font",keyword) == 0)
3043 (void) GetNextToken(q,&q,extent,token);
3044 (void) CloneString(&graphic_context[n]->font,token);
3045 if (LocaleCompare(
"none",token) == 0)
3046 graphic_context[n]->font=(
char *) RelinquishMagickMemory(
3047 graphic_context[n]->font);
3050 if (LocaleCompare(
"font-family",keyword) == 0)
3052 (void) GetNextToken(q,&q,extent,token);
3053 (void) CloneString(&graphic_context[n]->family,token);
3056 if (LocaleCompare(
"font-size",keyword) == 0)
3058 (void) GetNextToken(q,&q,extent,token);
3059 graphic_context[n]->pointsize=GetDrawValue(token,&next_token);
3060 if (token == next_token)
3061 ThrowPointExpectedException(image,token);
3064 if (LocaleCompare(
"font-stretch",keyword) == 0)
3069 (void) GetNextToken(q,&q,extent,token);
3070 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
3076 graphic_context[n]->stretch=(StretchType) stretch;
3079 if (LocaleCompare(
"font-style",keyword) == 0)
3084 (void) GetNextToken(q,&q,extent,token);
3085 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
3091 graphic_context[n]->style=(StyleType) style;
3094 if (LocaleCompare(
"font-weight",keyword) == 0)
3099 (void) GetNextToken(q,&q,extent,token);
3100 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token);
3102 weight=(ssize_t) StringToUnsignedLong(token);
3103 graphic_context[n]->weight=(size_t) weight;
3112 if (LocaleCompare(
"gradient-units",keyword) == 0)
3114 (void) GetNextToken(q,&q,extent,token);
3117 if (LocaleCompare(
"gravity",keyword) == 0)
3122 (void) GetNextToken(q,&q,extent,token);
3123 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
3129 graphic_context[n]->gravity=(GravityType) gravity;
3138 if (LocaleCompare(
"image",keyword) == 0)
3143 primitive_type=ImagePrimitive;
3144 (void) GetNextToken(q,&q,extent,token);
3145 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
3151 graphic_context[n]->compose=(CompositeOperator) compose;
3154 if (LocaleCompare(
"interline-spacing",keyword) == 0)
3156 (void) GetNextToken(q,&q,extent,token);
3157 graphic_context[n]->interline_spacing=GetDrawValue(token,
3159 if (token == next_token)
3160 ThrowPointExpectedException(image,token);
3163 if (LocaleCompare(
"interword-spacing",keyword) == 0)
3165 (void) GetNextToken(q,&q,extent,token);
3166 graphic_context[n]->interword_spacing=GetDrawValue(token,
3168 if (token == next_token)
3169 ThrowPointExpectedException(image,token);
3178 if (LocaleCompare(
"kerning",keyword) == 0)
3180 (void) GetNextToken(q,&q,extent,token);
3181 graphic_context[n]->kerning=GetDrawValue(token,&next_token);
3182 if (token == next_token)
3183 ThrowPointExpectedException(image,token);
3192 if (LocaleCompare(
"letter-spacing",keyword) == 0)
3194 (void) GetNextToken(q,&q,extent,token);
3195 if (IsValidPoint(token) == MagickFalse)
3197 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
3198 clone_info->text=AcquireString(
" ");
3199 status&=GetTypeMetrics(image,clone_info,&metrics);
3200 graphic_context[n]->kerning=metrics.width*
3201 GetDrawValue(token,&next_token);
3202 clone_info=DestroyDrawInfo(clone_info);
3203 if (token == next_token)
3204 ThrowPointExpectedException(image,token);
3207 if (LocaleCompare(
"line",keyword) == 0)
3209 primitive_type=LinePrimitive;
3218 if (LocaleCompare(
"mask",keyword) == 0)
3226 (void) GetNextToken(q,&q,extent,token);
3227 mask_path=(
const char *) GetValueFromSplayTree(macros,token);
3228 if (mask_path != (
const char *) NULL)
3230 if (graphic_context[n]->composite_mask != (
Image *) NULL)
3231 graphic_context[n]->composite_mask=
3232 DestroyImage(graphic_context[n]->composite_mask);
3233 graphic_context[n]->composite_mask=DrawCompositeMask(image,
3234 graphic_context[n],token,mask_path,&image->exception);
3235 if (graphic_context[n]->compliance != SVGCompliance)
3236 status=SetImageMask(image,graphic_context[n]->composite_mask);
3240 if (LocaleCompare(
"matte",keyword) == 0)
3242 primitive_type=MattePrimitive;
3251 if (LocaleCompare(
"offset",keyword) == 0)
3253 (void) GetNextToken(q,&q,extent,token);
3256 if (LocaleCompare(
"opacity",keyword) == 0)
3261 (void) GetNextToken(q,&q,extent,token);
3262 if (graphic_context[n]->clip_path != MagickFalse)
3264 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3265 opacity=1.0-MagickMin(MagickMax(factor*
3266 GetDrawValue(token,&next_token),0.0),1.0);
3267 if (token == next_token)
3268 ThrowPointExpectedException(image,token);
3269 if (graphic_context[n]->compliance == SVGCompliance)
3271 graphic_context[n]->fill_opacity*=opacity;
3272 graphic_context[n]->stroke_opacity*=opacity;
3276 graphic_context[n]->fill_opacity=(double) QuantumRange*opacity;
3277 graphic_context[n]->stroke_opacity=(double) QuantumRange*
3280 if (graphic_context[n]->fill.opacity != (
double) TransparentOpacity)
3282 graphic_context[n]->fill.opacity=
3283 graphic_context[n]->fill_opacity;
3284 graphic_context[n]->stroke.opacity=
3285 graphic_context[n]->stroke_opacity;
3289 graphic_context[n]->fill.opacity=(MagickRealType)
3290 ClampToQuantum((
double) QuantumRange*opacity);
3291 graphic_context[n]->stroke.opacity=(MagickRealType)
3292 ClampToQuantum((
double) QuantumRange*opacity);
3302 if (LocaleCompare(
"path",keyword) == 0)
3304 primitive_type=PathPrimitive;
3307 if (LocaleCompare(
"point",keyword) == 0)
3309 primitive_type=PointPrimitive;
3312 if (LocaleCompare(
"polyline",keyword) == 0)
3314 primitive_type=PolylinePrimitive;
3317 if (LocaleCompare(
"polygon",keyword) == 0)
3319 primitive_type=PolygonPrimitive;
3322 if (LocaleCompare(
"pop",keyword) == 0)
3324 if (GetNextToken(q,&q,extent,token) < 1)
3326 if (LocaleCompare(
"class",token) == 0)
3328 if (LocaleCompare(
"clip-path",token) == 0)
3330 if (LocaleCompare(
"defs",token) == 0)
3333 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3337 if (LocaleCompare(
"gradient",token) == 0)
3339 if (LocaleCompare(
"graphic-context",token) == 0)
3343 (void) ThrowMagickException(&image->exception,
3344 GetMagickModule(),DrawError,
3345 "UnbalancedGraphicContextPushPop",
"`%s'",token);
3350 if ((graphic_context[n]->clip_mask != (
char *) NULL) &&
3351 (graphic_context[n]->compliance != SVGCompliance))
3352 if (LocaleCompare(graphic_context[n]->clip_mask,
3353 graphic_context[n-1]->clip_mask) != 0)
3354 status=SetImageClipMask(image,(
Image *) NULL);
3355 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3359 if (LocaleCompare(
"mask",token) == 0)
3361 if (LocaleCompare(
"pattern",token) == 0)
3363 if (LocaleCompare(
"symbol",token) == 0)
3366 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3373 if (LocaleCompare(
"push",keyword) == 0)
3375 if (GetNextToken(q,&q,extent,token) < 1)
3377 if (LocaleCompare(
"class",token) == 0)
3382 for (p=q; *q !=
'\0'; )
3384 if (GetNextToken(q,&q,extent,token) < 1)
3386 if (LocaleCompare(token,
"pop") != 0)
3388 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3389 if (LocaleCompare(token,
"class") != 0)
3393 (void) GetNextToken(q,&q,extent,token);
3396 if (LocaleCompare(
"clip-path",token) == 0)
3398 (void) GetNextToken(q,&q,extent,token);
3399 for (p=q; *q !=
'\0'; )
3401 if (GetNextToken(q,&q,extent,token) < 1)
3403 if (LocaleCompare(token,
"pop") != 0)
3405 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3406 if (LocaleCompare(token,
"clip-path") != 0)
3410 if ((q == (
char *) NULL) || (p == (
char *) NULL) || ((q-4) < p))
3415 (void) GetNextToken(q,&q,extent,token);
3418 if (LocaleCompare(
"defs",token) == 0)
3421 graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
3425 if (LocaleCompare(
"gradient",token) == 0)
3428 key[2*MaxTextExtent],
3429 name[MaxTextExtent],
3430 type[MaxTextExtent];
3435 (void) GetNextToken(q,&q,extent,token);
3436 (void) CopyMagickString(name,token,MaxTextExtent);
3437 (void) GetNextToken(q,&q,extent,token);
3438 (void) CopyMagickString(type,token,MaxTextExtent);
3439 (void) GetNextToken(q,&q,extent,token);
3440 segment.x1=GetDrawValue(token,&next_token);
3441 if (token == next_token)
3442 ThrowPointExpectedException(image,token);
3443 (void) GetNextToken(q,&q,extent,token);
3444 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3445 ThrowPointExpectedException(image,token);
3447 (void) GetNextToken(q,&q,extent,token);
3448 segment.y1=GetDrawValue(token,&next_token);
3449 if (token == next_token)
3450 ThrowPointExpectedException(image,token);
3451 (void) GetNextToken(q,&q,extent,token);
3452 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3453 ThrowPointExpectedException(image,token);
3455 (void) GetNextToken(q,&q,extent,token);
3456 segment.x2=GetDrawValue(token,&next_token);
3457 if (token == next_token)
3458 ThrowPointExpectedException(image,token);
3459 (void) GetNextToken(q,&q,extent,token);
3460 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3461 ThrowPointExpectedException(image,token);
3463 (void) GetNextToken(q,&q,extent,token);
3464 segment.y2=GetDrawValue(token,&next_token);
3465 if (token == next_token)
3466 ThrowPointExpectedException(image,token);
3467 if (LocaleCompare(type,
"radial") == 0)
3469 (void) GetNextToken(q,&q,extent,token);
3470 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3471 ThrowPointExpectedException(image,token);
3473 (void) GetNextToken(q,&q,extent,token);
3475 for (p=q; *q !=
'\0'; )
3477 if (GetNextToken(q,&q,extent,token) < 1)
3479 if (LocaleCompare(token,
"pop") != 0)
3481 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3482 if (LocaleCompare(token,
"gradient") != 0)
3486 if ((q == (
char *) NULL) || (*q ==
'\0') ||
3487 (p == (
char *) NULL) || ((q-4) < p) ||
3488 ((q-p+4+1) > extent))
3493 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3494 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
3495 graphic_context[n]->affine.ry*segment.y1+
3496 graphic_context[n]->affine.tx;
3497 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
3498 graphic_context[n]->affine.sy*segment.y1+
3499 graphic_context[n]->affine.ty;
3500 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
3501 graphic_context[n]->affine.ry*segment.y2+
3502 graphic_context[n]->affine.tx;
3503 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
3504 graphic_context[n]->affine.sy*segment.y2+
3505 graphic_context[n]->affine.ty;
3506 (void) FormatLocaleString(key,MaxTextExtent,
"%s",name);
3507 (void) SetImageArtifact(image,key,token);
3508 (void) FormatLocaleString(key,MaxTextExtent,
"%s-type",name);
3509 (void) SetImageArtifact(image,key,type);
3510 (void) FormatLocaleString(key,MaxTextExtent,
"%s-geometry",name);
3511 (void) FormatLocaleString(geometry,MaxTextExtent,
3512 "%gx%g%+.15g%+.15g",
3513 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
3514 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
3515 bounds.x1,bounds.y1);
3516 (void) SetImageArtifact(image,key,geometry);
3517 (void) GetNextToken(q,&q,extent,token);
3520 if (LocaleCompare(
"graphic-context",token) == 0)
3523 graphic_context=(
DrawInfo **) ResizeQuantumMemory(
3524 graphic_context,(
size_t) (n+1),
sizeof(*graphic_context));
3525 if (graphic_context == (
DrawInfo **) NULL)
3527 (void) ThrowMagickException(&image->exception,
3528 GetMagickModule(),ResourceLimitError,
3529 "MemoryAllocationFailed",
"`%s'",image->filename);
3533 graphic_context[n]=CloneDrawInfo((
ImageInfo *) NULL,
3534 graphic_context[n-1]);
3537 (void) GetNextToken(q,&q,extent,token);
3538 (void) CloneString(&graphic_context[n]->
id,token);
3540 if (n > MagickMaxRecursionDepth)
3542 (void) ThrowMagickException(&image->exception,
3543 GetMagickModule(),DrawError,
3544 "VectorGraphicsNestedTooDeeply",
"`%s'",image->filename);
3549 if (LocaleCompare(
"mask",token) == 0)
3551 (void) GetNextToken(q,&q,extent,token);
3554 if (LocaleCompare(
"pattern",token) == 0)
3559 (void) GetNextToken(q,&q,extent,token);
3560 (void) CopyMagickString(name,token,MaxTextExtent);
3561 (void) GetNextToken(q,&q,extent,token);
3562 bounds.x=CastDoubleToLong(ceil(GetDrawValue(token,
3564 if (token == next_token)
3565 ThrowPointExpectedException(image,token);
3566 (void) GetNextToken(q,&q,extent,token);
3567 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3568 ThrowPointExpectedException(image,token);
3570 (void) GetNextToken(q,&q,extent,token);
3571 bounds.y=CastDoubleToLong(ceil(GetDrawValue(token,
3573 if (token == next_token)
3574 ThrowPointExpectedException(image,token);
3575 (void) GetNextToken(q,&q,extent,token);
3576 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3577 ThrowPointExpectedException(image,token);
3579 (void) GetNextToken(q,&q,extent,token);
3580 bounds.width=CastDoubleToUnsigned(GetDrawValue(token,
3582 if (token == next_token)
3583 ThrowPointExpectedException(image,token);
3584 (void) GetNextToken(q,&q,extent,token);
3585 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3586 ThrowPointExpectedException(image,token);
3588 (void) GetNextToken(q,&q,extent,token);
3589 bounds.height=CastDoubleToUnsigned(GetDrawValue(token,
3591 if (token == next_token)
3592 ThrowPointExpectedException(image,token);
3593 for (p=q; *q !=
'\0'; )
3595 if (GetNextToken(q,&q,extent,token) < 1)
3597 if (LocaleCompare(token,
"pop") != 0)
3599 (void) GetNextToken(q,(
const char **) NULL,extent,token);
3600 if (LocaleCompare(token,
"pattern") != 0)
3604 if ((q == (
char *) NULL) || (p == (
char *) NULL) ||
3605 ((q-4) < p) || ((size_t) (q-p+4+1) > extent))
3610 (void) CopyMagickString(token,p,(
size_t) (q-p-4+1));
3611 (void) FormatLocaleString(key,MaxTextExtent,
"%s",name);
3612 (void) SetImageArtifact(image,key,token);
3613 (void) FormatLocaleString(key,MaxTextExtent,
"%s-geometry",name);
3614 (void) FormatLocaleString(geometry,MaxTextExtent,
3615 "%.20gx%.20g%+.20g%+.20g",(
double) bounds.width,(double)
3616 bounds.height,(
double) bounds.x,(double) bounds.y);
3617 (void) SetImageArtifact(image,key,geometry);
3618 (void) GetNextToken(q,&q,extent,token);
3621 if (LocaleCompare(
"symbol",token) == 0)
3624 graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
3637 if (LocaleCompare(
"rectangle",keyword) == 0)
3639 primitive_type=RectanglePrimitive;
3642 if (LocaleCompare(
"rotate",keyword) == 0)
3644 (void) GetNextToken(q,&q,extent,token);
3645 angle=GetDrawValue(token,&next_token);
3646 if (token == next_token)
3647 ThrowPointExpectedException(image,token);
3648 affine.sx=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3649 affine.rx=sin(DegreesToRadians(fmod((
double) angle,360.0)));
3650 affine.ry=(-sin(DegreesToRadians(fmod((
double) angle,360.0))));
3651 affine.sy=cos(DegreesToRadians(fmod((
double) angle,360.0)));
3654 if (LocaleCompare(
"roundRectangle",keyword) == 0)
3656 primitive_type=RoundRectanglePrimitive;
3665 if (LocaleCompare(
"scale",keyword) == 0)
3667 (void) GetNextToken(q,&q,extent,token);
3668 affine.sx=GetDrawValue(token,&next_token);
3669 if (token == next_token)
3670 ThrowPointExpectedException(image,token);
3671 (void) GetNextToken(q,&q,extent,token);
3672 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3673 ThrowPointExpectedException(image,token);
3675 (void) GetNextToken(q,&q,extent,token);
3676 affine.sy=GetDrawValue(token,&next_token);
3677 if (token == next_token)
3678 ThrowPointExpectedException(image,token);
3681 if (LocaleCompare(
"skewX",keyword) == 0)
3683 (void) GetNextToken(q,&q,extent,token);
3684 angle=GetDrawValue(token,&next_token);
3685 if (token == next_token)
3686 ThrowPointExpectedException(image,token);
3687 affine.ry=sin(DegreesToRadians(angle));
3690 if (LocaleCompare(
"skewY",keyword) == 0)
3692 (void) GetNextToken(q,&q,extent,token);
3693 angle=GetDrawValue(token,&next_token);
3694 if (token == next_token)
3695 ThrowPointExpectedException(image,token);
3696 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
3699 if (LocaleCompare(
"stop-color",keyword) == 0)
3707 (void) GetNextToken(q,&q,extent,token);
3708 status&=QueryColorDatabase(token,&stop_color,&image->exception);
3709 type=LinearGradient;
3710 if (draw_info->gradient.type == RadialGradient)
3711 type=RadialGradient;
3712 (void) GradientImage(image,type,PadSpread,&start_color,&stop_color);
3713 start_color=stop_color;
3714 (void) GetNextToken(q,&q,extent,token);
3717 if (LocaleCompare(
"stroke",keyword) == 0)
3722 (void) GetNextToken(q,&q,extent,token);
3723 if (graphic_context[n]->clip_path != MagickFalse)
3725 mvg_class=(
const char *) GetValueFromSplayTree(macros,token);
3726 if (mvg_class != (
const char *) NULL)
3728 (void) DrawPatternPath(image,draw_info,mvg_class,
3729 &graphic_context[n]->stroke_pattern);
3732 (void) FormatLocaleString(pattern,MaxTextExtent,
"%s",token);
3733 if (GetImageArtifact(image,pattern) != (
const char *) NULL)
3735 (void) DrawPatternPath(image,draw_info,token,
3736 &graphic_context[n]->stroke_pattern);
3739 status&=QueryColorDatabase(token,&graphic_context[n]->stroke,
3741 if (graphic_context[n]->stroke_opacity != (MagickRealType) OpaqueOpacity)
3742 graphic_context[n]->stroke.opacity=ClampToQuantum(
3743 graphic_context[n]->stroke_opacity);
3746 if (LocaleCompare(
"stroke-antialias",keyword) == 0)
3748 (void) GetNextToken(q,&q,extent,token);
3749 graphic_context[n]->stroke_antialias=StringToLong(token) != 0 ?
3750 MagickTrue : MagickFalse;
3753 if (LocaleCompare(
"stroke-dasharray",keyword) == 0)
3755 if (graphic_context[n]->dash_pattern != (
double *) NULL)
3756 graphic_context[n]->dash_pattern=(
double *)
3757 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
3758 if (IsValidPoint(q) != MagickFalse)
3764 (void) GetNextToken(p,&p,extent,token);
3765 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3766 ThrowPointExpectedException(image,token);
3768 (void) GetNextToken(p,&p,extent,token);
3769 for (x=0; IsValidPoint(token) != MagickFalse; x++)
3771 (void) GetNextToken(p,&p,extent,token);
3773 (void) GetNextToken(p,&p,extent,token);
3775 graphic_context[n]->dash_pattern=(
double *)
3776 AcquireQuantumMemory((
size_t) (2*x+2),
3777 sizeof(*graphic_context[n]->dash_pattern));
3778 if (graphic_context[n]->dash_pattern == (
double *) NULL)
3780 (void) ThrowMagickException(&image->exception,
3781 GetMagickModule(),ResourceLimitError,
3782 "MemoryAllocationFailed",
"`%s'",image->filename);
3786 (void) memset(graphic_context[n]->dash_pattern,0,(
size_t)
3787 (2*x+2)*
sizeof(*graphic_context[n]->dash_pattern));
3788 for (j=0; j < x; j++)
3790 (void) GetNextToken(q,&q,extent,token);
3791 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3792 ThrowPointExpectedException(image,token);
3794 (void) GetNextToken(q,&q,extent,token);
3795 graphic_context[n]->dash_pattern[j]=GetDrawValue(token,
3797 if (token == next_token)
3798 ThrowPointExpectedException(image,token);
3799 if (graphic_context[n]->dash_pattern[j] <= 0.0)
3802 if (((x & 0x01) != 0) && (j == x))
3803 for ( ; j < (2*x); j++)
3804 graphic_context[n]->dash_pattern[j]=
3805 graphic_context[n]->dash_pattern[j-x];
3806 graphic_context[n]->dash_pattern[j]=0.0;
3809 (void) GetNextToken(q,&q,extent,token);
3812 if (LocaleCompare(
"stroke-dashoffset",keyword) == 0)
3814 (void) GetNextToken(q,&q,extent,token);
3815 graphic_context[n]->dash_offset=GetDrawValue(token,&next_token);
3816 if (token == next_token)
3817 ThrowPointExpectedException(image,token);
3820 if (LocaleCompare(
"stroke-linecap",keyword) == 0)
3825 (void) GetNextToken(q,&q,extent,token);
3826 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
3832 graphic_context[n]->linecap=(LineCap) linecap;
3835 if (LocaleCompare(
"stroke-linejoin",keyword) == 0)
3840 (void) GetNextToken(q,&q,extent,token);
3841 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
3848 graphic_context[n]->linejoin=(LineJoin) linejoin;
3851 if (LocaleCompare(
"stroke-miterlimit",keyword) == 0)
3853 (void) GetNextToken(q,&q,extent,token);
3854 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
3857 if (LocaleCompare(
"stroke-opacity",keyword) == 0)
3862 (void) GetNextToken(q,&q,extent,token);
3863 if (graphic_context[n]->clip_path != MagickFalse)
3865 factor=strchr(token,
'%') != (
char *) NULL ? 0.01 : 1.0;
3866 opacity=MagickMin(MagickMax(factor*
3867 GetDrawValue(token,&next_token),0.0),1.0);
3868 if (token == next_token)
3869 ThrowPointExpectedException(image,token);
3870 if (graphic_context[n]->compliance == SVGCompliance)
3871 graphic_context[n]->stroke_opacity*=(1.0-opacity);
3873 graphic_context[n]->stroke_opacity=((MagickRealType) QuantumRange-
3874 graphic_context[n]->stroke_opacity)*(1.0-opacity);
3875 if (graphic_context[n]->stroke.opacity != TransparentOpacity)
3876 graphic_context[n]->stroke.opacity=(Quantum)
3877 graphic_context[n]->stroke_opacity;
3879 graphic_context[n]->stroke.opacity=ClampToQuantum(
3880 (MagickRealType) QuantumRange*opacity);
3883 if (LocaleCompare(
"stroke-width",keyword) == 0)
3885 (void) GetNextToken(q,&q,extent,token);
3886 if (graphic_context[n]->clip_path != MagickFalse)
3888 graphic_context[n]->stroke_width=GetDrawValue(token,&next_token);
3889 if ((token == next_token) ||
3890 (graphic_context[n]->stroke_width < 0.0))
3891 ThrowPointExpectedException(image,token);
3900 if (LocaleCompare(
"text",keyword) == 0)
3902 primitive_type=TextPrimitive;
3906 if (LocaleCompare(
"text-align",keyword) == 0)
3911 (void) GetNextToken(q,&q,extent,token);
3912 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3918 graphic_context[n]->align=(AlignType) align;
3921 if (LocaleCompare(
"text-anchor",keyword) == 0)
3926 (void) GetNextToken(q,&q,extent,token);
3927 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
3933 graphic_context[n]->align=(AlignType) align;
3936 if (LocaleCompare(
"text-antialias",keyword) == 0)
3938 (void) GetNextToken(q,&q,extent,token);
3939 graphic_context[n]->text_antialias=StringToLong(token) != 0 ?
3940 MagickTrue : MagickFalse;
3943 if (LocaleCompare(
"text-undercolor",keyword) == 0)
3945 (void) GetNextToken(q,&q,extent,token);
3946 status&=QueryColorDatabase(token,&graphic_context[n]->undercolor,
3950 if (LocaleCompare(
"translate",keyword) == 0)
3952 (void) GetNextToken(q,&q,extent,token);
3953 affine.tx=GetDrawValue(token,&next_token);
3954 if (token == next_token)
3955 ThrowPointExpectedException(image,token);
3956 (void) GetNextToken(q,&q,extent,token);
3957 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
3958 ThrowPointExpectedException(image,token);
3960 (void) GetNextToken(q,&q,extent,token);
3961 affine.ty=GetDrawValue(token,&next_token);
3962 if (token == next_token)
3963 ThrowPointExpectedException(image,token);
3972 if (LocaleCompare(
"use",keyword) == 0)
3980 (void) GetNextToken(q,&q,extent,token);
3981 use=(
const char *) GetValueFromSplayTree(macros,token);
3982 if (use != (
const char *) NULL)
3984 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
3985 (void) CloneString(&clone_info->primitive,use);
3986 status=RenderMVGContent(image,clone_info,depth+1);
3987 clone_info=DestroyDrawInfo(clone_info);
3997 if (LocaleCompare(
"viewbox",keyword) == 0)
3999 (void) GetNextToken(q,&q,extent,token);
4000 graphic_context[n]->viewbox.x=CastDoubleToLong(ceil(
4001 GetDrawValue(token,&next_token)-0.5));
4002 if (token == next_token)
4003 ThrowPointExpectedException(image,token);
4004 (void) GetNextToken(q,&q,extent,token);
4005 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4006 ThrowPointExpectedException(image,token);
4008 (void) GetNextToken(q,&q,extent,token);
4009 graphic_context[n]->viewbox.y=CastDoubleToLong(ceil(
4010 GetDrawValue(token,&next_token)-0.5));
4011 if (token == next_token)
4012 ThrowPointExpectedException(image,token);
4013 (void) GetNextToken(q,&q,extent,token);
4014 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4015 ThrowPointExpectedException(image,token);
4017 (void) GetNextToken(q,&q,extent,token);
4018 graphic_context[n]->viewbox.width=CastDoubleToUnsigned(
4019 GetDrawValue(token,&next_token)+0.5);
4020 if (token == next_token)
4021 ThrowPointExpectedException(image,token);
4022 (void) GetNextToken(q,&q,extent,token);
4023 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4024 ThrowPointExpectedException(image,token);
4026 (void) GetNextToken(q,&q,extent,token);
4027 graphic_context[n]->viewbox.height=CastDoubleToUnsigned(
4028 GetDrawValue(token,&next_token)+0.5);
4029 if (token == next_token)
4030 ThrowPointExpectedException(image,token);
4039 if (LocaleCompare(
"word-spacing",keyword) == 0)
4041 (void) GetNextToken(q,&q,extent,token);
4042 graphic_context[n]->interword_spacing=GetDrawValue(token,
4044 if (token == next_token)
4045 ThrowPointExpectedException(image,token);
4057 if (status == MagickFalse)
4059 if ((fabs(affine.sx-1.0) >= MagickEpsilon) ||
4060 (fabs(affine.rx) >= MagickEpsilon) || (fabs(affine.ry) >= MagickEpsilon) ||
4061 (fabs(affine.sy-1.0) >= MagickEpsilon) ||
4062 (fabs(affine.tx) >= MagickEpsilon) || (fabs(affine.ty) >= MagickEpsilon))
4064 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
4065 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
4066 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
4067 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
4068 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
4070 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
4073 if (primitive_type == UndefinedPrimitive)
4075 if ((draw_info->debug != MagickFalse) && (q > p))
4076 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(int)
4083 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4084 if (primitive_info[i].text != (
char *) NULL)
4085 primitive_info[i].text=DestroyString(primitive_info[i].text);
4089 primitive_info[0].primitive=primitive_type;
4090 primitive_info[0].point.x=0.0;
4091 primitive_info[0].point.y=0.0;
4092 primitive_info[0].coordinates=0;
4093 primitive_info[0].method=FloodfillMethod;
4094 primitive_info[0].closed_subpath=MagickFalse;
4095 for (x=0; *q !=
'\0'; x++)
4100 if (IsValidPoint(q) == MagickFalse)
4102 (void) GetNextToken(q,&q,extent,token);
4103 point.x=GetDrawValue(token,&next_token);
4104 if (token == next_token)
4105 ThrowPointExpectedException(image,token);
4106 (void) GetNextToken(q,&q,extent,token);
4107 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
4108 ThrowPointExpectedException(image,token);
4110 (void) GetNextToken(q,&q,extent,token);
4111 point.y=GetDrawValue(token,&next_token);
4112 if (token == next_token)
4113 ThrowPointExpectedException(image,token);
4114 (void) GetNextToken(q,(
const char **) NULL,extent,token);
4116 (void) GetNextToken(q,&q,extent,token);
4117 primitive_info[i].primitive=primitive_type;
4118 primitive_info[i].point=point;
4119 primitive_info[i].coordinates=0;
4120 primitive_info[i].method=FloodfillMethod;
4121 primitive_info[i].closed_subpath=MagickFalse;
4124 if (i < (ssize_t) number_points)
4126 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points);
4127 primitive_info=(*mvg_info.primitive_info);
4128 if (status == MagickFalse)
4131 if (status == MagickFalse)
4133 if (primitive_info[j].text != (
char *) NULL)
4134 primitive_info[j].text=DestroyString(primitive_info[j].text);
4135 primitive_info[j].primitive=primitive_type;
4136 primitive_info[j].coordinates=(size_t) x;
4137 primitive_info[j].method=FloodfillMethod;
4138 primitive_info[j].closed_subpath=MagickFalse;
4142 bounds.x1=primitive_info[j].point.x;
4143 bounds.y1=primitive_info[j].point.y;
4144 bounds.x2=primitive_info[j].point.x;
4145 bounds.y2=primitive_info[j].point.y;
4146 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
4148 point=primitive_info[j+k].point;
4149 if (point.x < bounds.x1)
4151 if (point.y < bounds.y1)
4153 if (point.x > bounds.x2)
4155 if (point.y > bounds.y2)
4161 coordinates=(double) primitive_info[j].coordinates;
4162 switch (primitive_type)
4164 case RectanglePrimitive:
4169 case RoundRectanglePrimitive:
4176 alpha=bounds.x2-bounds.x1;
4177 beta=bounds.y2-bounds.y1;
4178 radius=hypot(alpha,beta);
4180 coordinates+=2.0*((size_t) ceil((
double) MagickPI*radius))+6.0*
4181 BezierQuantum+360.0;
4184 case BezierPrimitive:
4186 coordinates=(BezierQuantum*(double) primitive_info[j].coordinates);
4195 (void) GetNextToken(q,&q,extent,token);
4198 for (s=token; *s !=
'\0'; s=t)
4203 value=GetDrawValue(s,&t);
4212 for (s=token; *s !=
'\0'; s++)
4213 if (strspn(s,
"AaCcQqSsTt") != 0)
4214 coordinates+=(20.0*BezierQuantum)+360.0;
4220 if (status == MagickFalse)
4222 if (((
size_t) (i+coordinates)) >= number_points)
4227 number_points+=coordinates+1;
4228 if (number_points < (
size_t) coordinates)
4230 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4231 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
4237 status&=CheckPrimitiveExtent(&mvg_info,(
double) number_points);
4238 primitive_info=(*mvg_info.primitive_info);
4239 if (status == MagickFalse)
4242 status&=CheckPrimitiveExtent(&mvg_info,PrimitiveExtentPad);
4243 primitive_info=(*mvg_info.primitive_info);
4244 if (status == MagickFalse)
4247 switch (primitive_type)
4249 case PointPrimitive:
4252 if (primitive_info[j].coordinates != 1)
4257 status&=TracePoint(primitive_info+j,primitive_info[j].point);
4258 primitive_info=(*mvg_info.primitive_info);
4259 if (status == MagickFalse)
4261 i=(ssize_t) (j+primitive_info[j].coordinates);
4266 if (primitive_info[j].coordinates != 2)
4271 status&=TraceLine(primitive_info+j,primitive_info[j].point,
4272 primitive_info[j+1].point);
4273 primitive_info=(*mvg_info.primitive_info);
4274 if (status == MagickFalse)
4276 i=(ssize_t) (j+primitive_info[j].coordinates);
4279 case RectanglePrimitive:
4281 if (primitive_info[j].coordinates != 2)
4286 status&=TraceRectangle(primitive_info+j,primitive_info[j].point,
4287 primitive_info[j+1].point);
4288 primitive_info=(*mvg_info.primitive_info);
4289 if (status == MagickFalse)
4291 i=(ssize_t) (j+primitive_info[j].coordinates);
4294 case RoundRectanglePrimitive:
4296 if (primitive_info[j].coordinates != 3)
4301 if ((primitive_info[j+2].point.x < 0.0) ||
4302 (primitive_info[j+2].point.y < 0.0))
4307 if ((primitive_info[j+1].point.x-primitive_info[j].point.x) < 0.0)
4312 if ((primitive_info[j+1].point.y-primitive_info[j].point.y) < 0.0)
4317 status&=TraceRoundRectangle(&mvg_info,primitive_info[j].point,
4318 primitive_info[j+1].point,primitive_info[j+2].point);
4319 primitive_info=(*mvg_info.primitive_info);
4320 if (status == MagickFalse)
4322 i=(ssize_t) (j+primitive_info[j].coordinates);
4327 if (primitive_info[j].coordinates != 3)
4332 status&=TraceArc(&mvg_info,primitive_info[j].point,
4333 primitive_info[j+1].point,primitive_info[j+2].point);
4334 primitive_info=(*mvg_info.primitive_info);
4335 if (status == MagickFalse)
4337 i=(ssize_t) (j+primitive_info[j].coordinates);
4340 case EllipsePrimitive:
4342 if (primitive_info[j].coordinates != 3)
4347 if ((primitive_info[j+1].point.x < 0.0) ||
4348 (primitive_info[j+1].point.y < 0.0))
4353 status&=TraceEllipse(&mvg_info,primitive_info[j].point,
4354 primitive_info[j+1].point,primitive_info[j+2].point);
4355 primitive_info=(*mvg_info.primitive_info);
4356 if (status == MagickFalse)
4358 i=(ssize_t) (j+primitive_info[j].coordinates);
4361 case CirclePrimitive:
4363 if (primitive_info[j].coordinates != 2)
4368 status&=TraceCircle(&mvg_info,primitive_info[j].point,
4369 primitive_info[j+1].point);
4370 primitive_info=(*mvg_info.primitive_info);
4371 if (status == MagickFalse)
4373 i=(ssize_t) (j+primitive_info[j].coordinates);
4376 case PolylinePrimitive:
4378 if (primitive_info[j].coordinates < 1)
4385 case PolygonPrimitive:
4387 if (primitive_info[j].coordinates < 3)
4392 primitive_info[i]=primitive_info[j];
4393 primitive_info[i].coordinates=0;
4394 primitive_info[j].coordinates++;
4395 primitive_info[j].closed_subpath=MagickTrue;
4399 case BezierPrimitive:
4401 if (primitive_info[j].coordinates < 3)
4406 status&=TraceBezier(&mvg_info,primitive_info[j].coordinates);
4407 primitive_info=(*mvg_info.primitive_info);
4408 if (status == MagickFalse)
4410 i=(ssize_t) (j+primitive_info[j].coordinates);
4415 coordinates=(double) TracePath(image,&mvg_info,token);
4416 primitive_info=(*mvg_info.primitive_info);
4417 if (status == MagickFalse)
4419 if (coordinates < 0.0)
4424 i=(ssize_t) (j+coordinates);
4427 case ColorPrimitive:
4428 case MattePrimitive:
4433 if (primitive_info[j].coordinates != 1)
4438 (void) GetNextToken(q,&q,extent,token);
4439 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
4445 primitive_info[j].method=(PaintMethod) method;
4451 geometry[MagickPathExtent];
4453 if (primitive_info[j].coordinates != 1)
4459 (void) GetNextToken(q,&q,extent,token);
4460 (void) CloneString(&primitive_info[j].text,token);
4464 clone_info=CloneDrawInfo((
ImageInfo *) NULL,graphic_context[n]);
4465 if ((fabs(mvg_info.point.x-primitive_info->point.x) < MagickEpsilon) &&
4466 (fabs(mvg_info.point.y-primitive_info->point.y) < MagickEpsilon))
4468 mvg_info.point=primitive_info->point;
4469 primitive_info->point.x+=cursor;
4473 mvg_info.point=primitive_info->point;
4476 (void) FormatLocaleString(geometry,MagickPathExtent,
"%+f%+f",
4477 primitive_info->point.x,primitive_info->point.y);
4478 clone_info->render=MagickFalse;
4479 clone_info->text=AcquireString(token);
4480 status&=GetTypeMetrics(image,clone_info,&metrics);
4481 clone_info=DestroyDrawInfo(clone_info);
4482 cursor+=metrics.width;
4483 if (graphic_context[n]->compliance != SVGCompliance)
4487 case ImagePrimitive:
4489 if (primitive_info[j].coordinates != 2)
4494 (void) GetNextToken(q,&q,extent,token);
4495 (void) CloneString(&primitive_info[j].text,token);
4502 primitive_info[i].primitive=UndefinedPrimitive;
4503 if ((draw_info->debug != MagickFalse) && (q > p))
4504 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" %.*s",(int) (q-p),p);
4508 status&=CheckPrimitiveExtent(&mvg_info,ExpandAffine(
4509 &graphic_context[n]->affine));
4510 primitive_info=(*mvg_info.primitive_info);
4513 status&=CheckPrimitiveExtent(&mvg_info,(
double)
4514 graphic_context[n]->stroke_width);
4515 primitive_info=(*mvg_info.primitive_info);
4523 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4525 point=primitive_info[i].point;
4526 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
4527 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
4528 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
4529 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
4530 point=primitive_info[i].point;
4531 if (point.x < graphic_context[n]->bounds.x1)
4532 graphic_context[n]->bounds.x1=point.x;
4533 if (point.y < graphic_context[n]->bounds.y1)
4534 graphic_context[n]->bounds.y1=point.y;
4535 if (point.x > graphic_context[n]->bounds.x2)
4536 graphic_context[n]->bounds.x2=point.x;
4537 if (point.y > graphic_context[n]->bounds.y2)
4538 graphic_context[n]->bounds.y2=point.y;
4539 if (primitive_info[i].primitive == ImagePrimitive)
4541 if (i >= (ssize_t) number_points)
4542 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
4544 if (graphic_context[n]->render != MagickFalse)
4546 if ((n != 0) && (graphic_context[n]->compliance != SVGCompliance) &&
4547 (graphic_context[n]->clip_mask != (
char *) NULL) &&
4548 (LocaleCompare(graphic_context[n]->clip_mask,
4549 graphic_context[n-1]->clip_mask) != 0))
4554 clip_path=(
const char *) GetValueFromSplayTree(macros,
4555 graphic_context[n]->clip_mask);
4556 if (clip_path != (
const char *) NULL)
4557 (
void) SetImageArtifact(image,graphic_context[n]->clip_mask,
4559 status&=DrawClipPath(image,graphic_context[n],
4560 graphic_context[n]->clip_mask);
4562 status&=DrawPrimitive(image,graphic_context[n],primitive_info);
4564 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
4566 if (proceed == MagickFalse)
4571 if (draw_info->debug != MagickFalse)
4572 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end draw-image");
4576 macros=DestroySplayTree(macros);
4577 token=DestroyString(token);
4580 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4581 if (primitive_info[i].text != (
char *) NULL)
4582 primitive_info[i].text=DestroyString(primitive_info[i].text);
4583 primitive_info=(
PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
4585 primitive=DestroyString(primitive);
4586 for ( ; n >= 0; n--)
4587 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
4588 graphic_context=(
DrawInfo **) RelinquishMagickMemory(graphic_context);
4589 if (status == MagickFalse)
4590 ThrowBinaryImageException(DrawError,
4591 "NonconformingDrawingPrimitiveDefinition",keyword);
4592 return(status != 0 ? MagickTrue : MagickFalse);
4595 MagickExport MagickBooleanType DrawImage(
Image *image,
const DrawInfo *draw_info)
4597 return(RenderMVGContent(image,draw_info,0));
4629 MagickExport MagickBooleanType DrawPatternPath(
Image *image,
4633 property[MaxTextExtent];
4649 assert(image != (
Image *) NULL);
4650 assert(image->signature == MagickCoreSignature);
4651 assert(draw_info != (
const DrawInfo *) NULL);
4652 if (IsEventLogging() != MagickFalse)
4653 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4654 assert(name != (
const char *) NULL);
4655 (void) FormatLocaleString(property,MaxTextExtent,
"%s",name);
4656 path=GetImageArtifact(image,property);
4657 if (path == (
const char *) NULL)
4658 return(MagickFalse);
4659 (void) FormatLocaleString(property,MaxTextExtent,
"%s-geometry",name);
4660 geometry=GetImageArtifact(image,property);
4661 if (geometry == (
const char *) NULL)
4662 return(MagickFalse);
4663 if ((*pattern) != (
Image *) NULL)
4664 *pattern=DestroyImage(*pattern);
4665 image_info=AcquireImageInfo();
4666 image_info->size=AcquireString(geometry);
4667 *pattern=AcquireImage(image_info);
4668 image_info=DestroyImageInfo(image_info);
4669 (void) QueryColorDatabase(
"#00000000",&(*pattern)->background_color,
4671 (void) SetImageBackgroundColor(*pattern);
4672 if (draw_info->debug != MagickFalse)
4673 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4674 "begin pattern-path %s %s",name,geometry);
4675 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
4676 if (clone_info->fill_pattern != (
Image *) NULL)
4677 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4678 if (clone_info->stroke_pattern != (
Image *) NULL)
4679 clone_info->stroke_pattern=DestroyImage(clone_info->stroke_pattern);
4680 (void) FormatLocaleString(property,MaxTextExtent,
"%s-type",name);
4681 type=GetImageArtifact(image,property);
4682 if (type != (
const char *) NULL)
4683 clone_info->gradient.type=(GradientType) ParseCommandOption(
4684 MagickGradientOptions,MagickFalse,type);
4685 (void) CloneString(&clone_info->primitive,path);
4686 status=RenderMVGContent(*pattern,clone_info,0);
4687 clone_info=DestroyDrawInfo(clone_info);
4688 if (draw_info->debug != MagickFalse)
4689 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
"end pattern-path");
4727 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
4729 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
4730 polygon_info=(
PolygonInfo **) RelinquishMagickMemory(polygon_info);
4731 return(polygon_info);
4738 *magick_restrict path_info;
4746 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
4747 polygon_info=(
PolygonInfo **) AcquireQuantumMemory(number_threads,
4748 sizeof(*polygon_info));
4751 (void) ThrowMagickException(exception,GetMagickModule(),
4752 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4755 (void) memset(polygon_info,0,number_threads*
sizeof(*polygon_info));
4756 path_info=ConvertPrimitiveToPath(draw_info,primitive_info,exception);
4757 if (path_info == (
PathInfo *) NULL)
4758 return(DestroyPolygonTLS(polygon_info));
4759 polygon_info[0]=ConvertPathToPolygon(path_info,exception);
4762 (void) ThrowMagickException(exception,GetMagickModule(),
4763 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4764 return(DestroyPolygonTLS(polygon_info));
4766 path_info=(
PathInfo *) RelinquishMagickMemory(path_info);
4767 return(polygon_info);
4770 static MagickBooleanType AcquirePolygonEdgesTLS(
PolygonInfo **polygon_info,
4776 for (i=1; i < (ssize_t) number_threads; i++)
4784 polygon_info[i]=(
PolygonInfo *) AcquireMagickMemory(
4785 sizeof(*polygon_info[i]));
4788 (void) ThrowMagickException(exception,GetMagickModule(),
4789 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4790 return(MagickFalse);
4792 polygon_info[i]->number_edges=0;
4793 edge_info=polygon_info[0]->edges;
4794 polygon_info[i]->edges=(
EdgeInfo *) AcquireQuantumMemory(
4795 polygon_info[0]->number_edges,
sizeof(*edge_info));
4796 if (polygon_info[i]->edges == (
EdgeInfo *) NULL)
4798 (void) ThrowMagickException(exception,GetMagickModule(),
4799 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4800 return(MagickFalse);
4802 (void) memcpy(polygon_info[i]->edges,edge_info,
4803 polygon_info[0]->number_edges*
sizeof(*edge_info));
4804 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4805 polygon_info[i]->edges[j].points=(
PointInfo *) NULL;
4806 polygon_info[i]->number_edges=polygon_info[0]->number_edges;
4807 for (j=0; j < (ssize_t) polygon_info[i]->number_edges; j++)
4809 edge_info=polygon_info[0]->edges+j;
4810 polygon_info[i]->edges[j].points=(
PointInfo *) AcquireQuantumMemory(
4811 edge_info->number_points,
sizeof(*edge_info));
4812 if (polygon_info[i]->edges[j].points == (
PointInfo *) NULL)
4814 (void) ThrowMagickException(exception,GetMagickModule(),
4815 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
4816 return(MagickFalse);
4818 (void) memcpy(polygon_info[i]->edges[j].points,edge_info->points,
4819 edge_info->number_points*
sizeof(*edge_info->points));
4825 static size_t DestroyEdge(
PolygonInfo *polygon_info,
const ssize_t edge)
4827 assert(edge < (ssize_t) polygon_info->number_edges);
4828 polygon_info->edges[edge].points=(
PointInfo *) RelinquishMagickMemory(
4829 polygon_info->edges[edge].points);
4830 polygon_info->number_edges--;
4831 if (edge < (ssize_t) polygon_info->number_edges)
4832 (
void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
4833 (
size_t) (polygon_info->number_edges-edge)*
sizeof(*polygon_info->edges));
4834 return(polygon_info->number_edges);
4837 static double GetOpacityPixel(
PolygonInfo *polygon_info,
const double mid,
4838 const MagickBooleanType fill,
const FillRule fill_rule,
const ssize_t x,
4839 const ssize_t y,
double *stroke_opacity)
4866 *stroke_opacity=0.0;
4867 subpath_opacity=0.0;
4868 p=polygon_info->edges;
4869 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4871 if ((
double) y <= (p->bounds.y1-mid-0.5))
4873 if ((
double) y > (p->bounds.y2+mid+0.5))
4876 (void) DestroyEdge(polygon_info,j--);
4879 if (((
double) x <= (p->bounds.x1-mid-0.5)) ||
4880 ((
double) x > (p->bounds.x2+mid+0.5)))
4882 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
4883 for ( ; i < (ssize_t) p->number_points; i++)
4885 if ((
double) y <= (p->points[i-1].y-mid-0.5))
4887 if ((
double) y > (p->points[i].y+mid+0.5))
4889 if (p->scanline != (
double) y)
4891 p->scanline=(double) y;
4892 p->highwater=(size_t) i;
4898 delta.x=(q+1)->x-q->x;
4899 delta.y=(q+1)->y-q->y;
4900 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
4903 delta.x=(double) x-q->x;
4904 delta.y=(
double) y-q->y;
4905 distance=delta.x*delta.x+delta.y*delta.y;
4909 alpha=delta.x*delta.x+delta.y*delta.y;
4912 delta.x=(double) x-(q+1)->x;
4913 delta.y=(double) y-(q+1)->y;
4914 distance=delta.x*delta.x+delta.y*delta.y;
4918 alpha=MagickSafeReciprocal(alpha);
4919 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
4920 distance=alpha*beta*beta;
4927 if (p->ghostline == MagickFalse)
4930 if ((*stroke_opacity < 1.0) &&
4931 (distance <= ((alpha+0.25)*(alpha+0.25))))
4934 if (distance <= ((alpha+0.25)*(alpha+0.25)))
4935 *stroke_opacity=1.0;
4939 if (fabs(distance-1.0) >= MagickEpsilon)
4940 beta=sqrt((
double) distance);
4942 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
4943 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
4947 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
4949 if (distance <= 0.0)
4951 subpath_opacity=1.0;
4956 if (fabs(beta) < MagickEpsilon)
4959 if (fabs(distance-1.0) >= MagickEpsilon)
4960 beta=sqrt(distance);
4963 if (subpath_opacity < (alpha*alpha))
4964 subpath_opacity=alpha*alpha;
4970 if (fill == MagickFalse)
4972 if (subpath_opacity >= 1.0)
4978 p=polygon_info->edges;
4979 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
4981 if ((
double) y <= p->bounds.y1)
4983 if (((
double) y > p->bounds.y2) || ((
double) x <= p->bounds.x1))
4985 if ((
double) x > p->bounds.x2)
4987 winding_number+=p->direction != 0 ? 1 : -1;
4990 i=(ssize_t) MagickMax((
double) p->highwater,1.0);
4991 for ( ; i < (ssize_t) (p->number_points-1); i++)
4992 if ((
double) y <= p->points[i].y)
4995 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
4996 winding_number+=p->direction != 0 ? 1 : -1;
4998 if (fill_rule != NonZeroRule)
5000 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
5004 if (MagickAbsoluteValue(winding_number) != 0)
5006 return(subpath_opacity);
5009 static MagickBooleanType DrawPolygonPrimitive(
Image *image,
5012 typedef struct _ExtentInfo
5041 **magick_restrict polygon_info;
5056 assert(image != (
Image *) NULL);
5057 assert(image->signature == MagickCoreSignature);
5058 assert(draw_info != (
DrawInfo *) NULL);
5059 assert(draw_info->signature == MagickCoreSignature);
5061 if (IsEventLogging() != MagickFalse)
5062 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5063 if (primitive_info->coordinates <= 1)
5068 polygon_info=AcquirePolygonTLS(draw_info,primitive_info,&image->exception);
5070 return(MagickFalse);
5071 if (draw_info->debug != MagickFalse)
5072 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" begin draw-polygon");
5073 fill=(primitive_info->method == FillToBorderMethod) ||
5074 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
5075 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5076 bounds=polygon_info[0]->edges[0].bounds;
5077 artifact=GetImageArtifact(image,
"draw:render-bounding-rectangles");
5078 if (IsStringTrue(artifact) != MagickFalse)
5079 (void) DrawBoundingRectangles(image,draw_info,polygon_info[0]);
5080 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
5082 p=polygon_info[0]->edges+i;
5083 if (p->bounds.x1 < bounds.x1)
5084 bounds.x1=p->bounds.x1;
5085 if (p->bounds.y1 < bounds.y1)
5086 bounds.y1=p->bounds.y1;
5087 if (p->bounds.x2 > bounds.x2)
5088 bounds.x2=p->bounds.x2;
5089 if (p->bounds.y2 > bounds.y2)
5090 bounds.y2=p->bounds.y2;
5092 bounds.x1-=(mid+1.0);
5093 bounds.y1-=(mid+1.0);
5094 bounds.x2+=(mid+1.0);
5095 bounds.y2+=(mid+1.0);
5096 if ((bounds.x1 >= (
double) image->columns) ||
5097 (bounds.y1 >= (
double) image->rows) ||
5098 (bounds.x2 <= 0.0) || (bounds.y2 <= 0.0))
5100 polygon_info=DestroyPolygonTLS(polygon_info);
5103 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) image->columns-1.0 ?
5104 (
double) image->columns-1.0 : bounds.x1;
5105 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) image->rows-1.0 ?
5106 (
double) image->rows-1.0 : bounds.y1;
5107 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) image->columns-1.0 ?
5108 (
double) image->columns-1.0 : bounds.x2;
5109 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) image->rows-1.0 ?
5110 (
double) image->rows-1.0 : bounds.y2;
5111 poly_extent.x1=CastDoubleToLong(ceil(bounds.x1-0.5));
5112 poly_extent.y1=CastDoubleToLong(ceil(bounds.y1-0.5));
5113 poly_extent.x2=CastDoubleToLong(floor(bounds.x2+0.5));
5114 poly_extent.y2=CastDoubleToLong(floor(bounds.y2+0.5));
5115 number_threads=GetMagickNumberThreads(image,image,poly_extent.y2-
5116 poly_extent.y1+1,1);
5117 status=AcquirePolygonEdgesTLS(polygon_info,number_threads,&image->exception);
5118 if (status == MagickFalse)
5120 polygon_info=DestroyPolygonTLS(polygon_info);
5124 exception=(&image->exception);
5125 image_view=AcquireAuthenticCacheView(image,exception);
5126 if ((primitive_info->coordinates == 1) ||
5127 (polygon_info[0]->number_edges == 0))
5132 #if defined(MAGICKCORE_OPENMP_SUPPORT) 5133 #pragma omp parallel for schedule(static) shared(status) \ 5134 num_threads(number_threads) 5136 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5147 if (status == MagickFalse)
5150 q=GetCacheViewAuthenticPixels(image_view,x,y,(
size_t) (poly_extent.x2-
5157 for ( ; x <= poly_extent.x2; x++)
5159 if ((x == CastDoubleToLong(ceil(primitive_info->point.x-0.5))) &&
5160 (y == CastDoubleToLong(ceil(primitive_info->point.y-0.5))))
5161 (void) GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,q);
5164 sync=SyncCacheViewAuthenticPixels(image_view,exception);
5165 if (sync == MagickFalse)
5168 image_view=DestroyCacheView(image_view);
5169 polygon_info=DestroyPolygonTLS(polygon_info);
5170 if (draw_info->debug != MagickFalse)
5171 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5172 " end draw-polygon");
5178 poly_extent.y1=CastDoubleToLong(ceil(bounds.y1-0.5));
5179 poly_extent.y2=CastDoubleToLong(floor(bounds.y2+0.5));
5180 #if defined(MAGICKCORE_OPENMP_SUPPORT) 5181 #pragma omp parallel for schedule(static) shared(status) \ 5182 num_threads(number_threads) 5184 for (y=poly_extent.y1; y <= poly_extent.y2; y++)
5187 id = GetOpenMPThreadId();
5199 if (status == MagickFalse)
5201 q=GetCacheViewAuthenticPixels(image_view,poly_extent.x1,y,(
size_t)
5202 (poly_extent.x2-poly_extent.x1+1),1,exception);
5208 for (x=poly_extent.x1; x <= poly_extent.x2; x++)
5217 fill_opacity=GetOpacityPixel(polygon_info[
id],mid,fill,
5218 draw_info->fill_rule,x,y,&stroke_opacity);
5219 if (draw_info->stroke_antialias == MagickFalse)
5221 fill_opacity=fill_opacity >= AntialiasThreshold ? 1.0 : 0.0;
5222 stroke_opacity=stroke_opacity >= AntialiasThreshold ? 1.0 : 0.0;
5224 (void) GetFillColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,
5226 fill_opacity=(double) ((MagickRealType) QuantumRange-fill_opacity*
5227 ((MagickRealType) QuantumRange-(MagickRealType) fill_color.opacity));
5228 MagickCompositeOver(&fill_color,(MagickRealType) fill_opacity,q,
5229 (MagickRealType) q->opacity,q);
5230 (void) GetStrokeColor(draw_info,x-poly_extent.x1,y-poly_extent.y1,
5232 stroke_opacity=(double) ((MagickRealType) QuantumRange-stroke_opacity*
5233 ((MagickRealType) QuantumRange-(MagickRealType) stroke_color.opacity));
5234 MagickCompositeOver(&stroke_color,(MagickRealType) stroke_opacity,q,
5235 (MagickRealType) q->opacity,q);
5238 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5241 image_view=DestroyCacheView(image_view);
5242 polygon_info=DestroyPolygonTLS(polygon_info);
5243 if (draw_info->debug != MagickFalse)
5244 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-polygon");
5275 static void LogPrimitiveInfo(
const PrimitiveInfo *primitive_info)
5301 x=CastDoubleToLong(ceil(primitive_info->point.x-0.5));
5302 y=CastDoubleToLong(ceil(primitive_info->point.y-0.5));
5303 switch (primitive_info->primitive)
5305 case PointPrimitive:
5307 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5308 "PointPrimitive %.20g,%.20g %s",(double) x,(
double) y,
5309 methods[primitive_info->method]);
5312 case ColorPrimitive:
5314 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5315 "ColorPrimitive %.20g,%.20g %s",(double) x,(
double) y,
5316 methods[primitive_info->method]);
5319 case MattePrimitive:
5321 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5322 "MattePrimitive %.20g,%.20g %s",(double) x,(
double) y,
5323 methods[primitive_info->method]);
5328 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5329 "TextPrimitive %.20g,%.20g",(double) x,(
double) y);
5332 case ImagePrimitive:
5334 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5335 "ImagePrimitive %.20g,%.20g",(double) x,(
double) y);
5342 p=primitive_info[0].point;
5345 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
5347 point=primitive_info[i].point;
5348 if (coordinates <= 0)
5350 coordinates=(ssize_t) primitive_info[i].coordinates;
5351 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5352 " begin open (%.20g)",(double) coordinates);
5355 point=primitive_info[i].point;
5356 if ((fabs(q.x-point.x) >= MagickEpsilon) ||
5357 (fabs(q.y-point.y) >= MagickEpsilon))
5358 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5359 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
5361 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
5362 " %.20g: %g %g (duplicate)",(
double) coordinates,point.x,point.y);
5365 if (coordinates > 0)
5367 if ((fabs(p.x-point.x) >= MagickEpsilon) ||
5368 (fabs(p.y-point.y) >= MagickEpsilon))
5369 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end last (%.20g)",
5370 (double) coordinates);
5372 (
void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end open (%.20g)",
5373 (
double) coordinates);
5377 MagickExport MagickBooleanType DrawPrimitive(
Image *image,
5396 if (draw_info->debug != MagickFalse)
5398 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5399 " begin draw-primitive");
5400 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5401 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
5402 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
5403 draw_info->affine.tx,draw_info->affine.ty);
5405 exception=(&image->exception);
5407 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5408 ((IsPixelGray(&draw_info->fill) == MagickFalse) ||
5409 (IsPixelGray(&draw_info->stroke) == MagickFalse)))
5410 status=SetImageColorspace(image,sRGBColorspace);
5411 if (draw_info->compliance == SVGCompliance)
5413 status&=SetImageClipMask(image,draw_info->clipping_mask);
5414 status&=SetImageMask(image,draw_info->composite_mask);
5416 x=CastDoubleToLong(ceil(primitive_info->point.x-0.5));
5417 y=CastDoubleToLong(ceil(primitive_info->point.y-0.5));
5418 image_view=AcquireAuthenticCacheView(image,exception);
5419 switch (primitive_info->primitive)
5421 case ColorPrimitive:
5423 switch (primitive_info->method)
5431 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5434 (void) GetFillColor(draw_info,x,y,q);
5435 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5443 status&=GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
5444 for (y=0; y < (ssize_t) image->rows; y++)
5449 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5453 for (x=0; x < (ssize_t) image->columns; x++)
5455 if (IsColorSimilar(image,q,&target) == MagickFalse)
5460 (void) GetFillColor(draw_info,x,y,q);
5463 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5464 if (status == MagickFalse)
5469 case FloodfillMethod:
5470 case FillToBorderMethod:
5475 status&=GetOneVirtualMagickPixel(image,x,y,&target,exception);
5476 if (primitive_info->method == FillToBorderMethod)
5478 target.red=(MagickRealType) draw_info->border_color.red;
5479 target.green=(MagickRealType) draw_info->border_color.green;
5480 target.blue=(MagickRealType) draw_info->border_color.blue;
5482 status&=FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
5483 y,primitive_info->method == FloodfillMethod ? MagickFalse :
5489 for (y=0; y < (ssize_t) image->rows; y++)
5497 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5501 for (x=0; x < (ssize_t) image->columns; x++)
5503 (void) GetFillColor(draw_info,x,y,q);
5506 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5507 if (status == MagickFalse)
5515 case MattePrimitive:
5517 if (image->matte == MagickFalse)
5518 status&=SetImageAlphaChannel(image,OpaqueAlphaChannel);
5519 switch (primitive_info->method)
5530 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5533 (void) GetFillColor(draw_info,x,y,&pixel);
5534 SetPixelOpacity(q,pixel.opacity);
5535 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5544 status&=GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
5545 for (y=0; y < (ssize_t) image->rows; y++)
5553 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5557 for (x=0; x < (ssize_t) image->columns; x++)
5559 if (IsColorSimilar(image,q,&target) == MagickFalse)
5564 (void) GetFillColor(draw_info,x,y,&pixel);
5565 SetPixelOpacity(q,pixel.opacity);
5568 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5569 if (status == MagickFalse)
5574 case FloodfillMethod:
5575 case FillToBorderMethod:
5580 status&=GetOneVirtualMagickPixel(image,x,y,&target,exception);
5581 if (primitive_info->method == FillToBorderMethod)
5583 target.red=(MagickRealType) draw_info->border_color.red;
5584 target.green=(MagickRealType) draw_info->border_color.green;
5585 target.blue=(MagickRealType) draw_info->border_color.blue;
5587 status&=FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,
5588 y,primitive_info->method == FloodfillMethod ? MagickFalse :
5597 for (y=0; y < (ssize_t) image->rows; y++)
5605 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
5609 for (x=0; x < (ssize_t) image->columns; x++)
5611 (void) GetFillColor(draw_info,x,y,&pixel);
5612 SetPixelOpacity(q,pixel.opacity);
5615 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5616 if (status == MagickFalse)
5624 case ImagePrimitive:
5630 composite_geometry[MaxTextExtent];
5646 if (primitive_info->text == (
char *) NULL)
5648 clone_info=AcquireImageInfo();
5649 composite_images=(
Image *) NULL;
5650 if (LocaleNCompare(primitive_info->text,
"data:",5) == 0)
5651 composite_images=ReadInlineImage(clone_info,primitive_info->text,
5654 if (*primitive_info->text !=
'\0')
5659 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5661 (void) SetImageInfo(clone_info,1,exception);
5662 (void) CopyMagickString(clone_info->filename,primitive_info->text,
5664 if (clone_info->size != (
char *) NULL)
5665 clone_info->size=DestroyString(clone_info->size);
5666 if (clone_info->extract != (
char *) NULL)
5667 clone_info->extract=DestroyString(clone_info->extract);
5668 composite_images=StrictReadImage(clone_info,exception);
5670 clone_info=DestroyImageInfo(clone_info);
5671 if (composite_images == (
Image *) NULL)
5676 composite_image=RemoveFirstImageFromList(&composite_images);
5677 composite_images=DestroyImageList(composite_images);
5678 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
5679 NULL,(
void *) NULL);
5680 x1=CastDoubleToLong(ceil(primitive_info[1].point.x-0.5));
5681 y1=CastDoubleToLong(ceil(primitive_info[1].point.y-0.5));
5682 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
5683 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
5686 geometry[MaxTextExtent];
5691 (void) FormatLocaleString(geometry,MaxTextExtent,
"%gx%g!",
5692 primitive_info[1].point.x,primitive_info[1].point.y);
5693 composite_image->filter=image->filter;
5694 status&=TransformImage(&composite_image,(
char *) NULL,geometry);
5696 if (composite_image->matte == MagickFalse)
5697 status&=SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
5698 if (draw_info->opacity != OpaqueOpacity)
5699 status&=SetImageOpacity(composite_image,draw_info->opacity);
5700 SetGeometry(image,&geometry);
5701 image->gravity=draw_info->gravity;
5704 (void) FormatLocaleString(composite_geometry,MaxTextExtent,
5705 "%.20gx%.20g%+.20g%+.20g",(
double) composite_image->columns,(double)
5706 composite_image->rows,(
double) geometry.x,(double) geometry.y);
5707 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
5709 affine=draw_info->affine;
5710 affine.tx=(double) geometry.x;
5711 affine.ty=(
double) geometry.y;
5712 composite_image->interpolate=image->interpolate;
5713 if ((draw_info->compose == OverCompositeOp) ||
5714 (draw_info->compose == SrcOverCompositeOp))
5715 status&=DrawAffineImage(image,composite_image,&affine);
5717 status&=CompositeImage(image,draw_info->compose,composite_image,
5718 geometry.x,geometry.y);
5719 composite_image=DestroyImage(composite_image);
5722 case PointPrimitive:
5730 if ((y < 0) || (y >= (ssize_t) image->rows))
5732 if ((x < 0) || (x >= (ssize_t) image->columns))
5734 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
5737 (void) GetFillColor(draw_info,x,y,&fill_color);
5738 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
5739 (MagickRealType) q->opacity,q);
5740 status&=SyncCacheViewAuthenticPixels(image_view,exception);
5746 geometry[MaxTextExtent];
5751 if (primitive_info->text == (
char *) NULL)
5753 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5754 (void) CloneString(&clone_info->text,primitive_info->text);
5755 (void) FormatLocaleString(geometry,MaxTextExtent,
"%+f%+f",
5756 primitive_info->point.x,primitive_info->point.y);
5757 (void) CloneString(&clone_info->geometry,geometry);
5758 status&=AnnotateImage(image,clone_info);
5759 clone_info=DestroyDrawInfo(clone_info);
5771 if (IsEventLogging() != MagickFalse)
5772 LogPrimitiveInfo(primitive_info);
5773 scale=ExpandAffine(&draw_info->affine);
5774 if ((draw_info->dash_pattern != (
double *) NULL) &&
5775 (fabs(draw_info->dash_pattern[0]) >= MagickEpsilon) &&
5776 (fabs(scale*draw_info->stroke_width) >= MagickEpsilon) &&
5777 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
5782 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5783 clone_info->stroke_width=0.0;
5784 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
5785 status&=DrawPolygonPrimitive(image,clone_info,primitive_info);
5786 clone_info=DestroyDrawInfo(clone_info);
5787 if (status != MagickFalse)
5788 status&=DrawDashPolygon(draw_info,primitive_info,image);
5791 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5793 ((draw_info->stroke.opacity != (Quantum) TransparentOpacity) ||
5794 (draw_info->stroke_pattern != (
Image *) NULL)))
5806 closed_path=primitive_info[0].closed_subpath;
5807 i=(ssize_t) primitive_info[0].coordinates;
5808 x=fabs(primitive_info[i-1].point.x-primitive_info[0].point.x);
5809 y=fabs(primitive_info[i-1].point.y-primitive_info[0].point.y);
5810 if ((x < MagickEpsilon) && (y < MagickEpsilon))
5811 closed_path=MagickTrue;
5812 if ((((draw_info->linecap == RoundCap) ||
5813 (closed_path != MagickFalse)) &&
5814 (draw_info->linejoin == RoundJoin)) ||
5815 (primitive_info[i].primitive != UndefinedPrimitive))
5817 status&=DrawPolygonPrimitive(image,draw_info,primitive_info);
5820 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5821 clone_info->stroke_width=0.0;
5822 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
5823 status&=DrawPolygonPrimitive(image,clone_info,primitive_info);
5824 clone_info=DestroyDrawInfo(clone_info);
5825 if (status != MagickFalse)
5826 status&=DrawStrokePolygon(image,draw_info,primitive_info);
5829 status&=DrawPolygonPrimitive(image,draw_info,primitive_info);
5833 image_view=DestroyCacheView(image_view);
5834 if (draw_info->compliance == SVGCompliance)
5836 status&=SetImageClipMask(image,(
Image *) NULL);
5837 status&=SetImageMask(image,(
Image *) NULL);
5839 if (draw_info->debug != MagickFalse)
5840 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
" end draw-primitive");
5841 return(status != 0 ? MagickTrue : MagickFalse);
5874 static MagickBooleanType DrawRoundLinecap(
Image *image,
5883 if (primitive_info->coordinates < 1)
5884 return(MagickFalse);
5885 for (i=0; i < 4; i++)
5886 linecap[i]=(*primitive_info);
5887 linecap[0].coordinates=4;
5888 linecap[1].point.x+=2.0*MagickEpsilon;
5889 linecap[2].point.x+=2.0*MagickEpsilon;
5890 linecap[2].point.y+=2.0*MagickEpsilon;
5891 linecap[3].point.y+=2.0*MagickEpsilon;
5892 linecap[4].primitive=UndefinedPrimitive;
5893 return(DrawPolygonPrimitive(image,draw_info,linecap));
5896 static MagickBooleanType DrawStrokePolygon(
Image *image,
5918 if (draw_info->debug != MagickFalse)
5919 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5920 " begin draw-stroke-polygon");
5921 clone_info=CloneDrawInfo((
ImageInfo *) NULL,draw_info);
5922 clone_info->fill=draw_info->stroke;
5923 if (clone_info->fill_pattern != (
Image *) NULL)
5924 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
5925 if (clone_info->stroke_pattern != (
Image *) NULL)
5926 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
5927 MagickTrue,&clone_info->stroke_pattern->exception);
5928 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
5929 clone_info->stroke_width=0.0;
5930 clone_info->fill_rule=NonZeroRule;
5932 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=(ptrdiff_t) p->coordinates)
5934 if (p->coordinates == 1)
5936 stroke_polygon=TraceStrokePolygon(draw_info,p,&image->exception);
5942 status&=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
5943 stroke_polygon=(
PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
5946 q=p+p->coordinates-1;
5947 closed_path=p->closed_subpath;
5948 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
5950 status&=DrawRoundLinecap(image,draw_info,p);
5951 status&=DrawRoundLinecap(image,draw_info,q);
5954 clone_info=DestroyDrawInfo(clone_info);
5955 if (draw_info->debug != MagickFalse)
5956 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
5957 " end draw-stroke-polygon");
5958 return(status != 0 ? MagickTrue : MagickFalse);
5984 MagickExport
void GetAffineMatrix(
AffineMatrix *affine_matrix)
5987 if (IsEventLogging() != MagickFalse)
5988 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
5989 (void) memset(affine_matrix,0,
sizeof(*affine_matrix));
5990 affine_matrix->sx=1.0;
5991 affine_matrix->sy=1.0;
6032 assert(draw_info != (
DrawInfo *) NULL);
6033 if (IsEventLogging() != MagickFalse)
6034 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6035 (void) memset(draw_info,0,
sizeof(*draw_info));
6036 draw_info->image_info=CloneImageInfo(image_info);
6037 GetAffineMatrix(&draw_info->affine);
6038 exception=AcquireExceptionInfo();
6039 (void) QueryColorDatabase(
"#000F",&draw_info->fill,exception);
6040 (void) QueryColorDatabase(
"#FFF0",&draw_info->stroke,exception);
6041 draw_info->stroke_antialias=draw_info->image_info->antialias;
6042 draw_info->stroke_width=1.0;
6043 draw_info->fill_rule=EvenOddRule;
6044 draw_info->opacity=OpaqueOpacity;
6045 draw_info->fill_opacity=OpaqueOpacity;
6046 draw_info->stroke_opacity=OpaqueOpacity;
6047 draw_info->linecap=ButtCap;
6048 draw_info->linejoin=MiterJoin;
6049 draw_info->miterlimit=10;
6050 draw_info->decorate=NoDecoration;
6051 if (draw_info->image_info->font != (
char *) NULL)
6052 draw_info->font=AcquireString(draw_info->image_info->font);
6053 if (draw_info->image_info->density != (
char *) NULL)
6054 draw_info->density=AcquireString(draw_info->image_info->density);
6055 draw_info->text_antialias=draw_info->image_info->antialias;
6056 draw_info->pointsize=12.0;
6057 if (fabs(draw_info->image_info->pointsize) >= MagickEpsilon)
6058 draw_info->pointsize=draw_info->image_info->pointsize;
6059 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
6060 draw_info->border_color=draw_info->image_info->border_color;
6061 draw_info->compose=OverCompositeOp;
6062 if (draw_info->image_info->server_name != (
char *) NULL)
6063 draw_info->server_name=AcquireString(draw_info->image_info->server_name);
6064 draw_info->render=MagickTrue;
6065 draw_info->clip_path=MagickFalse;
6066 draw_info->debug=(GetLogEventMask() & (DrawEvent | AnnotateEvent)) != 0 ?
6067 MagickTrue : MagickFalse;
6068 option=GetImageOption(draw_info->image_info,
"direction");
6069 if (option != (
const char *) NULL)
6070 draw_info->direction=(DirectionType) ParseCommandOption(
6071 MagickDirectionOptions,MagickFalse,option);
6073 draw_info->direction=UndefinedDirection;
6074 option=GetImageOption(draw_info->image_info,
"encoding");
6075 if (option != (
const char *) NULL)
6076 (void) CloneString(&draw_info->encoding,option);
6077 option=GetImageOption(draw_info->image_info,
"family");
6078 if (option != (
const char *) NULL)
6079 (void) CloneString(&draw_info->family,option);
6080 option=GetImageOption(draw_info->image_info,
"fill");
6081 if (option != (
const char *) NULL)
6082 (void) QueryColorDatabase(option,&draw_info->fill,exception);
6083 option=GetImageOption(draw_info->image_info,
"gravity");
6084 if (option != (
const char *) NULL)
6085 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
6086 MagickFalse,option);
6087 option=GetImageOption(draw_info->image_info,
"interline-spacing");
6088 if (option != (
const char *) NULL)
6089 draw_info->interline_spacing=GetDrawValue(option,&next_token);
6090 option=GetImageOption(draw_info->image_info,
"interword-spacing");
6091 if (option != (
const char *) NULL)
6092 draw_info->interword_spacing=GetDrawValue(option,&next_token);
6093 option=GetImageOption(draw_info->image_info,
"kerning");
6094 if (option != (
const char *) NULL)
6095 draw_info->kerning=GetDrawValue(option,&next_token);
6096 option=GetImageOption(draw_info->image_info,
"stroke");
6097 if (option != (
const char *) NULL)
6098 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
6099 option=GetImageOption(draw_info->image_info,
"strokewidth");
6100 if (option != (
const char *) NULL)
6101 draw_info->stroke_width=GetDrawValue(option,&next_token);
6102 option=GetImageOption(draw_info->image_info,
"style");
6103 if (option != (
const char *) NULL)
6104 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
6105 MagickFalse,option);
6106 option=GetImageOption(draw_info->image_info,
"undercolor");
6107 if (option != (
const char *) NULL)
6108 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
6109 option=GetImageOption(draw_info->image_info,
"weight");
6110 if (option != (
const char *) NULL)
6115 weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option);
6117 weight=(ssize_t) StringToUnsignedLong(option);
6118 draw_info->weight=(size_t) weight;
6120 exception=DestroyExceptionInfo(exception);
6121 draw_info->signature=MagickCoreSignature;
6149 static inline double Permutate(
const ssize_t n,
const ssize_t k)
6158 for (i=k+1; i <= n; i++)
6160 for (i=1; i <= (n-k); i++)
6188 center.x=0.5*(end.x+start.x);
6189 center.y=0.5*(end.y+start.y);
6190 radius.x=fabs(center.x-start.x);
6191 radius.y=fabs(center.y-start.y);
6192 return(TraceEllipse(mvg_info,center,radius,degrees));
6195 static MagickBooleanType TraceArcPath(
MVGInfo *mvg_info,
const PointInfo start,
6197 const MagickBooleanType large_arc,
const MagickBooleanType sweep)
6234 offset=mvg_info->offset;
6235 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6236 primitive_info->coordinates=0;
6237 if ((fabs(start.x-end.x) < MagickEpsilon) &&
6238 (fabs(start.y-end.y) < MagickEpsilon))
6239 return(TracePoint(primitive_info,end));
6240 radii.x=fabs(arc.x);
6241 radii.y=fabs(arc.y);
6242 if ((radii.x < MagickEpsilon) || (radii.y < MagickEpsilon))
6243 return(TraceLine(primitive_info,start,end));
6244 cosine=cos(DegreesToRadians(fmod((
double) angle,360.0)));
6245 sine=sin(DegreesToRadians(fmod((
double) angle,360.0)));
6246 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
6247 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
6248 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
6250 if (delta < MagickEpsilon)
6251 return(TraceLine(primitive_info,start,end));
6254 radii.x*=sqrt((
double) delta);
6255 radii.y*=sqrt((
double) delta);
6257 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
6258 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
6259 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
6260 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
6261 alpha=points[1].x-points[0].x;
6262 beta=points[1].y-points[0].y;
6263 if (fabs(alpha*alpha+beta*beta) < MagickEpsilon)
6264 return(TraceLine(primitive_info,start,end));
6265 factor=MagickSafeReciprocal(alpha*alpha+beta*beta)-0.25;
6270 factor=sqrt((
double) factor);
6271 if (sweep == large_arc)
6274 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
6275 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
6276 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
6277 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
6278 if ((theta < 0.0) && (sweep != MagickFalse))
6279 theta+=2.0*MagickPI;
6281 if ((theta > 0.0) && (sweep == MagickFalse))
6282 theta-=2.0*MagickPI;
6283 arc_segments=(size_t) CastDoubleToLong(ceil(fabs((
double) (theta/(0.5*
6284 MagickPI+MagickEpsilon)))));
6287 for (i=0; i < (ssize_t) arc_segments; i++)
6289 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
6290 gamma=(8.0/3.0)*sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))*
6291 sin(fmod((
double) (0.5*beta),DegreesToRadians(360.0)))/
6292 sin(fmod((
double) beta,DegreesToRadians(360.0)));
6293 points[0].x=(double) (center.x+cos(fmod((
double) (alpha+(
double) i*theta/
6294 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((
double) (alpha+
6295 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6296 points[0].y=(double) (center.y+sin(fmod((
double) (alpha+(
double) i*theta/
6297 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((
double) (alpha+
6298 (
double) i*theta/arc_segments),DegreesToRadians(360.0))));
6299 points[2].x=(double) (center.x+cos(fmod((
double) (alpha+(double) (i+1)*
6300 theta/arc_segments),DegreesToRadians(360.0))));
6301 points[2].y=(double) (center.y+sin(fmod((
double) (alpha+(double) (i+1)*
6302 theta/arc_segments),DegreesToRadians(360.0))));
6303 points[1].x=(double) (points[2].x+gamma*sin(fmod((
double) (alpha+(double)
6304 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6305 points[1].y=(double) (points[2].y-gamma*cos(fmod((
double) (alpha+(double)
6306 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
6307 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
6308 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
6309 (p+1)->point.x=(
double) (cosine*radii.x*points[0].x-sine*radii.y*
6311 (p+1)->point.y=(
double) (sine*radii.x*points[0].x+cosine*radii.y*
6313 (p+2)->point.x=(
double) (cosine*radii.x*points[1].x-sine*radii.y*
6315 (p+2)->point.y=(
double) (sine*radii.x*points[1].x+cosine*radii.y*
6317 (p+3)->point.x=(
double) (cosine*radii.x*points[2].x-sine*radii.y*
6319 (p+3)->point.y=(
double) (sine*radii.x*points[2].x+cosine*radii.y*
6321 if (i == (ssize_t) (arc_segments-1))
6323 status&=TraceBezier(mvg_info,4);
6326 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
6327 mvg_info->offset+=p->coordinates;
6328 p+=(ptrdiff_t) p->coordinates;
6331 return(MagickFalse);
6332 mvg_info->offset=offset;
6333 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6334 primitive_info->coordinates=(
size_t) (p-primitive_info);
6335 primitive_info->closed_subpath=MagickFalse;
6336 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6338 p->primitive=primitive_info->primitive;
6344 static MagickBooleanType TraceBezier(
MVGInfo *mvg_info,
6345 const size_t number_coordinates)
6374 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6375 quantum=number_coordinates;
6376 for (i=0; i < (ssize_t) number_coordinates; i++)
6378 for (j=i+1; j < (ssize_t) number_coordinates; j++)
6380 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
6381 if (alpha > (
double) GetMaxMemoryRequest())
6383 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6384 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6385 return(MagickFalse);
6387 if (alpha > (
double) quantum)
6388 quantum=(
size_t) alpha;
6389 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
6390 if (alpha > (
double) quantum)
6391 quantum=(size_t) alpha;
6394 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6395 quantum=MagickMin(quantum/number_coordinates,BezierQuantum);
6396 if (quantum > (
double) GetMaxMemoryRequest())
6398 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6399 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6400 return(MagickFalse);
6402 coefficients=(
double *) AcquireQuantumMemory(number_coordinates,
6403 sizeof(*coefficients));
6404 points=(
PointInfo *) AcquireQuantumMemory(quantum,number_coordinates*
6406 if ((coefficients == (
double *) NULL) || (points == (
PointInfo *) NULL))
6409 points=(
PointInfo *) RelinquishMagickMemory(points);
6410 if (coefficients != (
double *) NULL)
6411 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6412 (void) ThrowMagickException(mvg_info->exception,GetMagickModule(),
6413 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
6414 return(MagickFalse);
6416 control_points=quantum*number_coordinates;
6417 if (CheckPrimitiveExtent(mvg_info,(
double) control_points+1) == MagickFalse)
6419 points=(
PointInfo *) RelinquishMagickMemory(points);
6420 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6421 return(MagickFalse);
6423 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6427 end=primitive_info[number_coordinates-1].point;
6428 for (i=0; i < (ssize_t) number_coordinates; i++)
6429 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
6431 for (i=0; i < (ssize_t) control_points; i++)
6436 alpha=pow((
double) (1.0-weight),(
double) number_coordinates-1.0);
6437 for (j=0; j < (ssize_t) number_coordinates; j++)
6439 point.x+=alpha*coefficients[j]*p->point.x;
6440 point.y+=alpha*coefficients[j]*p->point.y;
6441 alpha*=weight/(1.0-weight);
6445 weight+=1.0/control_points;
6451 for (i=0; i < (ssize_t) control_points; i++)
6453 if (TracePoint(p,points[i]) == MagickFalse)
6455 points=(
PointInfo *) RelinquishMagickMemory(points);
6456 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6457 return(MagickFalse);
6459 p+=(ptrdiff_t) p->coordinates;
6461 if (TracePoint(p,end) == MagickFalse)
6463 points=(
PointInfo *) RelinquishMagickMemory(points);
6464 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6465 return(MagickFalse);
6467 p+=(ptrdiff_t) p->coordinates;
6468 primitive_info->coordinates=(
size_t) (p-primitive_info);
6469 primitive_info->closed_subpath=MagickFalse;
6470 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6472 p->primitive=primitive_info->primitive;
6475 points=(
PointInfo *) RelinquishMagickMemory(points);
6476 coefficients=(
double *) RelinquishMagickMemory(coefficients);
6480 static MagickBooleanType TraceCircle(
MVGInfo *mvg_info,
const PointInfo start,
6492 alpha=end.x-start.x;
6494 radius=hypot((
double) alpha,(
double) beta);
6495 offset.x=(double) radius;
6496 offset.y=(double) radius;
6499 return(TraceEllipse(mvg_info,start,offset,degrees));
6502 static MagickBooleanType TraceEllipse(
MVGInfo *mvg_info,
const PointInfo center,
6528 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6529 primitive_info->coordinates=0;
6530 if ((fabs(radii.x) < MagickEpsilon) || (fabs(radii.y) < MagickEpsilon))
6532 delta=MagickSafeReciprocal(MagickMax(radii.x,radii.y));
6533 step=MagickPI/(MagickPI*MagickSafeReciprocal(delta))/8.0;
6534 angle.x=DegreesToRadians(arc.x);
6538 angle.y=DegreesToRadians(y);
6539 coordinates=ceil((angle.y-angle.x)/step+1.0);
6540 if (CheckPrimitiveExtent(mvg_info,coordinates+1) == MagickFalse)
6541 return(MagickFalse);
6543 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6544 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
6546 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*radii.x+center.x;
6547 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*radii.y+center.y;
6548 if (i++ >= (ssize_t) coordinates)
6550 if (TracePoint(p,point) == MagickFalse)
6551 return(MagickFalse);
6552 p+=(ptrdiff_t) p->coordinates;
6554 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*radii.x+center.x;
6555 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*radii.y+center.y;
6556 if (TracePoint(p,point) == MagickFalse)
6557 return(MagickFalse);
6558 p+=(ptrdiff_t) p->coordinates;
6559 primitive_info->coordinates=(
size_t) (p-primitive_info);
6560 primitive_info->closed_subpath=MagickFalse;
6561 x=fabs(primitive_info[0].point.x-
6562 primitive_info[primitive_info->coordinates-1].point.x);
6563 y=fabs(primitive_info[0].point.y-
6564 primitive_info[primitive_info->coordinates-1].point.y);
6565 if ((x < MagickEpsilon) && (y < MagickEpsilon))
6566 primitive_info->closed_subpath=MagickTrue;
6567 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
6569 p->primitive=primitive_info->primitive;
6575 static MagickBooleanType TraceLine(
PrimitiveInfo *primitive_info,
6578 if (TracePoint(primitive_info,start) == MagickFalse)
6579 return(MagickFalse);
6580 if (TracePoint(primitive_info+1,end) == MagickFalse)
6581 return(MagickFalse);
6582 (primitive_info+1)->primitive=primitive_info->primitive;
6583 primitive_info->coordinates=2;
6584 primitive_info->closed_subpath=MagickFalse;
6588 static ssize_t TracePath(
Image *image,
MVGInfo *mvg_info,
const char *path)
6592 token[MaxTextExtent] =
"";
6610 points[4] = { {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0} },
6633 subpath_offset=mvg_info->offset;
6634 primitive_info=(*mvg_info->primitive_info)+mvg_info->offset;
6637 number_coordinates=0;
6640 primitive_type=primitive_info->primitive;
6642 for (p=path; *p !=
'\0'; )
6644 if (status == MagickFalse)
6646 while (isspace((
int) ((
unsigned char) *p)) != 0)
6650 last_attribute=attribute;
6651 attribute=(int) (*p++);
6661 large_arc = MagickFalse,
6662 sweep = MagickFalse;
6672 (void) GetNextToken(p,&p,MaxTextExtent,token);
6673 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6674 ThrowPointExpectedException(image,token);
6676 (void) GetNextToken(p,&p,MaxTextExtent,token);
6677 arc.x=GetDrawValue(token,&next_token);
6678 if (token == next_token)
6679 ThrowPointExpectedException(image,token);
6680 (void) GetNextToken(p,&p,MaxTextExtent,token);
6681 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6682 ThrowPointExpectedException(image,token);
6684 (void) GetNextToken(p,&p,MaxTextExtent,token);
6685 arc.y=GetDrawValue(token,&next_token);
6686 if (token == next_token)
6687 ThrowPointExpectedException(image,token);
6688 (void) GetNextToken(p,&p,MaxTextExtent,token);
6689 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6690 ThrowPointExpectedException(image,token);
6692 (void) GetNextToken(p,&p,MaxTextExtent,token);
6693 angle=GetDrawValue(token,&next_token);
6694 if (token == next_token)
6695 ThrowPointExpectedException(image,token);
6696 (void) GetNextToken(p,&p,MaxTextExtent,token);
6697 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6698 ThrowPointExpectedException(image,token);
6700 (void) GetNextToken(p,&p,MaxTextExtent,token);
6701 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6702 (void) GetNextToken(p,&p,MaxTextExtent,token);
6703 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6704 ThrowPointExpectedException(image,token);
6706 (void) GetNextToken(p,&p,MaxTextExtent,token);
6707 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
6708 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6709 ThrowPointExpectedException(image,token);
6711 (void) GetNextToken(p,&p,MaxTextExtent,token);
6712 (void) GetNextToken(p,&p,MaxTextExtent,token);
6713 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6714 ThrowPointExpectedException(image,token);
6716 (void) GetNextToken(p,&p,MaxTextExtent,token);
6717 x=GetDrawValue(token,&next_token);
6718 if (token == next_token)
6719 ThrowPointExpectedException(image,token);
6720 (void) GetNextToken(p,&p,MaxTextExtent,token);
6721 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6722 ThrowPointExpectedException(image,token);
6724 (void) GetNextToken(p,&p,MaxTextExtent,token);
6725 y=GetDrawValue(token,&next_token);
6726 if (token == next_token)
6727 ThrowPointExpectedException(image,token);
6728 end.x=(double) (attribute == (
int)
'A' ? x : point.x+x);
6729 end.y=(double) (attribute == (
int)
'A' ? y : point.y+y);
6730 status&=TraceArcPath(mvg_info,point,end,arc,angle,large_arc,sweep);
6731 q=(*mvg_info->primitive_info)+mvg_info->offset;
6732 mvg_info->offset+=q->coordinates;
6733 q+=(ptrdiff_t) q->coordinates;
6735 while (isspace((
int) ((
unsigned char) *p)) != 0)
6739 }
while (IsValidPoint(p) != MagickFalse);
6751 for (i=1; i < 4; i++)
6753 (void) GetNextToken(p,&p,MaxTextExtent,token);
6754 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6755 ThrowPointExpectedException(image,token);
6757 (void) GetNextToken(p,&p,MaxTextExtent,token);
6758 x=GetDrawValue(token,&next_token);
6759 if (token == next_token)
6760 ThrowPointExpectedException(image,token);
6761 (void) GetNextToken(p,&p,MaxTextExtent,token);
6762 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6763 ThrowPointExpectedException(image,token);
6765 (void) GetNextToken(p,&p,MaxTextExtent,token);
6766 y=GetDrawValue(token,&next_token);
6767 if (token == next_token)
6768 ThrowPointExpectedException(image,token);
6769 end.x=(double) (attribute == (
int)
'C' ? x : point.x+x);
6770 end.y=(double) (attribute == (
int)
'C' ? y : point.y+y);
6773 for (i=0; i < 4; i++)
6774 (q+i)->point=points[i];
6775 if (TraceBezier(mvg_info,4) == MagickFalse)
6777 q=(*mvg_info->primitive_info)+mvg_info->offset;
6778 mvg_info->offset+=q->coordinates;
6779 q+=(ptrdiff_t) q->coordinates;
6781 while (isspace((
int) ((
unsigned char) *p)) != 0)
6785 }
while (IsValidPoint(p) != MagickFalse);
6793 (void) GetNextToken(p,&p,MaxTextExtent,token);
6794 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6795 ThrowPointExpectedException(image,token);
6797 (void) GetNextToken(p,&p,MaxTextExtent,token);
6798 x=GetDrawValue(token,&next_token);
6799 if (token == next_token)
6800 ThrowPointExpectedException(image,token);
6801 point.x=(double) (attribute == (
int)
'H' ? x: point.x+x);
6802 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6804 q=(*mvg_info->primitive_info)+mvg_info->offset;
6805 if (TracePoint(q,point) == MagickFalse)
6807 mvg_info->offset+=q->coordinates;
6808 q+=(ptrdiff_t) q->coordinates;
6809 while (isspace((
int) ((
unsigned char) *p)) != 0)
6813 }
while (IsValidPoint(p) != MagickFalse);
6824 (void) GetNextToken(p,&p,MaxTextExtent,token);
6825 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6826 ThrowPointExpectedException(image,token);
6828 (void) GetNextToken(p,&p,MaxTextExtent,token);
6829 x=GetDrawValue(token,&next_token);
6830 if (token == next_token)
6831 ThrowPointExpectedException(image,token);
6832 (void) GetNextToken(p,&p,MaxTextExtent,token);
6833 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6834 ThrowPointExpectedException(image,token);
6836 (void) GetNextToken(p,&p,MaxTextExtent,token);
6837 y=GetDrawValue(token,&next_token);
6838 if (token == next_token)
6839 ThrowPointExpectedException(image,token);
6840 point.x=(double) (attribute == (
int)
'L' ? x : point.x+x);
6841 point.y=(double) (attribute == (
int)
'L' ? y : point.y+y);
6842 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6844 q=(*mvg_info->primitive_info)+mvg_info->offset;
6845 if (TracePoint(q,point) == MagickFalse)
6847 mvg_info->offset+=q->coordinates;
6848 q+=(ptrdiff_t) q->coordinates;
6849 while (isspace((
int) ((
unsigned char) *p)) != 0)
6853 }
while (IsValidPoint(p) != MagickFalse);
6862 if (mvg_info->offset != subpath_offset)
6864 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
6865 primitive_info->coordinates=(size_t) (q-primitive_info);
6866 number_coordinates+=primitive_info->coordinates;
6868 subpath_offset=mvg_info->offset;
6873 (void) GetNextToken(p,&p,MaxTextExtent,token);
6874 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6875 ThrowPointExpectedException(image,token);
6877 (void) GetNextToken(p,&p,MaxTextExtent,token);
6878 x=GetDrawValue(token,&next_token);
6879 if (token == next_token)
6880 ThrowPointExpectedException(image,token);
6881 (void) GetNextToken(p,&p,MaxTextExtent,token);
6882 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6883 ThrowPointExpectedException(image,token);
6885 (void) GetNextToken(p,&p,MaxTextExtent,token);
6886 y=GetDrawValue(token,&next_token);
6887 if (token == next_token)
6888 ThrowPointExpectedException(image,token);
6889 point.x=(double) (attribute == (
int)
'M' ? x : point.x+x);
6890 point.y=(double) (attribute == (
int)
'M' ? y : point.y+y);
6894 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
6896 q=(*mvg_info->primitive_info)+mvg_info->offset;
6897 if (TracePoint(q,point) == MagickFalse)
6899 mvg_info->offset+=q->coordinates;
6900 q+=(ptrdiff_t) q->coordinates;
6901 while (isspace((
int) ((
unsigned char) *p)) != 0)
6905 }
while (IsValidPoint(p) != MagickFalse);
6917 for (i=1; i < 3; i++)
6919 (void) GetNextToken(p,&p,MaxTextExtent,token);
6920 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6921 ThrowPointExpectedException(image,token);
6923 (void) GetNextToken(p,&p,MaxTextExtent,token);
6924 x=GetDrawValue(token,&next_token);
6925 if (token == next_token)
6926 ThrowPointExpectedException(image,token);
6927 (void) GetNextToken(p,&p,MaxTextExtent,token);
6928 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6929 ThrowPointExpectedException(image,token);
6931 (void) GetNextToken(p,&p,MaxTextExtent,token);
6932 y=GetDrawValue(token,&next_token);
6933 if (token == next_token)
6934 ThrowPointExpectedException(image,token);
6937 end.x=(double) (attribute == (
int)
'Q' ? x : point.x+x);
6938 end.y=(double) (attribute == (
int)
'Q' ? y : point.y+y);
6941 for (i=0; i < 3; i++)
6942 (q+i)->point=points[i];
6943 if (TraceBezier(mvg_info,3) == MagickFalse)
6945 q=(*mvg_info->primitive_info)+mvg_info->offset;
6946 mvg_info->offset+=q->coordinates;
6947 q+=(ptrdiff_t) q->coordinates;
6949 while (isspace((
int) ((
unsigned char) *p)) != 0)
6953 }
while (IsValidPoint(p) != MagickFalse);
6964 points[0]=points[3];
6965 points[1].x=2.0*points[3].x-points[2].x;
6966 points[1].y=2.0*points[3].y-points[2].y;
6967 for (i=2; i < 4; i++)
6969 (void) GetNextToken(p,&p,MaxTextExtent,token);
6970 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6971 ThrowPointExpectedException(image,token);
6973 (void) GetNextToken(p,&p,MaxTextExtent,token);
6974 x=GetDrawValue(token,&next_token);
6975 if (token == next_token)
6976 ThrowPointExpectedException(image,token);
6977 (void) GetNextToken(p,&p,MaxTextExtent,token);
6978 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
6979 ThrowPointExpectedException(image,token);
6981 (void) GetNextToken(p,&p,MaxTextExtent,token);
6982 y=GetDrawValue(token,&next_token);
6983 if (token == next_token)
6984 ThrowPointExpectedException(image,token);
6987 end.x=(double) (attribute == (
int)
'S' ? x : point.x+x);
6988 end.y=(double) (attribute == (
int)
'S' ? y : point.y+y);
6991 if (strchr(
"CcSs",last_attribute) == (
char *) NULL)
6996 for (i=0; i < 4; i++)
6997 (q+i)->point=points[i];
6998 if (TraceBezier(mvg_info,4) == MagickFalse)
7000 q=(*mvg_info->primitive_info)+mvg_info->offset;
7001 mvg_info->offset+=q->coordinates;
7002 q+=(ptrdiff_t) q->coordinates;
7004 last_attribute=attribute;
7005 while (isspace((
int) ((
unsigned char) *p)) != 0)
7009 }
while (IsValidPoint(p) != MagickFalse);
7020 points[0]=points[2];
7021 points[1].x=2.0*points[2].x-points[1].x;
7022 points[1].y=2.0*points[2].y-points[1].y;
7023 for (i=2; i < 3; i++)
7025 (void) GetNextToken(p,&p,MaxTextExtent,token);
7026 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7027 ThrowPointExpectedException(image,token);
7029 (void) GetNextToken(p,&p,MaxTextExtent,token);
7030 x=GetDrawValue(token,&next_token);
7031 if (token == next_token)
7032 ThrowPointExpectedException(image,token);
7033 (void) GetNextToken(p,&p,MaxTextExtent,token);
7034 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7035 ThrowPointExpectedException(image,token);
7037 (void) GetNextToken(p,&p,MaxTextExtent,token);
7038 y=GetDrawValue(token,&next_token);
7039 if (token == next_token)
7040 ThrowPointExpectedException(image,token);
7041 end.x=(double) (attribute == (
int)
'T' ? x : point.x+x);
7042 end.y=(double) (attribute == (
int)
'T' ? y : point.y+y);
7045 if (status == MagickFalse)
7047 if (strchr(
"QqTt",last_attribute) == (
char *) NULL)
7052 for (i=0; i < 3; i++)
7053 (q+i)->point=points[i];
7054 if (TraceBezier(mvg_info,3) == MagickFalse)
7056 q=(*mvg_info->primitive_info)+mvg_info->offset;
7057 mvg_info->offset+=q->coordinates;
7058 q+=(ptrdiff_t) q->coordinates;
7060 last_attribute=attribute;
7061 while (isspace((
int) ((
unsigned char) *p)) != 0)
7065 }
while (IsValidPoint(p) != MagickFalse);
7076 (void) GetNextToken(p,&p,MaxTextExtent,token);
7077 if (IsValidListChar((
int) ((
unsigned char) *token)) == MagickFalse)
7078 ThrowPointExpectedException(image,token);
7080 (void) GetNextToken(p,&p,MaxTextExtent,token);
7081 y=GetDrawValue(token,&next_token);
7082 if (token == next_token)
7083 ThrowPointExpectedException(image,token);
7084 point.y=(double) (attribute == (
int)
'V' ? y : point.y+y);
7085 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7087 q=(*mvg_info->primitive_info)+mvg_info->offset;
7088 if (TracePoint(q,point) == MagickFalse)
7090 mvg_info->offset+=q->coordinates;
7091 q+=(ptrdiff_t) q->coordinates;
7092 while (isspace((
int) ((
unsigned char) *p)) != 0)
7096 }
while (IsValidPoint(p) != MagickFalse);
7106 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7108 q=(*mvg_info->primitive_info)+mvg_info->offset;
7109 if (TracePoint(q,point) == MagickFalse)
7111 mvg_info->offset+=q->coordinates;
7112 q+=(ptrdiff_t) q->coordinates;
7113 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7114 primitive_info->coordinates=(size_t) (q-primitive_info);
7115 primitive_info->closed_subpath=MagickTrue;
7116 number_coordinates+=primitive_info->coordinates;
7118 subpath_offset=mvg_info->offset;
7124 ThrowPointExpectedException(image,token);
7129 if (status == MagickFalse)
7131 primitive_info=(*mvg_info->primitive_info)+subpath_offset;
7132 primitive_info->coordinates=(size_t) (q-primitive_info);
7133 number_coordinates+=primitive_info->coordinates;
7134 for (i=0; i < (ssize_t) number_coordinates; i++)
7137 q->primitive=primitive_type;
7139 q->method=FillToBorderMethod;
7142 return((ssize_t) number_coordinates);
7145 static MagickBooleanType TraceRectangle(
PrimitiveInfo *primitive_info,
7158 if (TracePoint(p,start) == MagickFalse)
7159 return(MagickFalse);
7160 p+=(ptrdiff_t) p->coordinates;
7163 if (TracePoint(p,point) == MagickFalse)
7164 return(MagickFalse);
7165 p+=(ptrdiff_t) p->coordinates;
7166 if (TracePoint(p,end) == MagickFalse)
7167 return(MagickFalse);
7168 p+=(ptrdiff_t) p->coordinates;
7171 if (TracePoint(p,point) == MagickFalse)
7172 return(MagickFalse);
7173 p+=(ptrdiff_t) p->coordinates;
7174 if (TracePoint(p,start) == MagickFalse)
7175 return(MagickFalse);
7176 p+=(ptrdiff_t) p->coordinates;
7177 primitive_info->coordinates=(
size_t) (p-primitive_info);
7178 primitive_info->closed_subpath=MagickTrue;
7179 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7181 p->primitive=primitive_info->primitive;
7187 static MagickBooleanType TraceRoundRectangle(
MVGInfo *mvg_info,
7207 offset=mvg_info->offset;
7208 segment.x=fabs(end.x-start.x);
7209 segment.y=fabs(end.y-start.y);
7210 if ((segment.x < MagickEpsilon) || (segment.y < MagickEpsilon))
7212 (*mvg_info->primitive_info+mvg_info->offset)->coordinates=0;
7215 if (arc.x > (0.5*segment.x))
7216 arc.x=0.5*segment.x;
7217 if (arc.y > (0.5*segment.y))
7218 arc.y=0.5*segment.y;
7219 point.x=start.x+segment.x-arc.x;
7220 point.y=start.y+arc.y;
7223 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7224 return(MagickFalse);
7225 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7226 mvg_info->offset+=p->coordinates;
7227 point.x=start.x+segment.x-arc.x;
7228 point.y=start.y+segment.y-arc.y;
7231 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7232 return(MagickFalse);
7233 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7234 mvg_info->offset+=p->coordinates;
7235 point.x=start.x+arc.x;
7236 point.y=start.y+segment.y-arc.y;
7239 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7240 return(MagickFalse);
7241 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7242 mvg_info->offset+=p->coordinates;
7243 point.x=start.x+arc.x;
7244 point.y=start.y+arc.y;
7247 if (TraceEllipse(mvg_info,point,arc,degrees) == MagickFalse)
7248 return(MagickFalse);
7249 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7250 mvg_info->offset+=p->coordinates;
7251 if (CheckPrimitiveExtent(mvg_info,PrimitiveExtentPad) == MagickFalse)
7252 return(MagickFalse);
7253 p=(*mvg_info->primitive_info)+(ptrdiff_t) mvg_info->offset;
7254 if (TracePoint(p,(*mvg_info->primitive_info+offset)->point) == MagickFalse)
7255 return(MagickFalse);
7256 p+=(ptrdiff_t) p->coordinates;
7257 mvg_info->offset=offset;
7258 primitive_info=(*mvg_info->primitive_info)+offset;
7259 primitive_info->coordinates=(size_t) (p-primitive_info);
7260 primitive_info->closed_subpath=MagickTrue;
7261 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
7263 p->primitive=primitive_info->primitive;
7269 static MagickBooleanType TraceSquareLinecap(
PrimitiveInfo *primitive_info,
7270 const size_t number_vertices,
const double offset)
7287 for (i=1; i < (ssize_t) number_vertices; i++)
7289 dx=primitive_info[0].point.x-primitive_info[i].point.x;
7290 dy=primitive_info[0].point.y-primitive_info[i].point.y;
7291 if ((fabs((
double) dx) >= MagickEpsilon) ||
7292 (fabs((
double) dy) >= MagickEpsilon))
7295 if (i == (ssize_t) number_vertices)
7296 i=(ssize_t) number_vertices-1L;
7297 distance=hypot((
double) dx,(
double) dy);
7298 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
7299 dx*(distance+offset)/distance);
7300 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
7301 dy*(distance+offset)/distance);
7302 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
7304 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
7305 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
7306 if ((fabs((
double) dx) >= MagickEpsilon) ||
7307 (fabs((
double) dy) >= MagickEpsilon))
7310 distance=hypot((
double) dx,(
double) dy);
7311 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
7312 dx*(distance+offset)/distance);
7313 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
7314 dy*(distance+offset)/distance);
7321 #define MaxStrokePad (6*BezierQuantum+360) 7322 #define CheckPathExtent(pad_p,pad_q) \ 7324 if ((pad_p) > MaxBezierCoordinates) \ 7325 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \ 7327 if ((ssize_t) (p+(pad_p)) >= (ssize_t) extent_p) \ 7329 if (~extent_p < (pad_p)) \ 7330 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \ 7333 extent_p+=(pad_p); \ 7334 stroke_p=(PointInfo *) ResizeQuantumMemory(stroke_p,extent_p+ \ 7335 MaxStrokePad,sizeof(*stroke_p)); \ 7338 if ((pad_q) > MaxBezierCoordinates) \ 7339 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \ 7341 if ((ssize_t) (q+(pad_q)) >= (ssize_t) extent_q) \ 7343 if (~extent_q < (pad_q)) \ 7344 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \ 7347 extent_q+=(pad_q); \ 7348 stroke_q=(PointInfo *) ResizeQuantumMemory(stroke_q,extent_q+ \ 7349 MaxStrokePad,sizeof(*stroke_q)); \ 7352 if ((stroke_p == (PointInfo *) NULL) || (stroke_q == (PointInfo *) NULL)) \ 7354 if (stroke_p != (PointInfo *) NULL) \ 7355 stroke_p=(PointInfo *) RelinquishMagickMemory(stroke_p); \ 7356 if (stroke_q != (PointInfo *) NULL) \ 7357 stroke_q=(PointInfo *) RelinquishMagickMemory(stroke_q); \ 7358 polygon_primitive=(PrimitiveInfo *) \ 7359 RelinquishMagickMemory(polygon_primitive); \ 7360 (void) ThrowMagickException(exception,GetMagickModule(), \ 7361 ResourceLimitError,"MemoryAllocationFailed","`%s'",""); \ 7362 return((PrimitiveInfo *) NULL); \ 7366 typedef struct _StrokeSegment
7412 inverse_slope = {0.0, 0.0},
7419 number_vertices=primitive_info->coordinates;
7420 polygon_primitive=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7421 number_vertices+2UL,
sizeof(*polygon_primitive));
7424 (void) ThrowMagickException(exception,GetMagickModule(),
7425 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7428 (void) memcpy(polygon_primitive,primitive_info,(
size_t) number_vertices*
7429 sizeof(*polygon_primitive));
7430 offset.x=primitive_info[number_vertices-1].point.x-primitive_info[0].point.x;
7431 offset.y=primitive_info[number_vertices-1].point.y-primitive_info[0].point.y;
7432 closed_path=(fabs(offset.x) < MagickEpsilon) &&
7433 (fabs(offset.y) < MagickEpsilon) ? MagickTrue : MagickFalse;
7434 if ((draw_info->linejoin == MiterJoin) ||
7435 ((draw_info->linejoin == RoundJoin) && (closed_path != MagickFalse)))
7437 polygon_primitive[number_vertices]=primitive_info[1];
7440 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
7444 closed_path=primitive_info[0].closed_subpath;
7447 for (n=1; n < (ssize_t) number_vertices; n++)
7449 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
7450 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
7451 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
7454 if (n == (ssize_t) number_vertices)
7456 if ((draw_info->linecap != RoundCap) || (closed_path != MagickFalse))
7462 sizeof(*stroke_polygon));
7463 stroke_polygon[0]=polygon_primitive[0];
7464 stroke_polygon[0].coordinates=0;
7467 return(stroke_polygon);
7469 n=(ssize_t) number_vertices-1L;
7471 extent_p=2*number_vertices;
7472 extent_q=2*number_vertices;
7473 stroke_p=(
PointInfo *) AcquireQuantumMemory((
size_t) extent_p+MaxStrokePad,
7475 stroke_q=(
PointInfo *) AcquireQuantumMemory((
size_t) extent_q+MaxStrokePad,
7480 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7482 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7484 RelinquishMagickMemory(polygon_primitive);
7485 (void) ThrowMagickException(exception,GetMagickModule(),
7486 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7490 inverse_slope.p=0.0;
7491 if (fabs(dx.p) < MagickEpsilon)
7494 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7496 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7499 if (fabs(dy.p) < MagickEpsilon)
7502 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7504 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7509 inverse_slope.p=(-1.0*MagickSafeReciprocal(slope.p));
7511 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
7512 miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid);
7513 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
7514 (void) TraceSquareLinecap(polygon_primitive,number_vertices,mid);
7515 offset.x=sqrt((
double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
7516 offset.y=(double) (offset.x*inverse_slope.p);
7517 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
7519 box_p[0].x=polygon_primitive[0].point.x-offset.x;
7520 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
7521 box_p[1].x=polygon_primitive[n].point.x-offset.x;
7522 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
7523 box_q[0].x=polygon_primitive[0].point.x+offset.x;
7524 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
7525 box_q[1].x=polygon_primitive[n].point.x+offset.x;
7526 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
7530 box_p[0].x=polygon_primitive[0].point.x+offset.x;
7531 box_p[0].y=polygon_primitive[0].point.y+offset.y;
7532 box_p[1].x=polygon_primitive[n].point.x+offset.x;
7533 box_p[1].y=polygon_primitive[n].point.y+offset.y;
7534 box_q[0].x=polygon_primitive[0].point.x-offset.x;
7535 box_q[0].y=polygon_primitive[0].point.y-offset.y;
7536 box_q[1].x=polygon_primitive[n].point.x-offset.x;
7537 box_q[1].y=polygon_primitive[n].point.y-offset.y;
7544 stroke_q[p++]=box_q[0];
7545 stroke_p[q++]=box_p[0];
7546 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
7551 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
7552 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
7553 dot_product=dx.q*dx.q+dy.q*dy.q;
7554 if (dot_product < 0.25)
7557 inverse_slope.q=0.0;
7558 if (fabs(dx.q) < MagickEpsilon)
7561 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7563 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7566 if (fabs(dy.q) < MagickEpsilon)
7569 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
7571 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
7576 inverse_slope.q=(-1.0*MagickSafeReciprocal(slope.q));
7578 offset.x=sqrt((
double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
7579 offset.y=(double) (offset.x*inverse_slope.q);
7580 dot_product=dy.q*offset.x-dx.q*offset.y;
7581 if (dot_product > 0.0)
7583 box_p[2].x=polygon_primitive[n].point.x-offset.x;
7584 box_p[2].y=polygon_primitive[n].point.y-offset.y;
7585 box_p[3].x=polygon_primitive[i].point.x-offset.x;
7586 box_p[3].y=polygon_primitive[i].point.y-offset.y;
7587 box_q[2].x=polygon_primitive[n].point.x+offset.x;
7588 box_q[2].y=polygon_primitive[n].point.y+offset.y;
7589 box_q[3].x=polygon_primitive[i].point.x+offset.x;
7590 box_q[3].y=polygon_primitive[i].point.y+offset.y;
7594 box_p[2].x=polygon_primitive[n].point.x+offset.x;
7595 box_p[2].y=polygon_primitive[n].point.y+offset.y;
7596 box_p[3].x=polygon_primitive[i].point.x+offset.x;
7597 box_p[3].y=polygon_primitive[i].point.y+offset.y;
7598 box_q[2].x=polygon_primitive[n].point.x-offset.x;
7599 box_q[2].y=polygon_primitive[n].point.y-offset.y;
7600 box_q[3].x=polygon_primitive[i].point.x-offset.x;
7601 box_q[3].y=polygon_primitive[i].point.y-offset.y;
7603 if (fabs((
double) (slope.p-slope.q)) < MagickEpsilon)
7610 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
7611 box_p[3].y)/(slope.p-slope.q));
7612 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
7613 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
7614 box_q[3].y)/(slope.p-slope.q));
7615 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
7617 CheckPathExtent(MaxStrokePad,MaxStrokePad);
7618 dot_product=dx.q*dy.p-dx.p*dy.q;
7619 if (dot_product <= 0.0)
7620 switch (draw_info->linejoin)
7624 stroke_q[q++]=box_q[1];
7625 stroke_q[q++]=box_q[2];
7626 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7627 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7628 if (dot_product <= miterlimit)
7629 stroke_p[p++]=box_p[4];
7632 stroke_p[p++]=box_p[1];
7633 stroke_p[p++]=box_p[2];
7639 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7640 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7641 if (dot_product <= miterlimit)
7643 stroke_q[q++]=box_q[4];
7644 stroke_p[p++]=box_p[4];
7648 stroke_q[q++]=box_q[1];
7649 stroke_q[q++]=box_q[2];
7650 stroke_p[p++]=box_p[1];
7651 stroke_p[p++]=box_p[2];
7657 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7658 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7659 if (dot_product <= miterlimit)
7660 stroke_p[p++]=box_p[4];
7663 stroke_p[p++]=box_p[1];
7664 stroke_p[p++]=box_p[2];
7666 center=polygon_primitive[n].point;
7667 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
7668 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
7669 if (theta.q < theta.p)
7670 theta.q+=2.0*MagickPI;
7671 arc_segments=(size_t) CastDoubleToLong(ceil((
double) ((theta.q-
7672 theta.p)/(2.0*sqrt(MagickSafeReciprocal(mid))))));
7673 CheckPathExtent(MaxStrokePad,arc_segments+MaxStrokePad);
7674 stroke_q[q].x=box_q[1].x;
7675 stroke_q[q].y=box_q[1].y;
7677 for (j=1; j < (ssize_t) arc_segments; j++)
7679 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7680 stroke_q[q].x=(double) (center.x+mid*cos(fmod((
double)
7681 (theta.p+delta_theta),DegreesToRadians(360.0))));
7682 stroke_q[q].y=(double) (center.y+mid*sin(fmod((
double)
7683 (theta.p+delta_theta),DegreesToRadians(360.0))));
7686 stroke_q[q++]=box_q[2];
7693 switch (draw_info->linejoin)
7697 stroke_p[p++]=box_p[1];
7698 stroke_p[p++]=box_p[2];
7699 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7700 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7701 if (dot_product <= miterlimit)
7702 stroke_q[q++]=box_q[4];
7705 stroke_q[q++]=box_q[1];
7706 stroke_q[q++]=box_q[2];
7712 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7713 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7714 if (dot_product <= miterlimit)
7716 stroke_q[q++]=box_q[4];
7717 stroke_p[p++]=box_p[4];
7721 stroke_q[q++]=box_q[1];
7722 stroke_q[q++]=box_q[2];
7723 stroke_p[p++]=box_p[1];
7724 stroke_p[p++]=box_p[2];
7730 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
7731 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
7732 if (dot_product <= miterlimit)
7733 stroke_q[q++]=box_q[4];
7736 stroke_q[q++]=box_q[1];
7737 stroke_q[q++]=box_q[2];
7739 center=polygon_primitive[n].point;
7740 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
7741 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
7742 if (theta.p < theta.q)
7743 theta.p+=2.0*MagickPI;
7744 arc_segments=(size_t) CastDoubleToLong(ceil((
double) ((theta.p-
7745 theta.q)/(2.0*sqrt((
double) (MagickSafeReciprocal(mid)))))));
7746 CheckPathExtent(arc_segments+MaxStrokePad,MaxStrokePad);
7747 stroke_p[p++]=box_p[1];
7748 for (j=1; j < (ssize_t) arc_segments; j++)
7750 delta_theta=(double) (j*(theta.q-theta.p)/arc_segments);
7751 stroke_p[p].x=(double) (center.x+mid*cos(fmod((
double)
7752 (theta.p+delta_theta),DegreesToRadians(360.0))));
7753 stroke_p[p].y=(double) (center.y+mid*sin(fmod((
double)
7754 (theta.p+delta_theta),DegreesToRadians(360.0))));
7757 stroke_p[p++]=box_p[2];
7764 inverse_slope.p=inverse_slope.q;
7773 stroke_p[p++]=box_p[1];
7774 stroke_q[q++]=box_q[1];
7778 stroke_polygon=(
PrimitiveInfo *) AcquireQuantumMemory((
size_t)
7779 (p+q+2UL*closed_path+2UL),
sizeof(*stroke_polygon));
7782 (void) ThrowMagickException(exception,GetMagickModule(),
7783 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
7784 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7785 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7788 return(stroke_polygon);
7790 for (i=0; i < (ssize_t) p; i++)
7792 stroke_polygon[i]=polygon_primitive[0];
7793 stroke_polygon[i].point=stroke_p[i];
7795 if (closed_path != MagickFalse)
7797 stroke_polygon[i]=polygon_primitive[0];
7798 stroke_polygon[i].point=stroke_polygon[0].point;
7801 for ( ; i < (ssize_t) (p+q+closed_path); i++)
7803 stroke_polygon[i]=polygon_primitive[0];
7804 stroke_polygon[i].point=stroke_q[p+q+closed_path-(i+1)];
7806 if (closed_path != MagickFalse)
7808 stroke_polygon[i]=polygon_primitive[0];
7809 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
7812 stroke_polygon[i]=polygon_primitive[0];
7813 stroke_polygon[i].point=stroke_polygon[0].point;
7815 stroke_polygon[i].primitive=UndefinedPrimitive;
7816 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
7817 stroke_p=(
PointInfo *) RelinquishMagickMemory(stroke_p);
7818 stroke_q=(
PointInfo *) RelinquishMagickMemory(stroke_q);
7819 polygon_primitive=(
PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
7820 return(stroke_polygon);