From c836be0508b51ecccd893a833b0f290c627ad3bf Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Tue, 8 Nov 2016 11:44:44 +0100 Subject: [PATCH] printing: Do not truncate job names in GtkPrintOperation We are currently truncating job names to 255 bytes, because that's the maximum allowed length of job-name attribute in CUPS. This is a CUPS limitation that GtkPrintOperation shouldn't need to know, and it shouldn't affect other backends, that might have other limitations or even no limitation at all. This has another side effect, that what you set as GtkPrintOperation:job-name could be different to what you get if the property is truncated, this is not documented in gtk_print_operation_set_job_name(). So, I think the job name should be truncated by the CUPS backend, right before setting the job-name attribute. https://bugzilla.gnome.org/show_bug.cgi?id=774097 --- gtk/gtkprintoperation.c | 24 ++++--------------- .../printbackends/cups/gtkprintbackendcups.c | 20 ++++++++++++++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index db53d050cc..329a07aeaf 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -1606,33 +1606,17 @@ gtk_print_operation_set_job_name (GtkPrintOperation *op, const gchar *job_name) { GtkPrintOperationPrivate *priv; - gchar *end; g_return_if_fail (GTK_IS_PRINT_OPERATION (op)); g_return_if_fail (job_name != NULL); priv = op->priv; - g_free (priv->job_name); - /* - * according to http://datatracker.ietf.org/doc/rfc2911/, - * job names MUST NOT exceed 255 (MAX) octets. - * - * CUPS will not print jobs with names exceeding 255 chars. - */ - if (strlen (job_name) > 255) - { - end = g_utf8_find_prev_char (job_name, job_name + 255); - priv->job_name = g_utf8_substring (job_name, - 0, - g_utf8_pointer_to_offset (job_name, - end)); - } - else - { - priv->job_name = g_strdup (job_name); - } + if (g_strcmp0 (priv->job_name, job_name) == 0) + return; + g_free (priv->job_name); + priv->job_name = g_strdup (job_name); g_object_notify (G_OBJECT (op), "job-name"); } diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c index d1140764a7..2056434bea 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.c +++ b/modules/printbackends/cups/gtkprintbackendcups.c @@ -752,10 +752,26 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend, NULL, printer_absolute_uri); title = gtk_print_job_get_title (job); - if (title) + if (title) { + char *title_truncated = NULL; + size_t title_bytes = strlen (title); + + if (title_bytes >= IPP_MAX_NAME) + { + gchar *end; + + end = g_utf8_find_prev_char (title, title + IPP_MAX_NAME - 1); + title_truncated = g_utf8_substring (title, + 0, + g_utf8_pointer_to_offset (title, end)); + } + gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", - NULL, title); + NULL, + title_truncated ? title_truncated : title); + g_free (title_truncated); + } options_data = g_new0 (CupsOptionsData, 1); options_data->request = request;