Pango Layout Mystery



Hi Everybody,

I'm trying to understand some things about Pango layouts and how they relate to Gnome2::Canvas::Text items. I assume that internal to a Gnome2::Canvas::Text item there is lurking a Gtk2::Pango::Layout that unfortunately I can't get at :-(.

Can anyone explain to me why "$layout->get_pixel_size()" returns different values than those I'd get when I get the Gnome2:Canvas::Item 'text-height' and 'text-width' properties? I've looked at several other Layout properties (spacing, indent, justify) and they all return "0". In the example below, I get:

text, text: Hello World! font: Ariel Normal 10 text_height: 13 layout_height: 17 text_width: 66 layout_width: 76

Here's the example:

use strict;
use Gtk2 '-init';
use Gnome2::Canvas;

use constant TRUE=>1;
use constant FALSE=>0;

my $window = Gtk2::Window->new();

my $scroller = Gtk2::ScrolledWindow->new();

my $canvas = Gnome2::Canvas->new_aa();

$canvas->set_scroll_region(0,0,350,325);

$scroller->add($canvas);

$window->add($scroller);

$window->signal_connect('destroy'=>\&_closeapp);

$window->set_default_size(450,350);

my $root   = $canvas->root;

my $hello  = 'Hello World!';

my $font   = "Ariel Normal 10";

my $font_desc = Gtk2::Pango::FontDescription->from_string($font);

my $layout = $canvas->create_pango_layout($hello);

$layout->set_font_description($font_desc);

my $text = Gnome2::Canvas::Item->new($root, 'Gnome2::Canvas::Text',
                    text=>$hello,
                    font_desc=>$font_desc,
                    fill_color=>'black',
                    x=>100, y=>100);

my ($layout_width, $layout_height) = $layout->get_pixel_size();

my $text_width = $text->get('text-width');

my $text_height = $text->get('text-height');

print "text, text: $hello font: $font text_height: $text_height layout_height: $layout_height " .
     "text_width: $text_width  layout_width: $layout_width\n";

my $box = Gnome2::Canvas::Item->new($root, 'Gnome2::Canvas::Rect',
                   x1=>0, y1=>0, x2=>350, y2=>300,
                   fill_color=>'white',
                   outline_color=>'black');

$text->raise_to_top();

$box->lower_to_bottom();

$window->show_all();

Gtk2->main();

exit 0;


sub _closeapp
{
   Gtk2->main_quit();

   return 0;
}


Thanks for any light you may be able to shed on this mystery.
-James




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]