]> granicus.if.org Git - imagemagick/blobdiff - coders/svg.c
(no commit message)
[imagemagick] / coders / svg.c
index a68dec0b7b5c917de1458d171fe9fd51e37f5cc6..e6179ccabadc485f3d1560b42a7d2ef998af1ffb 100644 (file)
@@ -18,7 +18,7 @@
 %                                March 2000                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 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  %
@@ -59,6 +59,7 @@
 #include "magick/log.h"
 #include "magick/magick.h"
 #include "magick/memory_.h"
+#include "magick/module.h"
 #include "magick/monitor.h"
 #include "magick/monitor-private.h"
 #include "magick/quantum-private.h"
 #include "magick/resource_.h"
 #include "magick/static.h"
 #include "magick/string_.h"
-#include "magick/module.h"
+#include "magick/string-private.h"
 #include "magick/token.h"
 #include "magick/utility.h"
 #if defined(MAGICKCORE_XML_DELEGATE)
-#  if defined(__WINDOWS__)
+#  if defined(MAGICKCORE_WINDOWS_SUPPORT)
 #    if defined(__MINGW32__)
 #      define _MSC_VER
 #    else
@@ -140,7 +141,7 @@ typedef struct _SVGInfo
   AffineMatrix
     affine;
 
-  unsigned long
+  size_t
     width,
     height;
 
@@ -301,7 +302,7 @@ static double GetUserSpaceCoordinateValue(const SVGInfo *svg_info,int type,
   assert(string != (const char *) NULL);
   p=(const char *) string;
   GetMagickToken(p,&p,token);
-  value=atof(token);
+  value=StringToDouble(token);
   if (strchr(token,'%') != (char *) NULL)
     {
       double
@@ -374,13 +375,14 @@ static char **GetStyleTokens(void *context,const char *style,int *number_tokens)
     *text,
     **tokens;
 
-  register long
+  register ssize_t
     i;
 
   SVGInfo
     *svg_info;
 
   svg_info=(SVGInfo *) context;
+  (void) svg_info;
   *number_tokens=0;
   if (style == (const char *) NULL)
     return((char **) NULL);
@@ -405,7 +407,7 @@ static char **GetTransformTokens(void *context,const char *text,
     *p,
     *q;
 
-  register long
+  register ssize_t
     i;
 
   SVGInfo
@@ -712,6 +714,7 @@ static void SVGSetDocumentLocator(void *context,xmlSAXLocatorPtr location)
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
     "  SAX.setDocumentLocator()");
   svg_info=(SVGInfo *) context;
+  (void) svg_info;
 }
 
 static void SVGStartDocument(void *context)
@@ -791,7 +794,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
   SVGInfo
     *svg_info;
 
-  register long
+  register ssize_t
     i,
     j;
 
@@ -948,6 +951,14 @@ static void SVGStartElement(void *context,const xmlChar *name,
           break;
       }
     }
