Thread

Posted on Wed Oct 18 12:39:46 2006 by llhca
Imager and UNICODE characters

I desire release of a BMP picture with a text who have some UNICODE characters.

For example :

Hello ☺!

(Unicode character: smiley white face,U+263A )

The WINDOWS font using have this character

The bmp released have the UNICODE character replaced with three 'ASCII' characters,

Imager can it create images with characters UNICODE?

Where is the problem(s) in the following code ?

PERL: ActiveState

v5.8.8 built for MSWin32-x86-multi-thread

IMAGER:

v0.54

#!/usr/bin/perl #-w use warnings; use strict; use Imager; use encoding 'utf8'; # use a different file, depending on the font support you have in # your installed Imager. my $Font_Name="Courier New Bold"; my $font = Imager::Font->new(face=>$Font_Name) or die "Cannot load '" . $Font_Name . ": ", Imager->errstr; my $text ="Hello \x{263A}!"; my $text_size = 12; my $bbox = $font->bounding_box(string=>$text, size=>$text_size, ); my $X_Text=$bbox->total_width(); #debug print "long. texte: $X_Text\n"; my $Decal=$X_Text-$bbox->display_width(); #debug print "decal: $Decal \n"; my $Y_Text=$bbox->text_height(); #debug print "Haut. texte: $Y_Text\n"; my $Border_size=2; #debug print "bordure: $Border_size\n"; my $Text_Delim=1; #debug print "Delim: $Text_Delim\n"; my $X_Img_size=($X_Text-$Decal)+(($Border_size+$Text_Delim)*2); my $Y_Img_size=$Y_Text+(($Border_size+$Text_Delim)*2); my $image = Imager->new(xsize=>$X_Img_size, ysize => $Y_Img_size); #debug print "long image \$X_Img_size: $X_Img_size, Width: " . $image->getwidth . "\n"; #debug print "Haut image \$Y_Img_size: $Y_Img_size, height: " . $image->getheight . "\n"; $image->box(xmin => 0, ymin => 0, xmax => ( $X_Img_size-1), ymax => ($Y_Img_size-1), filled => 1, color => 'blue'); $image->box(xmin => $Border_size, ymin => $Border_size, xmax => (($image->getwidth)-$Border_size)-1, ymax => (($image->getheight)-$Border_size)-1, filled => 1, color => 'green'); #debug print " max x zone int: ".(($image->getwidth)-($Border_size))."\n"; #debug print " max y zone int: ".(($image->getheight)-($Border_size))."\n"; $font->align(string => $text, size => $text_size, color => 'red', x => ($image->getwidth/2)+$Decal, y => $image->getheight/2, halign => 'center', valign => 'center', image => $image); #debug print "Texte: \n $text\n"; $image->write(file=>'test1.bmp') or die 'Cannot save test1.bmp: ', $image->errstr;
Direct Responses: 3279 | Write a response
Posted on Thu Oct 19 02:20:26 2006 by tonyc in response to 3276
Re: Imager and UNICODE characters

The problem is that Imager's Win32 font driver currently doesn't support Unicode.

I'll look at this for the next release, but that might be a way off, since work is keeping me busy at the moment.

Direct Responses: 3282 | Write a response
Posted on Thu Oct 19 15:44:47 2006 by tonyc in response to 3279
Re: Imager and UNICODE characters

This is now fixed in svn.

svn co http://imager.perl.org/svn/trunk/Imager/

to try it out

Direct Responses: 3330 | Write a response
Posted on Wed Oct 25 16:05:11 2006 by llhca in response to 3282
Re: Imager and UNICODE characters

Thank for your quickly answer.

Now it's clear.

I tested the version stemming from SVN.

I added it to the version 5.8.7-5 of PERL, under CYGWIN version: 1.5.21-2.

Buid with GCC version: 3.4.4-1.

OS: Windows 2000 professional SP4

Generate bmp picture with Asian or Arabic UNICODE characters, into a text string, works fine.

However, the BBOX module return an erroneous value with the methods "descent" and "ascent".

see details into the folowing line:

