]> granicus.if.org Git - imagemagick/blobdiff - coders/caption.c
(no commit message)
[imagemagick] / coders / caption.c
index de8ce097561010438e56f8462595264c14977304..602839d7b3994bf32ccf1af6a0d595c6706c1a56 100644 (file)
 %                             Read Text Caption.                              %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                               February 2002                                 %
 %                                                                             %
 %                                                                             %
-%  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  %
@@ -110,6 +110,7 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
     *image;
 
   MagickBooleanType
+    split,
     status;
 
   register ssize_t
@@ -137,28 +138,31 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
   /*
     Format caption.
   */
-  option=GetImageArtifact(image,"filename");
+  option=GetImageOption(image_info,"filename");
   if (option == (const char *) NULL)
-    property=InterpretImageProperties(image_info,image,image_info->filename,
-      exception);
+    property=InterpretImageProperties((ImageInfo *) image_info,image,
+      image_info->filename,exception);
   else
     if (LocaleNCompare(option,"caption:",8) == 0)
-      property=InterpretImageProperties(image_info,image,option+8,exception);
+      property=InterpretImageProperties((ImageInfo *) image_info,image,option+8,
+        exception);
     else
-      property=InterpretImageProperties(image_info,image,option,exception);
+      property=InterpretImageProperties((ImageInfo *) image_info,image,option,
+        exception);
   (void) SetImageProperty(image,"caption",property,exception);
   property=DestroyString(property);
   caption=ConstantString(GetImageProperty(image,"caption",exception));
   draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
   (void) CloneString(&draw_info->text,caption);
-  gravity=GetImageArtifact(image,"gravity");
+  gravity=GetImageOption(image_info,"gravity");
   if (gravity != (char *) NULL)
     draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
       MagickFalse,gravity);
+  split=MagickFalse;
   if (image->columns == 0)
     {
       text=AcquireString(caption);
-      i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
+      i=FormatMagickCaption(image,draw_info,split,&metrics,&text,
         exception);
       (void) CloneString(&draw_info->text,text);
       text=DestroyString(text);
@@ -172,8 +176,9 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
     }
   if (image->rows == 0)
     {
+      split=MagickTrue;
       text=AcquireString(caption);
-      i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
+      i=FormatMagickCaption(image,draw_info,split,&metrics,&text,
         exception);
       (void) CloneString(&draw_info->text,text);
       text=DestroyString(text);
@@ -197,7 +202,7 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
       for ( ; ; draw_info->pointsize*=2.0)
       {
         text=AcquireString(caption);
-        i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
+        i=FormatMagickCaption(image,draw_info,split,&metrics,&text,
           exception);
         (void) CloneString(&draw_info->text,text);
         text=DestroyString(text);
@@ -208,17 +213,22 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
         status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
         width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
         height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
-        if ((width >= image->columns) && (height >= image->rows))
-          break;
-        if ((width >= (image->columns << 1)) || (height >= (image->rows << 1)))
-          break;
+        if ((image->columns != 0) && (image->rows != 0))
+          {
+            if ((width >= image->columns) && (height >= image->rows))
+              break;
+          }
+        else
+          if (((image->columns != 0) && (width >= image->columns)) ||
+              ((image->rows != 0) && (height >= image->rows)))
+            break;
       }
       high=draw_info->pointsize;
-      for (low=1.0; (high-low) > 1.0; )
+      for (low=1.0; (high-low) > 0.5; )
       {
         draw_info->pointsize=(low+high)/2.0;
         text=AcquireString(caption);
-        i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
+        i=FormatMagickCaption(image,draw_info,split,&metrics,&text,
           exception);
         (void) CloneString(&draw_info->text,text);
         text=DestroyString(text);
@@ -229,34 +239,24 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
         status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
         width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
         height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
-        if ((width <= image->columns) && (height <= image->rows))
-          low=draw_info->pointsize+1.0;
+        if ((image->columns != 0) && (image->rows != 0))
+          {
+            if ((width < image->columns) && (height < image->rows))
+              low=draw_info->pointsize+0.5;
+            else
+              high=draw_info->pointsize-0.5;
+          }
         else
-          high=draw_info->pointsize-1.0;
-      }
-      for (draw_info->pointsize=(low+high)/2.0; (high-low) > 1.0; )
-      {
-        text=AcquireString(caption);
-        i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
-          exception);
-        (void) CloneString(&draw_info->text,text);
-        text=DestroyString(text);
-        (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
-          -metrics.bounds.x1,metrics.ascent);
-        if (draw_info->gravity == UndefinedGravity)
-          (void) CloneString(&draw_info->geometry,geometry);
-        status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
-        width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
-        height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
-        if ((width <= image->columns) && (height <= image->rows))
-          break;
-        draw_info->pointsize--;
+          if (((image->columns != 0) && (width < image->columns)) ||
+              ((image->rows != 0) && (height < image->rows)))
+            low=draw_info->pointsize+0.5;
+          else
+            high=draw_info->pointsize-0.5;
       }
-      draw_info->pointsize--;
+      draw_info->pointsize=(low+high)/2.0-0.5;
     }
   (void) CloneString(&draw_info->text,caption);
-  i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&caption,
-    exception);
+  i=FormatMagickCaption(image,draw_info,split,&metrics,&caption,exception);
   if (SetImageBackgroundColor(image,exception) == MagickFalse)
     {
       image=DestroyImageList(image);