[gtk] Add gtk_printer_get_hard_margins_for_paper_size
- From: Marek Kašík <mkasik src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] Add gtk_printer_get_hard_margins_for_paper_size
- Date: Thu, 26 Apr 2018 12:21:55 +0000 (UTC)
commit b0bb7f3da4b174edc6e3e080849bf1ab950c3818
Author: Adrian Johnson <ajohnson redneon com>
Date: Thu Apr 12 11:31:37 2018 +0200
Add gtk_printer_get_hard_margins_for_paper_size
to retreive paper size specific hard margins and use this
to set the hard margins in the print context.
(modified by Marek Kasik <mkasik redhat com>)
https://bugzilla.gnome.org/show_bug.cgi?id=686109
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtkprintbackend.c | 18 +++++++++++
gtk/gtkprintbackend.h | 8 ++++-
gtk/gtkprinter.c | 31 +++++++++++++++++++
gtk/gtkprinter.h | 6 ++++
gtk/gtkprintoperation-unix.c | 3 +-
modules/printbackends/gtkprintbackendcups.c | 48 +++++++++++++++++++++++++++++
7 files changed, 113 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 7ea8aa8ba8..90d886cbc6 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5278,6 +5278,7 @@ gtk_printer_request_details
gtk_printer_get_capabilities
gtk_printer_get_default_page_size
gtk_printer_get_hard_margins
+gtk_printer_get_hard_margins_for_paper_size
GtkPrinterFunc
gtk_enumerate_printers
diff --git a/gtk/gtkprintbackend.c b/gtk/gtkprintbackend.c
index 0400100677..3651d79996 100644
--- a/gtk/gtkprintbackend.c
+++ b/gtk/gtkprintbackend.c
@@ -186,6 +186,12 @@ static gboolean fallback_printer_get_hard_margins (GtkPrinter
gdouble *bottom,
gdouble *left,
gdouble *right);
+static gboolean fallback_printer_get_hard_margins_for_paper_size (GtkPrinter *printer,
+ GtkPaperSize *paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right);
static GList * fallback_printer_list_papers (GtkPrinter *printer);
static GtkPageSetup * fallback_printer_get_default_page_size (GtkPrinter *printer);
static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer);
@@ -252,6 +258,7 @@ gtk_print_backend_class_init (GtkPrintBackendClass *class)
class->printer_request_details = fallback_printer_request_details;
class->printer_mark_conflicts = fallback_printer_mark_conflicts;
class->printer_get_hard_margins = fallback_printer_get_hard_margins;
+ class->printer_get_hard_margins_for_paper_size = fallback_printer_get_hard_margins_for_paper_size;
class->printer_list_papers = fallback_printer_list_papers;
class->printer_get_default_page_size = fallback_printer_get_default_page_size;
class->printer_get_capabilities = fallback_printer_get_capabilities;
@@ -375,6 +382,17 @@ fallback_printer_get_hard_margins (GtkPrinter *printer,
return FALSE;
}
+static gboolean
+fallback_printer_get_hard_margins_for_paper_size (GtkPrinter *printer,
+ GtkPaperSize *paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right)
+{
+ return FALSE;
+}
+
static GList *
fallback_printer_list_papers (GtkPrinter *printer)
{
diff --git a/gtk/gtkprintbackend.h b/gtk/gtkprintbackend.h
index a5be9fa9f5..2b4718e98c 100644
--- a/gtk/gtkprintbackend.h
+++ b/gtk/gtkprintbackend.h
@@ -133,11 +133,17 @@ struct _GtkPrintBackendClass
gchar **auth_info,
gboolean store_auth_info);
+ gboolean (*printer_get_hard_margins_for_paper_size) (GtkPrinter *printer,
+ GtkPaperSize *paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right);
+
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
- void (*_gtk_reserved4) (void);
};
#define GTK_PRINT_BACKEND_EXTENSION_POINT_NAME "gtk-print-backend"
diff --git a/gtk/gtkprinter.c b/gtk/gtkprinter.c
index 8339b5bd7a..d9ce1efadd 100644
--- a/gtk/gtkprinter.c
+++ b/gtk/gtkprinter.c
@@ -969,6 +969,37 @@ gtk_printer_get_hard_margins (GtkPrinter *printer,
return backend_class->printer_get_hard_margins (printer, top, bottom, left, right);
}
+/**
+ * gtk_printer_get_hard_margins_for_paper_size:
+ * @printer: a #GtkPrinter
+ * @paper_size: a #GtkPaperSize
+ * @top: (out): a location to store the top margin in
+ * @bottom: (out): a location to store the bottom margin in
+ * @left: (out): a location to store the left margin in
+ * @right: (out): a location to store the right margin in
+ *
+ * Retrieve the hard margins of @printer for @paper_size, i.e. the
+ * margins that define the area at the borders of the paper that the
+ * printer cannot print to.
+ *
+ * Note: This will not succeed unless the printer's details are available,
+ * see gtk_printer_has_details() and gtk_printer_request_details().
+ *
+ * Return value: %TRUE iff the hard margins were retrieved
+ */
+gboolean
+gtk_printer_get_hard_margins_for_paper_size (GtkPrinter *printer,
+ GtkPaperSize *paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right)
+{
+ GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
+
+ return backend_class->printer_get_hard_margins_for_paper_size (printer, paper_size, top, bottom, left,
right);
+}
+
/**
* gtk_printer_get_capabilities:
* @printer: a #GtkPrinter
diff --git a/gtk/gtkprinter.h b/gtk/gtkprinter.h
index bc02e93c0b..a3e3eb54a3 100644
--- a/gtk/gtkprinter.h
+++ b/gtk/gtkprinter.h
@@ -164,6 +164,12 @@ gboolean gtk_printer_get_hard_margins (GtkPrinter *pr
gdouble *bottom,
gdouble *left,
gdouble *right);
+gboolean gtk_printer_get_hard_margins_for_paper_size (GtkPrinter *printer,
+ GtkPaperSize *paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right);
/**
* GtkPrinterFunc:
diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c
index e0143c6e0b..7c044120b9 100644
--- a/gtk/gtkprintoperation-unix.c
+++ b/gtk/gtkprintoperation-unix.c
@@ -531,7 +531,8 @@ finish_print (PrintResponseData *rdata,
if (gtk_print_settings_get_number_up (settings) < 2)
{
- if (printer && gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right))
+ if (printer && (gtk_printer_get_hard_margins_for_paper_size (printer, gtk_page_setup_get_paper_size
(page_setup), &top, &bottom, &left, &right) ||
+ gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right)))
_gtk_print_context_set_hard_margins (priv->print_context, top, bottom, left, right);
}
else
diff --git a/modules/printbackends/gtkprintbackendcups.c b/modules/printbackends/gtkprintbackendcups.c
index 52614069d2..f530c0506e 100644
--- a/modules/printbackends/gtkprintbackendcups.c
+++ b/modules/printbackends/gtkprintbackendcups.c
@@ -193,6 +193,12 @@ static gboolean cups_printer_get_hard_margins (GtkPrinter
gdouble *bottom,
gdouble *left,
gdouble *right);
+static gboolean cups_printer_get_hard_margins_for_paper_size (GtkPrinter
*printer,
+ GtkPaperSize
*paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right);
static GtkPrintCapabilities cups_printer_get_capabilities (GtkPrinter
*printer);
static void set_option_from_settings (GtkPrinterOption
*option,
GtkPrintSettings
*setting);
@@ -355,6 +361,7 @@ gtk_print_backend_cups_class_init (GtkPrintBackendCupsClass *class)
backend_class->printer_list_papers = cups_printer_list_papers;
backend_class->printer_get_default_page_size = cups_printer_get_default_page_size;
backend_class->printer_get_hard_margins = cups_printer_get_hard_margins;
+ backend_class->printer_get_hard_margins_for_paper_size = cups_printer_get_hard_margins_for_paper_size;
backend_class->printer_get_capabilities = cups_printer_get_capabilities;
backend_class->set_password = gtk_print_backend_cups_set_password;
}
@@ -6697,6 +6704,47 @@ cups_printer_get_hard_margins (GtkPrinter *printer,
return result;
}
+static gboolean
+cups_printer_get_hard_margins_for_paper_size (GtkPrinter *printer,
+ GtkPaperSize *paper_size,
+ gdouble *top,
+ gdouble *bottom,
+ gdouble *left,
+ gdouble *right)
+{
+ ppd_file_t *ppd_file;
+ ppd_size_t *size;
+ const gchar *paper_name;
+ int i;
+
+ ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
+ if (ppd_file == NULL)
+ return FALSE;
+
+ paper_name = gtk_paper_size_get_ppd_name (paper_size);
+
+ for (i = 0; i < ppd_file->num_sizes; i++)
+ {
+ size = &ppd_file->sizes[i];
+ if (g_strcmp0(size->name, paper_name) == 0)
+ {
+ *top = size->length - size->top;
+ *bottom = size->bottom;
+ *left = size->left;
+ *right = size->width - size->right;
+ return TRUE;
+ }
+ }
+
+ /* Custom size */
+ *left = ppd_file->custom_margins[0];
+ *bottom = ppd_file->custom_margins[1];
+ *right = ppd_file->custom_margins[2];
+ *top = ppd_file->custom_margins[3];
+
+ return TRUE;
+}
+
static GtkPrintCapabilities
cups_printer_get_capabilities (GtkPrinter *printer)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]