Loading

Attempt at printing gtk-r

  1. extern crate cairo;
  2. extern crate glib;
  3. extern crate gtk;
  4. extern crate pango;
  5. extern crate pangocairo;
  6.  
  7. use crate::gtk::PrintOperationExt;
  8.  
  9. pub fn print_pdf(window: &gtk::Window) {
  10.     let print_operation = gtk::PrintOperation::new();
  11.  
  12.     let print_operation_result: gtk::PrintOperationResult;
  13.  
  14.     //print_operation.connect_begin_print(|_| {
  15.  
  16.     //});
  17.  
  18.     print_operation.connect_draw_page(|print_operation, print_context, num_pages| {
  19.         print_operation.set_n_pages(num_pages);
  20.     });
  21.  
  22.     print_operation.connect_draw_page(|print_operation, print_context, _| {
  23.         let cairo = print_context.get_cairo_context().expect("Error");
  24.  
  25.         let width = print_context.get_width();
  26.         let pango_layout = print_context.create_pango_layout().expect("Error");
  27.  
  28.         let font_description = pango::FontDescription::from_string("sans 14");
  29.         pango_layout.set_font_description(Option::from(&font_description));
  30.  
  31.         pango_layout.set_text("aaa");
  32.  
  33.         cairo.move_to(10.0, 10.0);
  34.  
  35.         cairo.set_source_rgb(0.0, 0.0, 0.0);
  36.         cairo.fill();
  37.  
  38.         pangocairo::functions::show_layout(&cairo, &pango_layout);
  39.     });
  40.  
  41.     print_operation
  42.         .run(gtk::PrintOperationAction::PrintDialog, Option::from(window))
  43.         .expect("Error");
  44. }