PrintOperation can't change it's page_setup

hi,

i wanted to eliminate the overhead on the user, who first have to set
the page_setup with Gtk::PrintOperation.run_page_setup_dialog, and then
print from the other dialog
Gtk::PrintOperation.run(Gtk::PrintOperation::Action::PRINT_DIALOG).

so i used the| |create-custom-widget and custom-widget-apply signals to
do that, because i found no other method for it.
first i created the page_size combo and the orientation combo in it, and
found out that changing the values messes up the cairo context, so i
wrote an example script for this demo, which calls the original
run_page_setup_dialog (for simplicity).
it’s attached.

the usage:

  1. run it without changing the page_setup in the custom tab, print to
    file.
  2. run it and change the page_setup, and print to file.
  3. compare the pdfs.

i also attach examples i created.

creating and positioning pango layouts works fine. (why)
the cairo_context looses it’s 0,0 coordinates?
i checked margins, they looked fine to me (page_setup selected from the
combo brings us the default margins for that format).
if i change the page_setup before i call the PrintOperation.run, than
it’s good.

please if anyone have any clue drop me an answer.
thanks for reading.

balint

Kou - since you’re the cairo expert, can you please take a look at this
issue, when you have the time.
is there a way i could reinitialize the cairo context (or should i?)
after changing the page_setup?

thanks in advice

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] PrintOperation can’t change it’s
page_setup” on Mon, 05 Nov 2007 19:53:37 +0200,
Dobai-Pataky Bálint [email protected] wrote:

Kou - since you’re the cairo expert, can you please take a look at this
issue, when you have the time.
is there a way i could reinitialize the cairo context (or should i?)
after changing the page_setup?

You can’t.
Use gtk/sample/misc/print.rb style approach. If you want to
know details, see
gtk/gtkprintoperation-unix.c:handle_print_response() in GTK+
source.

Thanks,

kou

Mathieu B. wrote:

Dobai-Pataky Bálint wrote:

i wanted to eliminate the overhead on the user, who first have to set
the page_setup with Gtk::PrintOperation.run_page_setup_dialog, and
then print from the other dialog
Gtk::PrintOperation.run(Gtk::PrintOperation::Action::PRINT_DIALOG).

Why do you want to change the cairo context for doing that?

because i think that the cairo part of the context gets messed up. (see
the previously attached simple code and the resulting pdfs).

In Fantasdic, I have a class Print that extends Gtk::PrintOperation. In
initialize I set the default settings like this:

yeah, but you have your app the page_size set up, and you have it
available on your Print::initialize.
try to put some page_setup related settings in the PrintOperation.run’s
tabs (or change the page_setup after the PrintOperation.run was invoked)
if you print only PangoLayouts than it’ll work, if you draw to the Cairo
context that’ll mess up coordinates.

with this option disabled, (0,0) is the the upper left corner

taking into account margins !

self.use_full_page = false
self.unit = Gtk::PaperSize::UNIT_POINTS

set default paper size

page_setup = Gtk::PageSetup.new
paper_size = Gtk::PaperSize.new(Gtk::PaperSize.default)
page_setup.paper_size_and_default_margins = paper_size
self.default_page_setup = page_setup

i tried this approach for setting the page_setup, but this works well
only in initialize of the PrintOperation.
i know you played around with Gtk::PrintOperaion a lot, until you wrote
the fantasdic print objects.
would you please take a look at the source code attached in my first
mail - it’s simple,
would you please explain it to me your understanding about it printing
A5 portrait?

Dobai-Pataky Bálint wrote:

i wanted to eliminate the overhead on the user, who first have to set
the page_setup with Gtk::PrintOperation.run_page_setup_dialog, and
then print from the other dialog
Gtk::PrintOperation.run(Gtk::PrintOperation::Action::PRINT_DIALOG).
Why do you want to change the cairo context for doing that?

In Fantasdic, I have a class Print that extends Gtk::PrintOperation. In
initialize I set the default settings like this:

with this option disabled, (0,0) is the the upper left corner

taking into account margins !

self.use_full_page = false
self.unit = Gtk::PaperSize::UNIT_POINTS

set default paper size

page_setup = Gtk::PageSetup.new
paper_size = Gtk::PaperSize.new(Gtk::PaperSize.default)
page_setup.paper_size_and_default_margins = paper_size
self.default_page_setup = page_setup

For more details:

http://svn.gnome.org/viewvc/fantasdic/trunk/lib/fantasdic/ui/print.rb?revision=218&view=markup

In my class MainApp, I have methods to load/save the settings from/to
the app config file. Also, when the user clicks on “print”, if a
@page_setup variable exists (either set from the page setup dialog or
from the config file), I pass it to my Print object. Otherwise, it’s no
problem since default values have been set as explained above.

For more details:

http://svn.gnome.org/viewvc/fantasdic/trunk/lib/fantasdic/ui/main_app.rb?revision=269&view=markup

In particular, see:

  • load_print_preferences
  • save_print_preferences
  • on_print_setup
  • on_print
  • on_print_preview

HTH,
Mathieu B.