[Vala] [Genie] Print Function



Hi All,

If you are interested, this is the function for print a TextView with GtkSourceView.

   context : PrintContext
   op : PrintOperation
   thecompositor : SourcePrintCompositor

   /* ********************************* */
   /*                    Print Function                        */
   /* ********************************* */

   def initialize_printer (theaction : string)
       op = new PrintOperation ()
       thecompositor = new SourcePrintCompositor.from_view(text_view)
       context = new PrintContext ()
       var paper_size = new PaperSize(PAPER_NAME_A4)
       var setup = new PageSetup()
       setup.set_paper_size(paper_size)
       op.set_default_page_setup(setup)
       op.set_unit(Unit.MM)
       thecompositor.set_body_font_name("Mono 9")
       thecompositor.set_left_margin(0.5, Unit.MM)
       thecompositor.set_right_margin(0.5, Unit.MM)
       thecompositor.set_top_margin(0.5, Unit.MM)
       thecompositor.set_bottom_margin(0.5, Unit.MM)
       if linenumber is "true"
           thecompositor.set_print_line_numbers(1)
       if highlightsyntax is "true"
           thecompositor.set_highlight_syntax(true)
       else if highlightsyntax is "false"
           thecompositor.set_highlight_syntax(false)
       op.paginate += paginate
       op.draw_page += draw_page
       if theaction is "preview"
           op.run (PrintOperationAction.PREVIEW, null)
       else if theaction is "print"
           op.run (PrintOperationAction.PRINT_DIALOG, null)

   def draw_page (context : PrintContext, page_nr : int)
       thecompositor.draw_page (context, page_nr)

   def paginate (context : PrintContext) : bool
       if (thecompositor.paginate (context))
           n_pages : int
           n_pages = thecompositor.get_n_pages()
           op.set_n_pages (n_pages)
           return true
       return false

!!! Call this function with initialize_printer(preview) or initialize_printer(print) !!!


Don't forget to modify the line 81 in gtksourceview-2.0.vapi with:
   [CCode (cheader_filename = "gtksourceview/gtksourceprintcompositor.h")]

Of course, you can download NicEdit (texteditor) here: http://www.murga-linux.com/puppy/viewtopic.php?mode=attach&id=19474

Nicolas.




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