Allow getting the printer's hard margins

Adds a way to get the unprintable area of the printer. Bug #468989.
parent e81dacb8
...@@ -6864,6 +6864,7 @@ gtk_printer_has_details ...@@ -6864,6 +6864,7 @@ gtk_printer_has_details
gtk_printer_request_details gtk_printer_request_details
gtk_printer_get_capabilities gtk_printer_get_capabilities
gtk_printer_get_default_page_size gtk_printer_get_default_page_size
gtk_printer_get_hard_margins
GtkPrinterFunc GtkPrinterFunc
gtk_enumerate_printers gtk_enumerate_printers
......
...@@ -2945,6 +2945,7 @@ gtk_printer_compare ...@@ -2945,6 +2945,7 @@ gtk_printer_compare
gtk_printer_has_details gtk_printer_has_details
gtk_printer_request_details gtk_printer_request_details
gtk_printer_get_capabilities gtk_printer_get_capabilities
gtk_printer_get_hard_margins
gtk_enumerate_printers gtk_enumerate_printers
gtk_print_capabilities_get_type G_GNUC_CONST gtk_print_capabilities_get_type G_GNUC_CONST
#endif #endif
......
...@@ -802,7 +802,8 @@ set_margins_from_printer (GtkCustomPaperUnixDialog *dialog, ...@@ -802,7 +802,8 @@ set_margins_from_printer (GtkCustomPaperUnixDialog *dialog,
gdouble top, bottom, left, right; gdouble top, bottom, left, right;
top = bottom = left = right = 0; top = bottom = left = right = 0;
_gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right); if (!gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right))
return;
priv->non_user_change = TRUE; priv->non_user_change = TRUE;
unit_widget_set (priv->top_widget, _gtk_print_convert_to_mm (top, GTK_UNIT_POINTS)); unit_widget_set (priv->top_widget, _gtk_print_convert_to_mm (top, GTK_UNIT_POINTS));
......
...@@ -349,11 +349,11 @@ G_DEFINE_TYPE (GtkPrintBackend, gtk_print_backend, G_TYPE_OBJECT) ...@@ -349,11 +349,11 @@ G_DEFINE_TYPE (GtkPrintBackend, gtk_print_backend, G_TYPE_OBJECT)
static void fallback_printer_request_details (GtkPrinter *printer); static void fallback_printer_request_details (GtkPrinter *printer);
static gboolean fallback_printer_mark_conflicts (GtkPrinter *printer, static gboolean fallback_printer_mark_conflicts (GtkPrinter *printer,
GtkPrinterOptionSet *options); GtkPrinterOptionSet *options);
static void fallback_printer_get_hard_margins (GtkPrinter *printer, static gboolean fallback_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top, gdouble *top,
gdouble *bottom, gdouble *bottom,
gdouble *left, gdouble *left,
gdouble *right); gdouble *right);
static GList * fallback_printer_list_papers (GtkPrinter *printer); static GList * fallback_printer_list_papers (GtkPrinter *printer);
static GtkPageSetup * fallback_printer_get_default_page_size (GtkPrinter *printer); static GtkPageSetup * fallback_printer_get_default_page_size (GtkPrinter *printer);
static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer); static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer);
...@@ -494,7 +494,7 @@ fallback_printer_mark_conflicts (GtkPrinter *printer, ...@@ -494,7 +494,7 @@ fallback_printer_mark_conflicts (GtkPrinter *printer,
return FALSE; return FALSE;
} }
static void static gboolean
fallback_printer_get_hard_margins (GtkPrinter *printer, fallback_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top, gdouble *top,
gdouble *bottom, gdouble *bottom,
...@@ -505,6 +505,8 @@ fallback_printer_get_hard_margins (GtkPrinter *printer, ...@@ -505,6 +505,8 @@ fallback_printer_get_hard_margins (GtkPrinter *printer,
*bottom = 0; *bottom = 0;
*left = 0; *left = 0;
*right = 0; *right = 0;
return TRUE;
} }
static GList * static GList *
......
...@@ -104,11 +104,11 @@ struct _GtkPrintBackendClass ...@@ -104,11 +104,11 @@ struct _GtkPrintBackendClass
GtkPageSetup *page_setup); GtkPageSetup *page_setup);
GList * (*printer_list_papers) (GtkPrinter *printer); GList * (*printer_list_papers) (GtkPrinter *printer);
GtkPageSetup * (*printer_get_default_page_size) (GtkPrinter *printer); GtkPageSetup * (*printer_get_default_page_size) (GtkPrinter *printer);
void (*printer_get_hard_margins) (GtkPrinter *printer, gboolean (*printer_get_hard_margins) (GtkPrinter *printer,
double *top, gdouble *top,
double *bottom, gdouble *bottom,
double *left, gdouble *left,
double *right); gdouble *right);
GtkPrintCapabilities (*printer_get_capabilities) (GtkPrinter *printer); GtkPrintCapabilities (*printer_get_capabilities) (GtkPrinter *printer);
/* Signals */ /* Signals */
......
...@@ -45,11 +45,6 @@ cairo_surface_t * _gtk_printer_create_cairo_surface (GtkPrinter ...@@ -45,11 +45,6 @@ cairo_surface_t * _gtk_printer_create_cairo_surface (GtkPrinter
gdouble width, gdouble width,
gdouble height, gdouble height,
GIOChannel *cache_io); GIOChannel *cache_io);
void _gtk_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
gdouble *left,
gdouble *right);
GHashTable * _gtk_printer_get_custom_widgets (GtkPrinter *printer); GHashTable * _gtk_printer_get_custom_widgets (GtkPrinter *printer);
/* GtkPrintJob private methods: */ /* GtkPrintJob private methods: */
......
...@@ -951,12 +951,12 @@ gtk_printer_list_papers (GtkPrinter *printer) ...@@ -951,12 +951,12 @@ gtk_printer_list_papers (GtkPrinter *printer)
/** /**
* gtk_printer_get_default_page_size: * gtk_printer_get_default_page_size:
* @printer: a #GtkPrinter * @printer: a #GtkPrinter
* *
* Returns default page size of @printer. * Returns default page size of @printer.
* *
* Return value: a newly allocated #GtkPageSetup with default page size of the printer. * Return value: a newly allocated #GtkPageSetup with default page size of the printer.
* *
* Since: 2.13 * Since: 2.14
*/ */
GtkPageSetup * GtkPageSetup *
gtk_printer_get_default_page_size (GtkPrinter *printer) gtk_printer_get_default_page_size (GtkPrinter *printer)
...@@ -969,16 +969,34 @@ gtk_printer_get_default_page_size (GtkPrinter *printer) ...@@ -969,16 +969,34 @@ gtk_printer_get_default_page_size (GtkPrinter *printer)
return backend_class->printer_get_default_page_size (printer); return backend_class->printer_get_default_page_size (printer);
} }
void /**
_gtk_printer_get_hard_margins (GtkPrinter *printer, * gtk_printer_get_hard_margins:
gdouble *top, * @printer: a #GtkPrinter
gdouble *bottom, * @top: a location to store the top margin in
gdouble *left, * @bottom: a location to store the bottom margin in
gdouble *right) * @left: a location to store the left margin in
* @right: a location to store the right margin in
*
* Retrieve the hard margins of @printer, 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
*
* Since: 2.18
*/
gboolean
gtk_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
gdouble *left,
gdouble *right)
{ {
GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend); GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
backend_class->printer_get_hard_margins (printer, top, bottom, left, right); return backend_class->printer_get_hard_margins (printer, top, bottom, left, right);
} }
/** /**
...@@ -993,7 +1011,7 @@ _gtk_printer_get_hard_margins (GtkPrinter *printer, ...@@ -993,7 +1011,7 @@ _gtk_printer_get_hard_margins (GtkPrinter *printer,
* *
* This will return 0 unless the printer's details are available, see * This will return 0 unless the printer's details are available, see
* gtk_printer_has_details() and gtk_printer_request_details(). * gtk_printer_has_details() and gtk_printer_request_details().
* * *
* Return value: the printer's capabilities * Return value: the printer's capabilities
* *
* Since: 2.12 * Since: 2.12
......
...@@ -113,6 +113,11 @@ gint gtk_printer_compare (GtkPrinter *a, ...@@ -113,6 +113,11 @@ gint gtk_printer_compare (GtkPrinter *a,
gboolean gtk_printer_has_details (GtkPrinter *printer); gboolean gtk_printer_has_details (GtkPrinter *printer);
void gtk_printer_request_details (GtkPrinter *printer); void gtk_printer_request_details (GtkPrinter *printer);
GtkPrintCapabilities gtk_printer_get_capabilities (GtkPrinter *printer); GtkPrintCapabilities gtk_printer_get_capabilities (GtkPrinter *printer);
gboolean gtk_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
gdouble *left,
gdouble *right);
typedef gboolean (*GtkPrinterFunc) (GtkPrinter *printer, typedef gboolean (*GtkPrinterFunc) (GtkPrinter *printer,
gpointer data); gpointer data);
......
...@@ -158,11 +158,11 @@ static GtkPageSetup * cups_printer_get_default_page_size (GtkPrinter ...@@ -158,11 +158,11 @@ static GtkPageSetup * cups_printer_get_default_page_size (GtkPrinter
static void cups_printer_request_details (GtkPrinter *printer); static void cups_printer_request_details (GtkPrinter *printer);
static gboolean cups_request_default_printer (GtkPrintBackendCups *print_backend); static gboolean cups_request_default_printer (GtkPrintBackendCups *print_backend);
static gboolean cups_request_ppd (GtkPrinter *printer); static gboolean cups_request_ppd (GtkPrinter *printer);
static void cups_printer_get_hard_margins (GtkPrinter *printer, static gboolean cups_printer_get_hard_margins (GtkPrinter *printer,
double *top, gdouble *top,
double *bottom, gdouble *bottom,
double *left, gdouble *left,
double *right); gdouble *right);
static GtkPrintCapabilities cups_printer_get_capabilities (GtkPrinter *printer); static GtkPrintCapabilities cups_printer_get_capabilities (GtkPrinter *printer);
static void set_option_from_settings (GtkPrinterOption *option, static void set_option_from_settings (GtkPrinterOption *option,
GtkPrintSettings *setting); GtkPrintSettings *setting);
...@@ -4428,7 +4428,7 @@ cups_printer_get_default_page_size (GtkPrinter *printer) ...@@ -4428,7 +4428,7 @@ cups_printer_get_default_page_size (GtkPrinter *printer)
return create_page_setup (ppd_file, size); return create_page_setup (ppd_file, size);
} }
static void static gboolean
cups_printer_get_hard_margins (GtkPrinter *printer, cups_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top, gdouble *top,
gdouble *bottom, gdouble *bottom,
...@@ -4439,12 +4439,14 @@ cups_printer_get_hard_margins (GtkPrinter *printer, ...@@ -4439,12 +4439,14 @@ cups_printer_get_hard_margins (GtkPrinter *printer,
ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer)); ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
if (ppd_file == NULL) if (ppd_file == NULL)
return; return FALSE;
*left = ppd_file->custom_margins[0]; *left = ppd_file->custom_margins[0];
*bottom = ppd_file->custom_margins[1]; *bottom = ppd_file->custom_margins[1];
*right = ppd_file->custom_margins[2]; *right = ppd_file->custom_margins[2];
*top = ppd_file->custom_margins[3]; *top = ppd_file->custom_margins[3];
return TRUE;
} }
static GtkPrintCapabilities static GtkPrintCapabilities
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment