Skip to content

Commit

Permalink
- the FT1.x driver now supports the align parameter correctly.
Browse files Browse the repository at this point in the history
  Tests were added to each driver to check correct handling of the align
  parameter.
  • Loading branch information
Tony Cook committed May 2, 2005
1 parent 6a00d62 commit 9ab6338
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 99 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -1076,6 +1076,9 @@ Revision history for Perl extension Imager.
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.

=================================================================

Expand Down
10 changes: 6 additions & 4 deletions Imager.xs
Expand Up @@ -1910,7 +1910,7 @@ MODULE = Imager PACKAGE = Imager


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
Expand All @@ -1921,6 +1921,7 @@ i_tt_text(handle,im,xb,yb,cl,points,str_sv,len_ignored,smooth,utf8)
int len_ignored
int smooth
int utf8
int align
PREINIT:
char *str;
STRLEN len;
Expand All @@ -1931,13 +1932,13 @@ i_tt_text(handle,im,xb,yb,cl,points,str_sv,len_ignored,smooth,utf8)
#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
Expand All @@ -1948,6 +1949,7 @@ i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8)
int len_ignored
int smooth
int utf8
int align
PREINIT:
char *str;
STRLEN len;
Expand All @@ -1958,7 +1960,7 @@ i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8)
#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

Expand Down
24 changes: 12 additions & 12 deletions font.c
Expand Up @@ -1562,8 +1562,6 @@ i_tt_rasterize( TT_Fonthandle *handle, TT_Raster_Map *bit, int cords[6], float p
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;
}
Expand Down Expand Up @@ -1593,19 +1591,20 @@ Interface to text rendering into a single channel in an image
*/

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;
Expand All @@ -1630,19 +1629,20 @@ Interface to text rendering in a single color onto an image
*/

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;
Expand Down
4 changes: 2 additions & 2 deletions image.h
Expand Up @@ -296,8 +296,8 @@ typedef struct TT_Fonthandle_ TT_Fonthandle;
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);
Expand Down
5 changes: 3 additions & 2 deletions lib/Imager/Font/Truetype.pm
Expand Up @@ -51,12 +51,13 @@ sub _draw {
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});
}
}

Expand Down
44 changes: 17 additions & 27 deletions t/t30t1font.t
Expand Up @@ -7,7 +7,7 @@
# 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;
Expand All @@ -22,13 +22,13 @@ my $fontname_afm=$ENV{'T1FONTTESTAFM'}||'./fontfiles/dcr10.afm';
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";
Expand Down Expand Up @@ -231,34 +231,24 @@ SKIP:
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");
}
}
Expand Down
42 changes: 16 additions & 26 deletions t/t35ttfont.t
@@ -1,7 +1,7 @@
#!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";
Expand All @@ -10,7 +10,7 @@ init_log("testout/t35ttfont.log",2);

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";

Expand All @@ -19,7 +19,7 @@ SKIP:

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();
Expand Down Expand Up @@ -199,34 +199,24 @@ SKIP:
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");
}

Expand Down
42 changes: 16 additions & 26 deletions t/t38ft2font.t
@@ -1,6 +1,6 @@
#!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'
Expand All @@ -18,13 +18,13 @@ my @base_color = (64, 255, 64);

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);
Expand Down Expand Up @@ -378,34 +378,24 @@ SKIP:
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");
}
}
Expand Down

0 comments on commit 9ab6338

Please sign in to comment.