+  if (strchr((char *) name,':') != (char *) NULL)
+    {
+      /*
+        Skip over namespace.
+      */
+      for ( ; *name != ':'; name++) ;
+      name++;
+    }
   switch (*name)
   {
     case 'C':
@@ -1015,7 +1026,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
         }
       if (LocaleCompare((const char *) name,"linearGradient") == 0)
         {
-          MVGPrintf(svg_info->file,"push gradient '%s' linear %g,%g %g,%g\n",id,
+          MVGPrintf(svg_info->file,
+            "push gradient '%s' linear %g,%g %g,%g\n",id,
             svg_info->segment.x1,svg_info->segment.y1,svg_info->segment.x2,
             svg_info->segment.y2);
           break;
@@ -1032,7 +1044,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
         }
       if (LocaleCompare((const char *) name,"pattern") == 0)
         {
-          MVGPrintf(svg_info->file,"push pattern '%s' %g,%g %g,%g\n",id,
+          MVGPrintf(svg_info->file,
+            "push pattern '%s' %g,%g %g,%g\n",id,
             svg_info->bounds.x,svg_info->bounds.y,svg_info->bounds.width,
             svg_info->bounds.height);
           break;
@@ -1054,7 +1067,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
     {
       if (LocaleCompare((const char *) name,"radialGradient") == 0)
         {
-          MVGPrintf(svg_info->file,"push gradient '%s' radial %g,%g %g,%g %g\n",
+          MVGPrintf(svg_info->file,
+            "push gradient '%s' radial %g,%g %g,%g %g\n",
             id,svg_info->element.cx,svg_info->element.cy,
             svg_info->element.major,svg_info->element.minor,
             svg_info->element.angle);
@@ -1099,8 +1113,9 @@ static void SVGStartElement(void *context,const xmlChar *name,
                 *text;
 
               text=EscapeString(svg_info->text,'\'');
-              MVGPrintf(svg_info->file,"text %g,%g '%s'\n",svg_info->bounds.x-
-                svg_info->center.x,svg_info->bounds.y-svg_info->center.y,text);
+              MVGPrintf(svg_info->file,"text %g,%g '%s'\n",
+                svg_info->bounds.x-svg_info->center.x,svg_info->bounds.y-
+                svg_info->center.y,text);
               text=DestroyString(text);
               draw_info=CloneDrawInfo(svg_info->image_info,(DrawInfo *) NULL);
               draw_info->pointsize=svg_info->pointsize;
@@ -1286,27 +1301,27 @@ static void SVGStartElement(void *context,const xmlChar *name,
                       {
                         p=(const char *) value;
                         GetMagickToken(p,&p,token);
-                        affine.sx=atof(value);
+                        affine.sx=StringToDouble(value);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.rx=atof(token);
+                        affine.rx=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.ry=atof(token);
+                        affine.ry=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.sy=atof(token);
+                        affine.sy=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.tx=atof(token);
+                        affine.tx=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.ty=atof(token);
+                        affine.ty=StringToDouble(token);
                         break;
                       }
                     break;
@@ -1386,18 +1401,19 @@ static void SVGStartElement(void *context,const xmlChar *name,
                   default:
                     break;
                 }
-                transform.sx=current.sx*affine.sx+current.ry*affine.rx;
-                transform.rx=current.rx*affine.sx+current.sy*affine.rx;
-                transform.ry=current.sx*affine.ry+current.ry*affine.sy;
-                transform.sy=current.rx*affine.ry+current.sy*affine.sy;
-                transform.tx=current.sx*affine.tx+current.ry*affine.ty+
-                  current.tx;
-                transform.ty=current.rx*affine.tx+current.sy*affine.ty+
-                  current.ty;
+                transform.sx=affine.sx*current.sx+affine.ry*current.rx;
+                transform.rx=affine.rx*current.sx+affine.sy*current.rx;
+                transform.ry=affine.sx*current.ry+affine.ry*current.sy;
+                transform.sy=affine.rx*current.ry+affine.sy*current.sy;
+                transform.tx=affine.sx*current.tx+affine.ry*current.ty+
+                  affine.tx;
+                transform.ty=affine.rx*current.tx+affine.sy*current.ty+
+                  affine.ty;
               }
-              MVGPrintf(svg_info->file,"affine %g %g %g %g %g %g\n",
-                transform.sx,transform.rx,transform.ry,transform.sy,
-                transform.tx,transform.ty);
+              MVGPrintf(svg_info->file,
+                "affine %g %g %g %g %g %g\n",transform.sx,
+                transform.rx,transform.ry,transform.sy,transform.tx,
+                transform.ty);
               for (j=0; tokens[j] != (char *) NULL; j++)
                 tokens[j]=DestroyString(tokens[j]);
               tokens=(char **) RelinquishMagickMemory(tokens);
@@ -1491,8 +1507,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
                 angle;
 
               angle=GetUserSpaceCoordinateValue(svg_info,0,value);
-              MVGPrintf(svg_info->file,"translate %g,%g\n",svg_info->bounds.x,
-                svg_info->bounds.y);
+              MVGPrintf(svg_info->file,"translate %g,%g\n",
+                svg_info->bounds.x,svg_info->bounds.y);
               svg_info->bounds.x=0;
               svg_info->bounds.y=0;
               MVGPrintf(svg_info->file,"rotate %g\n",angle);
@@ -1861,27 +1877,27 @@ static void SVGStartElement(void *context,const xmlChar *name,
                       {
                         p=(const char *) value;
                         GetMagickToken(p,&p,token);
-                        affine.sx=atof(value);
+                        affine.sx=StringToDouble(value);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.rx=atof(token);
+                        affine.rx=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.ry=atof(token);
+                        affine.ry=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.sy=atof(token);
+                        affine.sy=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.tx=atof(token);
+                        affine.tx=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        affine.ty=atof(token);
+                        affine.ty=StringToDouble(token);
                         break;
                       }
                     break;
@@ -1898,15 +1914,15 @@ static void SVGStartElement(void *context,const xmlChar *name,
 
                         p=(const char *) value;
                         GetMagickToken(p,&p,token);
-                        angle=atof(value);
+                        angle=StringToDouble(value);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        x=atof(token);
+                        x=StringToDouble(token);
                         GetMagickToken(p,&p,token);
                         if (*token == ',')
                           GetMagickToken(p,&p,token);
-                        y=atof(token);
+                        y=StringToDouble(token);
                         affine.sx=cos(DegreesToRadians(fmod(angle,360.0)));
                         affine.rx=sin(DegreesToRadians(fmod(angle,360.0)));
                         affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0))));
@@ -1977,18 +1993,19 @@ static void SVGStartElement(void *context,const xmlChar *name,
                   default:
                     break;
                 }
-                transform.sx=current.sx*affine.sx+current.ry*affine.rx;
-                transform.rx=current.rx*affine.sx+current.sy*affine.rx;
-                transform.ry=current.sx*affine.ry+current.ry*affine.sy;
-                transform.sy=current.rx*affine.ry+current.sy*affine.sy;
-                transform.tx=current.sx*affine.tx+current.ry*affine.ty+
-                  current.tx;
-                transform.ty=current.rx*affine.tx+current.sy*affine.ty+
-                  current.ty;
+                transform.sx=affine.sx*current.sx+affine.ry*current.rx;
+                transform.rx=affine.rx*current.sx+affine.sy*current.rx;
+                transform.ry=affine.sx*current.ry+affine.ry*current.sy;
+                transform.sy=affine.rx*current.ry+affine.sy*current.sy;
+                transform.tx=affine.sx*current.tx+affine.ry*current.ty+
+                  affine.tx;
+                transform.ty=affine.rx*current.tx+affine.sy*current.ty+
+                  affine.ty;
               }
-              MVGPrintf(svg_info->file,"affine %g %g %g %g %g %g\n",
-                transform.sx,transform.rx,transform.ry,transform.sy,
-                transform.tx,transform.ty);
+              MVGPrintf(svg_info->file,
+                "affine %g %g %g %g %g %g\n",transform.sx,
+                transform.rx,transform.ry,transform.sy,transform.tx,
+                transform.ty);
               for (j=0; tokens[j] != (char *) NULL; j++)
                 tokens[j]=DestroyString(tokens[j]);
               tokens=(char **) RelinquishMagickMemory(tokens);
@@ -2008,21 +2025,21 @@ static void SVGStartElement(void *context,const xmlChar *name,
             {
               p=(const char *) value;
               GetMagickToken(p,&p,token);
-              svg_info->view_box.x=atof(token);
+              svg_info->view_box.x=StringToDouble(token);
               GetMagickToken(p,&p,token);
               if (*token == ',')
                 GetMagickToken(p,&p,token);
-              svg_info->view_box.y=atof(token);
+              svg_info->view_box.y=StringToDouble(token);
               GetMagickToken(p,&p,token);
               if (*token == ',')
                 GetMagickToken(p,&p,token);
-              svg_info->view_box.width=atof(token);
+              svg_info->view_box.width=StringToDouble(token);
               if (svg_info->bounds.width == 0)
                 svg_info->bounds.width=svg_info->view_box.width;
               GetMagickToken(p,&p,token);
               if (*token == ',')
                 GetMagickToken(p,&p,token);
-              svg_info->view_box.height=atof(token);
+              svg_info->view_box.height=StringToDouble(token);
               if (svg_info->bounds.height == 0)
                 svg_info->bounds.height=svg_info->view_box.height;
               break;
@@ -2107,10 +2124,10 @@ static void SVGStartElement(void *context,const xmlChar *name,
           if ((svg_info->view_box.width == 0.0) ||
               (svg_info->view_box.height == 0.0))
             svg_info->view_box=svg_info->bounds;
-          svg_info->width=(unsigned long) (svg_info->bounds.width+0.5);
-          svg_info->height=(unsigned long) (svg_info->bounds.height+0.5);
-          MVGPrintf(svg_info->file,"viewbox 0 0 %lu %lu\n",svg_info->width,
-            svg_info->height);
+          svg_info->width=(size_t) floor(svg_info->bounds.width+0.5);
+          svg_info->height=(size_t) floor(svg_info->bounds.height+0.5);
+          MVGPrintf(svg_info->file,"viewbox 0 0 %.20g %.20g\n",(double)
+            svg_info->width,(double) svg_info->height);
           sx=(double) svg_info->width/svg_info->view_box.width;
           sy=(double) svg_info->height/svg_info->view_box.height;
           MVGPrintf(svg_info->file,"affine %g 0 0 %g 0.0 0.0\n",sx,sy);
@@ -2133,6 +2150,14 @@ static void SVGEndElement(void *context,const xmlChar *name)
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
     "  SAX.endElement(%s)",name);
   svg_info=(SVGInfo *) context;
+  if (strchr((char *) name,':') != (char *) NULL)
+    {
+      /*
+        Skip over namespace.
+      */
+      for ( ; *name != ':'; name++) ;
+      name++;
+    }
   switch (*name)
   {
     case 'C':
@@ -2140,9 +2165,9 @@ static void SVGEndElement(void *context,const xmlChar *name)
     {
       if (LocaleCompare((const char *) name,"circle") == 0)
         {
-          MVGPrintf(svg_info->file,"circle %g,%g %g,%g\n",svg_info->element.cx,
-            svg_info->element.cy,svg_info->element.cx,svg_info->element.cy+
-            svg_info->element.minor);
+          MVGPrintf(svg_info->file,"circle %g,%g %g,%g\n",
+            svg_info->element.cx,svg_info->element.cy,svg_info->element.cx,
+            svg_info->element.cy+svg_info->element.minor);
           MVGPrintf(svg_info->file,"pop graphic-context\n");
           break;
         }
@@ -2227,8 +2252,9 @@ static void SVGEndElement(void *context,const xmlChar *name)
     {
       if (LocaleCompare((const char *) name,"line") == 0)
         {
-          MVGPrintf(svg_info->file,"line %g,%g %g,%g\n",svg_info->segment.x1,
-            svg_info->segment.y1,svg_info->segment.x2,svg_info->segment.y2);
+          MVGPrintf(svg_info->file,"line %g,%g %g,%g\n",
+            svg_info->segment.x1,svg_info->segment.y1,svg_info->segment.x2,
+            svg_info->segment.y2);
           MVGPrintf(svg_info->file,"pop graphic-context\n");
           break;
         }
@@ -2290,7 +2316,8 @@ static void SVGEndElement(void *context,const xmlChar *name)
             svg_info->radius.x=svg_info->radius.y;
           if (svg_info->radius.y == 0.0)
             svg_info->radius.y=svg_info->radius.x;
-          MVGPrintf(svg_info->file,"roundRectangle %g,%g %g,%g %g,%g\n",
+          MVGPrintf(svg_info->file,
+            "roundRectangle %g,%g %g,%g %g,%g\n",
             svg_info->bounds.x,svg_info->bounds.y,svg_info->bounds.x+
             svg_info->bounds.width,svg_info->bounds.y+svg_info->bounds.height,
             svg_info->radius.x,svg_info->radius.y);
@@ -2329,8 +2356,9 @@ static void SVGEndElement(void *context,const xmlChar *name)
 
               text=EscapeString(svg_info->text,'\'');
               StripString(text);
-              MVGPrintf(svg_info->file,"text %g,%g '%s'\n",svg_info->bounds.x-
-                svg_info->center.x,svg_info->bounds.y-svg_info->center.y,text);
+              MVGPrintf(svg_info->file,"text %g,%g '%s'\n",
+                svg_info->bounds.x-svg_info->center.x,svg_info->bounds.y-
+                svg_info->center.y,text);
               text=DestroyString(text);
               *svg_info->text='\0';
             }
@@ -2352,8 +2380,8 @@ static void SVGEndElement(void *context,const xmlChar *name)
 
               text=EscapeString(svg_info->text,'\'');
               StripString(text);
-              MVGPrintf(svg_info->file,"text %g,%g '%s'\n",svg_info->bounds.x,
-                svg_info->bounds.y,text);
+              MVGPrintf(svg_info->file,"text %g,%g '%s'\n",
+                svg_info->bounds.x,svg_info->bounds.y,text);
               text=DestroyString(text);
               draw_info=CloneDrawInfo(svg_info->image_info,(DrawInfo *) NULL);
               draw_info->pointsize=svg_info->pointsize;
@@ -2391,7 +2419,7 @@ static void SVGCharacters(void *context,const xmlChar *c,int length)
   register char
     *p;
 
-  register long
+  register ssize_t
     i;
 
   SVGInfo
@@ -2401,7 +2429,7 @@ static void SVGCharacters(void *context,const xmlChar *c,int length)
     Receiving some characters from the parser.
   */
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-    "  SAX.characters(%s,%lu)",c,(unsigned long) length);
+    "  SAX.characters(%s,%.20g)",c,(double) length);
   svg_info=(SVGInfo *) context;
   if (svg_info->text != (char *) NULL)
     svg_info->text=(char *) ResizeQuantumMemory(svg_info->text,
@@ -2416,7 +2444,7 @@ static void SVGCharacters(void *context,const xmlChar *c,int length)
   if (svg_info->text == (char *) NULL)
     return;
   p=svg_info->text+strlen(svg_info->text);
-  for (i=0; i < (long) length; i++)
+  for (i=0; i < (ssize_t) length; i++)
     *p++=c[i];
   *p='\0';
 }
@@ -2457,6 +2485,7 @@ static void SVGIgnorableWhitespace(void *context,const xmlChar *c,int length)
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
     "  SAX.ignorableWhitespace(%.30s, %d)",c,length);
   svg_info=(SVGInfo *) context;
+  (void) svg_info;
 }
 
 static void SVGProcessingInstructions(void *context,const xmlChar *target,
@@ -2471,6 +2500,7 @@ static void SVGProcessingInstructions(void *context,const xmlChar *target,
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
     "  SAX.processingInstruction(%s, %s)",target,data);
   svg_info=(SVGInfo *) context;
+  (void) svg_info;
 }
 
 static void SVGComment(void *context,const xmlChar *value)
@@ -2647,7 +2677,6 @@ static void SVGExternalSubset(void *context,const xmlChar *name,
 }
 
 #if defined(MAGICKCORE_RSVG_DELEGATE)
-#if !defined(MAGICKCORE_CAIRO_DELEGATE)
 static void SVGSetImageSize(int *width,int *height,gpointer context)
 {
   Image
@@ -2658,7 +2687,6 @@ static void SVGSetImageSize(int *width,int *height,gpointer context)
   *height=(int) (*height*image->y_resolution/72.0);
 }
 #endif
-#endif
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }
@@ -2679,7 +2707,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
     status,
     unique_file;
 
-  long
+  ssize_t
     n;
 
   SVGInfo
@@ -2689,7 +2717,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
     message[MaxTextExtent];
 
   xmlSAXHandler
-    SAXModules;
+    sax_modules;
 
   xmlSAXHandlerPtr
     sax_handler;
@@ -2742,13 +2770,13 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
       GError
         *error;
 
-      long
+      ssize_t
         y;
 
       PixelPacket
         fill_color;
 
-      register long
+      register ssize_t
         x;
 
       register PixelPacket
@@ -2761,9 +2789,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
       if (svg_handle == (RsvgHandle *) NULL)
         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
       rsvg_handle_set_base_uri(svg_handle,image_info->filename);
-#if !defined(MAGICKCORE_CAIRO_DELEGATE)
       rsvg_handle_set_size_callback(svg_handle,SVGSetImageSize,image,NULL);
-#endif
       if ((image->x_resolution != 72.0) && (image->y_resolution != 72.0))
         rsvg_handle_set_dpi_x_y(svg_handle,image->x_resolution,
           image->y_resolution);
@@ -2780,16 +2806,21 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
         g_error_free(error);
 #if defined(MAGICKCORE_CAIRO_DELEGATE)
       rsvg_handle_get_dimensions(svg_handle,&dimension_info);
-      image->columns=dimension_info.width*image->x_resolution/72.0;
-      image->rows=dimension_info.height*image->y_resolution/72.0;
-      pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4*
-        image->rows*sizeof(*pixels));
+      image->columns=dimension_info.width;
+      image->rows=dimension_info.height;
+      pixels=(unsigned char *) NULL;
 #else
       pixel_info=rsvg_handle_get_pixbuf(svg_handle);
       rsvg_handle_free(svg_handle);
       image->columns=gdk_pixbuf_get_width(pixel_info);
       image->rows=gdk_pixbuf_get_height(pixel_info);
 #endif
+      image->matte=MagickTrue;
+      SetImageProperty(image,"svg:base-uri",
+        rsvg_handle_get_base_uri(svg_handle));
+      SetImageProperty(image,"svg:title",rsvg_handle_get_title(svg_handle));
+      SetImageProperty(image,"svg:description",
+        rsvg_handle_get_desc(svg_handle));
       if ((image->columns == 0) || (image->rows == 0))
         {
 #if !defined(MAGICKCORE_CAIRO_DELEGATE)
@@ -2799,74 +2830,86 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
           ThrowReaderException(MissingDelegateError,
             "NoDecodeDelegateForThisImageFormat");
         }
-#if defined(MAGICKCORE_CAIRO_DELEGATE)
-      if (pixels == (unsigned char *) NULL)
+      if (image_info->ping == MagickFalse)
         {
-          g_object_unref(svg_handle);
-          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-        }
+#if defined(MAGICKCORE_CAIRO_DELEGATE)
+          pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4*
+            image->rows*sizeof(*pixels));
+          if (pixels == (unsigned char *) NULL)
+            {
+              g_object_unref(svg_handle);
+              ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+            }
 #endif
-      image->matte=MagickTrue;
-      (void) SetImageBackgroundColor(image);
-      SetImageProperty(image,"svg:base-uri",
-        rsvg_handle_get_base_uri(svg_handle));
-      SetImageProperty(image,"svg:title",rsvg_handle_get_title(svg_handle));
-      SetImageProperty(image,"svg:description",
-        rsvg_handle_get_desc(svg_handle));
+          (void) SetImageBackgroundColor(image);
 #if defined(MAGICKCORE_CAIRO_DELEGATE)
-      cairo_surface=cairo_image_surface_create_for_data(pixels,
-        CAIRO_FORMAT_ARGB32,image->columns,image->rows,4*image->columns);
-      if (cairo_surface == (cairo_surface_t *) NULL)
-        {
-          pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+          cairo_surface=cairo_image_surface_create_for_data(pixels,
+            CAIRO_FORMAT_ARGB32,image->columns,image->rows,4*image->columns);
+          if (cairo_surface == (cairo_surface_t *) NULL)
+            {
+              pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+              g_object_unref(svg_handle);
+              ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+            }
+          cairo_info=cairo_create(cairo_surface);
+          cairo_set_operator(cairo_info,CAIRO_OPERATOR_CLEAR);
+          cairo_paint(cairo_info);
+          cairo_set_operator(cairo_info,CAIRO_OPERATOR_OVER);
+          rsvg_handle_render_cairo(svg_handle,cairo_info);
+          cairo_destroy(cairo_info);
+          cairo_surface_destroy(cairo_surface);
           g_object_unref(svg_handle);
-          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-        }
-      cairo_info=cairo_create(cairo_surface);
-      cairo_scale(cairo_info,image->x_resolution/72.0,image->y_resolution/72.0);
-      cairo_set_operator(cairo_info,CAIRO_OPERATOR_CLEAR);
-      cairo_paint(cairo_info);
-      cairo_set_operator(cairo_info,CAIRO_OPERATOR_OVER);
-      rsvg_handle_render_cairo(svg_handle,cairo_info);
-      cairo_destroy(cairo_info);
-      cairo_surface_destroy(cairo_surface);
-      g_object_unref(svg_handle);
-      p=pixels;
+          p=pixels;
 #else
-      p=gdk_pixbuf_get_pixels(pixel_info);
+          p=gdk_pixbuf_get_pixels(pixel_info);
 #endif
-      for (y=0; y < (long) image->rows; y++)
-      {
-        q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (PixelPacket *) NULL)
-          break;
-        for (x=0; x < (long) image->columns; x++)
-        {
+          for (y=0; y < (ssize_t) image->rows; y++)
+          {
+            q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+            if (q == (PixelPacket *) NULL)
+              break;
+            for (x=0; x < (ssize_t) image->columns; x++)
+            {
 #if defined(MAGICKCORE_CAIRO_DELEGATE)
-          fill_color.blue=ScaleCharToQuantum(*p++);
-          fill_color.green=ScaleCharToQuantum(*p++);
-          fill_color.red=ScaleCharToQuantum(*p++);
+              fill_color.blue=ScaleCharToQuantum(*p++);
+              fill_color.green=ScaleCharToQuantum(*p++);
+              fill_color.red=ScaleCharToQuantum(*p++);
 #else
-          fill_color.red=ScaleCharToQuantum(*p++);
-          fill_color.green=ScaleCharToQuantum(*p++);
-          fill_color.blue=ScaleCharToQuantum(*p++);
+              fill_color.red=ScaleCharToQuantum(*p++);
+              fill_color.green=ScaleCharToQuantum(*p++);
+              fill_color.blue=ScaleCharToQuantum(*p++);
 #endif
-          fill_color.opacity=QuantumRange-ScaleCharToQuantum(*p++);
-          MagickCompositeOver(&fill_color,fill_color.opacity,q,(MagickRealType)
-            q->opacity,q);
-          q++;
-        }
-        if (SyncAuthenticPixels(image,exception) == MagickFalse)
-          break;
-        if (image->previous == (Image *) NULL)
-          {
-            status=SetImageProgress(image,LoadImageTag,y,image->rows);
-            if (status == MagickFalse)
+              fill_color.opacity=QuantumRange-ScaleCharToQuantum(*p++);
+#if defined(MAGICKCORE_CAIRO_DELEGATE)
+              {
+                double
+                  gamma;
+    
+                gamma=1.0-QuantumScale*fill_color.opacity;
+                gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+                fill_color.blue*=gamma;
+                fill_color.green*=gamma;
+                fill_color.red*=gamma;
+              }
+#endif
+              MagickCompositeOver(&fill_color,fill_color.opacity,q,
+                (MagickRealType) q->opacity,q);
+              q++;
+            }
+            if (SyncAuthenticPixels(image,exception) == MagickFalse)
               break;
+            if (image->previous == (Image *) NULL)
+              {
+                status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+                image->rows);
+                if (status == MagickFalse)
+                  break;
+              }
           }
-      }
+        }
 #if defined(MAGICKCORE_CAIRO_DELEGATE)
