]> git.tdb.fi Git - ext/subsurface.git/blob - print.c
Print out only simplified depth profile
[ext/subsurface.git] / print.c
1 #include <gtk/gtk.h>
2
3 #include "dive.h"
4 #include "display.h"
5 #include "display-gtk.h"
6
7 static void show_one_dive(struct dive *dive, cairo_t *cr, double w, double h)
8 {
9         struct graphics_context gc = {
10                 .printer = 1,
11                 .cr = cr
12         };
13         plot(&gc, w, h, dive);
14 }
15
16 static void print(int divenr, cairo_t *cr, double x, double y, double w, double h)
17 {
18         struct dive *dive;
19
20         dive = get_dive(divenr);
21         if (!dive)
22                 return;
23         cairo_save(cr);
24         cairo_translate(cr, x, y);
25
26         /* We actually want to scale the text and the lines now */
27         cairo_scale(cr, 0.5, 0.5);
28
29         /* Dive plot in the upper half - note the scaling */
30         show_one_dive(dive, cr, w*2, h);
31
32         /* Dive information in the lower half */
33
34         cairo_restore(cr);
35 }
36
37 static void draw_page(GtkPrintOperation *operation,
38                         GtkPrintContext *context,
39                         gint page_nr,
40                         gpointer user_data)
41 {
42         int nr;
43         cairo_t *cr;
44         PangoLayout *layout;
45         double w, h;
46
47         cr = gtk_print_context_get_cairo_context(context);
48         layout=gtk_print_context_create_pango_layout(context);
49
50         w = gtk_print_context_get_width(context) / 2;
51         h = gtk_print_context_get_height(context) / 2;
52
53         nr = page_nr*4;
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
59         pango_cairo_show_layout(cr,layout);
60         g_object_unref(layout);
61 }
62
63 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
64 {
65 }
66
67 static GtkPrintSettings *settings = NULL;
68
69 void do_print(void)
70 {
71         int pages;
72         GtkPrintOperation *print;
73         GtkPrintOperationResult res;
74
75         print = gtk_print_operation_new();
76         if (settings != NULL)
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) {
85                 if (settings != NULL)
86                         g_object_unref(settings);
87                 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
88         }
89         g_object_unref(print);
90 }