Re: Gnomecanvas/TextItem question



Thanks for the pointer. I checked into it and found most of what I need,
but I can't get it working as it now complains that:
CRITICAL **: file pango-fontmap.c: line 83 (pango_font_map_load_font):
assertion `fontmap != NULL' failed at ./test.pl line 7.
CRITICAL **: file pango-fontmap.c: line 125
(pango_font_map_load_fontset): assertion `fontmap != NULL' failed at
./test.pl line 13.

The code I used was:

#!/usr/bin/perl -w
 
use Gtk2 -init;
use Gtk2::Pango;
  
$context = Gtk2::Pango::Context->new();
$context->load_font(Gtk2::Pango::FontDescription->from_string("Sans 24"));
   
$layout = Gtk2::Pango::Layout->new($context);
$layout->set_wrap('word');
$layout->set_width(600 * PANGO_SCALE);
$layout->set_text("This is a test\nThis is line 2");
my ($w,$h) = $layout->get_pixel_size;
print $w."x".$h."\n";


Am I missing something here? I tried to create a fontmap load it into
the context but Gtk2::Pango::Context->set_font_map does exist.

Thanks
 Chris

On Sun, Jan 18, 2004 at 11:56:13PM -0500, muppet wrote in a legally binding way:
Date: Sun, 18 Jan 2004 23:56:13 -0500
From: muppet <scott asofyet org>
To: Chris Debenham Sun COM
Cc: gtk-perl-list gnome org
Subject: Re: Gnomecanvas/TextItem question


On Sunday, January 18, 2004, at 09:23 PM, Chris Debenham - SSA Systems  
Engineer wrote:

Previously I did it by creating a Gtk::Gdk::Font with the font set
accordingly then used string_width to find wrapping and fudged a value
for string_height.
This doesn't seem to work anymore.

indeed it does not work anymore -- GdkFont was deprecated in favor of  
Pango, and thus no GdkFont-related stuff is bound into Gtk2.


Basically, how do I find the height of a arbitrary string for a given
font and given maximum width?

i'm not sure exactly of what to do, but i would start with  
$pango_layout->get_pixel_size.
http://developer.gnome.org/doc/API/2.0/pango/pango-Layout- 
Objects.html#pango-layout-get-pixel-size

here's the result of messing about for a few minutes with this.


#!/usr/bin/perl -w

use Gtk2 -init;
use Gtk2::Pango;
use Gnome2::Canvas;

$canvas = Gnome2::Canvas->new;
$window = Gtk2::Window->new;
$window->add ($canvas);
$window->show_all;
$window->signal_connect (delete_event => sub {Gtk2->main_quit});
$window->set_size_request (300,200);

$rich_text = Gnome2::Canvas::Item->new ($canvas->root,
                                      'Gnome2::Canvas::RichText',
                                      wrap_mode => 'word',
                                      editable => 0,
                                      cursor_visible => 0,
                                      x => 0, y => 0);
$rich_text->show;

update ();

$window->signal_connect (button_release_event => sub {update ();  
FALSE});

Gtk2->main;

sub update {
      my $text = `/usr/games/fortune`;
      my $layout = $canvas->create_pango_layout ($text);
      $layout->set_width (175 * PANGO_SCALE);
      my ($w, $h) = $layout->get_pixel_size;

      print "text dims : $w x $h\n";

      $rich_text->set (text => $text, width => $w, height => $h);
      $canvas->set_scroll_region (0, 0, $w, $h);

      if ($window->allocation->width < $w ||
          $window->allocation->height < $h) {
              $window->set_size_request ($w, $h);
              $window->queue_resize;
      }
}


--
Brian: If i recall correctly, this is the physics department.
Chris: That explains all that gravity.
      -- Family Guy, "The Story on Page One"

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

-- 
--------------------------------------------------------------------------------
  ,-_|\  Systems Engineer - eSun             E-mail : chris debenham sun com
 /     \ Sun Microsystems Australia Pty Ltd. Direct : +61 (2) 9844 5188
 \_,-\_* 828 Pacific Highway                 Phone  : +61 (2) 9844 5000
      v  Gordon, N.S.W. 2072                 Fax    : +61 (2) 9844 5189
                                             Mobile : +61 (40) 9844 514
--------------------------------------------------------------------------------
When Inspiration Strikes, It Usually Uses A Bar Of Soap. 
  In A Sock.



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