centre point if both 'x' and 'y' were non-zero.
- the internal i_tags_get_string() function now acts correctly for
integer only tags.
+- the FT1.x driver now supports the align parameter correctly.
+ Tests were added to each driver to check correct handling of the align
+ parameter.
=================================================================
undef_int
-i_tt_text(handle,im,xb,yb,cl,points,str_sv,len_ignored,smooth,utf8)
+i_tt_text(handle,im,xb,yb,cl,points,str_sv,len_ignored,smooth,utf8,align=1)
Imager::Font::TT handle
Imager::ImgRaw im
int xb
int len_ignored
int smooth
int utf8
+ int align
PREINIT:
char *str;
STRLEN len;
#endif
str = SvPV(str_sv, len);
RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str,
- len, smooth, utf8);
+ len, smooth, utf8, align);
OUTPUT:
RETVAL
undef_int
-i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8)
+i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8,align=1)
Imager::Font::TT handle
Imager::ImgRaw im
int xb
int len_ignored
int smooth
int utf8
+ int align
PREINIT:
char *str;
STRLEN len;
#endif
str = SvPV(str_sv, len);
RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len,
- smooth, utf8);
+ smooth, utf8, align);
OUTPUT:
RETVAL
return 0;
}
- /* ascent = ( handle->properties.horizontal->Ascender * handle->instanceh[inst].imetrics.y_ppem ) / handle->properties.header->Units_Per_EM; */
-
if ( smooth ) i_tt_done_raster_map( &small_bit );
return 1;
}
*/
undef_int
-i_tt_cp( TT_Fonthandle *handle, i_img *im, int xb, int yb, int channel, float points, char const* txt, int len, int smooth, int utf8 ) {
+i_tt_cp( TT_Fonthandle *handle, i_img *im, int xb, int yb, int channel, float points, char const* txt, int len, int smooth, int utf8, int align ) {
int cords[BOUNDING_BOX_COUNT];
- int ascent, st_offset;
+ int ascent, st_offset, y;
TT_Raster_Map bit;
i_clear_error();
if (! i_tt_rasterize( handle, &bit, cords, points, txt, len, smooth, utf8 ) ) return 0;
- ascent=cords[5];
- st_offset=cords[0];
+ ascent=cords[BBOX_ASCENT];
+ st_offset=cords[BBOX_NEG_WIDTH];
+ y = align ? yb-ascent : yb;
- i_tt_dump_raster_map_channel( im, &bit, xb-st_offset , yb-ascent, channel, smooth );
+ i_tt_dump_raster_map_channel( im, &bit, xb-st_offset , y, channel, smooth );
i_tt_done_raster_map( &bit );
return 1;
*/
undef_int
-i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8) {
+i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8, int align) {
int cords[BOUNDING_BOX_COUNT];
- int ascent, st_offset;
+ int ascent, st_offset, y;
TT_Raster_Map bit;
i_clear_error();
if (! i_tt_rasterize( handle, &bit, cords, points, txt, len, smooth, utf8 ) ) return 0;
- ascent=cords[5];
- st_offset=cords[0];
+ ascent=cords[BBOX_ASCENT];
+ st_offset=cords[BBOX_NEG_WIDTH];
+ y = align ? yb-ascent : yb;
- i_tt_dump_raster_map2( im, &bit, xb+st_offset, yb-ascent, cl, smooth );
+ i_tt_dump_raster_map2( im, &bit, xb+st_offset, y, cl, smooth );
i_tt_done_raster_map( &bit );
return 1;
undef_int i_init_tt( void );
TT_Fonthandle* i_tt_new(char *fontname);
void i_tt_destroy( TT_Fonthandle *handle );
-undef_int i_tt_cp( TT_Fonthandle *handle,i_img *im,int xb,int yb,int channel,float points,char const* txt,int len,int smooth, int utf8);
-undef_int i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8);
+undef_int i_tt_cp( TT_Fonthandle *handle,i_img *im,int xb,int yb,int channel,float points,char const* txt,int len,int smooth, int utf8, int align);
+undef_int i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8, int align);
undef_int i_tt_bbox( TT_Fonthandle *handle, float points,char *txt,int len,int cords[6], int utf8);
int i_tt_has_chars(TT_Fonthandle *handle, char const *text, int len, int utf8, char *out);
void i_tt_dump_names(TT_Fonthandle *handle);
Imager::i_tt_cp($self->{id},$input{image}{IMG},
$input{'x'}, $input{'y'}, $input{channel}, $input{size},
$input{string}, length($input{string}),$input{aa},
- $input{utf8});
+ $input{utf8}, $input{align});
} else {
Imager::i_tt_text($self->{id}, $input{image}{IMG},
$input{'x'}, $input{'y'}, $input{color},
$input{size}, $input{string},
- length($input{string}), $input{aa}, $input{utf8});
+ length($input{string}), $input{aa}, $input{utf8},
+ $input{align});
}
}
# 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 => 58;
+use Test::More tests => 64;
BEGIN { use_ok(Imager => ':all') }
#$Imager::DEBUG=1;
SKIP:
{
if (!(i_has_format("t1")) ) {
- skip("t1lib unavailable or disabled", 57);
+ skip("t1lib unavailable or disabled", 63);
}
elsif (! -f $fontname_pfb) {
- skip("cannot find fontfile for type 1 test $fontname_pfb", 57);
+ skip("cannot find fontfile for type 1 test $fontname_pfb", 63);
}
elsif (! -f $fontname_afm) {
- skip("cannot find fontfile for type 1 test $fontname_afm", 57);
+ skip("cannot find fontfile for type 1 test $fontname_afm", 63);
}
print "# has t1\n";
my $font = Imager::Font->new(file=>$deffont, type=>'t1');
ok($font, "loaded deffont OO")
or skip("could not load font:".Imager->errstr, 4);
- my $im = Imager->new(xsize=>70, ysize=>150);
- my %common1 =
+ my $im = Imager->new(xsize=>140, ysize=>150);
+ my %common =
(
font=>$font,
- text=>'A',
size=>40,
- color=>'white',
- x=>5,
aa=>1,
);
- my %common2 =
- (
- font=>$font,
- text=>'y',
- size=>40,
- color=>'white',
- x=>40,
- aa=>1,
- );
- $im->line(x1=>0, y1=>40, x2=>69, y2=>40, color=>'blue');
- $im->line(x1=>0, y1=>90, x2=>69, y2=>90, color=>'blue');
- $im->line(x1=>0, y1=>110, x2=>69, y2=>110, color=>'blue');
- ok($im->string(%common1, 'y'=>40), "no alignment A");
- ok($im->string(%common2, 'y'=>40), "no alignment y");
- ok($im->string(%common1, 'y'=>90, align=>1), "align=1");
- ok($im->string(%common2, 'y'=>90, align=>1), "align=1");
- ok($im->string(%common1, 'y'=>110, align=>0), "align=0");
- ok($im->string(%common2, 'y'=>110, align=>0), "align=0");
+ $im->line(x1=>0, y1=>40, x2=>139, y2=>40, color=>'blue');
+ $im->line(x1=>0, y1=>90, x2=>139, y2=>90, color=>'blue');
+ $im->line(x1=>0, y1=>110, x2=>139, y2=>110, color=>'blue');
+ for my $args ([ x=>5, text=>"A", color=>"white" ],
+ [ x=>40, text=>"y", color=>"white" ],
+ [ x=>75, text=>"A", cp=>1 ],
+ [ x=>110, text=>"y", cp=>1 ]) {
+ ok($im->string(%common, @$args, 'y'=>40), "A no alignment");
+ ok($im->string(%common, @$args, 'y'=>90, align=>1), "A align=1");
+ ok($im->string(%common, @$args, 'y'=>110, align=>0), "A align=0");
+ }
ok($im->write(file=>'testout/t30align.ppm'), "save align image");
}
}
#!perl -w
use strict;
use lib 't';
-use Test::More tests => 57;
+use Test::More tests => 63;
BEGIN { use_ok(Imager => ':all') }
require "t/testtools.pl";
SKIP:
{
- skip("freetype 1.x unavailable or disabled", 56)
+ skip("freetype 1.x unavailable or disabled", 62)
unless i_has_format("tt");
print "# has tt\n";
if (!ok(-f $fontname, "check test font file exists")) {
print "# cannot find fontfile for truetype test $fontname\n";
- skip('Cannot load test font', 55);
+ skip('Cannot load test font', 61);
}
i_init_fonts();
my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'tt');
ok($font, "loaded deffont OO")
or skip("could not load font:".Imager->errstr, 4);
- my $im = Imager->new(xsize=>70, ysize=>150);
- my %common1 =
+ my $im = Imager->new(xsize=>140, ysize=>150);
+ my %common =
(
font=>$font,
- text=>'A',
size=>40,
- color=>'white',
- x=>5,
aa=>1,
);
- my %common2 =
- (
- font=>$font,
- text=>'y',
- size=>40,
- color=>'white',
- x=>40,
- aa=>1,
- );
- $im->line(x1=>0, y1=>40, x2=>69, y2=>40, color=>'blue');
- $im->line(x1=>0, y1=>90, x2=>69, y2=>90, color=>'blue');
- $im->line(x1=>0, y1=>110, x2=>69, y2=>110, color=>'blue');
- ok($im->string(%common1, 'y'=>40), "A no alignment");
- ok($im->string(%common2, 'y'=>40), "y no alignment");
- ok($im->string(%common1, 'y'=>90, align=>1), "A align=1");
- ok($im->string(%common2, 'y'=>90, align=>1), "y align=1");
- ok($im->string(%common1, 'y'=>110, align=>0), "A align=0");
- ok($im->string(%common2, 'y'=>110, align=>0), "y align=0");
+ $im->line(x1=>0, y1=>40, x2=>139, y2=>40, color=>'blue');
+ $im->line(x1=>0, y1=>90, x2=>139, y2=>90, color=>'blue');
+ $im->line(x1=>0, y1=>110, x2=>139, y2=>110, color=>'blue');
+ for my $args ([ x=>5, text=>"A", color=>"white" ],
+ [ x=>40, text=>"y", color=>"white" ],
+ [ x=>75, text=>"A", cp=>1 ],
+ [ x=>110, text=>"y", cp=>1 ]) {
+ ok($im->string(%common, @$args, 'y'=>40), "A no alignment");
+ ok($im->string(%common, @$args, 'y'=>90, align=>1), "A align=1");
+ ok($im->string(%common, @$args, 'y'=>110, align=>0), "A align=0");
+ }
ok($im->write(file=>'testout/t35align.ppm'), "save align image");
}
#!perl -w
use strict;
-use Test::More tests => 152;
+use Test::More tests => 158;
++$|;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
SKIP:
{
- i_has_format("ft2") or skip("no freetype2 library found", 151);
+ i_has_format("ft2") or skip("no freetype2 library found", 157);
print "# has ft2\n";
my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
- -f $fontname or skip("cannot find fontfile $fontname", 151);
+ -f $fontname or skip("cannot find fontfile $fontname", 157);
my $bgcolor=i_color_new(255,0,0,0);
my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
ok($font, "loaded deffont OO")
or skip("could not load font:".Imager->errstr, 4);
- my $im = Imager->new(xsize=>70, ysize=>150);
- my %common1 =
+ my $im = Imager->new(xsize=>140, ysize=>150);
+ my %common =
(
font=>$font,
- text=>'A',
size=>40,
- color=>'white',
- x=>5,
aa=>1,
);
- my %common2 =
- (
- font=>$font,
- text=>'y',
- size=>40,
- color=>'white',
- x=>40,
- aa=>1,
- );
- $im->line(x1=>0, y1=>40, x2=>69, y2=>40, color=>'blue');
- $im->line(x1=>0, y1=>90, x2=>69, y2=>90, color=>'blue');
- $im->line(x1=>0, y1=>110, x2=>69, y2=>110, color=>'blue');
- ok($im->string(%common1, 'y'=>40), "A no alignment");
- ok($im->string(%common2, 'y'=>40), "y no alignment");
- ok($im->string(%common1, 'y'=>90, align=>1), "A align=1");
- ok($im->string(%common2, 'y'=>90, align=>1), "y align=1");
- ok($im->string(%common1, 'y'=>110, align=>0), "A align=0");
- ok($im->string(%common2, 'y'=>110, align=>0), "y align=0");
+ $im->line(x1=>0, y1=>40, x2=>139, y2=>40, color=>'blue');
+ $im->line(x1=>0, y1=>90, x2=>139, y2=>90, color=>'blue');
+ $im->line(x1=>0, y1=>110, x2=>139, y2=>110, color=>'blue');
+ for my $args ([ x=>5, text=>"A", color=>"white" ],
+ [ x=>40, text=>"y", color=>"white" ],
+ [ x=>75, text=>"A", cp=>1 ],
+ [ x=>110, text=>"y", cp=>1 ]) {
+ ok($im->string(%common, @$args, 'y'=>40), "A no alignment");
+ ok($im->string(%common, @$args, 'y'=>90, align=>1), "A align=1");
+ ok($im->string(%common, @$args, 'y'=>110, align=>0), "A align=0");
+ }
ok($im->write(file=>'testout/t38align.ppm'), "save align image");
}
}