diff --git a/libvips/create/text.c b/libvips/create/text.c index 763587b0..0825827b 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -48,8 +48,8 @@ */ /* -#define DEBUG */ +#define DEBUG #ifdef HAVE_CONFIG_H #include @@ -290,14 +290,18 @@ vips_text_autofit( VipsText *text, VipsRect *out_extents ) } } - if( difference > 0 ) { - text->dpi = lower_dpi; - *out_extents = lower_extents; - } - else { + /* If we've hit the target exactly and quit the loop, diff will be 0 + * and we can use upper. Otherwise we are straddling the target and we + * must take lower. + */ + if( difference == 0 ) { text->dpi = upper_dpi; *out_extents = upper_extents; } + else { + text->dpi = lower_dpi; + *out_extents = lower_extents; + } return( 0 ); }