(none) imager-devel
/ help / lists / applications / search /
 

Re: bounding boxes

From: Arnar Mar Hrafnkelsson (
05647@xyz.molar.is)
Date: Mon 19 Aug 2002 - 18:54:10 UTC


I think you don't want to pass those x=>0, and y=>0 parameters.
They actually try to take you screen coordinates.

use Imager;
foreach my $fontfile ("./UTRG____.pfa",
                      "./LucidaSansRegular.ttf",
                      "./times.ttf",
                      "./arial.ttf") {
    my $ttfont = Imager::Font->new(file => $fontfile,
                                    size => 24,
                                    );
    my $text = "Slaven Rezic";
    my(@bounds) = $ttfont->bounding_box(string => $text);
    # dump contents of @bounds:
        print "@bounds\n";

}

~~~~~~

I get these results:

1 -6 135 21 -1 18
1 -5 142 19 -1 19

-- Arnar

On 19 Aug 2002, Slaven Rezic wrote:

> Arnar Mar Hrafnkelsson <05647@xyz.molar.is> writes:
>
> > Slaven, can you supply those font files to us?
> >
>
> Yes. Look at http://www.rezic.de/tmp
>
> > I'm starting to think your freetype library is whacked or something.
> >
> > -- Arnar.
> >
> >
> >
> > On 17 Aug 2002, Slaven Rezic wrote:
> >
> > > Tony Cook <05723@xyz.molar.is> writes:
> > >
> > > > On 14 Aug 2002, Slaven Rezic wrote:
> > > >
> > > > > is the output of the bounding_box method in Imager::Font correct? The
> > > > > document states that the elements are: $neg_width, $global_descent,
> > > > > $pos_width, $global_ascent, $descent, $ascent; but in tests I got
> > > > > results like this (this should be a 24 point font): 1, -21, 135, 6,
> > > > > -1, 18. $neg_width, $pos_width, $descent and $ascent look right, but
> > > > > $global_descent and $global_ascent look wrong.
> > > >
> > > > I haven't had any problems with values from bounding_box(), except where
> > > > the font had bad values.
> > > >
> > > > Of course that doesn't mean there aren't problems, but I'd want to see the
> > > > font, your code, and know what text you were getting the bounding
> > > > box for.
> > >
> > > Here's a sample script with a Type1 and a TTF font:
> > >
> > > use Imager;
> > > foreach my $fontfile ("/usr/X11R6/lib/X11/fonts/Type1/UTRG____.pfa",
> > > "/usr/X11R6/lib/X11/fonts/ttf/LucidaSansRegular.ttf") {
> > > my $ttfont = Imager::Font->new(file => $fontfile,
> > > size => 24,
> > > );
> > > my $text = "Slaven Rezic";
> > > my(@bounds) = $ttfont->bounding_box(string => $text, canon => 0,
> > > x => 0, y => 0);
> > > # dump contents of @bounds:
> > > use Data::Dumper; print STDERR "Line " . __LINE__ . ", File: " . __FILE__ . "\n" . Data::Dumper->new([\@bounds],[])->Deparse(1)->Useqq(1)->Dump;
> > > }
> > > __END__
> > >
> > > The output is:
> > >
> > > Line 27, File: imager_short.pl
> > > $VAR1 = [
> > > 1,
> > > -21,
> > > 135,
> > > 6,
> > > -1,
> > > 18
> > > ];
> > > Line 27, File: imager_short.pl
> > > $VAR1 = [
> > > 1,
> > > -19,
> > > 141,
> > > 6,
> > > -1,
> > > 19
> > > ];
> > >
> > > My system is FreeBSD 4.6, the freetype version is 2.1.2.
> > >
> > > >
> > > > > And a request: it seems that bounding_box does not honor the current
> > > > > transformation. However, there is i_ft2_bbox_r() in the C code, which
> > > > > returns the bounding box using the transformation. Could
> > > > > bounding_box() be rewritten to use the current transformation?
> > > >
> > > > bounding_box() ignores the current tranformation because that would make
> > > > the ascent and descent information less meaningful.
> > > >
> > > > It would be useful to expose the transformed box, but I think an extra
> > > > function (or some option to bounding_box) would be better.
> > >
> > > Regards,
> > > Slaven
> > >
> > > --
> > > Slaven Rezic - 05681@xyz.molar.is
> > > BBBike - route planner for cyclists in Berlin
> > > WWW version: http://www.bbbike.de
> > > Perl/Tk version: http://bbbike.sourceforge.net
> > >
> > >
> > >
> >
> >
>
> --
> Slaven Rezic - 05681@xyz.molar.is
>
> Berlin Perl Mongers - http://berliner.pm.org
>