*_first = \&Imager::Font::_first;
-my $t1aa;
-
-# $T1AA is in there because for some reason (probably cache related) antialiasing
-# is a system wide setting in t1 lib.
+my $t1aa = 2;
sub new {
my $class = shift;
type => 't1',
size => $hsh{size},
color => $hsh{color},
+ t1aa => $t1aa,
}, $class;
}
$flags .= 'u' if $input{underline};
$flags .= 's' if $input{strikethrough};
$flags .= 'o' if $input{overline};
+ my $aa = $input{aa} ? $self->{t1aa} : 0;
if (exists $input{channel}) {
$self->{t1font}->cp($input{image}{IMG}, $input{'x'}, $input{'y'},
$input{channel}, $input{size},
$input{string}, length($input{string}), $input{align},
- $input{utf8}, $flags, $input{aa});
+ $input{utf8}, $flags, $aa)
+ or return;
} else {
$self->{t1font}->text($input{image}{IMG}, $input{'x'}, $input{'y'},
$input{color}, $input{size},
$input{string}, length($input{string}),
- $input{align}, $input{utf8}, $flags, $input{aa});
+ $input{align}, $input{utf8}, $flags, $aa)
+ or return;
}
return $self;
return $self->{t1font}->glyph_name($string, $utf8);
}
+sub set_aa_level {
+ my ($self, $new_t1aa) = @_;
+
+ if (!defined $new_t1aa ||
+ ($new_t1aa != 1 && $new_t1aa != 2)) {
+ Imager->_set_error("set_aa_level: parameter must be 1 or 2");
+ return;
+ }
+
+ if (ref $self) {
+ $self->_valid
+ or return;
+
+ $self->{t1aa} = $new_t1aa;
+ }
+ else {
+ $t1aa = $new_t1aa;
+ }
+
+ return 1;
+}
sub _valid {
my $self = shift;
Obviously, if you're calculating the bounding box the size of the line
is included in the box, and the line isn't drawn :)
+=head2 Anti-aliasing
+
+T1Lib supports multiple levels of anti-aliasing, by default, if you
+request anti-aliased output, Imager::Font::T1 will use the maximum
+level.
+
+You can override this with the set_t1_aa() method:
+
+=over
+
+=item set_aa_level()
+
+Usage:
+
+ $font->set_aa_level(1);
+ Imager::Font::T1->set_aa_level(2);
+
+Sets the T1Lib anti-aliasing level either for the specified font, or
+for new font objects.
+
+The only parameter must be 1 or 2.
+
+Returns true on success.
+
+=back
+
=head1 AUTHOR
Addi, Tony
static undef_int
i_init_t1_low(int t1log) {
int init_flags = IGNORE_CONFIGFILE|IGNORE_FONTDATABASE;
- mm_log((1,"init_t1()\n"));
+
+ mm_log((1,"init_t1(%d)\n", t1log));
i_clear_error();
return(1);
}
T1_SetLogLevel(T1LOG_DEBUG);
- i_t1_set_aa(1); /* Default Antialias value */
++t1_initialized;
++t1_active_fonts;
- mm_log((1, "i_t1_new() -> %d\n", font_id));
-
i_mutex_unlock(mutex);
font = mymalloc(sizeof(*font));
font->font_id = font_id;
+ mm_log((1, "i_t1_new() -> %p (%d)\n", font, font_id));
+
return font;
}
i_mutex_lock(mutex);
- mm_log((1,"i_t1_destroy(font_id %d)\n",font->font_id));
+ mm_log((1,"i_t1_destroy(font %p (%d))\n", font, font->font_id));
--t1_active_fonts;
str - string to render
len - string length
align - (0 - top of font glyph | 1 - baseline )
- aa - anti-aliasing
+ aa - anti-aliasing level
=cut
*/
unsigned int ch_mask_store;
- if (im == NULL) { mm_log((1,"i_t1_cp: Null image in input\n")); return(0); }
+ i_clear_error();
+
+ mm_log((1, "i_t1_cp(font %p (%d), im %p, (xb,yb)=" i_DFp ", channel %d, points %g, str %p, len %u, align %d, utf8 %d, flags '%s', aa %d)\n",
+ font, fontnum, im, i_DFcp(xb, yb), channel, points, str, (unsigned)len, align, utf8, flags, aa));
+
+ if (im == NULL) {
+ mm_log((1,"i_t1_cp: Null image in input\n"));
+ i_push_error(0, "null image");
+ return(0);
+ }
i_mutex_lock(mutex);
glyph=T1_AASetString( fontnum, str, len, 0, mod_flags, points, NULL);
}
if (glyph == NULL) {
+ t1_push_error();
+ i_push_error(0, "i_t1_cp: T1_AASetString failed");
i_mutex_unlock(mutex);
return 0;
}
space_position = T1_GetEncodingIndex(fontnum, "space");
- mm_log((1,"i_t1_bbox(fontnum %d,points %.2f,str '%.*s', len %d)\n",fontnum,points,len,str,len));
+ mm_log((1,"i_t1_bbox(font %p (%d),points %.2f,str '%.*s', len %d)\n",font, fontnum,points,len,str,len));
T1_LoadFont(fontnum); /* FIXME: Here a return code is ignored - haw haw haw */
if (len == 0) {
i_render *r;
int fontnum = font->font_id;
- if (im == NULL) { mm_log((1,"i_t1_cp: Null image in input\n")); return(0); }
+ mm_log((1, "i_t1_text(font %p (%d), im %p, (xb,yb)=" i_DFp ", cl (%d,%d,%d,%d), points %g, str %p, len %u, align %d, utf8 %d, flags '%s', aa %d)\n",
+ font, fontnum, im, i_DFcp(xb, yb), cl->rgba.r, cl->rgba.g, cl->rgba.b, cl->rgba.a, points, str, (unsigned)len, align, utf8, flags, aa));
+
+ i_clear_error();
+
+ if (im == NULL) {
+ i_push_error(0, "null image");
+ mm_log((1,"i_t1_text: Null image in input\n"));
+ return(0);
+ }
i_mutex_lock(mutex);
glyph=T1_AASetString( fontnum, (char *)str, len, 0, mod_flags, points, NULL);
}
if (glyph == NULL) {
+ mm_log((1, "T1_AASetString failed\n"));
+ t1_push_error();
+ i_push_error(0, "i_t1_text(): T1_AASetString failed");
i_mutex_unlock(mutex);
return 0;
}
use strict;
use Test::More;
use Imager ':all';
-use Imager::Test qw(diff_text_with_nul is_color3);
+use Imager::Test qw(diff_text_with_nul is_color3 is_image isnt_image);
use Imager::Font::T1;
use Cwd qw(getcwd abs_path);
#$Imager::DEBUG=1;
-plan tests => 96;
+plan tests => 108;
ok($Imager::formats{t1}, "must have t1");
ok($font, "found font by drive relative path")
or print "# path $drive_path\n";
}
+
+ {
+ Imager->log("Testing aa levels", 1);
+ my $f1 = Imager::Font->new(file => $deffont, type => "t1");
+ is($f1->{t1aa}, 2, "should have default aa level");
+ my $imbase = Imager->new(xsize => 100, ysize => 20);
+ ok($imbase->string(text => "test", size => 18, x => 5, y => 18,
+ color => "#FFF", font => $f1, aa => 1),
+ "draw text with def aa level");
+ ok(Imager::Font::T1->set_aa_level(1), "set aa level to 1");
+ my $f2 = Imager::Font->new(file => $deffont, type => "t1");
+ is($f2->{t1aa}, 1, "new font has new aa level");
+ my $imaa1 = Imager->new(xsize => 100, ysize => 20);
+ ok($imaa1->string(text => "test", size => 18, x => 5, y => 18,
+ color => "#FFF", font => $f2, aa => 1),
+ "draw text with non-def aa level");
+ isnt_image($imbase, $imaa1, "images should differ");
+ ok($f2->set_aa_level(2), "set aa level of font");
+ is($f2->{t1aa}, 2, "check new aa level");
+ my $imaa2 = Imager->new(xsize => 100, ysize => 20);
+ ok($imaa2->string(text => "test", size => 18, x => 5, y => 18,
+ color => "#FFF", font => $f2, aa => 1),
+ "draw text with non-def but 2 aa level");
+ is_image($imbase, $imaa2, "check images match");
+ }
+
+ { # error handling check
+ my $im = Imager->new(xsize => 100, ysize => 20);
+ my $fnum = Imager::Font->new(file => $deffont, type => "t1");
+ ok(!$im->string(font => $fnum, string => "text", size => -10),
+ "set invalid size");
+ is($im->errstr, "i_t1_text(): T1_AASetString failed: Invalid Argument in Function Call",
+ "check error message");
+ }
}
#malloc_state();