https://github.com/ImageMagick/ImageMagick/issues/1465
diff --git a/coders/svg.c b/coders/svg.c
index 60af0dc..cd20853 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -74,6 +74,7 @@
#include "MagickCore/string-private.h"
#include "MagickCore/token.h"
#include "MagickCore/utility.h"
+
#if defined(MAGICKCORE_XML_DELEGATE)
# if defined(MAGICKCORE_WINDOWS_SUPPORT)
# if !defined(__MINGW32__)
@@ -194,6 +195,12 @@
} SVGInfo;
/*
+ Static declarations.
+*/
+static char
+ SVGDensityGeometry[] = "96.0x96.0";
+
+/*
Forward declarations.
*/
static MagickBooleanType
@@ -237,7 +244,6 @@
return(MagickFalse);
}
-#if defined(MAGICKCORE_XML_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
@@ -265,6 +271,89 @@
%
*/
+static Image *RenderSVGImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
+{
+ char
+ background[MagickPathExtent],
+ command[MagickPathExtent],
+ *density,
+ input_filename[MagickPathExtent],
+ opacity[MagickPathExtent],
+ output_filename[MagickPathExtent],
+ unique[MagickPathExtent];
+
+ const DelegateInfo
+ *delegate_info;
+
+ Image
+ *next;
+
+ int
+ status;
+
+ struct stat
+ attributes;
+
+ /*
+ Our best hope for compliance with the SVG standard.
+ */
+ delegate_info=GetDelegateInfo("svg:decode",(char *) NULL,exception);
+ if (delegate_info == (const DelegateInfo *) NULL)
+ return((Image *) NULL);
+ status=AcquireUniqueSymbolicLink(image->filename,input_filename);
+ (void) AcquireUniqueFilename(output_filename);
+ (void) AcquireUniqueFilename(unique);
+ density=AcquireString("");
+ (void) FormatLocaleString(density,MagickPathExtent,"%.20g,%.20g",
+ image->resolution.x,image->resolution.y);
+ (void) FormatLocaleString(background,MagickPathExtent,
+ "rgb(%.20g%%,%.20g%%,%.20g%%)",
+ 100.0*QuantumScale*image->background_color.red,
+ 100.0*QuantumScale*image->background_color.green,
+ 100.0*QuantumScale*image->background_color.blue);
+ (void) FormatLocaleString(opacity,MagickPathExtent,"%.20g",QuantumScale*
+ image->background_color.alpha);
+ (void) FormatLocaleString(command,MagickPathExtent,
+ GetDelegateCommands(delegate_info),input_filename,output_filename,density,
+ background,opacity,unique);
+ density=DestroyString(density);
+ status=ExternalDelegateCommand(MagickFalse,image_info->verbose,command,
+ (char *) NULL,exception);
+ (void) RelinquishUniqueFileResource(unique);
+ (void) RelinquishUniqueFileResource(input_filename);
+ if ((status == 0) && (stat(output_filename,&attributes) == 0) &&
+ (attributes.st_size > 0))
+ {
+ Image
+ *svg_image;
+
+ ImageInfo
+ *read_info;
+
+ read_info=CloneImageInfo(image_info);
+ (void) CopyMagickString(read_info->filename,output_filename,
+ MagickPathExtent);
+ svg_image=ReadImage(read_info,exception);
+ read_info=DestroyImageInfo(read_info);
+ if (svg_image != (Image *) NULL)
+ {
+ (void) RelinquishUniqueFileResource(output_filename);
+ for (next=GetFirstImageInList(svg_image); next != (Image *) NULL; )
+ {
+ (void) CopyMagickString(next->filename,image->filename,
+ MaxTextExtent);
+ (void) CopyMagickString(next->magick,image->magick,MaxTextExtent);
+ next=GetNextImageInList(next);
+ }
+ return(svg_image);
+ }
+ }
+ (void) RelinquishUniqueFileResource(output_filename);
+ return((Image *) NULL);
+}
+
+#if defined(MAGICKCORE_XML_DELEGATE)
static SVGInfo *AcquireSVGInfo(void)
{
SVGInfo
@@ -3094,12 +3183,6 @@
}
#endif
-/*
- Static declarations.
-*/
-static char
- SVGDensityGeometry[] = "96.0x96.0";
-
static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
@@ -3165,81 +3248,14 @@
}
if (LocaleCompare(image_info->magick,"MSVG") != 0)
{
- const DelegateInfo
- *delegate_info;
+ Image
+ *svg_image;
- delegate_info=GetDelegateInfo("svg:decode",(char *) NULL,exception);
- if (delegate_info != (const DelegateInfo *) NULL)
+ svg_image=RenderSVGImage(image_info,image,exception);
+ if (svg_image != (Image *) NULL)
{
- char
- background[MagickPathExtent],
- command[MagickPathExtent],
- *density,
- input_filename[MagickPathExtent],
- opacity[MagickPathExtent],
- output_filename[MagickPathExtent],
- unique[MagickPathExtent];
-
- int
- status;
-
- struct stat
- attributes;
-
- /*
- Our best hope for compliance with the SVG standard.
- */
- status=AcquireUniqueSymbolicLink(image->filename,input_filename);
- (void) AcquireUniqueFilename(output_filename);
- (void) AcquireUniqueFilename(unique);
- density=AcquireString("");
- (void) FormatLocaleString(density,MagickPathExtent,"%.20g,%.20g",
- image->resolution.x,image->resolution.y);
- (void) FormatLocaleString(background,MagickPathExtent,
- "rgb(%.20g%%,%.20g%%,%.20g%%)",
- 100.0*QuantumScale*image->background_color.red,
- 100.0*QuantumScale*image->background_color.green,
- 100.0*QuantumScale*image->background_color.blue);
- (void) FormatLocaleString(opacity,MagickPathExtent,"%.20g",
- QuantumScale*image->background_color.alpha);
- (void) FormatLocaleString(command,MagickPathExtent,
- GetDelegateCommands(delegate_info),input_filename,output_filename,
- density,background,opacity,unique);
- density=DestroyString(density);
- status=ExternalDelegateCommand(MagickFalse,image_info->verbose,
- command,(char *) NULL,exception);
- (void) RelinquishUniqueFileResource(unique);
- (void) RelinquishUniqueFileResource(input_filename);
- if ((status == 0) && (stat(output_filename,&attributes) == 0) &&
- (attributes.st_size > 0))
- {
- Image
- *svg_image;
-
- ImageInfo
- *read_info;
-
- read_info=CloneImageInfo(image_info);
- (void) CopyMagickString(read_info->filename,output_filename,
- MagickPathExtent);
- svg_image=ReadImage(read_info,exception);
- read_info=DestroyImageInfo(read_info);
- (void) RelinquishUniqueFileResource(output_filename);
- if (svg_image != (Image *) NULL)
- {
- for (next=GetFirstImageInList(svg_image); next != (Image *) NULL; )
- {
- (void) CopyMagickString(next->filename,image->filename,
- MaxTextExtent);
- (void) CopyMagickString(next->magick,image->magick,
- MaxTextExtent);
- next=GetNextImageInList(next);
- }
- image=DestroyImage(image);
- return(svg_image);
- }
- }
- (void) RelinquishUniqueFileResource(output_filename);
+ image=DestroyImageList(image);
+ return(svg_image);
}
{
#if defined(MAGICKCORE_RSVG_DELEGATE)
@@ -3634,6 +3650,49 @@
(void) RelinquishUniqueFileResource(filename);
return(GetFirstImageInList(image));
}
+#else
+static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
+{
+ Image
+ *image,
+ *svg_image;
+
+ MagickBooleanType
+ status;
+
+ assert(image_info != (const ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ assert(exception != (ExceptionInfo *) NULL);
+ if (image_info->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+ image_info->filename);
+ assert(exception->signature == MagickCoreSignature);
+ image=AcquireImage(image_info,exception);
+ status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+ if (status == MagickFalse)
+ {
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
+ if ((fabs(image->resolution.x) < MagickEpsilon) ||
+ (fabs(image->resolution.y) < MagickEpsilon))
+ {
+ GeometryInfo
+ geometry_info;
+
+ MagickStatusType
+ flags;
+
+ flags=ParseGeometry(SVGDensityGeometry,&geometry_info);
+ image->resolution.x=geometry_info.rho;
+ image->resolution.y=geometry_info.sigma;
+ if ((flags & SigmaValue) == 0)
+ image->resolution.y=image->resolution.x;
+ }
+ svg_image=RenderSVGImage(image_info,image,exception);
+ image=DestroyImage(image);
+ return(svg_image);
+}
#endif
/*
@@ -3683,9 +3742,7 @@
LIBRSVG_MAJOR_VERSION,LIBRSVG_MINOR_VERSION,LIBRSVG_MICRO_VERSION);
#endif
entry=AcquireMagickInfo("SVG","SVG","Scalable Vector Graphics");
-#if defined(MAGICKCORE_XML_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadSVGImage;
-#endif
entry->encoder=(EncodeImageHandler *) WriteSVGImage;
entry->flags^=CoderBlobSupportFlag;
#if defined(MAGICKCORE_RSVG_DELEGATE)
@@ -3846,7 +3903,7 @@
ssize_t
value;
- value=strtol(point,&p,10);
+ value=(ssize_t) strtol(point,&p,10);
(void) value;
return(p != point ? MagickTrue : MagickFalse);
}
@@ -4000,7 +4057,7 @@
(void) WriteBlobString(image,"</svg>\n");
}
#endif
- CloseBlob(image);
+ (void) CloseBlob(image);
return(MagickTrue);
}
@@ -4134,7 +4191,7 @@
case '<': (void) WriteBlobString(image,"<"); break;
case '>': (void) WriteBlobString(image,">"); break;
case '&': (void) WriteBlobString(image,"&"); break;
- default: (void) WriteBlobByte(image,*q); break;
+ default: (void) WriteBlobByte(image,(unsigned char) *q); break;
}
(void) WriteBlobString(image,"</desc>\n");
continue;
@@ -4863,7 +4920,7 @@
}
}
primitive_info[j].primitive=primitive_type;
- primitive_info[j].coordinates=x;
+ primitive_info[j].coordinates=(size_t) x;
primitive_info[j].method=FloodfillMethod;
primitive_info[j].text=(char *) NULL;
if (active)
@@ -5107,7 +5164,7 @@
case '<': (void) WriteBlobString(image,"<"); break;
case '>': (void) WriteBlobString(image,">"); break;
case '&': (void) WriteBlobString(image,"&"); break;
- default: (void) WriteBlobByte(image,*p); break;
+ default: (void) WriteBlobByte(image,(unsigned char) *p); break;
}
(void) WriteBlobString(image,"</text>\n");
break;