From: cristy Date: Thu, 24 May 2012 12:20:45 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~5543 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994;p=imagemagick --- diff --git a/coders/caption.c b/coders/caption.c index ce62c487f..1a29559aa 100644 --- a/coders/caption.c +++ b/coders/caption.c @@ -161,8 +161,12 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info, char *text; + double + high, + low; + /* - Scale text up to fit bounding box. + Auto fit text into bounding box. */ for ( ; ; ) { @@ -181,13 +185,13 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info, height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5); if ((width > image->columns) && (height > image->rows)) break; - draw_info->pointsize++; + draw_info->pointsize*=2.0; } - /* - Scale text down to fit bounding box. - */ - for ( ; ; ) + high=draw_info->pointsize/2.0; + low=high/2.0; + while ((high-low) > 1.0) { + draw_info->pointsize=(low+high)/2.0; text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text, exception); @@ -201,9 +205,11 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info, 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--; + low=draw_info->pointsize+1.0; + else + high=draw_info->pointsize-1.0; } + draw_info->pointsize--; } i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&caption,exception); if (image->rows == 0)