From: Cristy Date: Sun, 3 Feb 2019 12:23:20 +0000 (-0500) Subject: https://github.com/ImageMagick/ImageMagick/issues/1465 X-Git-Tag: 7.0.8-26~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fedaa752e53f37258139fcc8802aad426f111bc0;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/1465 --- diff --git a/coders/svg.c b/coders/svg.c index 60af0dc63..cd2085378 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__) @@ -193,6 +194,12 @@ typedef struct _SVGInfo svgDepth; } SVGInfo; +/* + Static declarations. +*/ +static char + SVGDensityGeometry[] = "96.0x96.0"; + /* Forward declarations. */ @@ -237,7 +244,6 @@ static MagickBooleanType IsSVG(const unsigned char *magick,const size_t length) return(MagickFalse); } -#if defined(MAGICKCORE_XML_DELEGATE) /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % @@ -265,6 +271,89 @@ static MagickBooleanType IsSVG(const unsigned char *magick,const size_t length) % */ +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 @@ static void SVGExternalSubset(void *context,const xmlChar *name, } #endif -/* - Static declarations. -*/ -static char - SVGDensityGeometry[] = "96.0x96.0"; - static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception) { char @@ -3165,81 +3248,14 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception) } 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 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception) (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 @@ ModuleExport size_t RegisterSVGImage(void) 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 @@ static MagickBooleanType IsPoint(const char *point) 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 @@ static MagickBooleanType TraceSVGImage(Image *image,ExceptionInfo *exception) (void) WriteBlobString(image,"\n"); } #endif - CloseBlob(image); + (void) CloseBlob(image); return(MagickTrue); } @@ -4134,7 +4191,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image, 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,"\n"); continue; @@ -4863,7 +4920,7 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image, } } 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 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image, 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,"\n"); break;