gtk+ r21733 - in trunk: . docs/reference/gtk gtk modules/printbackends/cups modules/printbackends/file modules/printbackends/lpr modules/printbackends/test



Author: mkasik
Date: Thu Oct 30 16:24:27 2008
New Revision: 21733
URL: http://svn.gnome.org/viewvc/gtk+?rev=21733&view=rev

Log:
2008-10-30  Marek Kasik  <mkasik redhat com>

	Bug 339714 - Set printer dpi on cairo ps/pdf surfaces when printing

	* gtk/gtk.symbols
	* gtk/gtkprintsettings.c
	* gtk/gtkprintsettings.h
	* docs/reference/gtk/gtk-sections.txt
	* modules/printbackends/file/gtkprintbackendfile.c
	* modules/printbackends/test/gtkprintbackendtest.c
	* modules/printbackends/cups/gtkprintbackendcups.c
	* modules/printbackends/lpr/gtkprintbackendlpr.c:
	Added lpi (lines per inch) setting to GtkPrintSettings and support
	for anamorphic dpi. Surface fallback resolution is set to 2*lpi.


Modified:
   trunk/ChangeLog
   trunk/docs/reference/gtk/gtk-sections.txt
   trunk/gtk/gtk.symbols
   trunk/gtk/gtkprintsettings.c
   trunk/gtk/gtkprintsettings.h
   trunk/modules/printbackends/cups/gtkprintbackendcups.c
   trunk/modules/printbackends/file/gtkprintbackendfile.c
   trunk/modules/printbackends/lpr/gtkprintbackendlpr.c
   trunk/modules/printbackends/test/gtkprintbackendtest.c

Modified: trunk/docs/reference/gtk/gtk-sections.txt
==============================================================================
--- trunk/docs/reference/gtk/gtk-sections.txt	(original)
+++ trunk/docs/reference/gtk/gtk-sections.txt	Thu Oct 30 16:24:27 2008
@@ -6617,6 +6617,14 @@
 GTK_PRINT_SETTINGS_RESOLUTION
 gtk_print_settings_get_resolution
 gtk_print_settings_set_resolution
+gtk_print_settings_set_resolution_xy
+GTK_PRINT_SETTINGS_RESOLUTION_X
+gtk_print_settings_get_resolution_x
+GTK_PRINT_SETTINGS_RESOLUTION_Y
+gtk_print_settings_get_resolution_y
+GTK_PRINT_SETTINGS_PRINTER_LPI
+gtk_print_settings_get_printer_lpi
+gtk_print_settings_set_printer_lpi
 GTK_PRINT_SETTINGS_SCALE
 gtk_print_settings_get_scale
 gtk_print_settings_set_scale

Modified: trunk/gtk/gtk.symbols
==============================================================================
--- trunk/gtk/gtk.symbols	(original)
+++ trunk/gtk/gtk.symbols	Thu Oct 30 16:24:27 2008
@@ -2974,6 +2974,11 @@
 gtk_print_settings_set_number_up_layout
 gtk_print_settings_get_resolution
 gtk_print_settings_set_resolution
+gtk_print_settings_get_resolution_x
+gtk_print_settings_get_resolution_y
+gtk_print_settings_set_resolution_xy
+gtk_print_settings_get_printer_lpi
+gtk_print_settings_set_printer_lpi
 gtk_print_settings_get_scale
 gtk_print_settings_set_scale
 gtk_print_settings_get_print_pages

Modified: trunk/gtk/gtkprintsettings.c
==============================================================================
--- trunk/gtk/gtkprintsettings.c	(original)
+++ trunk/gtk/gtkprintsettings.c	Thu Oct 30 16:24:27 2008
@@ -1193,7 +1193,9 @@
  * @settings: a #GtkPrintSettings
  * @resolution: the resolution in dpi
  * 
- * Sets the value of %GTK_PRINT_SETTINGS_RESOLUTION.
+ * Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
+ * %GTK_PRINT_SETTINGS_RESOLUTION_X and 
+ * %GTK_PRINT_SETTINGS_RESOLUTION_Y.
  * 
  * Since: 2.10
  */
