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 75% - note the scaling */
30 show_one_dive(dive, cr, w*2, h*1.5);
32 /* Dive information in the lower 25% */
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)/3;
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);
58 print(nr+2, cr, 0, 2*h, w, h);
59 print(nr+3, cr, w, 2*h, w, h);
61 pango_cairo_show_layout(cr,layout);
62 g_object_unref(layout);
65 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
69 static GtkPrintSettings *settings = NULL;
74 GtkPrintOperation *print;
75 GtkPrintOperationResult res;
77 print = gtk_print_operation_new();
79 gtk_print_operation_set_print_settings(print, settings);
80 pages = (dive_table.nr + 5) / 6;
81 gtk_print_operation_set_n_pages(print, pages);
82 g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
83 g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
84 res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
85 GTK_WINDOW(main_window), NULL);
86 if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
88 g_object_unref(settings);
89 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
91 g_object_unref(print);