]> git.imager.perl.org - imager.git/commitdiff
fix rendering on alpha channel images for the T1lib driver.
authorTony Cook <tony@develop=help.com>
Sat, 5 May 2007 05:02:19 +0000 (05:02 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 5 May 2007 05:02:19 +0000 (05:02 +0000)
Changes
font.c
t/t30t1font.t

diff --git a/Changes b/Changes
index c36aeabdc5f658692c6a1f4979f55e0dfc94e44d..5143100c2ede7ae863533ec4d8b848135e989a24 100644 (file)
--- a/Changes
+++ b/Changes
@@ -26,6 +26,9 @@ Bug fixes:
  - fix rendering on alpha channel images for the FreeType 1.x driver.
    http://rt.cpan.org/Ticket/Display.html?id=11972
 
+ - fix rendering on alpha channel images for the T1lib driver.
+   http://rt.cpan.org/Ticket/Display.html?id=11972
+
 Imager 0.57 - 30 Apr 2007
 ===========
 
diff --git a/font.c b/font.c
index cd6aaef4d01c642f4cdb2faa2f6331a97c2c7f96..b8f33a1033a6818ab7c4a1325477b4144617aabe 100644 (file)
--- a/font.c
+++ b/font.c
@@ -411,6 +411,7 @@ i_t1_text(i_img *im,int xb,int yb,const i_color *cl,int fontnum,float points,con
   i_color val;
   unsigned char c,i;
   int mod_flags = t1_get_flags(flags);
+  i_render r;
 
   if (im == NULL) { mm_log((1,"i_t1_cp: Null image in input\n")); return(0); }
 
@@ -438,14 +439,13 @@ i_t1_text(i_img *im,int xb,int yb,const i_color *cl,int fontnum,float points,con
   mm_log((1,"width: %d height: %d\n",xsize,ysize));
 
   if (align==1) { xb+=glyph->metrics.leftSideBearing; yb-=glyph->metrics.ascent; }
-  
-  for(y=0;y<ysize;y++) for(x=0;x<xsize;x++) {
-    c=glyph->bits[y*xsize+x];
-    i=255-c;
-    i_gpix(im,x+xb,y+yb,&val);
-    for(ch=0;ch<im->channels;ch++) val.channel[ch]=(c*cl->channel[ch]+i*val.channel[ch])/255;
-    i_ppix(im,x+xb,y+yb,&val);
+
+  i_render_init(&r, im, xsize);
+  for(y=0;y<ysize;y++) {
+    i_render_color(&r, xb, yb+y, xsize, glyph->bits+y*xsize, cl);
   }
+  i_render_done(&r);
+    
   return 1;
 }
 
index fda87541e305ddfa60124d245d7a355bc0b0c13b..c0ead46e0b34a1150547a3143af4b16d9c709af1 100644 (file)
@@ -7,9 +7,9 @@
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 use strict;
-use Test::More tests => 90;
+use Test::More tests => 94;
 BEGIN { use_ok(Imager => ':all') }
-use Imager::Test qw(diff_text_with_nul);
+use Imager::Test qw(diff_text_with_nul is_color3);
 
 #$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", 89);
+    skip("t1lib unavailable or disabled", 93);
   }
   elsif (! -f $fontname_pfb) {
-    skip("cannot find fontfile for type 1 test $fontname_pfb", 89);
+    skip("cannot find fontfile for type 1 test $fontname_pfb", 93);
   }
   elsif (! -f $fontname_afm) {
-    skip("cannot find fontfile for type 1 test $fontname_afm", 89);
+    skip("cannot find fontfile for type 1 test $fontname_afm", 93);
   }
 
   print "# has t1\n";
@@ -46,7 +46,7 @@ SKIP:
 
   my $fnum=Imager::i_t1_new($fontname_pfb,$fontname_afm); # this will load the pfb font
   unless (ok($fnum >= 0, "load font $fontname_pfb")) {
-    skip("without the font I can't do a thing", 48);
+    skip("without the font I can't do a thing", 90);
   }
 
   my $bgcolor=Imager::Color->new(255,0,0,0);
@@ -326,6 +326,23 @@ SKIP:
                       font => $font, channel => 1, utf8 => 1);
 
   }
+
+  { # RT 11972
+    # when rendering to a transparent image the coverage should be
+    # expressed in terms of the alpha channel rather than the color
+    my $font = Imager::Font->new(file=>'fontfiles/dcr10.pfb', type=>'t1');
+    my $im = Imager->new(xsize => 40, ysize => 20, channels => 4);
+    ok($im->string(string => "AB", size => 20, aa => 2, color => '#F00',
+                  x => 0, y => 15, font => $font),
+       "draw to transparent image");
+    my $im_noalpha = $im->convert(preset => 'noalpha');
+    my $im_pal = $im->to_paletted(make_colors => 'mediancut');
+    my @colors = $im_pal->getcolors;
+    is(@colors, 2, "should be only 2 colors");
+    @colors = sort { ($a->rgba)[0] <=> ($b->rgba)[0] } @colors;
+    is_color3($colors[0], 0, 0, 0, "check we got black");
+    is_color3($colors[1], 255, 0, 0, "and red");
+  }
 }
 
 #malloc_state();