]> granicus.if.org Git - imagemagick/blobdiff - wand/drawing-wand.c
(no commit message)
[imagemagick] / wand / drawing-wand.c
index bec35b511a1d19d516c045d977afe7e90a68fcd7..e7eccec364065c9f04a414c2034df47599a19cea 100644 (file)
@@ -23,7 +23,7 @@
 %                                March 2002                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -50,6 +50,7 @@
 #include "wand/MagickWand.h"
 #include "wand/magick-wand-private.h"
 #include "wand/wand.h"
+#include "magick/string-private.h"
 \f
 /*
   Define declarations.
@@ -88,7 +89,7 @@ typedef enum
 
 struct _DrawingWand
 {
-  unsigned long
+  size_t
     id;
 
   char
@@ -109,7 +110,7 @@ struct _DrawingWand
     mvg_alloc,          /* total allocated memory */
     mvg_length;         /* total MVG length */
 
-  unsigned long
+  size_t
     mvg_width;          /* current line width */
 
   /* Pattern support */
@@ -123,7 +124,7 @@ struct _DrawingWand
     pattern_offset;
 
   /* Graphic wand */
-  unsigned long
+  size_t
     index;              /* array index */
 
   DrawInfo
@@ -133,7 +134,7 @@ struct _DrawingWand
     filter_off;         /* true if not filtering attributes */
 
   /* Pretty-printing depth */
-  unsigned long
+  size_t
     indent_depth;       /* number of left-hand pad characters */
 
   /* Path operation support */
@@ -147,7 +148,7 @@ struct _DrawingWand
     destroy,
     debug;
 
-  unsigned long
+  size_t
     signature;
 };
 
@@ -159,7 +160,7 @@ struct _DrawVTable
     const unsigned char *);
   void (*DrawArc)(DrawingWand *,const double,const double,const double,
     const double,const double,const double);
-  void (*DrawBezier)(DrawingWand *,const unsigned long,const PointInfo *);
+  void (*DrawBezier)(DrawingWand *,const size_t,const PointInfo *);
   void (*DrawCircle)(DrawingWand *,const double,const double,const double,
     const double);
   void (*DrawColor)(DrawingWand *,const double,const double,const PaintMethod);
@@ -205,8 +206,8 @@ struct _DrawVTable
   void (*DrawPathMoveToRelative)(DrawingWand *,const double,const double);
   void (*DrawPathStart)(DrawingWand *);
   void (*DrawPoint)(DrawingWand *,const double,const double);
-  void (*DrawPolygon)(DrawingWand *,const unsigned long,const PointInfo *);
-  void (*DrawPolyline)(DrawingWand *,const unsigned long,const PointInfo *);
+  void (*DrawPolygon)(DrawingWand *,const size_t,const PointInfo *);
+  void (*DrawPolyline)(DrawingWand *,const size_t,const PointInfo *);
   void (*DrawPopClipPath)(DrawingWand *);
   void (*DrawPopDefs)(DrawingWand *);
   MagickBooleanType (*DrawPopPattern)(DrawingWand *);
@@ -235,7 +236,7 @@ struct _DrawVTable
   void (*DrawSetFontSize)(DrawingWand *,const double);
   void (*DrawSetFontStretch)(DrawingWand *,const StretchType);
   void (*DrawSetFontStyle)(DrawingWand *,const StyleType);
-  void (*DrawSetFontWeight)(DrawingWand *,const unsigned long);
+  void (*DrawSetFontWeight)(DrawingWand *,const size_t);
   void (*DrawSetGravity)(DrawingWand *,const GravityType);
   void (*DrawRotate)(DrawingWand *,const double);
   void (*DrawScale)(DrawingWand *,const double,const double);
@@ -247,15 +248,15 @@ struct _DrawVTable
   void (*DrawSetStrokeDashOffset)(DrawingWand *,const double);
   void (*DrawSetStrokeLineCap)(DrawingWand *,const LineCap);
   void (*DrawSetStrokeLineJoin)(DrawingWand *,const LineJoin);
-  void (*DrawSetStrokeMiterLimit)(DrawingWand *,const unsigned long);
+  void (*DrawSetStrokeMiterLimit)(DrawingWand *,const size_t);
   MagickBooleanType (*DrawSetStrokePatternURL)(DrawingWand *,const char *);
   void (*DrawSetStrokeWidth)(DrawingWand *,const double);
   void (*DrawSetTextAntialias)(DrawingWand *,const MagickBooleanType);
   void (*DrawSetTextDecoration)(DrawingWand *,const DecorationType);
   void (*DrawSetTextUnderColor)(DrawingWand *,const PixelWand *);
   void (*DrawTranslate)(DrawingWand *,const double,const double);
-  void (*DrawSetViewbox)(DrawingWand *,unsigned long,unsigned long,
-    unsigned long,unsigned long);
+  void (*DrawSetViewbox)(DrawingWand *,size_t,size_t,
+    size_t,size_t);
   void (*PeekDrawingWand)(DrawingWand *);
   MagickBooleanType (*PopDrawingWand)(DrawingWand *);
   MagickBooleanType (*PushDrawingWand)(DrawingWand *);
