]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Sun, 22 Apr 2018 12:16:54 +0000 (08:16 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sun, 22 Apr 2018 12:17:16 +0000 (08:17 -0400)
MagickCore/draw.c
coders/svg.c

index 94dc44d2e588abfb9246e43f5fc16ba934efe037..8db2305b54262cb67a5ce81fbd8a447762072a18 100644 (file)
@@ -1691,7 +1691,7 @@ static size_t GetEllipseCoordinates(const PointInfo start,const PointInfo stop,
   return((size_t) floor((angle.y-angle.x)/step+0.5)+3);
 }
 
-static char *GetNodeByID(const char *primitive,const char *id)
+static char *GetGroupByURL(const char *primitive,const char *url)
 {
   char
     *token;
@@ -1758,7 +1758,7 @@ static char *GetNodeByID(const char *primitive,const char *id)
             if (*q == '"')
               {
                 GetNextToken(q,&q,extent,token);
-                if (LocaleCompare(id,token) == 0)
+                if (LocaleCompare(url,token) == 0)
                   {
                     /*
                       Start of group by ID.
@@ -1901,7 +1901,8 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
     defsDepth,
     j,
     k,
-    n;
+    n,
+    symbolDepth;
 
   StopInfo
     *stops;
@@ -1968,6 +1969,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   defsDepth=0;
+  symbolDepth=0;
   status=MagickTrue;
   for (q=primitive; *q != '\0'; )
   {
@@ -2478,6 +2480,13 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
               }
             if (LocaleCompare("pattern",token) == 0)
               break;
+            if (LocaleCompare("symbol",token) == 0)
+              {
+                symbolDepth--;
+                graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
+                  MagickTrue;
+                break;
+              }
             status=MagickFalse;
             break;
           }
@@ -2509,6 +2518,13 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
                 GetNextToken(q,&q,extent,token);
                 break;
               }
+            if (LocaleCompare("defs",token) == 0)
+              {
+                defsDepth++;
+                graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
+                  MagickTrue;
+                break;
+              }
             if (LocaleCompare("gradient",token) == 0)
               {
                 char
@@ -2593,6 +2609,24 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
                 GetNextToken(q,&q,extent,token);
                 break;
               }
+            if (LocaleCompare("graphic-context",token) == 0)
+              {
+                n++;
+                graphic_context=(DrawInfo **) ResizeQuantumMemory(
+                  graphic_context,(size_t) (n+1),sizeof(*graphic_context));
+                if (graphic_context == (DrawInfo **) NULL)
+                  {
+                    (void) ThrowMagickException(exception,GetMagickModule(),
+                      ResourceLimitError,"MemoryAllocationFailed","`%s'",
+                      image->filename);
+                    break;
+                  }
+                graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
+                  graphic_context[n-1]);
+                if (*q == '"')
+                  GetNextToken(q,&q,extent,token);
+                break;
+              }
             if (LocaleCompare("pattern",token) == 0)
               {
                 char
@@ -2656,28 +2690,10 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
                 GetNextToken(q,&q,extent,token);
                 break;
               }
-            if (LocaleCompare("graphic-context",token) == 0)
-              {
-                n++;
-                graphic_context=(DrawInfo **) ResizeQuantumMemory(
-                  graphic_context,(size_t) (n+1),sizeof(*graphic_context));
-                if (graphic_context == (DrawInfo **) NULL)
-                  {
-                    (void) ThrowMagickException(exception,GetMagickModule(),
-                      ResourceLimitError,"MemoryAllocationFailed","`%s'",
-                      image->filename);
-                    break;
-                  }
-                graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
-                  graphic_context[n-1]);
-                if (*q == '"')
-                  GetNextToken(q,&q,extent,token);
-                break;
-              }
-            if (LocaleCompare("defs",token) == 0)
+            if (LocaleCompare("symbol",token) == 0)
               {
-                defsDepth++;
-                graphic_context[n]->render=defsDepth > 0 ? MagickFalse :
+                symbolDepth++;
+                graphic_context[n]->render=symbolDepth > 0 ? MagickFalse :
                   MagickTrue;
                 break;
               }
@@ -3000,21 +3016,21 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
         if (LocaleCompare("use",keyword) == 0)
           {
             char
-              *node;
+              *group;
 
             /*
               Take a node from within the MVG document, and duplicate it here.
             */
             GetNextToken(q,&q,extent,token);
-            node=GetNodeByID(primitive,token);
-            if (node != (char *) NULL)
+            group=GetGroupByURL(primitive,token);
+            if (group != (char *) NULL)
               {
                 DrawInfo
                   *clone_info;
 
                 clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
-                (void) CloneString(&clone_info->primitive,node);
-                node=DestroyString(node);
+                (void) CloneString(&clone_info->primitive,group);
+                group=DestroyString(group);
                 status=DrawImage(image,clone_info,exception);
                 clone_info=DestroyDrawInfo(clone_info);
               }
index 8c2e7502b2511748a551671a6684b351a48b3706..482dd7a7aaf14beb9b9648261463ce7b92d27399 100644 (file)
@@ -1129,6 +1129,11 @@ static void SVGStartElement(void *context,const xmlChar *name,
     case 'S':
     case 's':
     {
+      if (LocaleCompare((const char *) name,"symbol") == 0)
+        {
+          (void) FormatLocaleFile(svg_info->file,"push symbol\n");
+          break;
+        }
       if (LocaleCompare((const char *) name,"svg") == 0)
         {
           PushGraphicContext(id);
@@ -1532,10 +1537,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
             }
           if (LocaleCompare(keyword,"href") == 0)
             {
-              if (*value != '#')
-                (void) CloneString(&svg_info->url,value);
-              else
-                (void) CloneString(&svg_info->url,value+1);
+              (void) CloneString(&svg_info->url,value);
               break;
             }
           break;
@@ -2218,10 +2220,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
             }
           if (LocaleCompare(keyword,"xlink:href") == 0)
             {
-              if (*value != '#')
-                (void) CloneString(&svg_info->url,value);
-              else
-                (void) CloneString(&svg_info->url,value+1);
+              (void) CloneString(&svg_info->url,value);
               break;
             }
           if (LocaleCompare(keyword,"x1") == 0)
@@ -2525,6 +2524,11 @@ static void SVGEndElement(void *context,const xmlChar *name)
             svg_info->stop_color,svg_info->offset);
           break;
         }
+      if (LocaleCompare((const char *) name,"symbol") == 0)
+        {
+          (void) FormatLocaleFile(svg_info->file,"pop symbol\n");
+          break;
+        }
       if (LocaleCompare((const char *) name,"svg") == 0)
         {
           (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n");
@@ -2599,7 +2603,8 @@ static void SVGEndElement(void *context,const xmlChar *name)
           if ((svg_info->bounds.x != 0.0) || (svg_info->bounds.y != 0.0))
             (void) FormatLocaleFile(svg_info->file,"translate %g,%g\n",
               svg_info->bounds.x,svg_info->bounds.y);
-          (void) FormatLocaleFile(svg_info->file,"use \"%s\"\n",svg_info->url);
+          (void) FormatLocaleFile(svg_info->file,"use \"url(%s)\"\n",
+            svg_info->url);
           (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n");
           break;
         }
@@ -4224,8 +4229,14 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image,
                 (void) WriteBlobString(image,"</pattern>\n");
                 break;
               }
-            if (LocaleCompare("defs",token) == 0)
-            (void) WriteBlobString(image,"</g>\n");
+            if (LocaleCompare("symbol",token) == 0)
+              {
+                (void) WriteBlobString(image,"</symbol>\n");
+                break;
+              }
+            if ((LocaleCompare("defs",token) == 0) ||
+                (LocaleCompare("symbol",token) == 0))
+              (void) WriteBlobString(image,"</g>\n");
             break;
           }
         if (LocaleCompare("push",keyword) == 0)
@@ -4328,6 +4339,11 @@ static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image,
                 (void) WriteBlobString(image,message);
                 break;
               }
+            if (LocaleCompare("symbol",token) == 0)
+              {
+                (void) WriteBlobString(image,"<symbol>\n");
+                break;
+              }
             break;
           }
         status=MagickFalse;