~ubuntu-branches/ubuntu/oneiric/almanah/oneiric

« back to all changes in this revision

Viewing changes to src/printing.c

  • Committer: Bazaar Package Importer
  • Author(s): Angel Abad
  • Date: 2011-04-18 16:21:36 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110418162136-l0ik4snrl420srer
Tags: 0.8.0-1
* New upstream release
* Temporarily remove evolution support in unstable
* Disable AM_GCONF_SOURCE_2 macro to fix ftbfs in unstable
  - debian/patches/disable_am_gconf_source_2
  - Build-Depends on dh-autoreconf
  - Use --with autoreconf in rules
* debian/control:
  - Build-Depends on libgtk-3-dev
* debian/rules:
  - Remove unnecessary override_dh_auto_install
* debian/copyright:
  - Update copyright years
  - Update license stanza
* Bump Standards-Version to 3.9.1 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "interface.h"
26
26
#include "main.h"
27
27
#include "printing.h"
 
28
#include "widgets/calendar.h"
28
29
 
29
30
#define TITLE_MARGIN_BOTTOM 15 /* margin under the title, in pixels */
 
31
#define IMPORTANT_MARGIN_TOP 3 /* margin above the "important" paragraph (and below the title), in pixels */
30
32
#define ENTRY_MARGIN_BOTTOM 10 /* margin under the entry, in pixels */
31
33
#define MAX_ORPHANS 3 /* maximum number of orphan lines to be forced to the next page */
32
34
#define PAGE_MARGIN 20 /* left- and right-hand page margin size, in pixels */
36
38
        GDate *start_date;
37
39
        GDate *end_date;
38
40
        GDate *current_date;
39
 
        GtkCalendar *start_calendar;
40
 
        GtkCalendar *end_calendar;
 
41
        AlmanahCalendar *start_calendar;
 
42
        AlmanahCalendar *end_calendar;
41
43
        GtkSpinButton *line_spacing_spin_button;
42
44
        gdouble line_spacing;
43
45
        guint current_line;
