logo       

Printing characters using Pango: msg#00261

Subject: Printing characters using Pango
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);
}


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe