handle the case where the right the of the character overlaps the
right*/
rightb = (gm->horiAdvance - gm->horiBearingX - gm->width)/64;
- if (rightb > 0)
- rightb = 0;
+ /*if (rightb > 0)
+ rightb = 0;*/
}
}
bbox[BBOX_NEG_WIDTH] = start;
bbox[BBOX_GLOBAL_DESCENT] = handle->face->size->metrics.descender / 64;
- bbox[BBOX_POS_WIDTH] = width - rightb;
+ bbox[BBOX_POS_WIDTH] = width;
+ if (rightb < 0)
+ bbox[BBOX_POS_WIDTH] -= rightb;
bbox[BBOX_GLOBAL_ASCENT] = handle->face->size->metrics.ascender / 64;
bbox[BBOX_DESCENT] = descent;
bbox[BBOX_ASCENT] = ascent;
bbox[BBOX_ADVANCE_WIDTH] = width;
+ bbox[BBOX_RIGHT_BEARING] = rightb;
+ mm_log((1, " bbox=> negw=%d glob_desc=%d pos_wid=%d glob_asc=%d desc=%d asc=%d adv_width=%d rightb=%d\n", bbox[0], bbox[1], bbox[2], bbox[3], bbox[4], bbox[5], bbox[6], bbox[7]));
- return BBOX_ADVANCE_WIDTH + 1;
+ return BBOX_RIGHT_BEARING + 1;
}
/*
# methods
my $start = $bbox->start_offset;
+ my $left_bearing = $bbox->left_bearing;
+ my $right_bearing = $bbox->right_bearing;
my $end = $bbox->end_offset;
my $gdescent = $box->global_descent;
my $gascent = $bbox->global_ascent;
my $total_width = $bbox->total_width;
my $fheight = $bbox->font_height;
my $theight = $bbox->text_height;
+ my $display_width = $bbox->display_width;
=head1 DESCRIPTION
The alias neg_width() is present to match the bounding_box()
documentation for list context.
+The alias left_bearing() is present to match font terminology.
+
=cut
sub start_offset {
return $_[0][0];
}
+sub left_bearing {
+ return $_[0][0];
+}
+
=item end_offset()
The offset from the selected drawing location to the right edge of the
$self->ascent - $self->descent;
}
+=item right_bearing
+
+The distance from the right of the last glyph to the end of the advance
+point.
+
+If the glyph overflows the right side of the advance width this value
+is negative.
+
+=cut
+
+sub right_bearing {
+ my $self = shift;
+
+ @$self >= 8 && return $self->[7]; # driver gives it to us
+
+ # otherwise the closest we have is the difference between the
+ # end_pos and advance_width
+ return $self->advance_width - $self->pos_width;
+}
+
+=item display_width
+
+The distance from the left-most pixel of the left-most glyph to the
+right-most pixel of the right-most glyph.
+
+Equals advance_width - left_bearing - right_bearing (and implemented
+that way.)
+
+=cut
+
+sub display_width {
+ my ($self) = @_;
+
+ $self->advance_width - $self->left_bearing - $self->right_bearing;
+}
+
=back
=head1 INTERNAL FUNCTIONS
#!perl -w
use strict;
-use Test::More tests => 138;
+use Test::More tests => 144;
+++$|;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
my @bbox=Imager::Font::FreeType2::i_ft2_bbox($ttraw, 50.0, 0, 'XMCLH', 0);
print "#bbox @bbox\n";
- is(@bbox, 7, "i_ft2_bbox() returns 7 values");
+ is(@bbox, 8, "i_ft2_bbox() returns 8 values");
ok(Imager::Font::FreeType2::i_ft2_cp($ttraw,$overlay,5,50,1,50.0,50, 'XMCLH',1,1, 0, 0), "drawn to channel");
i_line($overlay,0,50,100,50,$bgcolor,1);
@bbox = $oof->bounding_box(string=>"hello", size=>30);
my $bbox = $oof->bounding_box(string=>"hello", size=>30);
- is(@bbox, 7, "list bbox returned 7 items");
+ is(@bbox, 8, "list bbox returned 8 items");
ok($bbox->isa('Imager::Font::BBox'), "scalar bbox returned right class");
ok($bbox->start_offset == $bbox[0], "start_offset");
ok($bbox->end_offset == $bbox[2], "end_offset");
SKIP:
{
ok($exfont, "loaded existence font") or
- skip("couldn't load test font", 5);
+ skip("couldn't load test font", 11);
+
# the test font is known to have a shorter advance width for that char
my @bbox = $exfont->bounding_box(string=>"/", size=>100);
- is(@bbox, 7, "should be 7 entries");
+ is(@bbox, 8, "should be 8 entries");
isnt($bbox[6], $bbox[2], "different advance width");
my $bbox = $exfont->bounding_box(string=>"/", size=>100);
ok($bbox->pos_width != $bbox->advance_width, "OO check");
+ cmp_ok($bbox->right_bearing, '<', 0, "check right bearing");
+
+ cmp_ok($bbox->display_width, '>', $bbox->advance_width,
+ "check display width (roughly)");
+
+ # check with a char that fits inside the box
+ my $bbox = $exfont->bounding_box(string=>"!", size=>100);
+ print "# pos width ", $bbox->pos_width, "\n";
+ is($bbox->pos_width, $bbox->advance_width,
+ "check backwards compatibility");
+ cmp_ok($bbox->left_bearing, '>', 0, "left bearing positive");
+ cmp_ok($bbox->right_bearing, '>', 0, "right bearing positive");
+ cmp_ok($bbox->display_width, '<', $bbox->advance_width,
+ "display smaller than advance");
+
# name tests
# make sure the number of tests on each branch match
if (Imager::Font::FreeType2::i_ft2_can_face_name()) {