Skip Menu |

This queue is for tickets about the Imager CPAN distribution.

Report information
The Basics
Id: 13058
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Imager

People
Owner: TONYC [...] cpan.org
Requestors: michalis [...] linuxmail.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.43
  • 0.43_03
  • 0.44
  • 0.44_01
Fixed in: (no value)



Subject: Imager .45 and earlier bounding_box not calculated correctly for non-latin UTF strings
Fedora Core 1 perl v5.8.3 built for i386-linux-thread-multi Linux 2.4.22-1.2174.nptl sample: #!/usr/bin/perl use Text::Iconv; use Imager; my $enc2utf = new Text::Iconv('windows-1253', 'utf8'); my $img=Imager->new(xsize=>100,ysize=>22,channels=>3); my $font=Imager::Font->new(file => '/usr/local/share/ttf-fonts/Trebucbd.ttf', color=>$blue, size=>13, aa=>1); $text=$enc2utf->convert($ARGV[0]); my @metrics = $font->bounding_box(string => $text); print "$metrics[2], $text\n"; $img->string(font=>$font, text=>$text, x=>1, utf8=>1, y=>19); $img->write(file=>'test.png"); use with ./scriptname "Some greek text" (sample with written greek text may be provided if needed). The UTF-8 strings' width is miscalculated but written correctly. If you use latin text, it's calculated correctly For usage over a UTF-enabled console, replace the line $text=$enc2utf->convert($ARGV[0]); with $text=$ARGV[0]; The result is the same
Show quoted text
> #!/usr/bin/perl > use Text::Iconv; > use Imager; > > my $enc2utf = new Text::Iconv('windows-1253', 'utf8'); > my $img=Imager->new(xsize=>100,ysize=>22,channels=>3); > my $font=Imager::Font->new(file => '/usr/local/share/ttf- > fonts/Trebucbd.ttf', color=>$blue, size=>13, aa=>1); > $text=$enc2utf->convert($ARGV[0]); > my @metrics = $font->bounding_box(string => $text); > print "$metrics[2], $text\n"; > $img->string(font=>$font, text=>$text, x=>1, utf8=>1, y=>19); > $img->write(file=>'test.png");
Supply the utf8 flag to the bounding_box() method too: my @metrics = $font->bounding_box(string => $text, utf8=>1); Without that flag, and without the scalar being marked as utf8 at the perl level, Imager can only assume it's Latin-1. Please let me know if this solves the problem for you. If this does solve the problem, then there's still a bug - in the documentation that doesn't mention the utf8 option for bounding_box(). Thanks for reporting this problem.
[TONYC - Thu Jun 2 06:19:10 2005]: Show quoted text
> > #!/usr/bin/perl > > use Text::Iconv; > > use Imager; > > > > my $enc2utf = new Text::Iconv('windows-1253', 'utf8'); > > my $img=Imager->new(xsize=>100,ysize=>22,channels=>3); > > my $font=Imager::Font->new(file => '/usr/local/share/ttf- > > fonts/Trebucbd.ttf', color=>$blue, size=>13, aa=>1); > > $text=$enc2utf->convert($ARGV[0]); > > my @metrics = $font->bounding_box(string => $text); > > print "$metrics[2], $text\n"; > > $img->string(font=>$font, text=>$text, x=>1, utf8=>1, y=>19); > > $img->write(file=>'test.png");
> > Supply the utf8 flag to the bounding_box() method too: > > my @metrics = $font->bounding_box(string => $text, utf8=>1); > > Without that flag, and without the scalar being marked as utf8 at the > perl level, Imager can only assume it's Latin-1. > > Please let me know if this solves the problem for you. > > If this does solve the problem, then there's still a bug - in the > documentation that doesn't mention the utf8 option for bounding_box(). > > Thanks for reporting this problem.
Hi, thanks for the responce, you're right, adding the utf8 flag solves the problem. If I had seen the source, I would have found it myself so I'm a little embarassed here :( Still, as you say, the documentation has to be updated. Thanks again. Michalis
fixed for 0.46.