@@ -410,12 +411,12 @@ static void MvgAppendColor(DrawingWand *wand,const PixelPacket *color)
 }
 
 static void MvgAppendPointsCommand(DrawingWand *wand,const char *command,
-  const unsigned long number_coordinates,const PointInfo *coordinates)
+  const size_t number_coordinates,const PointInfo *coordinates)
 {
   const PointInfo
     *coordinate;
 
-  unsigned long
+  size_t
     i;
 
   (void) MvgPrintf(wand,"%s",command);
@@ -548,21 +549,21 @@ WandExport DrawingWand *CloneDrawingWand(const DrawingWand *wand)
   DrawingWand
     *clone_wand;
 
-  register long
+  register ssize_t
     i;
 
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  clone_wand=(DrawingWand *) AcquireMagickMemory(sizeof(*clone_wand));
+  clone_wand=(DrawingWand *) AcquireAlignedMemory(1,sizeof(*clone_wand));
   if (clone_wand == (DrawingWand *) NULL)
     ThrowWandFatalException(ResourceLimitFatalError,
       "MemoryAllocationFailed",GetExceptionMessage(errno));
   (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
   clone_wand->id=AcquireWandId();
-  (void) FormatMagickString(clone_wand->name,MaxTextExtent,"DrawingWand-%lu",
-    clone_wand->id);
+  (void) FormatMagickString(clone_wand->name,MaxTextExtent,"DrawingWand-%.20g",
+    (double) clone_wand->id);
   clone_wand->exception=AcquireExceptionInfo();
   InheritException(clone_wand->exception,wand->exception);
   clone_wand->mvg=AcquireString(wand->mvg);
@@ -578,7 +579,7 @@ WandExport DrawingWand *CloneDrawingWand(const DrawingWand *wand)
   if (clone_wand->graphic_context == (DrawInfo **) NULL)
     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
       GetExceptionMessage(errno));
-  for (i=0; i <= (long) wand->index; i++)
+  for (i=0; i <= (ssize_t) wand->index; i++)
     clone_wand->graphic_context[i]=
       CloneDrawInfo((ImageInfo *) NULL,wand->graphic_context[i]);
   clone_wand->filter_off=wand->filter_off;
@@ -679,8 +680,8 @@ WandExport void DrawAffine(DrawingWand *wand,const AffineMatrix *affine)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   assert(affine != (const AffineMatrix *) NULL);
   AdjustAffine(wand,affine);
-  (void) MvgPrintf(wand,"affine %g,%g,%g,%g,%g,%g\n",affine->sx,affine->rx,
-    affine->ry,affine->sy,affine->tx,affine->ty);
+  (void) MvgPrintf(wand,"affine %g,%g,%g,%g,%g,%g\n",
+    affine->sx,affine->rx,affine->ry,affine->sy,affine->tx,affine->ty);
 }
 \f
 /*
@@ -816,7 +817,8 @@ WandExport void DrawArc(DrawingWand *wand,const double sx,const double sy,
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  (void) MvgPrintf(wand,"arc %g,%g %g,%g %g,%g\n",sx,sy,ex,ey,sd,ed);
+  (void) MvgPrintf(wand,"arc %g,%g %g,%g %g,%g\n",sx,sy,ex,
+    ey,sd,ed);
 }
 \f
 /*
@@ -835,7 +837,7 @@ WandExport void DrawArc(DrawingWand *wand,const double sx,const double sy,
 %  The format of the DrawBezier method is:
 %
 %      void DrawBezier(DrawingWand *wand,
-%        const unsigned long number_coordinates,const PointInfo *coordinates)
+%        const size_t number_coordinates,const PointInfo *coordinates)
 %
 %  A description of each parameter follows:
 %
@@ -847,7 +849,7 @@ WandExport void DrawArc(DrawingWand *wand,const double sx,const double sy,
 %
 */
 WandExport void DrawBezier(DrawingWand *wand,
-  const unsigned long number_coordinates,const PointInfo *coordinates)
+  const size_t number_coordinates,const PointInfo *coordinates)
 {
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -993,7 +995,7 @@ WandExport MagickBooleanType DrawComposite(DrawingWand *wand,
   register char
     *p;
 
-  register long
+  register ssize_t
     i;
 
   size_t
@@ -1031,18 +1033,18 @@ WandExport MagickBooleanType DrawComposite(DrawingWand *wand,
       char
         buffer[MaxTextExtent];
 
-      (void) FormatMagickString(buffer,MaxTextExtent,"%ld bytes",
+      (void) FormatMagickString(buffer,MaxTextExtent,"%.20g bytes",(double)
         (4L*blob_length/3L+4L));
       ThrowDrawException(ResourceLimitWarning,"MemoryAllocationFailed",
         wand->name);
       return(MagickFalse);
     }
-  mode=MagickOptionToMnemonic(MagickComposeOptions,(long) compose);
+  mode=MagickOptionToMnemonic(MagickComposeOptions,(ssize_t) compose);
   media_type=MagickToMime(image->magick);
-  (void) MvgPrintf(wand,"image %s %g,%g %g,%g 'data:%s;base64,\n",mode,x,y,
-    width,height,media_type);
+  (void) MvgPrintf(wand,"image %s %g,%g %g,%g 'data:%s;base64,\n",
+    mode,x,y,width,height,media_type);
   p=base64;
-  for (i=(long) encoded_length; i > 0; i-=76)
+  for (i=(ssize_t) encoded_length; i > 0; i-=76)
   {
     (void) MvgPrintf(wand,"%.76s",p);
     p+=76;
@@ -1099,7 +1101,7 @@ WandExport void DrawColor(DrawingWand *wand,const double x,const double y,
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   (void) MvgPrintf(wand,"color %g,%g '%s'\n",x,y,MagickOptionToMnemonic(
-    MagickMethodOptions,(long) paint_method));
+    MagickMethodOptions,(ssize_t) paint_method));
 }
 \f
 /*
@@ -1173,7 +1175,8 @@ WandExport void DrawEllipse(DrawingWand *wand,const double ox,const double oy,
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  (void) MvgPrintf(wand,"ellipse %g,%g %g,%g %g,%g\n",ox,oy,rx,ry,start,end);
+  (void) MvgPrintf(wand,"ellipse %g,%g %g,%g %g,%g\n",ox,oy,
+    rx,ry,start,end);
 }
 \f
 /*
@@ -1680,14 +1683,14 @@ WandExport StyleType DrawGetFontStyle(const DrawingWand *wand)
 %
 %  The format of the DrawGetFontWeight method is:
 %
-%      unsigned long DrawGetFontWeight(const DrawingWand *wand)
+%      size_t DrawGetFontWeight(const DrawingWand *wand)
 %
 %  A description of each parameter follows:
 %
 %    o wand: the drawing wand.
 %
 */
-WandExport unsigned long DrawGetFontWeight(const DrawingWand *wand)
+WandExport size_t DrawGetFontWeight(const DrawingWand *wand)
 {
   assert(wand != (const DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -1852,7 +1855,7 @@ WandExport void DrawGetStrokeColor(const DrawingWand *wand,
 %  The format of the DrawGetStrokeDashArray method is:
 %
 %      double *DrawGetStrokeDashArray(const DrawingWand *wand,
-%        unsigned long *number_elements)
+%        size_t *number_elements)
 %
 %  A description of each parameter follows:
 %
@@ -1862,7 +1865,7 @@ WandExport void DrawGetStrokeColor(const DrawingWand *wand,
 %
 */
 WandExport double *DrawGetStrokeDashArray(const DrawingWand *wand,
-  unsigned long *number_elements)
+  size_t *number_elements)
 {
   double
     *dash_array;
@@ -1873,17 +1876,17 @@ WandExport double *DrawGetStrokeDashArray(const DrawingWand *wand,
   register double
     *q;
 
-  register long
+  register ssize_t
     i;
 
-  unsigned long
+  size_t
     n;
 
   assert(wand != (const DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  assert(number_elements != (unsigned long *) NULL);
+  assert(number_elements != (size_t *) NULL);
   n=0;
   p=CurrentContext->dash_pattern;
   if (p != (const double *) NULL)
@@ -1897,7 +1900,7 @@ WandExport double *DrawGetStrokeDashArray(const DrawingWand *wand,
         sizeof(*dash_array));
       p=CurrentContext->dash_pattern;
       q=dash_array;
-      for (i=0; i < (long) n; i++)
+      for (i=0; i < (ssize_t) n; i++)
         *q++=(*p++);
     }
   return(dash_array);
@@ -2021,14 +2024,14 @@ WandExport LineJoin DrawGetStrokeLineJoin(const DrawingWand *wand)
 %
 %  The format of the DrawGetStrokeMiterLimit method is:
 %
-%      unsigned long DrawGetStrokeMiterLimit(const DrawingWand *wand)
+%      size_t DrawGetStrokeMiterLimit(const DrawingWand *wand)
 %
 %  A description of each parameter follows:
 %
 %    o wand: the drawing wand.
 %
 */
-WandExport unsigned long DrawGetStrokeMiterLimit(const DrawingWand *wand)
+WandExport size_t DrawGetStrokeMiterLimit(const DrawingWand *wand)
 {
   assert(wand != (const DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -2378,7 +2381,7 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   MagickPixelPacket
     pixel;
 
-  register long
+  register ssize_t
     i;
 
   XMLTreeInfo
@@ -2400,14 +2403,14 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(
-        MagickClipPathOptions,(long) CurrentContext->clip_units),MaxTextExtent);
+        MagickClipPathOptions,(ssize_t) CurrentContext->clip_units),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"decorate",0);
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(
-        MagickDecorateOptions,(long) CurrentContext->decorate),MaxTextExtent);
+        MagickDecorateOptions,(ssize_t) CurrentContext->decorate),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"encoding",0);
@@ -2435,7 +2438,7 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(
-        MagickFillRuleOptions,(long) CurrentContext->fill_rule),MaxTextExtent);
+        MagickFillRuleOptions,(ssize_t) CurrentContext->fill_rule),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"font",0);
@@ -2455,20 +2458,20 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(
-        MagickStretchOptions,(long) CurrentContext->stretch),MaxTextExtent);
+        MagickStretchOptions,(ssize_t) CurrentContext->stretch),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"font-style",0);
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(
-        MagickStyleOptions,(long) CurrentContext->style),MaxTextExtent);
+        MagickStyleOptions,(ssize_t) CurrentContext->style),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"font-weight",0);
   if (child != (XMLTreeInfo *) NULL)
     {
-      (void) FormatMagickString(value,MaxTextExtent,"%lu",
+      (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
         CurrentContext->weight);
       (void) SetXMLTreeContent(child,value);
     }
@@ -2476,7 +2479,7 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(MagickGravityOptions,
-        (long) CurrentContext->gravity),MaxTextExtent);
+        (ssize_t) CurrentContext->gravity),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"stroke",0);
@@ -2527,20 +2530,21 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(MagickLineCapOptions,
-        (long) CurrentContext->linecap),MaxTextExtent);
+        (ssize_t) CurrentContext->linecap),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"stroke-linejoin",0);
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(
-        MagickLineJoinOptions,(long) CurrentContext->linejoin),MaxTextExtent);
+        MagickLineJoinOptions,(ssize_t) CurrentContext->linejoin),
+        MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"stroke-miterlimit",0);
   if (child != (XMLTreeInfo *) NULL)
     {
-      (void) FormatMagickString(value,MaxTextExtent,"%lu",
+      (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
         CurrentContext->miterlimit);
       (void) SetXMLTreeContent(child,value);
     }
@@ -2562,7 +2566,7 @@ WandExport char *DrawGetVectorGraphics(DrawingWand *wand)
   if (child != (XMLTreeInfo *) NULL)
     {
       (void) CopyMagickString(value,MagickOptionToMnemonic(MagickAlignOptions,
-        (long) CurrentContext->align),MaxTextExtent);
+        (ssize_t) CurrentContext->align),MaxTextExtent);
       (void) SetXMLTreeContent(child,value);
     }
   child=AddChildToXMLTree(xml_info,"text-antialias",0);
