From 4c84ccfb2334bbfd264736bcaa2b983c448c9966 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sat, 5 May 2007 05:02:19 +0000 Subject: [PATCH] fix rendering on alpha channel images for the T1lib driver. --- Changes | 3 +++ font.c | 14 +++++++------- t/t30t1font.t | 29 +++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Changes b/Changes index c36aeabd..5143100c 100644 --- 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 cd6aaef4..b8f33a10 100644 --- 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;ybits[y*xsize+x]; - i=255-c; - i_gpix(im,x+xb,y+yb,&val); - for(ch=0;chchannels;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;ybits+y*xsize, cl); } + i_render_done(&r); + return 1; } diff --git a/t/t30t1font.t b/t/t30t1font.t index fda87541..c0ead46e 100644 --- a/t/t30t1font.t +++ b/t/t30t1font.t @@ -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();