Permalink
Browse files

[rt #73359] draw non-aa text in alpha combining mode for FT1

  • Loading branch information...
1 parent b9459ad commit dcab59bcc8a42ab7a7eea1217a0d886ecf2af760 @tonycoz committed Jun 10, 2013
Showing with 73 additions and 10 deletions.
  1. +3 −0 Changes
  2. +11 −3 fontft1.c
  3. +59 −7 t/350-font/030-ttoo.t
View
@@ -34,6 +34,9 @@ Imager release history. Older releases can be found in Changes.old
- some XS code formatting
+ - TT (Freetype 1.x) and FT2 (Freetype 2.x) non-antialiased rendering
+ now renders in alpha-combining mode, to match antialiased output.
+ https://rt.cpan.org/Ticket/Display.html?id=73359
Imager 0.96 - 19 May 2013
===========
View
@@ -871,22 +871,30 @@ i_tt_dump_raster_map2( i_img* im, TT_Raster_Map* bit, i_img_dim xb, i_img_dim yb
}
i_render_done(&r);
} else {
+ unsigned char *bmp = mymalloc(bit->width);
+ i_render r;
+
+ i_render_init(&r, im, bit->width);
+
for(y=0;y<bit->rows;y++) {
unsigned mask = 0x80;
unsigned char *p = bmap + y * bit->cols;
+ unsigned char *pout = bmp;
for(x = 0; x < bit->width; x++) {
- if (*p & mask) {
- i_ppix(im, x+xb, y+yb, cl);
- }
+ *pout++ = (*p & mask) ? 0xFF : 0;
mask >>= 1;
if (!mask) {
mask = 0x80;
++p;
}
}
+
+ i_render_color(&r, xb, yb+y, bit->cols, bmp, cl);
}
+ i_render_done(&r);
+ myfree(bmp);
}
}
View
@@ -10,19 +10,18 @@ use strict;
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
-use Test::More tests => 16;
+use Test::More tests => 26;
-BEGIN { use_ok('Imager') };
+use Imager;
-BEGIN {
- require Imager::Test;
- Imager::Test->import(qw(isnt_image));
-}
+use Imager::Test qw(isnt_image is_image);
-d "testout" or mkdir "testout";
Imager->open_log(log => "testout/t36oofont.log");
+my @test_output;
+
my $fontname_tt=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
my $green=Imager::Color->new(92,205,92,128);
@@ -33,7 +32,7 @@ die $Imager::ERRSTR unless $red;
SKIP:
{
$Imager::formats{"tt"} && -f $fontname_tt
- or skip("FT1.x missing or disabled", 14);
+ or skip("FT1.x missing or disabled", 24);
my $img=Imager->new(xsize=>300, ysize=>100) or die "$Imager::ERRSTR\n";
@@ -97,6 +96,59 @@ SKIP:
isnt_image($work, $cmp, "make sure something was drawn");
}
}
+
+ { # RT 73359
+ # non-AA font drawing isn't normal mode
+
+ Imager->log("testing no-aa normal output\n");
+
+ my $font = Imager::Font->new(file => "fontfiles/ImUgly.ttf", type => "tt");
+
+ ok($font, "make a work font");
+
+ my %common =
+ (
+ x => 10,
+ font => $font,
+ size => 25,
+ aa => 0,
+ align => 0,
+ );
+
+ # build our comparison image
+ my $cmp = Imager->new(xsize => 120, ysize => 100);
+ my $layer = Imager->new(xsize => 120, ysize => 100, channels => 4);
+ ok($layer->string(%common, y => 10, text => "full", color => "#8080FF"),
+ "draw non-aa text at full coverage to layer image");
+ ok($layer->string(%common, y => 40, text => "half", color => "#FF808080"),
+ "draw non-aa text at half coverage to layer image");
+ ok($layer->string(%common, y => 70, text => "quarter", color => "#80FF8040"),
+ "draw non-aa text at zero coverage to layer image");
+ ok($cmp->rubthrough(src => $layer), "rub layer onto comparison image");
+
+ my $im = Imager->new(xsize => 120, ysize => 100);
+ ok($im->string(%common, y => 10, text => "full", color => "#8080FF"),
+ "draw non-aa text at full coverage");
+ ok($im->string(%common, y => 40, text => "half", color => "#FF808080"),
+ "draw non-aa text at half coverage");
+ ok($im->string(%common, y => 70, text => "quarter", color => "#80FF8040"),
+ "draw non-aa text at zero coverage");
+ is_image($im, $cmp, "check the result");
+
+ push @test_output, "ttaanorm.ppm", "ttaacmp.ppm";
+ ok($cmp->write(file => "testout/ttaacmp.ppm"), "save cmp image")
+ or diag "Saving cmp image: ", $cmp->errstr;
+ ok($im->write(file => "testout/ttaanorm.ppm"), "save test image")
+ or diag "Saving result image: ", $im->errstr;
+ }
+}
+
+Imager->close_log;
+
+END {
+ unless ($ENV{IMAGER_KEEP_FILES}) {
+ unlink map "testout/$_", @test_output;
+ }
}
ok(1, "end");

0 comments on commit dcab59b

Please sign in to comment.