diff --git a/coders/caption.c b/coders/caption.c index 5f9778e7c0..5abd93dbd3 100644 --- a/coders/caption.c +++ b/coders/caption.c @@ -91,19 +91,20 @@ % o exception: return any errors or warnings in this structure. % */ + static inline void AdjustTypeMetricBounds(TypeMetric *metrics) { - if (metrics->bounds.x1 < 0.0) - { - double - new_x1; + double + x1; - new_x1=ceil(-metrics->bounds.x1+0.5); - metrics->width+=new_x1+new_x1; - metrics->bounds.x1=new_x1; + if (metrics->bounds.x1 >= 0.0) + { + metrics->bounds.x1=0.0; + return; } - else - metrics->bounds.x1=0.0; + x1=ceil(-metrics->bounds.x1+0.5); + metrics->width+=x1+x1; + metrics->bounds.x1=x1; } static Image *ReadCAPTIONImage(const ImageInfo *image_info, @@ -325,7 +326,7 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info, Draw caption. */ i=FormatMagickCaption(image,draw_info,split,&metrics,&caption,exception); - AdjustTypeMetricBounds(&metrics); + AdjustTypeMetricBounds(&metrics); (void) CloneString(&draw_info->text,caption); caption=DestroyString(caption); (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", diff --git a/coders/label.c b/coders/label.c index 7d87ed4733..c47f3e4e79 100644 --- a/coders/label.c +++ b/coders/label.c @@ -87,19 +87,20 @@ % o exception: return any errors or warnings in this structure. % */ + static inline void AdjustTypeMetricBounds(TypeMetric *metrics) { - if (metrics->bounds.x1 < 0.0) - { - double - new_x1; + double + x1; - new_x1=ceil(-metrics->bounds.x1+0.5); - metrics->width+=new_x1+new_x1; - metrics->bounds.x1=new_x1; + if (metrics->bounds.x1 >= 0.0) + { + metrics->bounds.x1=0.0; + return; } - else - metrics->bounds.x1=0.0; + x1=ceil(-metrics->bounds.x1+0.5); + metrics->width+=x1+x1; + metrics->bounds.x1=x1; } static Image *ReadLABELImage(const ImageInfo *image_info, @@ -279,8 +280,8 @@ static Image *ReadLABELImage(const ImageInfo *image_info, */ (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", (draw_info->direction == RightToLeftDirection ? (double) image->columns- - metrics.bounds.x2 : metrics.bounds.x1),(draw_info->gravity == UndefinedGravity ? - MagickMax(metrics.ascent,metrics.bounds.y2) : 0.0)); + metrics.bounds.x2 : metrics.bounds.x1),(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)