-      pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+      if (pixels != (unsigned char *) NULL)
+        pixels=(unsigned char *) RelinquishMagickMemory(pixels);
 #else
       g_object_unref(G_OBJECT(pixel_info));
 #endif
@@ -2907,35 +2950,35 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
     (void) LogMagickEvent(CoderEvent,GetMagickModule(),"begin SAX");
   xmlInitParser();
   (void) xmlSubstituteEntitiesDefault(1);
-  (void) ResetMagickMemory(&SAXModules,0,sizeof(SAXModules));
-  SAXModules.internalSubset=SVGInternalSubset;
-  SAXModules.isStandalone=SVGIsStandalone;
-  SAXModules.hasInternalSubset=SVGHasInternalSubset;
-  SAXModules.hasExternalSubset=SVGHasExternalSubset;
-  SAXModules.resolveEntity=SVGResolveEntity;
-  SAXModules.getEntity=SVGGetEntity;
-  SAXModules.entityDecl=SVGEntityDeclaration;
-  SAXModules.notationDecl=SVGNotationDeclaration;
-  SAXModules.attributeDecl=SVGAttributeDeclaration;
-  SAXModules.elementDecl=SVGElementDeclaration;
-  SAXModules.unparsedEntityDecl=SVGUnparsedEntityDeclaration;
-  SAXModules.setDocumentLocator=SVGSetDocumentLocator;
-  SAXModules.startDocument=SVGStartDocument;
-  SAXModules.endDocument=SVGEndDocument;
-  SAXModules.startElement=SVGStartElement;
-  SAXModules.endElement=SVGEndElement;
-  SAXModules.reference=SVGReference;
-  SAXModules.characters=SVGCharacters;
-  SAXModules.ignorableWhitespace=SVGIgnorableWhitespace;
-  SAXModules.processingInstruction=SVGProcessingInstructions;
-  SAXModules.comment=SVGComment;
-  SAXModules.warning=SVGWarning;
-  SAXModules.error=SVGError;
-  SAXModules.fatalError=SVGError;
-  SAXModules.getParameterEntity=SVGGetParameterEntity;
-  SAXModules.cdataBlock=SVGCDataBlock;
-  SAXModules.externalSubset=SVGExternalSubset;
-  sax_handler=(&SAXModules);
+  (void) ResetMagickMemory(&sax_modules,0,sizeof(sax_modules));
+  sax_modules.internalSubset=SVGInternalSubset;
+  sax_modules.isStandalone=SVGIsStandalone;
+  sax_modules.hasInternalSubset=SVGHasInternalSubset;
+  sax_modules.hasExternalSubset=SVGHasExternalSubset;
+  sax_modules.resolveEntity=SVGResolveEntity;
+  sax_modules.getEntity=SVGGetEntity;
+  sax_modules.entityDecl=SVGEntityDeclaration;
+  sax_modules.notationDecl=SVGNotationDeclaration;
+  sax_modules.attributeDecl=SVGAttributeDeclaration;
+  sax_modules.elementDecl=SVGElementDeclaration;
+  sax_modules.unparsedEntityDecl=SVGUnparsedEntityDeclaration;
+  sax_modules.setDocumentLocator=SVGSetDocumentLocator;
+  sax_modules.startDocument=SVGStartDocument;
+  sax_modules.endDocument=SVGEndDocument;
+  sax_modules.startElement=SVGStartElement;
+  sax_modules.endElement=SVGEndElement;
+  sax_modules.reference=SVGReference;
+  sax_modules.characters=SVGCharacters;
+  sax_modules.ignorableWhitespace=SVGIgnorableWhitespace;
+  sax_modules.processingInstruction=SVGProcessingInstructions;
+  sax_modules.comment=SVGComment;
+  sax_modules.warning=SVGWarning;
+  sax_modules.error=SVGError;
+  sax_modules.fatalError=SVGError;
+  sax_modules.getParameterEntity=SVGGetParameterEntity;
+  sax_modules.cdataBlock=SVGCDataBlock;
+  sax_modules.externalSubset=SVGExternalSubset;
+  sax_handler=(&sax_modules);
   n=ReadBlob(image,MaxTextExtent,message);
   if (n > 0)
     {
@@ -3020,10 +3063,10 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
 %
 %  The format of the RegisterSVGImage method is:
 %
-%      unsigned long RegisterSVGImage(void)
+%      size_t RegisterSVGImage(void)
 %
 */
-ModuleExport unsigned long RegisterSVGImage(void)
+ModuleExport size_t RegisterSVGImage(void)
 {
   char
     version[MaxTextExtent];
@@ -3188,8 +3231,8 @@ static void AffineToTransform(Image *image,AffineMatrix *affine)
         }
     }
   (void) FormatMagickString(transform,MaxTextExtent,
-    "\" transform=\"matrix(%g %g %g %g %g %g)\">\n",affine->sx,affine->rx,
-    affine->ry,affine->sy,affine->tx,affine->ty);
+    "\" transform=\"matrix(%g %g %g %g %g %g)\">\n",
+    affine->sx,affine->rx,affine->ry,affine->sy,affine->tx,affine->ty);
   (void) WriteBlobString(image,transform);
 }
 
