GNOME Bugzilla – Bug 390128
Custom paper sizes rejected by gtk_paper_size_new()
Last modified: 2018-04-15 00:21:45 UTC
Please describe the problem: The subject says it all - if I try to pass a valid custom paper size (i.e. a valid "name" value from ~/.gtk-custom-papers) to gtk_paper_size_new(), the result is a Gtk-WARNING **: Unknown paper size <paper size id> The name is shown as selected paper size in the page setup dialogue, though, but gtk_paper_size_new() apparently returns the default instead, so a call to gtk_page_setup_set_paper_size_and_default_margins(page_setup, paper_size) with the paper size returned above will actually set the "wrong" defaults. Steps to reproduce: 1. Create a custom paper size with name e.g. "A4 with my margins" 2. Call gtk_paper_size_new("A4 with my margins") Actual results: see above Expected results: gtk_paper_size_new() should load the paper size from ~/.gtk-custom-papers instead of complaining (at least on platforms where custom paper sizes are supported). Does this happen every time? yes Other information: The page setup dialogue lets me add a custom paper size with the same name as a standard one (e.g. "A5"). Such names should be rejected.
I don't think this is a bug. If you already have a GtkPageSetup for the custom paper (e.g. out of the page setup dialogue), you can get the paper from it with gtk_page_setup_get_paper_size. If you want to create a new custom paper, you should use gtk_paper_size_new_custom.
I must admit I didn't explain the full use case... In the application, the user creates a new paper using the page setup dialogue. I then call gtk_paper_size_get_name() to store the name of the preferred paper in a config file (GKeyFile). When the applicaton is run next time, I read the last paper size from the config file and try to initialise the GtkPageSetup using this value, i.e. something like <snip> gchar *paper_size_name = g_key_file_get_value(key_file, "Print", "PaperSize", NULL); GtkPageOrientation orientation = (GtkPageOrientation) g_key_file_get_integer(key_file, "Print", "Orientation", NULL); GtkPaperSize *paper_size; paper_size = gtk_paper_size_new(paper_size_name); g_free(paper_size_name); gtk_page_setup_set_paper_size_and_default_margins(page_setup, paper_size); gtk_paper_size_free(paper_size); gtk_page_setup_set_orientation(page_setup, orientation); </snip> This works nicely (i.e. sets the sizes and the names) for standard sizes, and it would be handy if I could restore custom ones, too. I even don't see a way from the api to restore the sizes if I only store the page name. So I actually had to keep the sizes in my config file for a full restore which IMHO is always a bad idea (keeping redundant information at different places).
Note bug 344515 which will add support for print settings/page setup [de]serialisation to gtk+. Meanwhile, you could do it like this: save the ppd name of the paper size if it has one, and try to recreate it by ppdname (gtk_paper_size_new), else fall back to gtk_paper_size_new_custom.
I agree that this is a bit of a problem. Maybe we need a function like gtk_paper_size_lookup (const gchar *name) which would first try to intepret name as a standard paper name, then try as a PPD paper name, and finally load the saved custom paper sizes and look in there.
Bug 426129 is clearly a related bug. I would have expected that for custom papersizes gtk_paper_size_get_name would yield a name of the form custom_..._...x... that can then be read by gtk_paper_size_new. So we could easily store those names (even for custom papersizes).
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla. If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab: https://gitlab.gnome.org/GNOME/gtk/issues/new