]> granicus.if.org Git - imagemagick/commitdiff
Fixed several issues with FormatMagickCaption.
authorDirk Lemstra <dirk@git.imagemagick.org>
Sat, 15 Sep 2018 13:28:06 +0000 (15:28 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sat, 15 Sep 2018 13:28:06 +0000 (15:28 +0200)
MagickCore/annotate.c

index df08da93f40993c9d01962573173fd5db24dc81e..187aaa909e89b38a4ec7ac158425a2cfe4866bbd 100644 (file)
@@ -592,7 +592,6 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
   ExceptionInfo *exception)
 {
   MagickBooleanType
-    digit,
     status;
 
   register char
@@ -609,18 +608,17 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
   ssize_t
     n;
 
-  digit=MagickFalse;
   q=draw_info->text;
   s=(char *) NULL;
-  width=0;
   for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
   {
-    if ((digit == MagickFalse) && (IsUTFSpace(GetUTFCode(p)) != MagickFalse))
+    if (IsUTFSpace(GetUTFCode(p)) != MagickFalse)
       s=p;
-    digit=((GetUTFCode(p) >= 0x0030) && (GetUTFCode(p) <= 0x0039)) ?
-      MagickTrue : MagickFalse;
     if (GetUTFCode(p) == '\n')
-      q=draw_info->text;
+      {
+        q=draw_info->text;
+        continue;
+      }
     for (i=0; i < (ssize_t) GetUTFOctets(p); i++)
       *q++=(*(p+i));
     *q='\0';
@@ -628,9 +626,9 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
     if (status == MagickFalse)
       break;
     width=(size_t) floor(metrics->width+draw_info->stroke_width+0.5);
-    if ((width <= image->columns) || (s == (char *) NULL))
+    if (width <= image->columns)
       continue;
-    if (GetUTFOctets(s) == 1)
+    if (s != (char *) NULL)
       {
         *s='\n';
         p=s;
@@ -638,67 +636,16 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
     else
       if (split != MagickFalse)
         {
-          char
-            *target;
-
           /*
             No convenient line breaks-- insert newline.
           */
-          target=AcquireString(*caption);
           n=p-(*caption);
-          CopyMagickString(target,*caption,n+1);
-          ConcatenateMagickString(target,"\n",strlen(*caption)+1);
-          ConcatenateMagickString(target,p,strlen(*caption)+2);
-          (void) DestroyString(*caption);
-          *caption=target;
-          p=(*caption)+n;
-        }
-    q=draw_info->text;
-    s=(char *) NULL;
-  }
-  if (width > image->columns)
-    {
-      char
-        *text;
-
-      /*
-        No convenient break point, force one.
-      */
-      text=AcquireString(draw_info->text);
-      q=draw_info->text;
-      s=(char *) NULL;
-      for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
-      {
-        if (IsUTFSpace(GetUTFCode(p)) != MagickFalse)
-          s=p;
-        if (GetUTFCode(p) == '\n')
-          q=draw_info->text;
-        for (i=0; i < (ssize_t) GetUTFOctets(p); i++)
-          *q++=(*(p+i));
-        *q='\0';
-        status=GetTypeMetrics(image,draw_info,metrics,exception);
-        if (status == MagickFalse)
-          break;
-        width=(size_t) floor(metrics->width+draw_info->stroke_width+0.5);
-        if ((width <= image->columns) || (strcmp(text,draw_info->text) == 0))
-          continue;
-        (void) strcpy(text,draw_info->text);
-        if ((s != (char *) NULL) && (GetUTFOctets(s) == 1))
-          {
-            *s='\n';
-            p=s;
-          }
-        else
-          if ((s != (char *) NULL) || (split != MagickFalse))
+          if ((n > 0) && ((*caption)[n-1] != '\n'))
             {
               char
                 *target;
 
-              /*
-                No convenient line breaks-- insert newline.
-              */
               target=AcquireString(*caption);
-              n=p-(*caption);
               CopyMagickString(target,*caption,n+1);
               ConcatenateMagickString(target,"\n",strlen(*caption)+1);
               ConcatenateMagickString(target,p,strlen(*caption)+2);
@@ -706,11 +653,10 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
               *caption=target;
               p=(*caption)+n;
             }
-        q=draw_info->text;
-        s=(char *) NULL;
-      }
-      text=DestroyString(text);
-    }
+        }
+    q=draw_info->text;
+    s=(char *) NULL;
+  }
   n=0;
   for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
     if (GetUTFCode(p) == '\n')