@@ -3198,22 +3241,23 @@ static MagickBooleanType IsPoint(const char *point)
   char
     *p;
 
-  long
+  ssize_t
     value;
 
   value=strtol(point,&p,10);
+  (void) value;
   return(p != point ? MagickTrue : MagickFalse);
 }
 
 static MagickBooleanType TraceSVGImage(Image *image)
 {
-  long
+  ssize_t
     y;
 
   register const PixelPacket
     *p;
 
-  register long
+  register ssize_t
     x;
 
 #if defined(MAGICKCORE_AUTOTRACE_DELEGATE)
@@ -3233,10 +3277,10 @@ static MagickBooleanType TraceSVGImage(Image *image)
     ImageType
       type;
 
-    register long
+    register ssize_t
       i;
 
-    unsigned long
+    size_t
       number_planes;
 
     /*
@@ -3250,18 +3294,18 @@ static MagickBooleanType TraceSVGImage(Image *image)
       number_planes=1;
     trace=at_bitmap_new(image->columns,image->rows,number_planes);
     i=0;
-    for (y=0; y < (long) image->rows; y++)
+    for (y=0; y < (ssize_t) image->rows; y++)
     {
       p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
       if (p == (const PixelPacket *) NULL)
         break;
-      for (x=0; x < (long) image->columns; x++)
+      for (x=0; x < (ssize_t) image->columns; x++)
       {
-        trace->bitmap[i++]=p->red;
+        trace->bitmap[i++]=GetRedPixelComponent(p);
         if (number_planes == 3)
           {
-            trace->bitmap[i++]=p->green;
-            trace->bitmap[i++]=p->blue;
+            trace->bitmap[i++]=GetGreenPixelComponent(p);
+            trace->bitmap[i++]=GetBluePixelComponent(p);
           }
         p++;
       }
@@ -3297,22 +3341,24 @@ static MagickBooleanType TraceSVGImage(Image *image)
     (void) WriteBlobString(image,
       "  \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
     (void) FormatMagickString(message,MaxTextExtent,
-      "<svg width=\"%lu\" height=\"%lu\">\n",image->columns,image->rows);
+      "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) image->columns,
+      (double) image->rows);
     (void) WriteBlobString(image,message);
     GetMagickPixelPacket(image,&pixel);
-    for (y=0; y < (long) image->rows; y++)
+    for (y=0; y < (ssize_t) image->rows; y++)
     {
       p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetVirtualIndexQueue(image);
-      for (x=0; x < (long) image->columns; x++)
+      for (x=0; x < (ssize_t) image->columns; x++)
       {
         SetMagickPixelPacket(image,p,indexes+x,&pixel);
         (void) QueryMagickColorname(image,&pixel,SVGCompliance,tuple,
           &image->exception);
         (void) FormatMagickString(message,MaxTextExtent,
-          "  <circle cx=\"%ld\" cy=\"%ld\" r=\"1\" fill=\"%s\"/>\n",x,y,tuple);
+          "  <circle cx=\"%.20g\" cy=\"%.20g\" r=\"1\" fill=\"%s\"/>\n",
+          (double) x,(double) y,tuple);
         (void) WriteBlobString(image,message);
         p++;
       }
@@ -3345,7 +3391,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
   int
     n;
 
-  long
+  ssize_t
     j;
 
   MagickBooleanType
@@ -3361,10 +3407,10 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
   PrimitiveType
     primitive_type;
 
-  register long
+  register ssize_t
     x;
 
-  register long
+  register ssize_t
     i;
 
   size_t
@@ -3373,7 +3419,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
   SVGInfo
     svg_info;
 
-  unsigned long
+  size_t
     number_points;
 
   /*
@@ -3407,7 +3453,8 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
   (void) WriteBlobString(image,
     "  \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
   (void) FormatMagickString(message,MaxTextExtent,
-    "<svg width=\"%lu\" height=\"%lu\">\n",image->columns,image->rows);
+    "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) image->columns,(double)
+    image->rows);
   (void) WriteBlobString(image,message);
   /*
     Allocate primitive info memory.
@@ -3464,34 +3511,34 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
         if (LocaleCompare("affine",keyword) == 0)
           {
             GetMagickToken(q,&q,token);
-            affine.sx=atof(token);
+            affine.sx=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.rx=atof(token);
+            affine.rx=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.ry=atof(token);
+            affine.ry=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.sy=atof(token);
+            affine.sy=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.tx=atof(token);
+            affine.tx=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.ty=atof(token);
+            affine.ty=StringToDouble(token);
             break;
           }
         if (LocaleCompare("angle",keyword) == 0)
           {
             GetMagickToken(q,&q,token);
-            affine.rx=atof(token);
-            affine.ry=atof(token);
+            affine.rx=StringToDouble(token);
+            affine.ry=StringToDouble(token);
             break;
           }
         if (LocaleCompare("arc",keyword) == 0)
@@ -3806,23 +3853,23 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
                 GetMagickToken(q,&q,token);
                 (void) CopyMagickString(type,token,MaxTextExtent);
                 GetMagickToken(q,&q,token);
-                svg_info.segment.x1=atof(token);
-                svg_info.element.cx=atof(token);
+                svg_info.segment.x1=StringToDouble(token);
+                svg_info.element.cx=StringToDouble(token);
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                svg_info.segment.y1=atof(token);
-                svg_info.element.cy=atof(token);
+                svg_info.segment.y1=StringToDouble(token);
+                svg_info.element.cy=StringToDouble(token);
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                svg_info.segment.x2=atof(token);
-                svg_info.element.major=atof(token);
+                svg_info.segment.x2=StringToDouble(token);
+                svg_info.element.major=StringToDouble(token);
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                svg_info.segment.y2=atof(token);
-                svg_info.element.minor=atof(token);
+                svg_info.segment.y2=StringToDouble(token);
+                svg_info.element.minor=StringToDouble(token);
                 (void) FormatMagickString(message,MaxTextExtent,
                   "<%sGradient id=\"%s\" x1=\"%g\" y1=\"%g\" x2=\"%g\" "
                   "y2=\"%g\">\n",type,name,svg_info.segment.x1,
@@ -3832,12 +3879,13 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
                     GetMagickToken(q,&q,token);
                     if (*token == ',')
                       GetMagickToken(q,&q,token);
-                    svg_info.element.angle=atof(token);
+                    svg_info.element.angle=StringToDouble(token);
                     (void) FormatMagickString(message,MaxTextExtent,
                       "<%sGradient id=\"%s\" cx=\"%g\" cy=\"%g\" r=\"%g\" "
-                      "fx=\"%g\" fy=\"%g\">\n",type,name,svg_info.element.cx,
-                      svg_info.element.cy,svg_info.element.angle,
-                      svg_info.element.major,svg_info.element.minor);
+                      "fx=\"%g\" fy=\"%g\">\n",type,name,
+                      svg_info.element.cx,svg_info.element.cy,
+                      svg_info.element.angle,svg_info.element.major,
+                      svg_info.element.minor);
                   }
                 (void) WriteBlobString(image,message);
                 break;
@@ -3858,23 +3906,24 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
                 GetMagickToken(q,&q,token);
                 (void) CopyMagickString(name,token,MaxTextExtent);
                 GetMagickToken(q,&q,token);
-                svg_info.bounds.x=atof(token);
+                svg_info.bounds.x=StringToDouble(token);
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                svg_info.bounds.y=atof(token);
+                svg_info.bounds.y=StringToDouble(token);
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                svg_info.bounds.width=atof(token);
+                svg_info.bounds.width=StringToDouble(token);
                 GetMagickToken(q,&q,token);
                 if (*token == ',')
                   GetMagickToken(q,&q,token);
-                svg_info.bounds.height=atof(token);
+                svg_info.bounds.height=StringToDouble(token);
                 (void) FormatMagickString(message,MaxTextExtent,
                   "<pattern id=\"%s\" x=\"%g\" y=\"%g\" width=\"%g\" "
-                  "height=\"%g\">\n",name,svg_info.bounds.x,svg_info.bounds.y,
-                  svg_info.bounds.width,svg_info.bounds.height);
+                  "height=\"%g\">\n",name,svg_info.bounds.x,
+                  svg_info.bounds.y,svg_info.bounds.width,
+                  svg_info.bounds.height);
                 (void) WriteBlobString(image,message);
                 break;
               }
@@ -3913,11 +3962,11 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
         if (LocaleCompare("scale",keyword) == 0)
           {
             GetMagickToken(q,&q,token);
-            affine.sx=atof(token);
+            affine.sx=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.sy=atof(token);
+            affine.sy=StringToDouble(token);
             break;
           }
         if (LocaleCompare("skewX",keyword) == 0)
@@ -3969,7 +4018,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
           {
             if (IsPoint(q))
               {
-                long
+                ssize_t
                   k;
 
                 p=q;
@@ -4068,11 +4117,11 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
         if (LocaleCompare("translate",keyword) == 0)
           {
             GetMagickToken(q,&q,token);
-            affine.tx=atof(token);
+            affine.tx=StringToDouble(token);
             GetMagickToken(q,&q,token);
             if (*token == ',')
               GetMagickToken(q,&q,token);
-            affine.ty=atof(token);
+            affine.ty=StringToDouble(token);
             break;
           }
         status=MagickFalse;
@@ -4121,11 +4170,11 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
       if (IsPoint(q) == MagickFalse)
         break;
       GetMagickToken(q,&q,token);
-      point.x=atof(token);
+      point.x=StringToDouble(token);
       GetMagickToken(q,&q,token);
       if (*token == ',')
         GetMagickToken(q,&q,token);
-      point.y=atof(token);
+      point.y=StringToDouble(token);
       GetMagickToken(q,(const char **) NULL,token);
       if (*token == ',')
         GetMagickToken(q,&q,token);
@@ -4134,7 +4183,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
       primitive_info[i].coordinates=0;
       primitive_info[i].method=FloodfillMethod;
       i++;
-      if (i < (long) (number_points-6*BezierQuantum-360))
+      if (i < (ssize_t) (number_points-6*BezierQuantum-360))
         continue;
       number_points+=6*BezierQuantum+360;
       primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
@@ -4206,10 +4255,11 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
           }
         (void) FormatMagickString(message,MaxTextExtent,
           "  <rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" "
-          "ry=\"%g\"/>\n",primitive_info[j].point.x,primitive_info[j].point.y,
-          primitive_info[j+1].point.x-primitive_info[j].point.x,
-          primitive_info[j+1].point.y-primitive_info[j].point.y,
-          primitive_info[j+2].point.x,primitive_info[j+2].point.y);
+          "ry=\"%g\"/>\n",primitive_info[j].point.x,
+          primitive_info[j].point.y,primitive_info[j+1].point.x-
+          primitive_info[j].point.x,primitive_info[j+1].point.y-
+          primitive_info[j].point.y,primitive_info[j+2].point.x,
+          primitive_info[j+2].point.y);
         (void) WriteBlobString(image,message);
         break;
       }
@@ -4329,7 +4379,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image)
         for (p=token; *p != '\0'; p++)
           if (isalpha((int) *p))
             number_attributes++;
-        if (i > (long) (number_points-6*BezierQuantum*number_attributes-1))
+        if (i > (ssize_t) (number_points-6*BezierQuantum*number_attributes-1))
           {
             number_points+=6*BezierQuantum*number_attributes;
             primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,