printing content of goocanvasmm

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

printing content of goocanvasmm

Klaus Rudolph
I want to print the content of a goocanvasmm.

The only resource I found about printing is:
https://developer.gnome.org/gtkmm-tutorial/stable/chapter-printing.html.en

This is very very complex and I did not catch how I can involve a canvas
here. All I found is a very magic class "PrintFormOperation" which can
be filled with "comments" which will later be printed. Maybe I
misunderstood that completely. But this was the only connection I found
from the text widget to the printing. No idea how that works!

But coming form this point it looks I have to completely write my own
method to render the canvas into some kind of Pango...something. Wow! I
have never looked so deep into the gtkmm stuff.

Can somebody give me a hint how to rewrite the canvasmm to get a print
output. Sorry, but I have never written code to directly render
something. And rewriting all the stuff for canvas looks very unlucky...

Maybe there is some document to start reading with?

The job sounds so simple: Print a canvas, but after looking in the
printing example I am totally confused :-(

Regards
Klaus
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: printing content of goocanvasmm

Tom Schoonjans
Hi Klaus,

The Canvas documentation mentions a method render (https://developer.gnome.org/goocanvasmm/stable/classGoocanvas_1_1Canvas.html#a54aa434b9bfa110dc74e1435b9a6f81d), which can be used to draw the canvas onto a cairo context of your choosing. 

I think you can use this method from a Gtk::PrintOperation’s signal_draw_page handler, where the cairo context can be fetched from the printcontext using get_cairo_context.

I explained a similar workflow in https://tschoonj.github.io/blog/2015/07/05/embedding-plplot-in-gtk-drawingareas/ where you can send the contents of a Gtk::DrawingArea to either a file or a printer.

Best,

Tom

On 29 Dec 2017, at 13:12, Klaus Rudolph <[hidden email]> wrote:

I want to print the content of a goocanvasmm.

The only resource I found about printing is: https://developer.gnome.org/gtkmm-tutorial/stable/chapter-printing.html.en

This is very very complex and I did not catch how I can involve a canvas here. All I found is a very magic class "PrintFormOperation" which can be filled with "comments" which will later be printed. Maybe I misunderstood that completely. But this was the only connection I found from the text widget to the printing. No idea how that works!

But coming form this point it looks I have to completely write my own method to render the canvas into some kind of Pango...something. Wow! I have never looked so deep into the gtkmm stuff.

Can somebody give me a hint how to rewrite the canvasmm to get a print output. Sorry, but I have never written code to directly render something. And rewriting all the stuff for canvas looks very unlucky...

Maybe there is some document to start reading with?

The job sounds so simple: Print a canvas, but after looking in the printing example I am totally confused :-(

Regards
Klaus
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: printing content of goocanvasmm

Klaus Rudolph
Hi Tom,


> The Canvas documentation mentions a method render
> (https://developer.gnome.org/goocanvasmm/stable/classGoocanvas_1_1Canvas.html#a54aa434b9bfa110dc74e1435b9a6f81d),
> which can be used to draw the canvas onto a cairo context of your choosing.

here I have still a problem: If I want to split up my canvas to multiple
print pages, how can I shift the rendering to the page position 0,0? The
render method offers a "Bounds" parameter which works like a clipping
rect over the drawing area. But now I need that this area is shifted to
a other position in the cairo context.

eg. have a canvas with 200x200 in size. Printing is in 100x100 pages.
So I need for page 2 that area 100,0 is printed in the printer context
on 0x0. Any idea how that can be performed?

>
> I think you can use this method from a Gtk::PrintOperation’s
> signal_draw_page handler, where the cairo context can be fetched from
> the printcontext using get_cairo_context.

Yes, I found that and has already forwarded the call to on_draw. That
works also but can not handle areas to print. Great finding! Thanks!


>
> I explained a similar workflow in
> https://tschoonj.github.io/blog/2015/07/05/embedding-plplot-in-gtk-drawingareas/ where
> you can send the contents of a Gtk::DrawingArea to either a file or a
> printer.


I will take a look into!

Thanks
  Klaus
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: printing content of goocanvasmm

Tom Schoonjans
Hi Klaus,

You will need to set the number of pages to 4 first:

        operation->set_n_pages(4);

Then the signal_draw_page handler will be called 4 times, with the second argument being the page number (zero based).
Based on the page number, you should be able to determine the Bounds that should be used for the current page.

Best,

Tom

> On 29 Dec 2017, at 15:00, Klaus <[hidden email]> wrote:
>
> Hi Tom,
>
>
>> The Canvas documentation mentions a method render (https://developer.gnome.org/goocanvasmm/stable/classGoocanvas_1_1Canvas.html#a54aa434b9bfa110dc74e1435b9a6f81d), which can be used to draw the canvas onto a cairo context of your choosing.
>
> here I have still a problem: If I want to split up my canvas to multiple print pages, how can I shift the rendering to the page position 0,0? The render method offers a "Bounds" parameter which works like a clipping rect over the drawing area. But now I need that this area is shifted to a other position in the cairo context.
>
> eg. have a canvas with 200x200 in size. Printing is in 100x100 pages.
> So I need for page 2 that area 100,0 is printed in the printer context on 0x0. Any idea how that can be performed?
>
>> I think you can use this method from a Gtk::PrintOperation’s signal_draw_page handler, where the cairo context can be fetched from the printcontext using get_cairo_context.
>
> Yes, I found that and has already forwarded the call to on_draw. That works also but can not handle areas to print. Great finding! Thanks!
>
>
>> I explained a similar workflow in https://tschoonj.github.io/blog/2015/07/05/embedding-plplot-in-gtk-drawingareas/ where you can send the contents of a Gtk::DrawingArea to either a file or a printer.
>
>
> I will take a look into!
>
> Thanks
> Klaus

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: printing content of goocanvasmm

Klaus Rudolph
Hi,

sounds like a misunderstanding ;)


> operation->set_n_pages(4);

Set was already done.

>
> Then the signal_draw_page handler will be called 4 times, with the second argument being the page number (zero based).
> Based on the page number, you should be able to determine the Bounds that should be used for the current page.

The bounds argument did NOT move the content, it only mask the rest out.
I try to explain again:

Lets say a size of printing paper have 100x100 pixels and the canvas has
200x200 pixels. Lets assume we print in the order top left, top right,
bottom left, bottom right.

For the second page, top right, it should be the bounds { 100, 0, 200,
100 }. But the result is, that this prints to  { 100, 0, 200, 100 } on
the paper, which is not the expected result. What is missing is some
kind of moving. I have no idea if we can give move the cairo context
before draw on it or if it is possible for the canvas to move.

Regards
  Klaus

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list