@@ -1203,6 +1205,100 @@
 {
   gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION,
 			      resolution);
+  gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X,
+			      resolution);
+  gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y,
+			      resolution);
+}
+
+/**
+ * gtk_print_settings_get_resolution_x:
+ * @settings: a #GtkPrintSettings
+ * 
+ * Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_X.
+ * 
+ * Return value: the horizontal resolution in dpi
+ *
+ * Since: 2.16
+ */
+gint
+gtk_print_settings_get_resolution_x (GtkPrintSettings *settings)
+{
+  return gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X);
+}
+
+/**
+ * gtk_print_settings_get_resolution_y:
+ * @settings: a #GtkPrintSettings
+ * 
+ * Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_Y.
+ * 
+ * Return value: the vertical resolution in dpi
+ *
+ * Since: 2.16
+ */
+gint
+gtk_print_settings_get_resolution_y (GtkPrintSettings *settings)
+{
+  return gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y);
+}
+
+/**
+ * gtk_print_settings_set_resolution_xy:
+ * @settings: a #GtkPrintSettings
+ * @resolution_x: the horizontal resolution in dpi
+ * @resolution_y: the vertical resolution in dpi
+ * 
+ * Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
+ * %GTK_PRINT_SETTINGS_RESOLUTION_X and
+ * %GTK_PRINT_SETTINGS_RESOLUTION_Y.
+ * 
+ * Since: 2.16
+ */
+void
+gtk_print_settings_set_resolution_xy (GtkPrintSettings *settings,
+				      gint              resolution_x,
+				      gint              resolution_y)
+{
+  gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X,
+			      resolution_x);
+  gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y,
+			      resolution_y);
+  gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION,
+			      resolution_x);
+}
+
+/**
+ * gtk_print_settings_get_printer_lpi:
+ * @settings: a #GtkPrintSettings
+ * 
+ * Gets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI.
+ * 
+ * Return value: the resolution in lpi (lines per inch)
+ *
+ * Since: 2.16
+ */
+gdouble
+gtk_print_settings_get_printer_lpi (GtkPrintSettings *settings)
+{
+  return gtk_print_settings_get_double (settings, GTK_PRINT_SETTINGS_PRINTER_LPI);
+}
+
+/**
+ * gtk_print_settings_set_printer_lpi:
+ * @settings: a #GtkPrintSettings
+ * @resolution: the resolution in lpi (lines per inch)
+ * 
+ * Sets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI
+ * 
+ * Since: 2.16
+ */
+void
+gtk_print_settings_set_printer_lpi (GtkPrintSettings *settings,
+				    gdouble           lpi)
+{
+  gtk_print_settings_set_double (settings, GTK_PRINT_SETTINGS_PRINTER_LPI,
+			         lpi);
 }
 
 /**

Modified: trunk/gtk/gtkprintsettings.h
==============================================================================
--- trunk/gtk/gtkprintsettings.h	(original)
+++ trunk/gtk/gtkprintsettings.h	Thu Oct 30 16:24:27 2008
@@ -133,6 +133,9 @@
 #define GTK_PRINT_SETTINGS_NUMBER_UP        "number-up"
 #define GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT "number-up-layout"
 #define GTK_PRINT_SETTINGS_OUTPUT_BIN       "output-bin"
+#define GTK_PRINT_SETTINGS_RESOLUTION_X     "resolution-x"
+#define GTK_PRINT_SETTINGS_RESOLUTION_Y     "resolution-y"
+#define GTK_PRINT_SETTINGS_PRINTER_LPI      "printer-lpi"
 
 #define GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT  "output-file-format"
 #define GTK_PRINT_SETTINGS_OUTPUT_URI          "output-uri"
@@ -188,6 +191,14 @@
 gint                  gtk_print_settings_get_resolution        (GtkPrintSettings   *settings);
 void                  gtk_print_settings_set_resolution        (GtkPrintSettings   *settings,
 								gint                resolution);
+gint                  gtk_print_settings_get_resolution_x      (GtkPrintSettings   *settings);
+gint                  gtk_print_settings_get_resolution_y      (GtkPrintSettings   *settings);
+void                  gtk_print_settings_set_resolution_xy     (GtkPrintSettings   *settings,
+								gint                resolution_x,
+								gint                resolution_y);
+gdouble               gtk_print_settings_get_printer_lpi       (GtkPrintSettings   *settings);
+void                  gtk_print_settings_set_printer_lpi       (GtkPrintSettings   *settings,
+								gdouble             lpi);
 gdouble               gtk_print_settings_get_scale             (GtkPrintSettings   *settings);
 void                  gtk_print_settings_set_scale             (GtkPrintSettings   *settings,
 								gdouble             scale);

Modified: trunk/modules/printbackends/cups/gtkprintbackendcups.c
==============================================================================
--- trunk/modules/printbackends/cups/gtkprintbackendcups.c	(original)
+++ trunk/modules/printbackends/cups/gtkprintbackendcups.c	Thu Oct 30 16:24:27 2008
@@ -316,6 +316,10 @@
   cairo_surface_t *surface; 
   ppd_file_t      *ppd_file = NULL;
   ppd_attr_t      *ppd_attr = NULL;
+  ppd_attr_t      *ppd_attr_res = NULL;
+  ppd_attr_t      *ppd_attr_screen_freq = NULL;
+  ppd_attr_t      *ppd_attr_res_screen_freq = NULL;
+  gchar           *res_string = NULL;
   int              level = 2;
  
   /* TODO: check if it is a ps or pdf printer */