Initial version: file name : oldversion.bmp Has Win32 fonts Text: Hello Box ! pour le 'fun' Size of text: 36 bbox->start_offset (or neg_with, or left_bearing: 3 bbox->pos_width (or end_offset): 361 bbox->global_descent: 8 bbox->global_ascent: 33 bbox->descent: -7 <=============== bbox->ascent: 26 <=============== bbox->advance_width: 361 bbox->total_width: 358 bbox->font_height: 25 bbox->text_height: 33 <=============== bbox->right_bearing: 2 bbox->display_width: 356 image->getwidth: 362 image->getheight: 39 ---------------------------------------------- new version: file name : newversion.bmp Has Win32 fonts Text: Hello Box ! pour le 'fun' Size of text: 36 bbox=>start_offset (or neg_with, or left_bearing: 3 bbox=>pos_width (or end_offset): 361 bbox=>global_descent: 8 bbox=>global_ascent: 33 bbox->descent: 8 <=============== bbox->ascent: 33 <=============== bbox=>advance_width: 361 bbox->total_width: 358 bbox=>font_height: 25 bbox->text_height: 25 <=============== bbox->right_bearing: 2 bbox->display_width: 356 image->getwidth: 362 image->getheight: 31

llca

P.S.:

I apologize for the delai of the answer but I am boeotian "Rooki" with those processus

;-)

Direct Responses: 3350 | Write a response
Posted on Fri Oct 27 17:37:47 2006 by llhca in response to 3330
Re: Imager and UNICODE characters

I have made some research into the files got from SVN.

It seems that the problems reported in my message ("Re: Imager and UNICODE characters",Wed Oct 25 15:05:11 2006) was caused by a erroneous affectation of a data into the file win32.c.

Win32.c:
... 45 int i_wf_bbox(.... ... ... 75 workp = text; 76 work_len = 0; 77 while (work_len > 0) { 78 unsigned long c; 79 unsigned char cp; .....

I changed the line 76 like this : work_len = length;

Is it correct ?

I have some doubts because the tests report some anomalies:

=============================
t00basic........ok
t01introvert....ok
t020masked......ok
t021sixteen.....ok
t022double......ok
t023palette.....ok
t05error........ok
t07iolayer......ok
t1000files......ok
t101jpeg........ok
82/86 skipped: no jpeg support
t102png.........ok
27/32 skipped: no png support
t103raw.........ok
t104ppm.........ok
t105gif.........ok
121/125 skipped: no gif support
t106tiff........ok
123/127 skipped: no tiff support
t107bmp.........ok
t108tga.........ok
t15color........ok
1/47 skipped: no X rgb.txt found
t16matrix.......ok
t20fill.........ok
t21draw.........ok
t30t1font.......ok
76/77 skipped: t1lib unavailable or disabled
t35ttfont.......ok
71/72 skipped: freetype 1.x unavailable or disabled
t36oofont.......ok
18/20 skipped: various reasons
t37w32font......ok 2/38# Looks like you planned 38 tests but ran 1 extra.
t37w32font......dubious
Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 39
Failed 1/38 tests, 97.37% okay (less 11 skipped tests: 26 okay, 68.42%)
t38ft2font......ok
164/165 skipped: no freetype2 library found
t40scale........ok
3/223 skipped: optional module Image::Math::Constrain not installed
t50basicoo......ok
t55trans........ok
4/5 skipped: # warning transform: expr given and Affix::Infix2Postfix is
not avaliable.
t56postfix......ok
t57infix........ok
t58trans2.......ok
t59assem........ok
t61filters......ok
t64copyflip.....ok
t65crop.........ok
t66paste........ok
t67convert......ok
t68map..........ok
t69rubthru......ok
t70newgif.......ok
t75polyaa.......ok
t80texttools....ok
9/11 skipped: Need Freetype 1.x or 2.x to test
t81hlines.......ok
t82inline.......skipped
all skipped: Inline required for testing API
t90cc...........ok
t91pod..........skipped
all skipped: Test::Pod 1.00 required for testing POD
t92samples......ok
t93podcover.....skipped
all skipped: Test::Pod::Coverage 1.08 required for POD coverage
t94kwalitee.....ok
tr18561.........ok
tr18561b........ok
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t37w32font.t 1 256 38 1 2.63% 39
3 tests and 710 subtests skipped.
Failed 1/52 test scripts, 98.08% okay. -1/2456 subtests failed, 100.04% okay.
make: *** [test_dynamic] Erreur 14

==================

and, when i use this text : "Hello \x{263A}!", with the windows font "Arial", there is not the same same space between the bottom of the 'smiley' and the bottom of the picture ( 2 pixels) than when i use this text "Hello Box ! pour le 'fun'" (3 pixels between the bottom of the 'P' and the bottom of the picture.

My program creates an image which should have the height and the length of the text more 3 pixels.

best Regards
Direct Responses: 3361 | Write a response
Posted on Sun Oct 29 10:42:16 2006 by tonyc in response to 3350
Re: Imager and UNICODE characters

Your change was more correct than it was. Thanks for tracking that down.

I've made some other changes that fixe other problems in the UTF8 support and fix an old problem with clipping characters that overhang the left and right ends.

If you want to take a look at current svn you should find it gives you a much tighter bounding box - check the testout/t37w32_bang.ppm and testout/t37w32_slash.ppm for examples.

Write a response