]> git.imager.perl.org - imager.git/commitdiff
bounding_box() for the t1 driver wasn't converting from UTF8 to ascii
authorTony Cook <tony@develop=help.com>
Thu, 20 Jul 2006 14:35:22 +0000 (14:35 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 20 Jul 2006 14:35:22 +0000 (14:35 +0000)
when calculating the advance width.

fixes http://rt.cpan.org/Ticket/Display.html?id=20554

font.c
t/t30t1font.t

diff --git a/font.c b/font.c
index 6f72710e3d122d83a8d5e61e208b068d23675dd9..9e09b417c12fb6f190fbcf971802073b9b01ce05 100644 (file)
--- a/font.c
+++ b/font.c
@@ -343,15 +343,16 @@ i_t1_bbox(int fontnum,float points,const char *str,int len,int cords[6], int utf
     advance = 0;
   }
   else {
-    advance = T1_GetStringWidth(fontnum, (char *)str, len, 0, mod_flags);
     if (utf8) {
       int worklen;
       char *work = t1_from_utf8(str, len, &worklen);
+      advance = T1_GetStringWidth(fontnum, work, worklen, 0, mod_flags);
       bbox = T1_GetStringBBox(fontnum,work,worklen,0,mod_flags);
       t1_fix_bbox(&bbox, work, worklen, advance, space_position);
       myfree(work);
     }
     else {
+      advance = T1_GetStringWidth(fontnum, (char *)str, len, 0, mod_flags);
       bbox = T1_GetStringBBox(fontnum,(char *)str,len,0,mod_flags);
       t1_fix_bbox(&bbox, str, len, advance, space_position);
     }
index 4331e649b624ae15b9d5700d0ea8eb45befe1370..2a3370f27544210a1ddcf6e7bb1882c2c468e4d2 100644 (file)
@@ -8,7 +8,7 @@
 # (It may become useful if the test is moved to ./t subdirectory.)
 use strict;
 use lib 't';
-use Test::More tests => 76;
+use Test::More tests => 77;
 BEGIN { use_ok(Imager => ':all') }
 
 #$Imager::DEBUG=1;
@@ -23,13 +23,13 @@ my $fontname_afm=$ENV{'T1FONTTESTAFM'}||'./fontfiles/dcr10.afm';
 SKIP:
 {
   if (!(i_has_format("t1")) ) {
-    skip("t1lib unavailable or disabled", 75);
+    skip("t1lib unavailable or disabled", 76);
   }
   elsif (! -f $fontname_pfb) {
-    skip("cannot find fontfile for type 1 test $fontname_pfb", 75);
+    skip("cannot find fontfile for type 1 test $fontname_pfb", 76);
   }
   elsif (! -f $fontname_afm) {
-    skip("cannot find fontfile for type 1 test $fontname_afm", 75);
+    skip("cannot find fontfile for type 1 test $fontname_afm", 76);
   }
 
   print "# has t1\n";
@@ -292,6 +292,22 @@ SKIP:
     is($bbox_spbangsp->start_offset, 0, "sp ! sp start_offset");
     is($bbox_spbangsp->end_offset, $exp_advance, "sp ! sp end_offset");
   }
+
+ SKIP:
+  { # http://rt.cpan.org/Ticket/Display.html?id=20554
+    # this is "A\xA1\x{2010}A"
+    # the t1 driver is meant to ignore any UTF8 characters over 0xff
+    print "# issue 20554\n";
+    my $text = pack("C*", 0x41, 0xC2, 0xA1, 0xE2, 0x80, 0x90, 0x41);
+    my $tran_text = "A\xA1A";
+    my $font = Imager::Font->new(file => 'fontfiles/dcr10.pfb', type => 't1');
+    $font
+      or skip("cannot load font fontfiles/fcr10.pfb:".Imager->errstr, 1);
+    my $bbox_utf8 = $font->bounding_box(string => $text, utf8 => 1, size => 36);
+    my $bbox_tran = $font->bounding_box(string => $tran_text, size => 36);
+    is($bbox_utf8->advance_width, $bbox_tran->advance_width,
+       "advance widths should match");
+  }
 }
 
 #malloc_state();