Comment 61 for bug 998156

TJ (tj) wrote :

In modules/printbackends/cups/gtkprintbackendcups.c:

 static void
 add_cups_options (const gchar *key,
    const gchar *value,
    gpointer user_data)
 {
 ...
   /* Add "Custom." prefix to custom values. */
   if (custom_value)
    {
      new_value = g_strdup_printf ("Custom.%s", value);
      gtk_cups_request_encode_option (request, key, new_value);
      g_free (new_value);
    }
   else
    gtk_cups_request_encode_option (request, key, value);
 }

This is called from:

 static void gtk_print_backend_cups_print_stream (...) {
 ...
  gtk_print_settings_foreach (settings, add_cups_options, options_data);
 ...
 }

which is called via the ops pointer print_stream:

 backend_class->print_stream = gtk_print_backend_cups_print_stream;

The "Custom." code was added:

commit 8170436e61ea68c713d75ad374d22c3261be9203
Author: Benjamin Berg <email address hidden>
Date: Sat Dec 24 17:26:32 2011 +0100

    Set cups Custom print options correctly (bug #543520, patch by Marek Kašík)

    This patch fixes the cups print backend to pass Custom options with
    the "Custom." prefix to cups if neccessary.

https://bugzilla.gnome.org/show_bug.cgi?id=543520

In comment nos. 25 and 27 of that report Benjamin Berg describes this "Custom." prefix problem and a patch to remove it when the GTK+ print dialog. Commit 8170436e61ea68 was found to cause a crash in Thunderbird and Inkscape, and was subsequently revised by commit 9afe13bf91.

commit 9afe13bf91d8e80c4def7d3944d56542ce13733f
Author: Marek Kasik <email address hidden>
Date: Tue Jan 31 12:15:43 2012 +0100

    printing: Don't crash when printing

    This commit fixes crash which occurs in Firefox, Thunderbird and Inkscape
    during printing. This crash was caused because of wrong handling of Custom
    CUPS options. (#543520)

These commits are included in Ubuntu's 3.4.2 release.

My suspicion is that this code in create_pickone_option () {
...
      if (option->type != GTK_PRINTER_OPTION_TYPE_PICKONE)
        {
          if (g_str_has_prefix (ppd_option->defchoice, "Custom."))
            gtk_printer_option_set (option, ppd_option->defchoice + 7);
          else
            gtk_printer_option_set (option, ppd_option->defchoice);
        }
      else
...
}

isn't being executed in some circumstances, leading to the "Custom." prefix received from CUPS then being further prefixed by add_cups_options() when the ->print_stream op is called.