@@ -2717,7 +2721,7 @@ WandExport void DrawMatte(DrawingWand *wand,const double x,const double y,
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   (void) MvgPrintf(wand,"matte %g,%g '%s'\n",x,y,MagickOptionToMnemonic(
-    MagickMethodOptions,(long) paint_method));
+    MagickMethodOptions,(ssize_t) paint_method));
 }
 \f
 /*
@@ -2813,7 +2817,8 @@ static void DrawPathCurveTo(DrawingWand *wand,const PathMode mode,
         mode == AbsolutePathMode ? 'C' : 'c',x1,y1,x2,y2,x,y);
     }
   else
-    (void) MvgAutoWrapPrintf(wand," %g,%g %g,%g %g,%g",x1,y1,x2,y2,x,y);
+    (void) MvgAutoWrapPrintf(wand," %g,%g %g,%g %g,%g",x1,y1,
+      x2,y2,x,y);
 }
 
 WandExport void DrawPathCurveToAbsolute(DrawingWand *wand,const double x1,
@@ -2923,8 +2928,8 @@ static void DrawPathCurveToQuadraticBezier(DrawingWand *wand,
     {
       wand->path_operation=PathCurveToQuadraticBezierOperation;
       wand->path_mode=mode;
-      (void) MvgAutoWrapPrintf(wand, "%c%g,%g %g,%g",mode == AbsolutePathMode ?
-        'Q' : 'q',x1,y1,x,y);
+      (void) MvgAutoWrapPrintf(wand, "%c%g,%g %g,%g",
+         mode == AbsolutePathMode ? 'Q' : 'q',x1,y1,x,y);
     }
   else
     (void) MvgAutoWrapPrintf(wand," %g,%g %g,%g",x1,y1,x,y);
@@ -3149,8 +3154,8 @@ static void DrawPathCurveToSmooth(DrawingWand *wand,const PathMode mode,
     {
       wand->path_operation=PathCurveToSmoothOperation;
       wand->path_mode=mode;
-      (void) MvgAutoWrapPrintf(wand,"%c%g,%g %g,%g",mode == AbsolutePathMode ?
-        'S' : 's',x2,y2,x,y);
+      (void) MvgAutoWrapPrintf(wand,"%c%g,%g %g,%g",
+        mode == AbsolutePathMode ? 'S' : 's',x2,y2,x,y);
     }
   else
     (void) MvgAutoWrapPrintf(wand," %g,%g %g,%g",x2,y2,x,y);
@@ -3284,8 +3289,8 @@ static void DrawPathEllipticArc(DrawingWand *wand, const PathMode mode,
         large_arc_flag,sweep_flag,x,y);
     }
   else
-    (void) MvgAutoWrapPrintf(wand," %g,%g %g %u %u %g,%g",rx,ry,x_axis_rotation,
-      large_arc_flag,sweep_flag,x,y);
+    (void) MvgAutoWrapPrintf(wand," %g,%g %g %u %u %g,%g",rx,ry,
+      x_axis_rotation,large_arc_flag,sweep_flag,x,y);
 }
 
 WandExport void DrawPathEllipticArcAbsolute(DrawingWand *wand,const double rx,
@@ -3855,7 +3860,7 @@ WandExport void DrawPoint(DrawingWand *wand,const double x,const double y)
 %  The format of the DrawPolygon method is:
 %
 %      void DrawPolygon(DrawingWand *wand,
-%        const unsigned long number_coordinates,const PointInfo *coordinates)
+%        const size_t number_coordinates,const PointInfo *coordinates)
 %
 %  A description of each parameter follows:
 %
@@ -3867,7 +3872,7 @@ WandExport void DrawPoint(DrawingWand *wand,const double x,const double y)
 %
 */
 WandExport void DrawPolygon(DrawingWand *wand,
-  const unsigned long number_coordinates,const PointInfo *coordinates)
+  const size_t number_coordinates,const PointInfo *coordinates)
 {
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -3893,7 +3898,7 @@ WandExport void DrawPolygon(DrawingWand *wand,
 %  The format of the DrawPolyline method is:
 %
 %      void DrawPolyline(DrawingWand *wand,
-%        const unsigned long number_coordinates,const PointInfo *coordinates)
+%        const size_t number_coordinates,const PointInfo *coordinates)
 %
 %  A description of each parameter follows:
 %
@@ -3905,7 +3910,7 @@ WandExport void DrawPolygon(DrawingWand *wand,
 %
 */
 WandExport void DrawPolyline(DrawingWand *wand,
-  const unsigned long number_coordinates,const PointInfo *coordinates)
+  const size_t number_coordinates,const PointInfo *coordinates)
 {
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -4022,9 +4027,9 @@ WandExport MagickBooleanType DrawPopPattern(DrawingWand *wand)
     }
   (void) FormatMagickString(key,MaxTextExtent,"%s",wand->pattern_id);
   (void) SetImageArtifact(wand->image,key,wand->mvg+wand->pattern_offset);
-  (void) FormatMagickString(geometry,MaxTextExtent,"%lux%lu%+ld%+ld",
-    wand->pattern_bounds.width,wand->pattern_bounds.height,
-    wand->pattern_bounds.x,wand->pattern_bounds.y);
+  (void) FormatMagickString(geometry,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
+    (double) wand->pattern_bounds.width,(double) wand->pattern_bounds.height,
+    (double) wand->pattern_bounds.x,(double) wand->pattern_bounds.y);
   (void) SetImageArtifact(wand->image,key,geometry);
   wand->pattern_id=DestroyString(wand->pattern_id);
   wand->pattern_offset=0;
@@ -4165,14 +4170,14 @@ WandExport MagickBooleanType DrawPushPattern(DrawingWand *wand,
       return(MagickFalse);
     }
   wand->filter_off=MagickTrue;
-  (void) MvgPrintf(wand,"push pattern %s %g,%g %g,%g\n",pattern_id,x,y,
-    width,height);
+  (void) MvgPrintf(wand,"push pattern %s %g,%g %g,%g\n",pattern_id,
+    x,y,width,height);
   wand->indent_depth++;
   wand->pattern_id=AcquireString(pattern_id);
-  wand->pattern_bounds.x=(long) ceil(x-0.5);
-  wand->pattern_bounds.y=(long) ceil(y-0.5);
-  wand->pattern_bounds.width=(unsigned long) (width+0.5);
-  wand->pattern_bounds.height=(unsigned long) (height+0.5);
+  wand->pattern_bounds.x=(ssize_t) ceil(x-0.5);
+  wand->pattern_bounds.y=(ssize_t) ceil(y-0.5);
+  wand->pattern_bounds.width=(size_t) floor(width+0.5);
+  wand->pattern_bounds.height=(size_t) floor(height+0.5);
   wand->pattern_offset=wand->mvg_length;
   return(MagickTrue);
 }
