After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 390128 - Custom paper sizes rejected by gtk_paper_size_new()
Custom paper sizes rejected by gtk_paper_size_new()
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Printing
2.10.x
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-12-27 20:36 UTC by albrecht.dress
Modified: 2018-04-15 00:21 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16



Description albrecht.dress 2006-12-27 20:36:28 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.
Comment 1 Christian Persch 2006-12-27 22:18:49 UTC
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.
Comment 2 albrecht.dress 2006-12-28 11:00:49 UTC
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).
Comment 3 Christian Persch 2006-12-29 21:16:58 UTC
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.
Comment 4 Matthias Clasen 2007-01-02 19:25:13 UTC
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.
Comment 5 Andreas J. Guelzow 2007-04-13 06:39:58 UTC
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).
Comment 6 Matthias Clasen 2018-02-10 05:03:52 UTC
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.
Comment 7 Matthias Clasen 2018-04-15 00:21:45 UTC
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