]> granicus.if.org Git - imagemagick/blobdiff - coders/svg.c
Added support for writing RLE compressed TGA files.
[imagemagick] / coders / svg.c
index b13881f670879b45ac20b214dca352afcb317398..e94646142b429ed9e6b36062aa4fbe82416e97cf 100644 (file)
 %                  Read/Write Scalable Vector Graphics Format                 %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                             William Radcliffe                               %
 %                                March 2000                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 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  %
@@ -278,7 +278,7 @@ static SVGInfo *DestroySVGInfo(SVGInfo *svg_info)
   if (svg_info->text != (char *) NULL)
     svg_info->text=DestroyString(svg_info->text);
   if (svg_info->scale != (double *) NULL)
-    svg_info->scale=(double *) (svg_info->scale);
+    svg_info->scale=(double *) RelinquishMagickMemory(svg_info->scale);
   if (svg_info->title != (char *) NULL)
     svg_info->title=DestroyString(svg_info->title);
   if (svg_info->comment != (char *) NULL)
@@ -2875,6 +2875,9 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
         cairo_t
           *cairo_image;
 
+        MemoryInfo
+          *pixel_info;
+
         register unsigned char
           *p;
 
@@ -2886,7 +2889,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
 
 #else
         GdkPixbuf
-          *pixel_info;
+          *pixel_buffer;
 
         register const guchar
           *p;
@@ -2915,8 +2918,9 @@ 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);
-        rsvg_handle_set_dpi_x_y(svg_handle,image->resolution.x,
-          image->resolution.y);
+        if ((image->resolution.x != 90.0) && (image->resolution.y != 90.0))
+          rsvg_handle_set_dpi_x_y(svg_handle,image->resolution.x,
+            image->resolution.y);
         while ((n=ReadBlob(image,MaxTextExtent,message)) != 0)
         {
           error=(GError *) NULL;
@@ -2930,14 +2934,14 @@ 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=image->resolution.x*dimension_info.width/72.0;
-        image->rows=image->resolution.y*dimension_info.height/72.0;
-        pixels=(unsigned char *) NULL;
+        image->columns=image->resolution.x*dimension_info.width/90.0;
+        image->rows=image->resolution.y*dimension_info.height/90.0;
+        pixel_info=(MemoryInfo *) NULL;
 #else
-        pixel_info=rsvg_handle_get_pixbuf(svg_handle);
+        pixel_buffer=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);
+        image->columns=gdk_pixbuf_get_width(pixel_buffer);
+        image->rows=gdk_pixbuf_get_height(pixel_buffer);
 #endif
         image->alpha_trait=BlendPixelTrait;
         SetImageProperty(image,"svg:base-uri",
@@ -2945,7 +2949,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
         if ((image->columns == 0) || (image->rows == 0))
           {
 #if !defined(MAGICKCORE_CAIRO_DELEGATE)
-            g_object_unref(G_OBJECT(pixel_info));
+            g_object_unref(G_OBJECT(pixel_buffer));
 #endif
             g_object_unref(svg_handle);
             ThrowReaderException(MissingDelegateError,
@@ -2962,14 +2966,14 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
             stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
               image->columns);
 #endif
-            pixels=(unsigned char *) AcquireQuantumMemory(stride,image->rows*
-              sizeof(*pixels));
-            if (pixels == (unsigned char *) NULL)
+            pixel_info=AcquireVirtualMemory(stride,image->rows*sizeof(*pixels));
+            if (pixel_info == (MemoryInfo *) NULL)
               {
                 g_object_unref(svg_handle);
                 ThrowReaderException(ResourceLimitError,
                   "MemoryAllocationFailed");
               }
+            pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info);
 #endif
             (void) SetImageBackgroundColor(image,exception);
 #if defined(MAGICKCORE_CAIRO_DELEGATE)
@@ -2977,7 +2981,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
               CAIRO_FORMAT_ARGB32,image->columns,image->rows,stride);
             if (cairo_surface == (cairo_surface_t *) NULL)
               {
-                pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+                pixel_info=RelinquishVirtualMemory(pixel_info);
                 g_object_unref(svg_handle);
                 ThrowReaderException(ResourceLimitError,
                   "MemoryAllocationFailed");
@@ -2986,15 +2990,15 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
             cairo_set_operator(cairo_image,CAIRO_OPERATOR_CLEAR);
             cairo_paint(cairo_image);
             cairo_set_operator(cairo_image,CAIRO_OPERATOR_OVER);
-            cairo_scale(cairo_image,image->resolution.x/72.0,
-              image->resolution.y/72.0);
+            cairo_scale(cairo_image,image->resolution.x/90.0,
+              image->resolution.y/90.0);
             rsvg_handle_render_cairo(svg_handle,cairo_image);
             cairo_destroy(cairo_image);
             cairo_surface_destroy(cairo_surface);
             g_object_unref(svg_handle);
             p=pixels;
 #else
-            p=gdk_pixbuf_get_pixels(pixel_info);
+            p=gdk_pixbuf_get_pixels(pixel_buffer);
 #endif
             GetPixelInfo(image,&fill_color);
             for (y=0; y < (ssize_t) image->rows; y++)
@@ -3042,10 +3046,10 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
             }
           }
 #if defined(MAGICKCORE_CAIRO_DELEGATE)
