Commit 25522558 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos Committed by Carlos Garcia Campos

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
parent 0bccddb2
......@@ -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");
}
......
......@@ -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;
......
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