aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-format-html-print.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2007-07-06 22:19:16 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2007-07-06 22:19:16 +0800
commit4e4d7e38f19498e1840f22e3aa42335ccea5ec45 (patch)
tree23f545e45f27c594a81bb108a388d99d13026333 /mail/em-format-html-print.c
parent8ee43fc1fb4c9f792116c5502da61cd00d112610 (diff)
downloadgsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.tar
gsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.tar.gz
gsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.tar.bz2
gsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.tar.lz
gsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.tar.xz
gsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.tar.zst
gsoc2013-evolution-4e4d7e38f19498e1840f22e3aa42335ccea5ec45.zip
** Fixes bug #446894
2007-07-06 Matthew Barnes <mbarnes@redhat.com> ** Fixes bug #446894 * ui/evolution.xml: Add a filepagesetup command, and a corresponding menu item within the print place holder. net result is to add a "file -> page setup" menu item to all components, just above the print menu items. * shell/e-shell-window-commands.c (command_page_setup): Callback for new FilePageSetup verb. * mail/em-format-html-print.c: Use new gtk_html_print_operation_run() function in GtkHTML. * e-util/e-print.c (load_page_setup): Extract GtkPageSetup properties from a GtkPrintSettings object. * e-util/e-print.c (save_page_setup): Merge GtkPageSetup properties into a GtkPrintSettings object. * e-util/e-print.[ch] (e_print_run_page_setup_dialog): New function runs a preconfigured Page Setup dialog and saves the configuration to GConf (/apps/evolution/shell/printing). svn path=/trunk/; revision=33762
Diffstat (limited to 'mail/em-format-html-print.c')
-rw-r--r--mail/em-format-html-print.c110
1 files changed, 57 insertions, 53 deletions
diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c
index ebda5aaf2a..a674b59368 100644
--- a/mail/em-format-html-print.c
+++ b/mail/em-format-html-print.c
@@ -112,84 +112,88 @@ em_format_html_print_new (EMFormatHTML *source, GtkPrintOperationAction action)
return efhp;
}
-struct footer_info {
- PangoLayout *layout;
- gint page_num, pages;
-};
-
-static void
-efhp_footer_cb (GtkHTML *html, GtkPrintContext *context, gdouble x, gdouble y,
- gdouble width, gdouble height, gpointer data)
+static gint
+efhp_calc_footer_height (GtkHTML *html,
+ GtkPrintOperation *operation,
+ GtkPrintContext *context)
{
- struct footer_info *info = data;
- gchar *footer_text;
- cairo_t *cr;
-
- footer_text = g_strdup_printf (_("Page %d of %d"),
- info->page_num++, info->pages);
+ PangoContext *pango_context;
+ PangoFontDescription *desc;
+ PangoFontMetrics *metrics;
+ gint footer_height;
- pango_layout_set_text (info->layout, footer_text, -1);
- pango_layout_set_width (info->layout, pango_units_from_double (width));
+ pango_context = gtk_print_context_create_pango_context (context);
+ desc = pango_font_description_from_string ("Sans Regular 10");
- cr = gtk_print_context_get_cairo_context (context);
+ metrics = pango_context_get_metrics (
+ pango_context, desc, pango_language_get_default ());
+ footer_height =
+ pango_font_metrics_get_ascent (metrics) +
+ pango_font_metrics_get_descent (metrics);
+ pango_font_metrics_unref (metrics);
- cairo_save (cr);
- cairo_set_source_rgb (cr, .0, .0, .0);
- cairo_move_to (cr, x, y);
- pango_cairo_show_layout (cr, info->layout);
- cairo_restore (cr);
+ pango_font_description_free (desc);
+ g_object_unref (pango_context);
- g_free (footer_text);
+ return footer_height;
}
-static void
-mail_draw_page (GtkPrintOperation *print, GtkPrintContext *context,
- gint page_nr, EMFormatHTMLPrint *efhp)
+static void
+efhp_draw_footer (GtkHTML *html,
+ GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ gint page_nr,
+ PangoRectangle *rec)
{
- GtkHTML *html = efhp->parent.html;
PangoFontDescription *desc;
- PangoFontMetrics *metrics;
- struct footer_info info;
- gdouble footer_height;
+ PangoLayout *layout;
+ gdouble x, y;
+ gint n_pages;
+ gchar *text;
+ cairo_t *cr;
+
+ g_object_get (operation, "n-pages", &n_pages, NULL);
+ text = g_strdup_printf (_("Page %d of %d"), page_nr + 1, n_pages);
desc = pango_font_description_from_string ("Sans Regular 10");
+ layout = gtk_print_context_create_pango_layout (context);
+ pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+ pango_layout_set_font_description (layout, desc);
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_set_width (layout, rec->width);
- info.layout = gtk_print_context_create_pango_layout (context);
- pango_layout_set_alignment (info.layout, PANGO_ALIGN_CENTER);
- pango_layout_set_font_description (info.layout, desc);
+ x = pango_units_to_double (rec->x);
+ y = pango_units_to_double (rec->y);
- metrics = pango_context_get_metrics (
- pango_layout_get_context (info.layout),
- desc, pango_language_get_default ());
- footer_height = pango_units_to_double (
- pango_font_metrics_get_ascent (metrics) +
- pango_font_metrics_get_descent (metrics));
- pango_font_metrics_unref (metrics);
+ cr = gtk_print_context_get_cairo_context (context);
- pango_font_description_free (desc);
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, .0, .0, .0);
+ cairo_move_to (cr, x, y);
+ pango_cairo_show_layout (cr, layout);
+ cairo_restore (cr);
- info.page_num = 1;
- info.pages = gtk_html_print_page_get_pages_num (
- html, context, 0.0, footer_height);
+ g_object_unref (layout);
+ pango_font_description_free (desc);
- gtk_html_print_page_with_header_footer (
- html, context, 0.0, footer_height,
- NULL, efhp_footer_cb, &info);
+ g_free (text);
}
static void
emfhp_complete (EMFormatHTMLPrint *efhp)
{
GtkPrintOperation *operation;
+ GError *error = NULL;
operation = e_print_operation_new ();
- gtk_print_operation_set_n_pages (operation, 1);
-
- g_signal_connect (
- operation, "draw-page",
- G_CALLBACK (mail_draw_page), efhp);
- gtk_print_operation_run (operation, efhp->action, NULL, NULL);
+ gtk_html_print_operation_run (
+ efhp->parent.html, operation, efhp->action, NULL,
+ (GtkHTMLPrintCalcHeight) NULL,
+ (GtkHTMLPrintCalcHeight) efhp_calc_footer_height,
+ (GtkHTMLPrintDrawFunc) NULL,
+ (GtkHTMLPrintDrawFunc) efhp_draw_footer,
+ NULL, &error);
g_object_unref (operation);
}