-
-\f
-static void
-create_xr_print_driver (GtkPrintContext *context, PsppireOutputWindow *window)
-{
- struct string_map options;
- GtkPageSetup *page_setup;
- double width, height;
- double left_margin;
- double right_margin;
- double top_margin;
- double bottom_margin;
-
- page_setup = gtk_print_context_get_page_setup (context);
- width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
- height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
- left_margin = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM);
- right_margin = gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM);
- top_margin = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM);
- bottom_margin = gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM);
-
- string_map_init (&options);
- string_map_insert_nocopy (&options, xstrdup ("paper-size"),
- xasprintf("%.2fx%.2fmm", width, height));
- string_map_insert_nocopy (&options, xstrdup ("left-margin"),
- xasprintf ("%.2fmm", left_margin));
- string_map_insert_nocopy (&options, xstrdup ("right-margin"),
- xasprintf ("%.2fmm", right_margin));
- string_map_insert_nocopy (&options, xstrdup ("top-margin"),
- xasprintf ("%.2fmm", top_margin));
- string_map_insert_nocopy (&options, xstrdup ("bottom-margin"),
- xasprintf ("%.2fmm", bottom_margin));
-
- window->print_xrd =
- xr_driver_create (gtk_print_context_get_cairo_context (context), &options);
-
- string_map_destroy (&options);
-}
-
-static gboolean
-paginate (GtkPrintOperation *operation,
- GtkPrintContext *context,
- PsppireOutputWindow *window)
-{
- g_print ("%s\n", __FUNCTION__);
-
- if ( window->print_item < window->n_items )
- {
- g_print ("Passing item %d\n", window->print_item);
- xr_driver_output_item (window->print_xrd, window->items[window->print_item++]);
- bool x = xr_driver_need_new_page (window->print_xrd);
- if ( x )
- {
- g_print ("Need new page: %d\n", x);
- xr_driver_next_page (window->print_xrd, NULL);
- window->print_n_pages ++;
- }
- return FALSE;
- }
- else
- {
- g_print ("Number of pages is %d\n", window->print_n_pages);
- gtk_print_operation_set_n_pages (operation, window->print_n_pages);
- window->print_item = 0;
-
- create_xr_print_driver (context, window);
-
- return TRUE;
- }
-}
-
-static void
-begin_print (GtkPrintOperation *operation,
- GtkPrintContext *context,
- PsppireOutputWindow *window)
-{
- g_print ("%s\n", __FUNCTION__);
-
- create_xr_print_driver (context, window);
-
- window->print_item = 0;
- window->print_n_pages = 1;
-}
-
-static void
-end_print (GtkPrintOperation *operation,
- GtkPrintContext *context,
- PsppireOutputWindow *window)
-{
- g_print ("%s\n", __FUNCTION__);
- // xr_driver_destroy (window->print_xrd);
-}
-
-static void
-done (GtkPrintOperation *operation,
- GtkPrintOperationResult result,
- gpointer user_data)
-{
- g_print ("%s %d\n", __FUNCTION__, result);
-}
-
-
-static void
-draw_page (GtkPrintOperation *operation,
- GtkPrintContext *context,
- gint page_number,
- PsppireOutputWindow *window)
-{
- g_print ("%s: %d\n", __FUNCTION__, page_number);
-
- xr_driver_next_page (window->print_xrd, gtk_print_context_get_cairo_context (context));
- while ( window->print_item < window->n_items)
- {
- xr_driver_output_item (window->print_xrd, window->items [window->print_item++]);
- if ( xr_driver_need_new_page (window->print_xrd) )
- break;
- }
-}
-
-