The issue is that Cairo::PdfSurface and Cairo::PsSurface default to using
points as the unit, while Gtk2::PrintOperation defaults to using pixels as the
unit.
The solution is simply to say
$po-set_unit('points');
From: Jeff Hallock
Sent: Thursday, June 03, 2010 11:22 AM
To: gtk-perl-list@gnome.org
Subject: Printing/Creating PDf/Postscript
I am attempting to create reports using Gtk2/Cairo/Pango. My reports should be
able to write to a print operation, or
a cairo surface. This seems simple enough - just pass in the Cairo context you
want to write to. The problem I am running into is when draw text on a context
from a print operation - the text appears extremely tiny on the page (look at
print_op.pdf).
When drawing to a Cairo Surface - the output is as expected (see
surface.pdf/surface.ps).
surface_po_diff.pl is the script that created these files so you can run it
yourself.
What is going on here?
How can write this code, so the print_text function prints the same size on the
print operation and a cairo surface that I create myself.
Thanks in advance for any input!
- Jeffrey Ray
# prints to print driver - text is tiny
my $window = Gtk2::Window-new;
my $po = Gtk2::PrintOperation-new;
$po-set_n_pages( 1 );
$po-signal_connect('draw-page' = sub {
my ($po, $print_context, $number) = @_;
my $cr = $print_context-get_cairo_context;
print_text($cr);
});
$po-run('print-dialog', $window);
# creates a pdf file, text is large
my $surface = Cairo::PdfSurface-create ( 'surface.pdf', 612, 792);
my $cr = Cairo::Context-create( $surface );
print_text($cr);
$cr-show_page;
$surface-finish;
# creates a ps file, text is large
$surface = Cairo::PdfSurface-create ( 'surface.ps', 612, 792);
$cr = Cairo::Context-create( $surface );
print_text($cr);
$cr-show_page;
$surface-finish;
sub print_text {
my $cr = shift;
my $layout = Pango::Cairo::create_layout( $cr );
$layout-set_markup( 'Foo:Bar' );
my $attrlist = Pango::AttrList-new;
my $font = Pango::AttrFontDesc-new(
Pango::FontDescription-from_string('calibri,arial 10') );
$attrlist-insert($font);
$layout-set_attributes( $attrlist );
Pango::Cairo::update_layout( $cr, $layout );
Pango::Cairo::show_layout( $cr, $layout );
}
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list