Commit 8472ed597 for imagemagick.org
commit 8472ed597e2245c410375cbb34041cf25883f050
Author: Cristy <urban-warrior@imagemagick.org>
Date: Tue Dec 1 19:42:14 2026 -0500
if no size fit the box, auto-fit ended an empty label
diff --git a/coders/label.c b/coders/label.c
index 12b85d812..228a9e215 100644
--- a/coders/label.c
+++ b/coders/label.c
@@ -124,6 +124,7 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
size_t
height,
+ label_length,
width;
/*
@@ -143,15 +144,17 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
- (void) SetImageBackgroundColor(image,exception);
+ if (SetImageBackgroundColor(image,exception) == MagickFalse)
+ return(DestroyImageList(image));
}
label=InterpretImageProperties((ImageInfo *) image_info,image,
image_info->filename,exception);
if (label == (char *) NULL)
return(DestroyImageList(image));
(void) SetImageProperty(image,"label",label,exception);
+ label_length=strlen(label);
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
- width=CastDoubleToSizeT(0.5*draw_info->pointsize*strlen(label)+0.5);
+ width=CastDoubleToSizeT(0.5*draw_info->pointsize*label_length+0.5);
if (AcquireMagickResource(WidthResource,width) == MagickFalse)
{
label=DestroyString(label);
@@ -161,8 +164,10 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
draw_info->text=ConstantString(label);
(void) memset(&metrics,0,sizeof(metrics));
status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
- AdjustTypeMetricBounds(&metrics);
- if ((image->columns == 0) && (image->rows == 0))
+ if (status != MagickFalse)
+ AdjustTypeMetricBounds(&metrics);
+ if ((status != MagickFalse) && (image->columns == 0) &&
+ (image->rows == 0))
{
image->columns=CastDoubleToSizeT(floor(metrics.width+
draw_info->stroke_width+0.5));
@@ -170,7 +175,7 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
draw_info->stroke_width+0.5));
}
else
- if ((status != MagickFalse) && (strlen(label) > 0) &&
+ if ((status != MagickFalse) && (label_length > 0) &&
(((image->columns == 0) || (image->rows == 0)) ||
(fabs(image_info->pointsize) < MagickEpsilon)))
{
@@ -222,7 +227,7 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
metrics.underline_position+draw_info->stroke_width+0.5);
if ((image->columns != 0) && (image->rows != 0))
{
- if ((width > image->columns) && (height > image->rows))
+ if ((width > image->columns) || (height > image->rows))
break;
if ((width <= image->columns) && (height <= image->rows))
low=draw_info->pointsize;
@@ -270,19 +275,25 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
high=draw_info->pointsize-0.5;
}
if (status != MagickFalse)
- draw_info->pointsize=floor(low-0.5);
+ draw_info->pointsize=MagickMax(floor(low-0.5),1.0);
}
- label=DestroyString(label);
- if (status == MagickFalse)
- {
- draw_info=DestroyDrawInfo(draw_info);
- image=DestroyImageList(image);
- return((Image *) NULL);
- }
+ label=DestroyString(label);
+ if (status == MagickFalse)
+ {
+ draw_info=DestroyDrawInfo(draw_info);
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
/*
- Draw label.
+ Determine final image extent.
*/
status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
+ if (status == MagickFalse)
+ {
+ draw_info=DestroyDrawInfo(draw_info);
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
AdjustTypeMetricBounds(&metrics);
if (image->columns == 0)
image->columns=CastDoubleToSizeT(floor(metrics.width+
@@ -317,13 +328,13 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
(draw_info->gravity == SouthWestGravity)) ? MagickTrue : MagickFalse;
(void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g",
(draw_info->direction == RightToLeftDirection ? (double) image->columns-
- (draw_info->gravity == UndefinedGravity ? metrics.bounds.x2 : 0.0) :
+ (draw_info->gravity == UndefinedGravity ? metrics.bounds.x2 : 0.0) :
(left_bearing != MagickFalse ? metrics.bounds.x1 : 0.0)),
- (draw_info->gravity == UndefinedGravity ?
+ (draw_info->gravity == UndefinedGravity ?
MagickMax(metrics.ascent,metrics.bounds.y2) : 0.0));
(void) CloneString(&draw_info->geometry,geometry);
status=AnnotateImage(image,draw_info,exception);
- if (image_info->pointsize == 0.0)
+ if (fabs(image_info->pointsize) < MagickEpsilon)
(void) FormatImageProperty(image,"label:pointsize","%.17g",
draw_info->pointsize);
draw_info=DestroyDrawInfo(draw_info);