@@ -4381,7 +4386,8 @@ WandExport void DrawRoundRectangle(DrawingWand *wand,double x1,double y1,
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  (void) MvgPrintf(wand,"roundrectangle %g,%g %g,%g %g,%g\n",x1,y1,x2,y2,rx,ry);
+  (void) MvgPrintf(wand,"roundrectangle %g,%g %g,%g %g,%g\n",
+    x1,y1,x2,y2,rx,ry);
 }
 \f
 /*
@@ -4504,7 +4510,7 @@ WandExport void DrawSetBorderColor(DrawingWand *wand,const PixelWand *border_wan
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  DrawSetClipPath() associates a named clipping path with the image.  Only
-%  the areas drawn on by the clipping path will be modified as long as it
+%  the areas drawn on by the clipping path will be modified as ssize_t as it
 %  remains in effect.
 %
 %  The format of the DrawSetClipPath method is:
@@ -4577,7 +4583,7 @@ WandExport void DrawSetClipRule(DrawingWand *wand,const FillRule fill_rule)
     {
       CurrentContext->fill_rule=fill_rule;
       (void) MvgPrintf(wand, "clip-rule '%s'\n",MagickOptionToMnemonic(
-        MagickFillRuleOptions,(long) fill_rule));
+        MagickFillRuleOptions,(ssize_t) fill_rule));
     }
 }
 \f
@@ -4631,7 +4637,7 @@ WandExport void DrawSetClipUnits(DrawingWand *wand,
           AdjustAffine(wand,&affine);
         }
       (void) MvgPrintf(wand, "clip-units '%s'\n",MagickOptionToMnemonic(
-        MagickClipPathOptions,(long) clip_units));
+        MagickClipPathOptions,(ssize_t) clip_units));
     }
 }
 \f
@@ -4718,7 +4724,7 @@ WandExport void DrawSetFillOpacity(DrawingWand *wand,const double fill_opacity)
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  opacity=RoundToQuantum((double) QuantumRange*(1.0-fill_opacity));
+  opacity=ClampToQuantum((double) QuantumRange*(1.0-fill_opacity));
   if ((wand->filter_off != MagickFalse) ||
       (CurrentContext->fill.opacity != opacity))
     {
@@ -4761,11 +4767,11 @@ WandExport void DrawSetOpacity(DrawingWand *wand,const double opacity)
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  quantum_opacity=RoundToQuantum((double) QuantumRange*(1.0-opacity));
+  quantum_opacity=ClampToQuantum((double) QuantumRange*(1.0-opacity));
   if ((wand->filter_off != MagickFalse) ||
       (CurrentContext->opacity != quantum_opacity))
     {
-      CurrentContext->opacity=opacity;
+      CurrentContext->opacity=(Quantum) opacity;
       (void) MvgPrintf(wand,"opacity %g\n",opacity);
     }
 }
@@ -4869,7 +4875,7 @@ WandExport void DrawSetFillRule(DrawingWand *wand,const FillRule fill_rule)
     {
       CurrentContext->fill_rule=fill_rule;
       (void) MvgPrintf(wand, "fill-rule '%s'\n",MagickOptionToMnemonic(
-        MagickFillRuleOptions,(long) fill_rule));
+        MagickFillRuleOptions,(ssize_t) fill_rule));
     }
 }
 \f
@@ -5038,7 +5044,7 @@ WandExport void DrawSetFontStretch(DrawingWand *wand,
     {
       CurrentContext->stretch=font_stretch;
       (void) MvgPrintf(wand, "font-stretch '%s'\n",MagickOptionToMnemonic(
-        MagickStretchOptions,(long) font_stretch));
+        MagickStretchOptions,(ssize_t) font_stretch));
     }
 }
 \f
@@ -5078,7 +5084,7 @@ WandExport void DrawSetFontStyle(DrawingWand *wand,const StyleType style)
     {
       CurrentContext->style=style;
       (void) MvgPrintf(wand, "font-style '%s'\n",MagickOptionToMnemonic(
-        MagickStyleOptions,(long) style));
+        MagickStyleOptions,(ssize_t) style));
     }
 }
 \f
@@ -5098,7 +5104,7 @@ WandExport void DrawSetFontStyle(DrawingWand *wand,const StyleType style)
 %  The format of the DrawSetFontWeight method is:
 %
 %      void DrawSetFontWeight(DrawingWand *wand,
-%        const unsigned long font_weight)
+%        const size_t font_weight)
 %
 %  A description of each parameter follows:
 %
@@ -5108,7 +5114,7 @@ WandExport void DrawSetFontStyle(DrawingWand *wand,const StyleType style)
 %
 */
 WandExport void DrawSetFontWeight(DrawingWand *wand,
-  const unsigned long font_weight)
+  const size_t font_weight)
 {
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -5118,7 +5124,7 @@ WandExport void DrawSetFontWeight(DrawingWand *wand,
       (CurrentContext->weight != font_weight))
     {
       CurrentContext->weight=font_weight;
-      (void) MvgPrintf(wand,"font-weight %lu\n",font_weight);
+      (void) MvgPrintf(wand,"font-weight %.20g\n",(double) font_weight);
     }
 }
 \f
