Skip to content

Commit

Permalink
fix rendering on alpha channel images for the T1lib driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Cook committed May 5, 2007
1 parent fa08165 commit 4c84ccf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -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
===========

Expand Down
14 changes: 7 additions & 7 deletions font.c
Expand Up @@ -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); }

Expand Down Expand Up @@ -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;
}

Expand Down
29 changes: 23 additions & 6 deletions t/t30t1font.t
Expand Up @@ -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;

Expand All @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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();

0 comments on commit 4c84ccf

Please sign in to comment.