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 );

}

 

Attachment: surface.pdf
Description: surface.pdf

Attachment: surface.ps
Description: surface.ps

Attachment: print_op.pdf
Description: print_op.pdf

Attachment: surface_po_diff.pl
Description: surface_po_diff.pl



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