Printing characters using Pango
- From: Samuel <spam debain org>
- To: gtk-perl-list gnome org
- Subject: Printing characters using Pango
- Date: Sat, 24 Jan 2004 21:57:33 +0100
Hello,
I am trying to draw some characters to a Gtk2::DrawingArea using Pango,
but some of the characters just won't work.
All the characters with an ASCII value smaller then 128 work like a
charm, but all of the values above will print only junk.
Also, this happens only with *some* fonts.
The font that I use is at http://sam.homeunix.com/musical.ttf (just in
case) and I have appended my test code below.
Is it a problem with me being too dumb? Is it Pango? Is it the font?
I have tried this for hours now, but I'm kind of stuck here...
Any help greatly appreciated.
Thanks,
-Samuel
--------------------------------------------------------
#!/usr/bin/env perl
use strict;
use Gtk2 -init;
use constant TRUE => 1;
use constant FALSE => 0;
# Create the widgets.
my $window = Gtk2::Window->new('toplevel');
my $vbox = Gtk2::VBox->new(FALSE, 0);
my $button = Gtk2::Button->new("Quit");
my $drawarea = Gtk2::DrawingArea->new;
my $pixmap;
$window->set_name("Test Window");
$vbox->set_size_request(400, 400);
# Add the widgets to the window.
$window->add($vbox);
$vbox->pack_start($drawarea, TRUE, TRUE, 0);
$vbox->pack_start($button, FALSE, FALSE, 0);
# Connect signals.
$window->signal_connect(destroy => sub { exit(0); });
$button->signal_connect_swapped(clicked => sub { $_[0]->destroy; },
$window);
$drawarea->signal_connect(configure_event => sub { &draw_something; });
$drawarea->signal_connect(expose_event => sub { &_on_expose_event; });
# Show all widgets.
$vbox->show;
$drawarea->show;
$button->show;
$window->show;
Gtk2->main;
## Purpose: Redraw the screen from the backing pixmap.
##
sub _on_expose_event {
my($self, $event) = @_;
$self->window->draw_drawable($self->style->fg_gc($self->state),
$pixmap,
$event->area->x,
$event->area->y,
$event->area->x,
$event->area->y,
$event->area->width,
$event->area->height);
return FALSE;
}
## Draw something into the area.
##
sub draw_something {
my $layout = $drawarea->create_pango_layout('');
my $font = Gtk2::Pango::FontDescription->new();
$pixmap = Gtk2::Gdk::Pixmap->new($drawarea->window, 400, 400, -1);
$pixmap->draw_rectangle($drawarea->style->white_gc,
TRUE, 0, 0, 400, 400);
$font->set_size(30 * Gtk2::Pango->scale);
$font->set_family('MusicSymbols');
$layout->set_font_description($font);
$layout->set_text("Test Text: " . chr 65); # This works fine...
$pixmap->draw_layout($drawarea->style->black_gc, 20, 20, $layout);
$layout->set_text("Test Text: " . chr 206); # ...while this doesn't.
$pixmap->draw_layout($drawarea->style->black_gc, 20, 100, $layout);
$layout->set_text("Test Text: " . chr 0xf0ce); # neighter does UTF.
$pixmap->draw_layout($drawarea->style->black_gc, 20, 200, $layout);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]