@@ -5161,7 +5167,7 @@ WandExport void DrawSetGravity(DrawingWand *wand,const GravityType gravity)
     {
       CurrentContext->gravity=gravity;
       (void) MvgPrintf(wand,"gravity '%s'\n",MagickOptionToMnemonic(
-        MagickGravityOptions,(long) gravity));
+        MagickGravityOptions,(ssize_t) gravity));
     }
 }
 \f
@@ -5340,7 +5346,7 @@ WandExport void DrawSetStrokeAntialias(DrawingWand *wand,
 %  The format of the DrawSetStrokeDashArray method is:
 %
 %      MagickBooleanType DrawSetStrokeDashArray(DrawingWand *wand,
-%        const unsigned long number_elements,const double *dash_array)
+%        const size_t number_elements,const double *dash_array)
 %
 %  A description of each parameter follows:
 %
@@ -5352,7 +5358,7 @@ WandExport void DrawSetStrokeAntialias(DrawingWand *wand,
 %
 */
 WandExport MagickBooleanType DrawSetStrokeDashArray(DrawingWand *wand,
-  const unsigned long number_elements,const double *dash_array)
+  const size_t number_elements,const double *dash_array)
 {
   MagickBooleanType
     update;
@@ -5363,10 +5369,10 @@ WandExport MagickBooleanType DrawSetStrokeDashArray(DrawingWand *wand,
   register double
     *q;
 
-  register long
+  register ssize_t
     i;
 
-  unsigned long
+  size_t
     n_new,
     n_old;
 
@@ -5392,7 +5398,7 @@ WandExport MagickBooleanType DrawSetStrokeDashArray(DrawingWand *wand,
         {
           p=dash_array;
           q=CurrentContext->dash_pattern;
-          for (i=0; i < (long) n_new; i++)
+          for (i=0; i < (ssize_t) n_new; i++)
           {
             if (fabs((*p)-(*q)) > MagickEpsilon)
               {
@@ -5420,7 +5426,7 @@ WandExport MagickBooleanType DrawSetStrokeDashArray(DrawingWand *wand,
             }
           q=CurrentContext->dash_pattern;
           p=dash_array;
-          for (i=0; i < (long) n_new; i++)
+          for (i=0; i < (ssize_t) n_new; i++)
             *q++=(*p++);
           *q=0;
         }
@@ -5431,7 +5437,7 @@ WandExport MagickBooleanType DrawSetStrokeDashArray(DrawingWand *wand,
         {
           p=dash_array;
           (void) MvgPrintf(wand,"%g",*p++);
-          for (i=1; i < (long) n_new; i++)
+          for (i=1; i < (ssize_t) n_new; i++)
             (void) MvgPrintf(wand,",%g",*p++);
           (void) MvgPrintf(wand,"\n");
         }
@@ -5518,7 +5524,7 @@ WandExport void DrawSetStrokeLineCap(DrawingWand *wand,const LineCap linecap)
     {
       CurrentContext->linecap=linecap;
       (void) MvgPrintf(wand,"stroke-linecap '%s'\n",MagickOptionToMnemonic(
-        MagickLineCapOptions,(long) linecap));
+        MagickLineCapOptions,(ssize_t) linecap));
     }
 }
 \f
@@ -5560,7 +5566,7 @@ WandExport void DrawSetStrokeLineJoin(DrawingWand *wand,const LineJoin linejoin)
     {
       CurrentContext->linejoin=linejoin;
       (void) MvgPrintf(wand, "stroke-linejoin '%s'\n",MagickOptionToMnemonic(
-        MagickLineJoinOptions,(long) linejoin));
+        MagickLineJoinOptions,(ssize_t) linejoin));
     }
 }
 \f
