8 #include "display-gtk.h"
10 static void show_text(cairo_t *cr, int size, double x, double y, const char *fmt, ...)
16 vsnprintf(buffer, sizeof(buffer), fmt, args);
19 cairo_set_font_size(cr, size);
23 char *n = strchr(p, '\n');
26 cairo_move_to(cr, x, y);
27 cairo_show_text(cr, p);
34 * You know what? Maybe somebody can do a real Pango layout thing.
36 * I'm going to do this with the cairo engine instead. I can only learn so
37 * many new interfaces.
39 static void show_dive_text(struct dive *dive, cairo_t *cr, double w, double h)
43 tm = gmtime(&dive->when);
44 show_text(cr, 16, 0, 2, "Dive #%d - %s, %s %d, %d %d:%02d",
47 monthname(tm->tm_mon),
48 tm->tm_mday, tm->tm_year + 1900,
49 tm->tm_hour, tm->tm_min);
51 show_text(cr, 10, w*0.6, 0,
52 "Max depth: %d ft\nDuration: %d:%02d",
53 to_feet(dive->maxdepth),
54 dive->duration.seconds / 60,
55 dive->duration.seconds % 60);
57 show_text(cr, 10, 0, 20, "%s", dive->location ?: "");
58 show_text(cr, 10, 0, 30, "%s", dive->notes ?: "");
61 static void show_dive_profile(struct dive *dive, cairo_t *cr, double w, double h)
63 struct graphics_context gc = {
67 plot(&gc, w, h, dive);
70 static void print(int divenr, cairo_t *cr, double x, double y, double w, double h)
74 dive = get_dive(divenr);
78 cairo_translate(cr, x, y);
80 /* We actually want to scale the text and the lines now */
81 cairo_scale(cr, 0.5, 0.5);
83 /* Dive plot in the upper 75% - note the scaling */
84 show_dive_profile(dive, cr, w*2, h*1.5);
86 /* Dive information in the lower 25% */
87 cairo_translate(cr, 0, h*1.5);
88 show_dive_text(dive, cr, w*2, h*0.5);
93 static void draw_page(GtkPrintOperation *operation,
94 GtkPrintContext *context,
102 cr = gtk_print_context_get_cairo_context(context);
104 w = gtk_print_context_get_width(context)/2;
105 h = gtk_print_context_get_height(context)/3;
108 print(nr+0, cr, 0, 0, w, h);
109 print(nr+1, cr, w, 0, w, h);
110 print(nr+2, cr, 0, h, w, h);
111 print(nr+3, cr, w, h, w, h);
112 print(nr+2, cr, 0, 2*h, w, h);
113 print(nr+3, cr, w, 2*h, w, h);
116 static void begin_print(GtkPrintOperation *operation, gpointer user_data)
120 static GtkPrintSettings *settings = NULL;
125 GtkPrintOperation *print;
126 GtkPrintOperationResult res;
128 print = gtk_print_operation_new();
129 if (settings != NULL)
130 gtk_print_operation_set_print_settings(print, settings);
131 pages = (dive_table.nr + 5) / 6;
132 gtk_print_operation_set_n_pages(print, pages);
133 g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
134 g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
135 res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
136 GTK_WINDOW(main_window), NULL);
137 if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
138 if (settings != NULL)
139 g_object_unref(settings);
140 settings = g_object_ref(gtk_print_operation_get_print_settings(print));
142 g_object_unref(print);