]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Sat, 9 Jun 2018 18:44:34 +0000 (14:44 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sat, 9 Jun 2018 18:44:34 +0000 (14:44 -0400)
MagickCore/draw.c
coders/svg.c

index 970af134657687b3bb5832d60729e28516746d92..f71ad89f1931df6908c61fb1e021bc381fce8e0b 100644 (file)
@@ -2367,6 +2367,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
   double
     angle,
     coordinates,
+    cursor,
     factor,
     primitive_extent;
 
@@ -2491,6 +2492,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
     }
   token=AcquireString(primitive);
   extent=strlen(token)+MagickPathExtent;
+  cursor=0.0;
   defsDepth=0;
   symbolDepth=0;
   macros=GetMVGMacros(primitive);
@@ -3613,6 +3615,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
         if (LocaleCompare("text",keyword) == 0)
           {
             primitive_type=TextPrimitive;
+            affine.tx+=cursor;
             break;
           }
         if (LocaleCompare("text-align",keyword) == 0)
@@ -4140,6 +4143,12 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
       }
       case TextPrimitive:
       {
+        DrawInfo
+          *clone_info;
+
+        TypeMetric
+          metrics;
+
         if (primitive_info[j].coordinates != 1)
           {
             status=MagickFalse;
@@ -4148,6 +4157,18 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
         if (*token != ',')
           GetNextToken(q,&q,extent,token);
         primitive_info[j].text=AcquireString(token);
+        /*
+          Compute text cursor offset.
+        */
+        clone_info=CloneDrawInfo((ImageInfo *) NULL,graphic_context[n]);
+        if (clone_info->density != (char *) NULL)
+          clone_info->density=DestroyString(clone_info->density);
+        clone_info->render=MagickFalse;
+        clone_info->text=AcquireString(token);
+        (void) ConcatenateString(&clone_info->text," ");
+        status&=GetTypeMetrics(image,clone_info,&metrics,exception);
+        clone_info=DestroyDrawInfo(clone_info);
+        cursor+=metrics.width;
         break;
       }
       case ImagePrimitive:
index 91e3397ed5a94e2c7d85a6f54b915bde0b60ac08..2d44b303d350132af54c5173ba56094914a6cc53 100644 (file)
@@ -1410,12 +1410,6 @@ static void SVGStartElement(void *context,const xmlChar *name,
         {
           if (*svg_info->text != '\0')
             {
-              DrawInfo
-                *draw_info;
-
-              TypeMetric
-                metrics;
-
               char
                 *text;
 
@@ -1424,14 +1418,6 @@ static void SVGStartElement(void *context,const xmlChar *name,
                 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;
-              draw_info->text=AcquireString(svg_info->text);
-              (void) ConcatenateString(&draw_info->text," ");
-              (void) GetTypeMetrics(svg_info->image,draw_info,
-                &metrics,svg_info->exception);
-              svg_info->bounds.x+=metrics.width;
-              draw_info=DestroyDrawInfo(draw_info);
               *svg_info->text='\0';
             }
           PushGraphicContext(id);
@@ -2627,12 +2613,6 @@ static void SVGEndElement(void *context,const xmlChar *name)
         {
           if (*svg_info->text != '\0')
             {
-              DrawInfo
-                *draw_info;
-
-              TypeMetric
-                metrics;
-
               char
                 *text;
 
@@ -2641,14 +2621,6 @@ static void SVGEndElement(void *context,const xmlChar *name)
                 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;
-              draw_info->text=AcquireString(svg_info->text);
-              (void) ConcatenateString(&draw_info->text," ");
-              (void) GetTypeMetrics(svg_info->image,draw_info,&metrics,
-                svg_info->exception);
-              svg_info->bounds.x+=metrics.width;
-              draw_info=DestroyDrawInfo(draw_info);
               *svg_info->text='\0';
             }
           (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n");