From 29b6e6587aee192bdac9ac75b30ef62e74a05fbf Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 30 Jul 2008 09:52:42 +0000 Subject: [PATCH] Fix problems in handling custom paper sizes. The DEVMODE::dmPaperWidth and 2008-07-30 Tor Lillqvist * gtk/gtkprintoperation-win32.c: Fix problems in handling custom paper sizes. The DEVMODE::dmPaperWidth and dmPaperLength are in tenths of a millimeter, and the RECT passed to CreateEnhMetaFile() is in hundredths of a millimeter. Patch by Sven Neumann. svn path=/trunk/; revision=20916 --- ChangeLog | 7 +++++++ gtk/gtkprintoperation-win32.c | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 091480ca3f..627d4736fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-07-30 Tor Lillqvist + + * gtk/gtkprintoperation-win32.c: Fix problems in handling custom + paper sizes. The DEVMODE::dmPaperWidth and dmPaperLength are in + tenths of a millimeter, and the RECT passed to CreateEnhMetaFile() + is in hundredths of a millimeter. Patch by Sven Neumann. + 2008-07-28 Matthias Clasen * gtk/gtktreemodel.c: Small doc improvements. diff --git a/gtk/gtkprintoperation-win32.c b/gtk/gtkprintoperation-win32.c index f368e42839..ec6f9cc02c 100644 --- a/gtk/gtkprintoperation-win32.c +++ b/gtk/gtkprintoperation-win32.c @@ -439,6 +439,8 @@ win32_start_page (GtkPrintOperation *op, { devmode->dmPaperSize = DMPAPER_USER; devmode->dmFields |= DM_PAPERWIDTH | DM_PAPERLENGTH; + + /* Lengths in DEVMODE are in tenths of a millimeter */ devmode->dmPaperWidth = gtk_paper_size_get_width (paper_size, GTK_UNIT_MM) * 10.0; devmode->dmPaperLength = gtk_paper_size_get_height (paper_size, GTK_UNIT_MM) * 10.0; } @@ -672,10 +674,12 @@ devmode_to_settings (GtkPrintSettings *settings, -1, NULL, NULL, NULL); if (form_name == NULL || form_name[0] == 0) form_name = g_strdup (_("Custom size")); + + /* Lengths in DEVMODE are in tenths of a millimeter */ paper_size = gtk_paper_size_new_custom (form_name, form_name, - devmode->dmPaperWidth * 10.0, - devmode->dmPaperLength * 10.0, + devmode->dmPaperWidth / 10.0, + devmode->dmPaperLength / 10.0, GTK_UNIT_MM); gtk_print_settings_set_paper_size (settings, paper_size); gtk_paper_size_free (paper_size); @@ -954,8 +958,10 @@ devmode_from_settings (GtkPrintSettings *settings, { devmode->dmPaperSize = DMPAPER_USER; devmode->dmFields |= DM_PAPERWIDTH | DM_PAPERLENGTH; - devmode->dmPaperWidth = gtk_paper_size_get_width (paper_size, GTK_UNIT_MM) / 10.0; - devmode->dmPaperLength = gtk_paper_size_get_height (paper_size, GTK_UNIT_MM) / 10.0; + + /* Lengths in DEVMODE are in tenths of a millimeter */ + devmode->dmPaperWidth = gtk_paper_size_get_width (paper_size, GTK_UNIT_MM) * 10.0; + devmode->dmPaperLength = gtk_paper_size_get_height (paper_size, GTK_UNIT_MM) * 10.0; } gtk_paper_size_free (paper_size); } @@ -1726,7 +1732,6 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation gchar **target) { GtkPaperSize *paper_size; - double w, h; HDC metafile_dc; RECT rect; char *template; @@ -1745,13 +1750,12 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation g_free (filename); paper_size = gtk_page_setup_get_paper_size (page_setup); - w = gtk_paper_size_get_width (paper_size, GTK_UNIT_MM); - h = gtk_paper_size_get_height (paper_size, GTK_UNIT_MM); - + + /* The rectangle dimensions are given in hundredths of a millimeter */ rect.left = 0; - rect.right = w*100; + rect.right = 100.0 * gtk_paper_size_get_width (paper_size, GTK_UNIT_MM); rect.top = 0; - rect.bottom = h*100; + rect.bottom = 100.0 * gtk_paper_size_get_height (paper_size, GTK_UNIT_MM); metafile_dc = CreateEnhMetaFileW (NULL, filename_utf16, &rect, L"Gtk+\0Print Preview\0\0");