]> granicus.if.org Git - imagemagick/commitdiff
If a convenient line break is not found, force it for caption:
authorCristy <urban-warrior@imagemagick.org>
Sat, 19 Nov 2016 14:23:07 +0000 (09:23 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sat, 19 Nov 2016 14:23:07 +0000 (09:23 -0500)
ChangeLog
MagickCore/annotate.c

index 9c2cc936e113ea78bb020618bec09def2f1fe78b..e542787a740f5910024e5649d6ad19c67b4d8de6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-11-18  7.0.3-8 Cristy  <quetzlzacatenango@image...>
   * Support the phash:colorspaces and phash:normalize options.
+  * If a convenient line break is not found, force it for caption: (reference
+    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=30887).
 
 2016-11-15  7.0.3-7 Cristy  <quetzlzacatenango@image...>
   * Release ImageMagick version 7.0.3-7, GIT revision 19024:87aca83:20161115.
index 5e92ae27e5718857b260a40c1fef9588e043ee89..a53173924396021e4f1dd5e3e72b627e7d07c4c1 100644 (file)
@@ -613,6 +613,7 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
     n;
 
   digit=MagickFalse;
+  width=0;
   q=draw_info->text;
   s=(char *) NULL;
   for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
@@ -658,6 +659,61 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
     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))
+            {
+              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;
+      }
+      text=DestroyString(text);
+    }
   n=0;
   for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p))
     if (GetUTFCode(p) == '\n')