FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

printing cairo

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
tezem



Joined: 18 Feb 2008
Posts: 14

PostPosted: Wed May 28, 2008 3:32 am    Post subject: printing cairo Reply with quote

Is there a quick example on how to print cairo stuff?
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed May 28, 2008 12:14 pm    Post subject: Reply with quote

gtk.PrintJob.getSurface() return a cairo surface to draw on.

I don't have an example tough.
Back to top
View user's profile Send private message
tezem



Joined: 18 Feb 2008
Posts: 14

PostPosted: Sun Sep 28, 2008 3:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Sep 28, 2008 8:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group