-        if (pixels != (unsigned char *) NULL)
-          pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+        if (pixel_info != (MemoryInfo *) NULL)
+          pixel_info=RelinquishVirtualMemory(pixel_info);
 #else
-        g_object_unref(G_OBJECT(pixel_info));
+        g_object_unref(G_OBJECT(pixel_buffer));
 #endif
         (void) CloseBlob(image);
         return(GetFirstImageInList(image));
@@ -3070,9 +3074,14 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
   /*
     Parse SVG file.
   */
+  if (image == (Image *) NULL)
+    return((Image *) NULL);
   svg_info=AcquireSVGInfo();
   if (svg_info == (SVGInfo *) NULL)
-    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    {
+      (void) fclose(file);
+      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    }
   svg_info->file=file;
   svg_info->exception=exception;
   svg_info->image=image;
@@ -3083,7 +3092,6 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
     (void) CloneString(&svg_info->size,image_info->size);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(CoderEvent,GetMagickModule(),"begin SAX");
-  xmlInitParser();
   (void) xmlSubstituteEntitiesDefault(1);
   (void) ResetMagickMemory(&sax_modules,0,sizeof(sax_modules));
   sax_modules.internalSubset=SVGInternalSubset;
@@ -3130,7 +3138,6 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
   xmlFreeParserCtxt(svg_info->parser);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(CoderEvent,GetMagickModule(),"end SAX");
-  xmlCleanupParser();
   (void) fclose(file);
   (void) CloseBlob(image);
   image->columns=svg_info->width;
@@ -3215,7 +3222,12 @@ ModuleExport size_t RegisterSVGImage(void)
   (void) CopyMagickString(version,"XML " LIBXML_DOTTED_VERSION,MaxTextExtent);
 #endif
 #if defined(MAGICKCORE_RSVG_DELEGATE)
+#if !GLIB_CHECK_VERSION(2,35,0)
   g_type_init();
+#endif
+#if defined(MAGICKCORE_XML_DELEGATE)
+  xmlInitParser();
+#endif
   (void) FormatLocaleString(version,MaxTextExtent,"RSVG %d.%d.%d",
     LIBRSVG_MAJOR_VERSION,LIBRSVG_MINOR_VERSION,LIBRSVG_MICRO_VERSION);
 #endif
@@ -3227,6 +3239,7 @@ ModuleExport size_t RegisterSVGImage(void)
   entry->blob_support=MagickFalse;
   entry->seekable_stream=MagickFalse;
   entry->description=ConstantString("Scalable Vector Graphics");
+  entry->mime_type=ConstantString("image/svg+xml");
   if (*version != '\0')
     entry->version=ConstantString(version);
   entry->magick=(IsImageFormatHandler *) IsSVG;
@@ -3240,6 +3253,7 @@ ModuleExport size_t RegisterSVGImage(void)
   entry->blob_support=MagickFalse;
   entry->seekable_stream=MagickFalse;
   entry->description=ConstantString("Compressed Scalable Vector Graphics");
+  entry->mime_type=ConstantString("image/svg+xml");
   if (*version != '\0')
     entry->version=ConstantString(version);
   entry->magick=(IsImageFormatHandler *) IsSVG;
@@ -3283,6 +3297,9 @@ ModuleExport void UnregisterSVGImage(void)
   (void) UnregisterMagickInfo("SVGZ");
   (void) UnregisterMagickInfo("SVG");
   (void) UnregisterMagickInfo("MSVG");
+#if defined(MAGICKCORE_XML_DELEGATE)
+  xmlCleanupParser();
+#endif
 }
 \f
 /*