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

Re: bounding boxes

From: Slaven Rezic (
05605@xyz.molar.is)
Date: Sat 17 Aug 2002 - 10:41:15 UTC

  • Next message: Arnar Mar Hrafnkelsson: "Re: bounding boxes"

    Tony Cook <05564@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 - 05605@xyz.molar.is
        BBBike - route planner for cyclists in Berlin
        WWW version:     http://www.bbbike.de
        Perl/Tk version: http://bbbike.sourceforge.net
    



  •