]> git.tdb.fi Git - ext/subsurface.git/blob - print.c
Make the printout look different
[ext/subsurface.git] / print.c
1 #include <gtk/gtk.h>
2
3 #include "dive.h"
4 #include "display.h"
5
6 static void draw_page(GtkPrintOperation *operation,
7                         GtkPrintContext *context,
8                         gint page_nr,
9                         gpointer user_data)
10 {
11         cairo_t *cr;
12         PangoLayout *layout;
13         double w, h;
14         struct graphics_context gc = { .printer = 1 };
15
16         cr = gtk_print_context_get_cairo_context(context);
17         gc.cr = cr;
18
19         layout=gtk_print_context_create_pango_layout(context);
20
21         w = gtk_print_context_get_width(context);
22         h = gtk_print_context_get_height(context);
23
24         /* Do the profile on the top half of the page.. */
25         plot(&gc, w, h/2, current_dive);
26
27         pango_cairo_show_layout(cr,layout);
28         g_object_unref(layout);
29 }
30
31 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
32 {
33 }
34
35 static GtkPrintSettings *settings = NULL;
36
37 void do_print(void)
38 {
39         GtkPrintOperation *print;
40         GtkPrintOperationResult res;
41
42         print = gtk_print_operation_new();
43         if (settings != NULL)
44                 gtk_print_operation_set_print_settings(print, settings);
45         gtk_print_operation_set_n_pages(print, 1);
46         g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
47         g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
48         res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
49                                          GTK_WINDOW(main_window), NULL);
50         if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
51                 if (settings != NULL)
52                         g_object_unref(settings);
53                 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
54         }
55         g_object_unref(print);
56 }