@@ -330,6 +334,57 @@
 
       if (ppd_attr != NULL)
         level = atoi (ppd_attr->value);
+
+      if (gtk_print_settings_get_resolution (settings) == 0)
+        {
+          ppd_attr_res = ppdFindAttr (ppd_file, "DefaultResolution", NULL);
+
+          if (ppd_attr_res != NULL)
+            {
+              int res, res_x, res_y;
+
+              if (sscanf (ppd_attr_res->value, "%dx%ddpi", &res_x, &res_y) == 2)
+                {
+                  if (res_x != 0 && res_y != 0)
+                    gtk_print_settings_set_resolution_xy (settings, res_x, res_y);
+                }
+              else if (sscanf (ppd_attr_res->value, "%ddpi", &res) == 1)
+                {
+                  if (res != 0)
+                    gtk_print_settings_set_resolution (settings, res);
+                }
+              else
+                gtk_print_settings_set_resolution (settings, 300);
+            }
+        }
+
+      res_string = g_strdup_printf ("%ddpi", 
+                                    gtk_print_settings_get_resolution (settings));
+      ppd_attr_res_screen_freq = ppdFindAttr (ppd_file, "ResScreenFreq", res_string);
+      g_free (res_string);
+
+      if (ppd_attr_res_screen_freq == NULL)
+        {
+          res_string = g_strdup_printf ("%dx%ddpi", 
+                                        gtk_print_settings_get_resolution_x (settings),
+                                        gtk_print_settings_get_resolution_y (settings));
+          ppd_attr_res_screen_freq = ppdFindAttr (ppd_file, "ResScreenFreq", res_string);
+          g_free (res_string);
+        }
+
+      ppd_attr_screen_freq = ppdFindAttr (ppd_file, "ScreenFreq", NULL);
+
+      if (ppd_attr_res_screen_freq != NULL)
+        gtk_print_settings_set_printer_lpi (settings, atof (ppd_attr_res_screen_freq->value));
+      else if (ppd_attr_screen_freq != NULL)
+        gtk_print_settings_set_printer_lpi (settings, atof (ppd_attr_screen_freq->value));
+      else
+        gtk_print_settings_set_printer_lpi (settings, 150.0);
+    }
+  else
+    {
+      gtk_print_settings_set_resolution (settings, 300);
+      gtk_print_settings_set_printer_lpi (settings, 150.0);
     }
 
   if (level == 2)
@@ -338,8 +393,9 @@
   if (level == 3)
     cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_3);
 
-  /* TODO: DPI from settings object? */
-  cairo_surface_set_fallback_resolution (surface, 300, 300);
+  cairo_surface_set_fallback_resolution (surface,
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings),
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings));
 
   return surface;
 }