241
243
print_entry (GtkPrintOperation *operation, GtkPrintContext *context, AlmanahPrintOperation *almanah_operation)
242
244
{
243
245
        AlmanahEntry *entry;
244
 
        gchar title[100], *title_markup;
245
 
        PangoLayout *title_layout = NULL, *entry_layout;
 
246
        gchar title[100], *markup;
 
247
        PangoLayout *title_layout = NULL, *important_layout = NULL, *entry_layout;
246
248
        PangoLayoutLine *entry_line;
247
249
        PangoRectangle logical_extents;
248
250
        gint height, line_height;
249
251
        guint i;
250
 
        gdouble title_y = 0, entry_y;
 
252
        gdouble title_y = 0, important_y = 0, entry_y;
251
253
        cairo_t *cr = NULL;
252
254
 
 
255
        entry = almanah_storage_manager_get_entry (almanah->storage_manager, almanah_operation->current_date);
 
256
 
253
257
        if (almanah_operation->current_line == 0) {
254
258
                /* Set up the title layout */
255
259
                title_layout = gtk_print_context_create_pango_layout (context);
257
261
 
258
262
                /* Translators: This is a strftime()-format string for the date displayed above each printed entry. */
259
263
                g_date_strftime (title, sizeof (title), _("%A, %e %B %Y"), almanah_operation->current_date);
260
 
                title_markup = g_strdup_printf ("<b>%s</b>", title);
261
 
                pango_layout_set_markup (title_layout, title_markup, -1);
262
 
                g_free (title_markup);
 
264
                markup = g_strdup_printf ("<b>%s</b>", title);
 
265
                pango_layout_set_markup (title_layout, markup, -1);
 
266
                g_free (markup);
263
267
 
264
268
                title_y = almanah_operation->y;
265
269
                pango_layout_get_pixel_size (title_layout, NULL, &height);
266
 
                almanah_operation->y += height + TITLE_MARGIN_BOTTOM;
 
270
                almanah_operation->y += height;
 
271
 
 
272
                if (entry != NULL && almanah_entry_is_important (entry) == TRUE) {
 
273
                        /* State that it's an important entry */
 
274
                        important_layout = gtk_print_context_create_pango_layout (context);
 
275
                        pango_layout_set_width (title_layout, (gtk_print_context_get_width (context) - 2 * PAGE_MARGIN) * PANGO_SCALE);
 
276
 
 
277
                        markup = g_strdup_printf ("<i>%s</i>", _("This entry is marked as important."));
 
278
                        pango_layout_set_markup (important_layout, markup, -1);
 
279
                        g_free (markup);
 
280
 
 
281
                        /* If the important paragraph is displayed, it's displayed IMPORTANT_MARGIN_TOP pixels below the bottom of the title
 
282
                         * paragraph, and then the entry content is displayed TITLE_MARGIN_BOTTOM pixels below the bottom of the important paragraph. */
 
283
                        almanah_operation->y += IMPORTANT_MARGIN_TOP;
 
284
                        important_y = almanah_operation->y;
 
285
                        pango_layout_get_pixel_size (important_layout, NULL, &height);
 
286
                        almanah_operation->y += height;
 
287
                }
 
288
 
 
289
                almanah_operation->y += TITLE_MARGIN_BOTTOM;
267
290
        }
268
291
 
269
292
        /* Set up the entry layout */
271
294
        pango_layout_set_width (entry_layout, (gtk_print_context_get_width (context) - 2 * PAGE_MARGIN) * PANGO_SCALE);
272
295
        pango_layout_set_ellipsize (entry_layout, PANGO_ELLIPSIZE_NONE);
273
296
 
274
 
        entry = almanah_storage_manager_get_entry (almanah->storage_manager, almanah_operation->current_date);
275
 
 
276
297
        if (entry == NULL || almanah_entry_is_empty (entry)) {
277
298
                gchar *entry_text = g_strdup_printf ("<i>%s</i>", _("No entry for this date."));
278
299
                pango_layout_set_markup (entry_layout, entry_text, -1);
280
301
                GtkTextIter start, end;
281
302
 
282
303
                gtk_text_buffer_set_text (almanah_operation->buffer, "", 0);
283
 
                if (almanah_entry_get_content (entry, almanah_operation->buffer, TRUE, NULL) == TRUE) {
 
304
                if (almanah_entry_get_content (entry, almanah_operation->buffer, FALSE, NULL) == TRUE) {
284
305
                        gtk_text_buffer_get_bounds (almanah_operation->buffer, &start, &end);
285
306
                        lay_out_entry (entry_layout, &start, &end);
286
307
                }
290
311
                g_object_unref (entry);
291
312
 
292
313
        /* Check we're not orphaning things */
293
 
        entry_line = pango_layout_get_line_readonly (entry_layout, MIN (pango_layout_get_line_count (entry_layout) - 1, almanah_operation->current_line + MAX_ORPHANS));
 
314
        entry_line = pango_layout_get_line_readonly (entry_layout, MIN ((guint) pango_layout_get_line_count (entry_layout) - 1, almanah_operation->current_line + MAX_ORPHANS));
294
315
        pango_layout_line_get_pixel_extents (entry_line, NULL, &logical_extents);
295
316
        line_height = pango_layout_get_spacing (entry_layout) / PANGO_SCALE + (gint) (almanah_operation->line_spacing * ((gdouble) logical_extents.height));
296
317
 
298
319
                /* Not enough space on the page to contain the title and orphaned lines */
299
320
                if (title_layout != NULL)
300
321
                        g_object_unref (title_layout);
 
322
                if (important_layout != NULL)
 
323
                        g_object_unref (important_layout);
301
324
                g_object_unref (entry_layout);
302
325
 
303
326
                almanah_operation->current_line = 0;
312
335
                        /* Draw the title */
313
336
                        cairo_move_to (cr, PAGE_MARGIN, title_y);
314
337
                        pango_cairo_show_layout (cr, title_layout);
 
338
 
 
339
                        if (important_layout != NULL) {
 
340
                                /* Draw the important paragraph */
 
341
                                cairo_move_to (cr, PAGE_MARGIN, important_y);
 
342
                                pango_cairo_show_layout (cr, important_layout);
 
343
                        }
315
344
                }
316
345
        }
317
346
 
329
358
                        /* Paint the rest on the next page */
330
359
                        if (title_layout != NULL)
331
360
                                g_object_unref (title_layout);
 
361
                        if (important_layout != NULL)
 
362
                                g_object_unref (important_layout);
332
363
                        g_object_unref (entry_layout);
333
364
 
334
365
                        almanah_operation->current_line = i;
350
381
 
351
382
        if (title_layout != NULL)
352
383
                g_object_unref (title_layout);
 
384
        if (important_layout != NULL)
 
385
                g_object_unref (important_layout);
353
386
        g_object_unref (entry_layout);
354
387
 
355
388
        almanah_operation->current_line = 0;
411
444
        GtkBox *vbox, *hbox;
412
445
 
413
446
        /* Start and end calendars */
414
 
        start_calendar = gtk_calendar_new ();
415
 
        g_signal_connect (start_calendar, "month-changed", G_CALLBACK (almanah_calendar_month_changed_cb), NULL);
416
 
        end_calendar = gtk_calendar_new ();
417
 
        g_signal_connect (end_calendar, "month-changed", G_CALLBACK (almanah_calendar_month_changed_cb), NULL);
 
447
        start_calendar = almanah_calendar_new ();
 
448
        end_calendar = almanah_calendar_new ();
 
449
 
 
450
        g_object_set (G_OBJECT (start_calendar), "show-details", FALSE, NULL);
 
451
        g_object_set (G_OBJECT (end_calendar), "show-details", FALSE, NULL);
418
452
 
419
453
        start_label = GTK_LABEL (gtk_label_new (_("Start date:")));
420
454
        gtk_misc_set_alignment (GTK_MISC (start_label), 0.0, 0.5);
430
464
        gtk_table_attach (table, GTK_WIDGET (start_label), 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
431
465
        gtk_table_attach (table, GTK_WIDGET (end_label), 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
432
466
 
433
 
        almanah_operation->start_calendar = GTK_CALENDAR (start_calendar);
434
 
        almanah_operation->end_calendar = GTK_CALENDAR (end_calendar);
 
467
        almanah_operation->start_calendar = ALMANAH_CALENDAR (start_calendar);
 
468
        almanah_operation->end_calendar = ALMANAH_CALENDAR (end_calendar);
435
469
 
436
470
        /* Line spacing */
437
471
        line_spacing_label = GTK_LABEL (gtk_label_new (_("Line spacing:")));
450
484
        gtk_widget_show_all (GTK_WIDGET (vbox));
451
485
 
452
486
        /* Make sure they have the dates with entries marked */
453
 
        almanah_calendar_month_changed_cb (GTK_CALENDAR (start_calendar), NULL);
454
 
        almanah_calendar_month_changed_cb (GTK_CALENDAR (end_calendar), NULL);
 
487
        almanah_calendar_select_today (almanah_operation->start_calendar);
 
488
        almanah_calendar_select_today (almanah_operation->end_calendar);
455
489
 
456
490
        return GTK_WIDGET (vbox);
457
491
}
459
493
static void
460
494
custom_widget_apply_cb (GtkPrintOperation *operation, GtkWidget *widget, AlmanahPrintOperation *almanah_operation)
461
495
{
462
 
        guint year, month, day;
463
 
 
464
496
        /* Start date */
465
 
        gtk_calendar_get_date (almanah_operation->start_calendar, &year, &month, &day);
466
 
        g_date_set_dmy (almanah_operation->start_date, day, month + 1, year);
467
 
        g_date_set_dmy (almanah_operation->current_date, day, month + 1, year);
 
497
        almanah_calendar_get_date (almanah_operation->start_calendar, almanah_operation->start_date);
 
498
        almanah_calendar_get_date (almanah_operation->start_calendar, almanah_operation->current_date);
468
499
 
469
500
        /* End date */
470
 
        gtk_calendar_get_date (almanah_operation->end_calendar, &year, &month, &day);
471
 
        g_date_set_dmy (almanah_operation->end_date, day, month + 1, year);
 
501
        almanah_calendar_get_date (almanah_operation->end_calendar, almanah_operation->end_date);
472
502
 
473
503
        /* Ensure they're in order */
474
504
        if (g_date_compare (almanah_operation->start_date, almanah_operation->end_date) > 0) {