5 #include "display-gtk.h"
7 static void show_one_dive(struct dive *dive, cairo_t *cr, double w, double h)
9 struct graphics_context gc = {
13 plot(&gc, w, h, dive);
16 static void print(int divenr, cairo_t *cr, double x, double y, double w, double h)
20 dive = get_dive(divenr);
24 cairo_translate(cr, x, y);
26 /* We actually want to scale the text and the lines now */
27 cairo_scale(cr, 0.5, 0.5);
29 /* Dive plot in the upper half - note the scaling */
30 show_one_dive(dive, cr, w*2, h);
32 /* Dive information in the lower half */
37 static void draw_page(GtkPrintOperation *operation,
38 GtkPrintContext *context,
47 cr = gtk_print_context_get_cairo_context(context);
48 layout=gtk_print_context_create_pango_layout(context);
50 w = gtk_print_context_get_width(context) / 2;
51 h = gtk_print_context_get_height(context) / 2;
54 print(nr+0, cr, 0, 0, w, h);
55 print(nr+1, cr, w, 0, w, h);
56 print(nr+2, cr, 0, h, w, h);
57 print(nr+3, cr, w, h, w, h);
59 pango_cairo_show_layout(cr,layout);
60 g_object_unref(layout);
63 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
67 static GtkPrintSettings *settings = NULL;
72 GtkPrintOperation *print;
73 GtkPrintOperationResult res;
75 print = gtk_print_operation_new();
77 gtk_print_operation_set_print_settings(print, settings);
78 pages = (dive_table.nr + 3) / 4;
79 gtk_print_operation_set_n_pages(print, pages);
80 g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
81 g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
82 res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
83 GTK_WINDOW(main_window), NULL);
84 if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
86 g_object_unref(settings);
87 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
89 g_object_unref(print);