Blob Blame History Raw
From 83edea9c0319d6e5f9c65338ddbc31c24ae736c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Wilmet?= <swilmet@gnome.org>
Date: Sat, 6 Jun 2015 20:36:36 +0200
Subject: [PATCH 11/26] Printing: fix margins

GTK+'s default margins are too small. It was not possible to use a hole
punch, and with some printers the text was truncated on the right.

Add gsettings to configure margins, with better defaults (25mm on each
side). The unit chosen is the millimeter, because it's the international
standard.

https://bugzilla.gnome.org/show_bug.cgi?id=572741
---
 data/org.gnome.gedit.gschema.xml.in | 20 ++++++++++++++++++++
 gedit/gedit-print-job.c             | 19 ++++++++++++++++---
 gedit/gedit-settings.h              |  4 ++++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/data/org.gnome.gedit.gschema.xml.in b/data/org.gnome.gedit.gschema.xml.in
index a01b3ec..c34e4db 100644
--- a/data/org.gnome.gedit.gschema.xml.in
+++ b/data/org.gnome.gedit.gschema.xml.in
@@ -222,6 +222,26 @@
       <summary>Line Number Font for Printing</summary>
       <description>Specifies the font to use for line numbers when printing. This will only take effect if the "Print Line Numbers" option is non-zero.</description>
     </key>
+    <key name="margin-left" type="d">
+      <default>25</default>
+      <summary>Margin Left</summary>
+      <description>The left margin, in millimeters.</description>
+    </key>
+    <key name="margin-top" type="d">
+      <default>25</default>
+      <summary>Margin Top</summary>
+      <description>The top margin, in millimeters.</description>
+    </key>
+    <key name="margin-right" type="d">
+      <default>25</default>
+      <summary>Margin Right</summary>
+      <description>The right margin, in millimeters.</description>
+    </key>
+    <key name="margin-bottom" type="d">
+      <default>25</default>
+      <summary>Margin Bottom</summary>
+      <description>The bottom margin, in millimeters.</description>
+    </key>
   </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.preferences.encodings" path="/org/gnome/gedit/preferences/encodings/">
     <key name="auto-detected" type="as">
diff --git a/gedit/gedit-print-job.c b/gedit/gedit-print-job.c
index a19ef65..34816da 100644
--- a/gedit/gedit-print-job.c
+++ b/gedit/gedit-print-job.c
@@ -507,6 +507,7 @@ create_compositor (GeditPrintJob *job)
 	GtkWrapMode wrap_mode;
 	guint print_line_numbers;
 	gboolean print_header;
+	gdouble margin;
 
 	/* Create and initialize print compositor */
 	print_font_body = g_settings_get_string (job->priv->print_settings,
@@ -540,9 +541,17 @@ create_compositor (GeditPrintJob *job)
 						     "header-font-name", print_font_header,
 						     NULL));
 
-	g_free (print_font_body);
-	g_free (print_font_header);
-	g_free (print_font_numbers);
+	margin = g_settings_get_double (job->priv->print_settings, GEDIT_SETTINGS_PRINT_MARGIN_LEFT);
+	gtk_source_print_compositor_set_left_margin (job->priv->compositor, margin, GTK_UNIT_MM);
+
+	margin = g_settings_get_double (job->priv->print_settings, GEDIT_SETTINGS_PRINT_MARGIN_TOP);
+	gtk_source_print_compositor_set_top_margin (job->priv->compositor, margin, GTK_UNIT_MM);
+
+	margin = g_settings_get_double (job->priv->print_settings, GEDIT_SETTINGS_PRINT_MARGIN_RIGHT);
+	gtk_source_print_compositor_set_right_margin (job->priv->compositor, margin, GTK_UNIT_MM);
+
+	margin = g_settings_get_double (job->priv->print_settings, GEDIT_SETTINGS_PRINT_MARGIN_BOTTOM);
+	gtk_source_print_compositor_set_bottom_margin (job->priv->compositor, margin, GTK_UNIT_MM);
 
 	if (print_header)
 	{
@@ -568,6 +577,10 @@ create_compositor (GeditPrintJob *job)
 		g_free (name_to_display);
 		g_free (left);
 	}
+
+	g_free (print_font_body);
+	g_free (print_font_header);
+	g_free (print_font_numbers);
 }
 
 static void
diff --git a/gedit/gedit-settings.h b/gedit/gedit-settings.h
index 39ee82e..85cdc94 100644
--- a/gedit/gedit-settings.h
+++ b/gedit/gedit-settings.h
@@ -108,6 +108,10 @@ void			 gedit_settings_set_list			(GSettings     *settings,
 #define GEDIT_SETTINGS_PRINT_FONT_NUMBERS_PANGO		"print-font-numbers-pango"
 #define GEDIT_SETTINGS_ENCODING_AUTO_DETECTED		"auto-detected"
 #define GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU		"shown-in-menu"
+#define GEDIT_SETTINGS_PRINT_MARGIN_LEFT		"margin-left"
+#define GEDIT_SETTINGS_PRINT_MARGIN_TOP			"margin-top"
+#define GEDIT_SETTINGS_PRINT_MARGIN_RIGHT		"margin-right"
+#define GEDIT_SETTINGS_PRINT_MARGIN_BOTTOM		"margin-bottom"
 #define GEDIT_SETTINGS_ACTIVE_PLUGINS			"active-plugins"
 #define GEDIT_SETTINGS_ENSURE_TRAILING_NEWLINE		"ensure-trailing-newline"
 
-- 
1.8.3.1