View previous topic :: View next topic |
Author |
Message |
tezem
Joined: 18 Feb 2008 Posts: 14
|
Posted: Wed May 28, 2008 3:32 am Post subject: printing cairo |
|
|
Is there a quick example on how to print cairo stuff? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Wed May 28, 2008 12:14 pm Post subject: |
|
|
gtk.PrintJob.getSurface() return a cairo surface to draw on.
I don't have an example tough. |
|
Back to top |
|
|
tezem
Joined: 18 Feb 2008 Posts: 14
|
Posted: Sun Sep 28, 2008 3:25 am Post subject: |
|
|
Quote: | You only need to deal directly with print jobs if you use the non-portable GtkPrintUnixDialog API. |
Therefore I tried to use the high level printing API with PrintOperation. I have a button which calls:
Code: | private void print(Button b) {
PrintOperation print = new PrintOperation();
print.addOnBeginPrint(&grid.begin_print);
print.addOnDrawPage(&grid.print_page);
GError** error;
print.run(GtkPrintOperationAction.PRINT_DIALOG, this, error);
} |
I get the print dialog correctly, but when I click preview the program runs into an infinite loop calling grid.print_page again and again. Here is my grid.print_page:
Code: | private void print_page(GtkPrintContext* c, int a, PrintOperation o) {
PrintContext pc = new PrintContext(c);
Context cr = pc.getCairoContext;
double width = pc.getPageSetup.getPageWidth(GtkUnit.POINTS);
double height = pc.getPageSetup.getPageHeight(GtkUnit.POINTS);writefln("test");
renderSudoku(cr, cast(int)width, cast(int)height);
} |
In renderSudoku all the cairo stuff is done.
I don't know what to do in begin_print but I added it because I thought it is somehow needed. Can somebody give me a hint why the Preview/Printing is not working and what I should do in begin_print? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Sep 28, 2008 8:30 am Post subject: |
|
|
You'll need to set the number of pages before starting with the drawing. You can do this PrintOperation.setNPages.
Calculating the number of pages needed is usually done in the BeginPrint event handler. |
|
Back to top |
|
|
|