@@ -5584,7 +5590,7 @@ WandExport void DrawSetStrokeLineJoin(DrawingWand *wand,const LineJoin linejoin)
 %  The format of the DrawSetStrokeMiterLimit method is:
 %
 %      void DrawSetStrokeMiterLimit(DrawingWand *wand,
-%        const unsigned long miterlimit)
+%        const size_t miterlimit)
 %
 %  A description of each parameter follows:
 %
@@ -5594,7 +5600,7 @@ WandExport void DrawSetStrokeLineJoin(DrawingWand *wand,const LineJoin linejoin)
 %
 */
 WandExport void DrawSetStrokeMiterLimit(DrawingWand *wand,
-  const unsigned long miterlimit)
+  const size_t miterlimit)
 {
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
@@ -5603,7 +5609,7 @@ WandExport void DrawSetStrokeMiterLimit(DrawingWand *wand,
   if (CurrentContext->miterlimit != miterlimit)
     {
       CurrentContext->miterlimit=miterlimit;
-      (void) MvgPrintf(wand,"stroke-miterlimit %lu\n",miterlimit);
+      (void) MvgPrintf(wand,"stroke-miterlimit %.20g\n",(double) miterlimit);
     }
 }
 \f
@@ -5642,7 +5648,7 @@ WandExport void DrawSetStrokeOpacity(DrawingWand *wand,
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  opacity=RoundToQuantum((double) QuantumRange*(1.0-stroke_opacity));
+  opacity=ClampToQuantum((double) QuantumRange*(1.0-stroke_opacity));
   if ((wand->filter_off != MagickFalse) ||
       (CurrentContext->stroke.opacity != opacity))
     {
@@ -5729,7 +5735,7 @@ WandExport void DrawSetTextAlignment(DrawingWand *wand,
     {
       CurrentContext->align=alignment;
       (void) MvgPrintf(wand,"text-align '%s'\n",MagickOptionToMnemonic(
-        MagickAlignOptions,(long) alignment));
+        MagickAlignOptions,(ssize_t) alignment));
     }
 }
 \f
@@ -5814,7 +5820,7 @@ WandExport void DrawSetTextDecoration(DrawingWand *wand,
     {
       CurrentContext->decorate=decoration;
       (void) MvgPrintf(wand,"decorate '%s'\n",MagickOptionToMnemonic(
-        MagickDecorateOptions,(long) decoration));
+        MagickDecorateOptions,(ssize_t) decoration));
     }
 }
 \f