@@ -3282,7 +3338,16 @@
       else
 	{
 	  int res = gtk_print_settings_get_resolution (settings);
-	  if (res != 0)
+	  int res_x = gtk_print_settings_get_resolution_x (settings);
+	  int res_y = gtk_print_settings_get_resolution_y (settings);
+
+          if (res_x != res_y)
+            {
+	      value = g_strdup_printf ("%dx%ddpi", res_x, res_y);
+	      gtk_printer_option_set (option, value);
+	      g_free (value);
+            }
+          else if (res != 0)
 	    {
 	      value = g_strdup_printf ("%ddpi", res);
 	      gtk_printer_option_set (option, value);
@@ -3371,10 +3436,19 @@
 			    settings, GTK_PRINT_SETTINGS_QUALITY, "OutputMode");
   else if (strcmp (option->name, "cups-Resolution") == 0)
     {
-      int res = atoi (value);
-      /* TODO: What if resolution is on XXXxYYYdpi form? */
-      if (res != 0)
-	gtk_print_settings_set_resolution (settings, res);
+      int res, res_x, res_y;
+
+      if (sscanf (value, "%dx%ddpi", &res_x, &res_y) == 2)
+        {
+          if (res_x != 0 && res_y != 0)
+            gtk_print_settings_set_resolution_xy (settings, res_x, res_y);
+        }
+      else if (sscanf (value, "%ddpi", &res) == 1)
+        {
+          if (res != 0)
+            gtk_print_settings_set_resolution (settings, res);
+        }
+
       gtk_print_settings_set (settings, option->name, value);
     }
   else if (strcmp (option->name, "gtk-paper-type") == 0)

Modified: trunk/modules/printbackends/file/gtkprintbackendfile.c
==============================================================================
--- trunk/modules/printbackends/file/gtkprintbackendfile.c	(original)
+++ trunk/modules/printbackends/file/gtkprintbackendfile.c	Thu Oct 30 16:24:27 2008
@@ -306,8 +306,12 @@
   else
     surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height);
 
-  /* TODO: DPI from settings object? */
-  cairo_surface_set_fallback_resolution (surface, 300, 300);
+  if (gtk_print_settings_get_printer_lpi (settings) == 0.0)
+    gtk_print_settings_set_printer_lpi (settings, 150.0);
+
+  cairo_surface_set_fallback_resolution (surface,
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings),
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings));
 
   return surface;
 }

Modified: trunk/modules/printbackends/lpr/gtkprintbackendlpr.c
==============================================================================
--- trunk/modules/printbackends/lpr/gtkprintbackendlpr.c	(original)
+++ trunk/modules/printbackends/lpr/gtkprintbackendlpr.c	Thu Oct 30 16:24:27 2008
@@ -211,8 +211,12 @@
   
   surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height);
 
-  /* TODO: DPI from settings object? */
-  cairo_surface_set_fallback_resolution (surface, 300, 300);
+  if (gtk_print_settings_get_printer_lpi (settings) == 0.0)
+    gtk_print_settings_set_printer_lpi (settings, 150.0);
+
+  cairo_surface_set_fallback_resolution (surface,
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings),
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings));
 
   return surface;
 }

Modified: trunk/modules/printbackends/test/gtkprintbackendtest.c
==============================================================================
--- trunk/modules/printbackends/test/gtkprintbackendtest.c	(original)
+++ trunk/modules/printbackends/test/gtkprintbackendtest.c	Thu Oct 30 16:24:27 2008
@@ -306,8 +306,12 @@
   else
     surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height);
 
-  /* TODO: DPI from settings object? */
-  cairo_surface_set_fallback_resolution (surface, 300, 300);
+  if (gtk_print_settings_get_printer_lpi (settings) == 0.0)
+    gtk_print_settings_set_printer_lpi (settings, 150.0);
+
+  cairo_surface_set_fallback_resolution (surface,
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings),
+                                         2.0 * gtk_print_settings_get_printer_lpi (settings));
 
   return surface;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]