Re: Gtk2::PrintOperation



On 7 August 2010 09:30, Emmanuele Bassi <ebassi gmail com> wrote:
well, Cairo doesn't know anything about GdkPixbufs, so perl-Gtk2 has to
"sub-class" the Cairo::Context by adding a Gtk2::Gdk::Cairo::Context
type to its @ISA. while perl-Gtk2 does it for the one returned by
Gtk2::Gdk::Cairo::create(), it doesn't do it for the one created by the
Gtk2::PrintContext API[0].

Thanks for the explanation.

For those interested, to do multipage prints, you have to set up a
callback for the begin_print signal to sort out the pagination first:

 $op->signal_connect( begin_print => sub {
  my ($op, $context) = @_;

  my $print_settings = $op->get_print_settings;
  my $pages  = $print_settings->get( 'print-pages' );
  if ($pages eq 'ranges') {

# sort out pagination here

  }
  else {

# or here

  }
  $op->set_n_pages( $num_pages ); # calculated above
 });

 $op->signal_connect( draw_page => sub {
  my ($op, $context, $page_number) = @_;

  my $cr = $context->get_cairo_context;

  # Context dimensions
  my $pwidth  = $context->get_width;
  my $pheight = $context->get_height;

  # Image dimensions
  my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file( $filename[$page_number] );
  my $iwidth  = $pixbuf->get_width;
  my $iheight = $pixbuf->get_height;

  # Scale context to fit image
  my $scale = $pwidth / $iwidth;
  $scale = $pheight / $iheight if ( $pheight / $iheight < $scale );
  $cr->scale( $scale, $scale );

  # Set source pixbuf
  Gtk2::Gdk::Cairo::Context::set_source_pixbuf( $cr, $pixbuf, 0, 0 );

  # Paint
  $cr->paint;

  return;
 } );

 my $res = $op->run( 'print-dialog', $parent );



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