@@ -6127,8 +6133,8 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->fill.opacity=RoundToQuantum((MagickRealType)
-          QuantumRange*(1.0-atof(value)));
+        CurrentContext->fill.opacity=ClampToQuantum((MagickRealType)
+          QuantumRange*(1.0-StringToDouble(value)));
     }
   child=GetXMLTreeChild(xml_info,"fill-rule");
   if (child != (XMLTreeInfo *) NULL)
@@ -6149,7 +6155,7 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->pointsize=atof(value);
+        CurrentContext->pointsize=StringToDouble(value);
     }
   child=GetXMLTreeChild(xml_info,"font-stretch");
   if (child != (XMLTreeInfo *) NULL)
@@ -6172,7 +6178,7 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->weight=(unsigned long) atol(value);
+        CurrentContext->weight=StringToUnsignedLong(value);
     }
   child=GetXMLTreeChild(xml_info,"gravity");
   if (child != (XMLTreeInfo *) NULL)
@@ -6195,7 +6201,7 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->stroke_antialias=atol(value) != 0 ? MagickTrue :
+        CurrentContext->stroke_antialias=StringToLong(value) != 0 ? MagickTrue :
           MagickFalse;
     }
   child=GetXMLTreeChild(xml_info,"stroke-dasharray");
@@ -6207,10 +6213,10 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
       const char
         *q;
 
