]> granicus.if.org Git - imagemagick/blobdiff - coders/label.c
(no commit message)
[imagemagick] / coders / label.c
index fed0dda020fdc1014d07306a3845847eaabac401..1055032387cf06f7a9d727ac0f7fc3aefe2f45e4 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2012 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  %
 /*
   Include declarations.
 */
-#include "magick/studio.h"
-#include "magick/annotate.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/draw.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/image.h"
-#include "magick/image-private.h"
-#include "magick/list.h"
-#include "magick/magick.h"
-#include "magick/memory_.h"
-#include "magick/property.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
-#include "magick/utility.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/annotate.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/draw.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/property.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
+#include "MagickCore/utility.h"
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -121,12 +121,13 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
-  image=AcquireImage(image_info);
+  image=AcquireImage(image_info,exception);
   (void) ResetImagePage(image,"0x0+0+0");
-  property=InterpretImageProperties(image_info,image,image_info->filename);
-  (void) SetImageProperty(image,"label",property);
+  property=InterpretImageProperties(image_info,image,image_info->filename,
+    exception);
+  (void) SetImageProperty(image,"label",property,exception);
   property=DestroyString(property);
-  label=GetImageProperty(image,"label");
+  label=GetImageProperty(image,"label",exception);
   draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
   draw_info->text=ConstantString(label);
   if (((image->columns != 0) || (image->rows != 0)) &&
@@ -135,35 +136,35 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
       /*
         Fit label to canvas size.
       */
-      status=GetMultilineTypeMetrics(image,draw_info,&metrics);
+      status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
       for ( ; status != MagickFalse; draw_info->pointsize*=2.0)
       {
         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 (((image->columns != 0) && (width > (image->columns+1))) ||
-            ((image->rows != 0) && (height > (image->rows+1))))
+        if (((image->columns != 0) && (width >= image->columns)) ||
+            ((image->rows != 0) && (height >= image->rows)))
           break;
-        status=GetMultilineTypeMetrics(image,draw_info,&metrics);
+        status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
       }
+      draw_info->pointsize/=2.0;
       for ( ; status != MagickFalse; draw_info->pointsize--)
       {
         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 ((image->columns != 0) && (width <= (image->columns+1)) &&
-           ((image->rows == 0) || (height <= (image->rows+1))))
+        if ((image->columns != 0) && (width < image->columns) &&
+           ((image->rows == 0) || (height < image->rows)))
           break;
-        if ((image->rows != 0) && (height <= (image->rows+1)) &&
-           ((image->columns == 0) || (width <= (image->columns+1))))
+        if ((image->rows != 0) && (height < image->rows) &&
+           ((image->columns == 0) || (width < image->columns)))
           break;
         if (draw_info->pointsize < 2.0)
           break;
-        status=GetMultilineTypeMetrics(image,draw_info,&metrics);
+        status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
       }
     }
-  status=GetMultilineTypeMetrics(image,draw_info,&metrics);
+  status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
   if (status == MagickFalse)
     {
-      InheritException(exception,&image->exception);
       image=DestroyImageList(image);
       return((Image *) NULL);
     }
@@ -171,30 +172,32 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
     image->columns=(size_t) (metrics.width+draw_info->stroke_width+1.5);
   if (image->columns == 0)
     image->columns=(size_t) (draw_info->pointsize+draw_info->stroke_width+1.5);
-  if ((draw_info->gravity == UndefinedGravity) ||
-      (draw_info->direction == RightToLeftDirection))
+  if (draw_info->gravity == UndefinedGravity)
     {
       (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
         -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+
         draw_info->stroke_width/2.0);
+      (void) CloneString(&draw_info->geometry,geometry);
+    }
+  if (draw_info->direction == RightToLeftDirection)
+    {
       if (draw_info->direction == RightToLeftDirection)
         (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
           image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),
           metrics.ascent+draw_info->stroke_width/2.0);
-      draw_info->geometry=AcquireString(geometry);
+      (void) CloneString(&draw_info->geometry,geometry);
     }
   if (image->rows == 0)
     image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
   if (image->rows == 0)
     image->rows=(size_t) floor(draw_info->pointsize+draw_info->stroke_width+
       0.5);
-  if (SetImageBackgroundColor(image) == MagickFalse)
+  if (SetImageBackgroundColor(image,exception) == MagickFalse)
     {
-      InheritException(exception,&image->exception);
       image=DestroyImageList(image);
       return((Image *) NULL);
     }
-  (void) AnnotateImage(image,draw_info);
+  (void) AnnotateImage(image,draw_info,exception);
   if (image_info->pointsize == 0.0)
     {
       char
@@ -202,7 +205,7 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
 
       (void) FormatLocaleString(pointsize,MaxTextExtent,"%.20g",
         draw_info->pointsize);
-      (void) SetImageProperty(image,"label:pointsize",pointsize);
+      (void) SetImageProperty(image,"label:pointsize",pointsize,exception);
     }
   draw_info=DestroyDrawInfo(draw_info);
   return(GetFirstImageInList(image));