-      long
+      ssize_t
         j;
 
-      register long
+      register ssize_t
         x;
 
       value=GetXMLTreeContent(child);
@@ -6245,7 +6251,7 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                CurrentContext->dash_pattern[j]=atof(token);
+                CurrentContext->dash_pattern[j]=StringToDouble(token);
               }
               if ((x & 0x01) != 0)
                 for ( ; j < (2*x); j++)
@@ -6260,7 +6266,7 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->dash_offset=atof(value);
+        CurrentContext->dash_offset=StringToDouble(value);
     }
   child=GetXMLTreeChild(xml_info,"stroke-linecap");
   if (child != (XMLTreeInfo *) NULL)
@@ -6283,22 +6289,22 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->miterlimit=(unsigned long) atol(value);
+        CurrentContext->miterlimit=StringToUnsignedLong(value);
     }
   child=GetXMLTreeChild(xml_info,"stroke-opacity");
   if (child != (XMLTreeInfo *) NULL)
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->stroke.opacity=RoundToQuantum((MagickRealType)
-          QuantumRange*(1.0-atof(value)));
+        CurrentContext->stroke.opacity=ClampToQuantum((MagickRealType)
+          QuantumRange*(1.0-StringToDouble(value)));
     }
   child=GetXMLTreeChild(xml_info,"stroke-width");
   if (child != (XMLTreeInfo *) NULL)
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->stroke_width=atof(value);
+        CurrentContext->stroke_width=StringToDouble(value);
     }
   child=GetXMLTreeChild(xml_info,"text-align");
   if (child != (XMLTreeInfo *) NULL)
@@ -6313,7 +6319,7 @@ WandExport MagickBooleanType DrawSetVectorGraphics(DrawingWand *wand,
     {
       value=GetXMLTreeContent(child);
       if (value != (const char *) NULL)
-        CurrentContext->text_antialias=atol(value) != 0 ? MagickTrue :
+        CurrentContext->text_antialias=StringToLong(value) != 0 ? MagickTrue :
           MagickFalse;
     }
   child=GetXMLTreeChild(xml_info,"text-undercolor");
@@ -6479,8 +6485,8 @@ WandExport void DrawTranslate(DrawingWand *wand,const double x,const double y)
 %
 %  The format of the DrawSetViewbox method is:
 %
-%      void DrawSetViewbox(DrawingWand *wand,unsigned long x1,
-%        unsigned long y1,unsigned long x2,unsigned long y2)
+%      void DrawSetViewbox(DrawingWand *wand,size_t x1,
+%        size_t y1,size_t x2,size_t y2)
 %
 %  A description of each parameter follows:
 %
@@ -6495,14 +6501,15 @@ WandExport void DrawTranslate(DrawingWand *wand,const double x,const double y)
 %    o y2: bottom y ordinate
 %
 */
-WandExport void DrawSetViewbox(DrawingWand *wand,unsigned long x1,
-  unsigned long y1,unsigned long x2,unsigned long y2)
+WandExport void DrawSetViewbox(DrawingWand *wand,ssize_t x1,ssize_t y1,
+  ssize_t x2,ssize_t y2)
 {
   assert(wand != (DrawingWand *) NULL);
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  (void) MvgPrintf(wand,"viewbox %lu %lu %lu %lu\n",x1,y1,x2,y2);
+  (void) MvgPrintf(wand,"viewbox %.20g %.20g %.20g %.20g\n",(double) x1,
+    (double) y1,(double) x2,(double) y2);
 }
 \f
 /*
@@ -6565,20 +6572,20 @@ WandExport DrawingWand *NewDrawingWand(void)
   DrawingWand
     *wand;
 
-  unsigned long
+  size_t
     depth;
 
   quantum=GetMagickQuantumDepth(&depth);
   if (depth != MAGICKCORE_QUANTUM_DEPTH)
     ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
-  wand=(DrawingWand *) AcquireMagickMemory(sizeof(*wand));
+  wand=(DrawingWand *) AcquireAlignedMemory(1,sizeof(*wand));
   if (wand == (DrawingWand *) NULL)
     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
       GetExceptionMessage(errno));
   (void) ResetMagickMemory(wand,0,sizeof(*wand));
   wand->id=AcquireWandId();
-  (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",DrawingWandId,
-    wand->id);
+  (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%.20g",DrawingWandId,
+    (double) wand->id);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   wand->mvg=(char *) NULL;
@@ -6592,7 +6599,7 @@ WandExport DrawingWand *NewDrawingWand(void)
   wand->pattern_bounds.width=0;
   wand->pattern_bounds.height=0;
   wand->index=0;
-  wand->graphic_context=(DrawInfo **) AcquireMagickMemory(sizeof(
+  wand->graphic_context=(DrawInfo **) AcquireAlignedMemory(1,sizeof(
     *wand->graphic_context));
   if (wand->graphic_context == (DrawInfo **) NULL)
     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",