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 339592 - Add print-to-postscript
Add print-to-postscript
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-04-24 16:01 UTC by Alexander Larsson
Modified: 2011-02-04 16:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
first patch, for comments (27.56 KB, patch)
2006-06-15 21:05 UTC, Christian Persch
none Details | Review
this is easilty possible now (29.61 KB, image/png)
2006-06-17 05:25 UTC, Matthias Clasen
  Details
updated patch (29.46 KB, patch)
2006-06-17 22:30 UTC, Christian Persch
none Details | Review
step 1 (6.22 KB, patch)
2006-06-19 13:38 UTC, Christian Persch
none Details | Review
step 2 (18.78 KB, patch)
2006-06-19 14:29 UTC, Christian Persch
none Details | Review
step 1 updated (6.21 KB, patch)
2006-06-19 18:31 UTC, Christian Persch
none Details | Review
step 1 update 2 (6.23 KB, patch)
2006-06-20 16:38 UTC, Christian Persch
committed Details | Review
step 2 updated (18.71 KB, patch)
2006-06-20 17:42 UTC, Christian Persch
committed Details | Review
step 3 (6.43 KB, patch)
2006-06-20 19:26 UTC, Christian Persch
none Details | Review
step 3 updated (9.84 KB, patch)
2006-06-21 19:13 UTC, Christian Persch
none Details | Review

Description Alexander Larsson 2006-04-24 16:01:42 UTC
Right now the dialog only supports print-to-file as PDF.
We might want to add postscript support too.

Possible approaches:
* Convert print-to-pdf backend to print-to-file and have a postscript/pdf option (that would be availible on a tab)
* Add a separate print-to-ps backend that shows up next to the print-to-pdf selection in the printer list. 

With the second approach we could default to not have ps in the default list of backends so only people who manually added it sees it.
Comment 1 Behdad Esfahbod 2006-04-24 21:46:38 UTC
I prefer an approach that allows print to SVG and PNG down the road...  YMMV
Comment 2 Christian Persch 2006-06-10 21:04:32 UTC
I need this for Epiphany. Currently gecko can only produce postscript, which I have to send to the printer with gtk_print_job_send.
So I need both a print-to-postscript option *and* a way to disable print-to-pdf (since the pdf backend cannot convert the postscript stream to pdf).
Comment 3 Matthias Clasen 2006-06-11 13:34:30 UTC
would adding a GENERATE_PDF capability be a good way to hide the 
"print to pdf" in the printer list ?
Comment 4 Alexander Larsson 2006-06-12 08:16:40 UTC
A GENERATE_PDF capability sounds like a good idea.
Comment 5 Christian Persch 2006-06-12 11:58:05 UTC
I would prefer to make this print-to-file backend with an option of the format, and setting the capabilities only makes some formats (pdf) unavailable, not the whole print-to-file concept.
Comment 6 Matthias Clasen 2006-06-12 14:14:41 UTC
Well, if none of the supported formats can be generated, we should obviously
hide the print-to-file backend from the ui...
Comment 7 Matthias Clasen 2006-06-12 16:52:38 UTC
2006-06-12  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkprintjob.h: Add a GTK_PRINT_CAPABILITY_GENERATE_PDF
	capability.
	
	* gtk/gtkprintunixdialog.c: Use it here to hide "Print to PDF" 
	from the printer list.  (#339592, Christian Persch)

Needs some more work to actually get the printer's ability to accept
PDF/PS. Right now, its hardcoded to look for _("Print to PDF").
Comment 8 Christian Persch 2006-06-15 21:05:07 UTC
Created attachment 67442 [details] [review]
first patch, for comments

This patch makes the pdf backend in a print-to-file backend (I haven't renamed/moved the file yet since that would make the diff unreadable).

There are a couple of problems remaining:
- I'd like the Format combo to show in the main page besides the filename input instead of on a page of its own, but haven't found a way yet
- if the app can only provide ps or only pdf, the printer shouldn't offer to switch; I haven't found out how to do that
Comment 9 Matthias Clasen 2006-06-16 05:02:47 UTC
If you give the format printeroption the same special name "gtk-main-dialog-custom-input", it'll show up in that spot.
But that seems slightly wrong, I don't think the extension point
should be picked by option name (which seems to imply that 
there can only be one option per extension point). Instead,
they should be picked by group, I think, and there should
be one special group for the widgets that end up on the
first

For the second issue, gtkprintunixdialog.c probably needs to
translate the GENERATE_PDF (and a new GENERATE_PS) into settings
so that they are available to the backend printer code when
it adds the options to the print dialog.
Comment 10 Matthias Clasen 2006-06-16 18:29:49 UTC
Ok, I have committed the change to add a GtkPrintSettings argument to
the create_cairo_surface printer method.
Comment 11 Christian Persch 2006-06-16 22:51:07 UTC
I think I'll split the option placement problem into a separate bug and work on that after this one is resolved, otherwise the patch becomes too involved/big.

So I don't understand what the GENERATE_PDF flag is supposed to mean....

gtk_print_unix_dialog_set_manual_capabilities says:
 * This lets you specify the printing capabilities your application
 * supports. For instance, if you can handle scaling the output then
 * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then
 * the dialog will only let you select the scale if the printing
 * system automatically handles scaling.

But I don't want to generate PDF/PS output, I want to deliver the *input* to the printer in a stream in that format... so I think this flag should actually be reversed? gtkprintunixdialog does:
     if ((priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF) == 0)
	result = gtk_printer_accepts_ps (printer);
when instead it should do
      if (priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF)
	result = gtk_printer_accepts_pdf (printer);
      else if (priv->manual_capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS)
	result = gtk_printer_accepts_ps (printer);

Does that make sense, or am I just not understanding this correctly?
Comment 12 Matthias Clasen 2006-06-17 01:47:32 UTC
there is two sides here: the format(s) accepted by the printer, and
what the application can provide. 

The accepts_ps and accepts_pdf functions are meant to cover the first (what can the printer accept) and GENERATE_PDF/GENERATE_PS are meant to indicate what the
application can create.

If you are using the highlevel api, then the app can always create both (since 
cairo has ps and pdf surfaces). The print-to-file printer can always accept both
(since it just writes it to a file)

I believe your rewriting of the matching logic is roughly equivalent to 
what is already there.
Comment 13 Matthias Clasen 2006-06-17 05:24:15 UTC
I have now cleaned up the handling of option groups, and it should be easy
to add the format selection to the main tab.
Comment 14 Matthias Clasen 2006-06-17 05:25:40 UTC
Created attachment 67525 [details]
this is easilty possible now
Comment 15 Christian Persch 2006-06-17 22:30:44 UTC
Created attachment 67551 [details] [review]
updated patch
Comment 16 Matthias Clasen 2006-06-19 05:12:57 UTC
I have now added the GENERATE_PS capability and capabilities are now
passed to printer_get_options, so that the file backend can decide
whether or not to show the file format option based on the GENERATE_X
capabilities.

Christian, if you update your patch, can you please split it in a
series of independent patches, that makes it easier to review, a la:

1) add export-format and export-uri print settings
2) make pdf backend support postscript output
3) rename pdf backend to file backend
Comment 17 Christian Persch 2006-06-19 13:38:19 UTC
Created attachment 67630 [details] [review]
step 1

Add EXPORT_URI and EXPORT_FILE_FORMAT settings, and fix gtkprinteroptionwidget to put an URI into the setting (and fix the encoding issue there).

Next up: rename to "file" backend.
Comment 18 Christian Persch 2006-06-19 14:29:04 UTC
Created attachment 67635 [details] [review]
step 2

Move from pdf/ to file/ and renamed to GtkPrintBackendPdf to GtkPrintBackendFile (with patch from step 1 applied, of course).
Comment 19 Matthias Clasen 2006-06-19 18:03:35 UTC
Comments on "step 1":

- I don't think switching from a filename to an uri will buy us much
  (although I don't have strong feelings about it).

- I think the printer-specific export- options should not be defined
  in gtkprintsettings.h

- I wonder if the naming export- confuses print-to-file and the export
  action even more. Maybe we should make the export action use these
  settings ? Need to discuss with alex

- I think the FILESAVE code in gtkprinteroptionwidget.c should not
  hardcode "Print to file", but use the display_text of the option.

Comment 20 Christian Persch 2006-06-19 18:25:05 UTC
(In reply to comment #19)
> Comments on "step 1":
> 
> - I don't think switching from a filename to an uri will buy us much
>   (although I don't have strong feelings about it).
How I see programs using this is like this: the user inputs a non-local URI (so the setting really has to be an URI). Program saves the setting, changes to that to temp file, prints, then uploads the temp file to the real location with gnome-vfs.
And the encoding fix is really necessary.
And this also ensures that the setting value is UTF-8, so I can store it in a keyfile.

> - I think the printer-specific export- options should not be defined
>   in gtkprintsettings.h
They should be defined *somewhere*, otherwise people won't know what option to use unless they read the source. Is there any other appropriate header?

> - I wonder if the naming export- confuses print-to-file and the export
>   action even more. Maybe we should make the export action use these
>   settings ? Need to discuss with alex
I don't care about the name... it was "pdf-filename", both parts wrong :)
"print-to-uri" ? "print-destination-uri" ? "destination-uri" ?

> - I think the FILESAVE code in gtkprinteroptionwidget.c should not
>   hardcode "Print to file", but use the display_text of the option.

I'll fix that.
Comment 21 Christian Persch 2006-06-19 18:31:16 UTC
Created attachment 67647 [details] [review]
step 1 updated

Use the display name as filechoose title.

Although there's some inconsistency here, since this doesn't select the filename to print to, just the directory... but that's for another bug.
Comment 22 Matthias Clasen 2006-06-19 18:40:15 UTC
> > - I think the printer-specific export- options should not be defined
> >   in gtkprintsettings.h
> They should be defined *somewhere*, otherwise people won't know what option to
> use unless they read the source. Is there any other appropriate header?

I guess my point is that people really should not have to know about driver-specific options. These should solely be used for communication 
between the backend and the option widgets.

Comment 23 Christian Persch 2006-06-19 19:24:43 UTC
There is one legitimate use of that setting by the program itself: when you manage your printing not with the gtkprintoperation but just use gtkprintjob, you can optimise the case of print-to-file by just printing directly to that file instead of a temp file which you then gtk_print_job_send.
Comment 24 Matthias Clasen 2006-06-20 13:39:00 UTC
here is the highlights of my quick discussion with alex:

<alex> +  file = g_locale_from_utf8 (gtk_entry_get_text (GTK_ENTRY (priv->entry)),
<alex> +        -1, NULL, NULL, NULL);
<alex> Surely the filename shouldn't be in locale encoding
<mclasen> right, it needs to be in filename encoding


- We really don't see the point in going through the uri; 
  lets keep it a filename for now. 

- There is potential for confusion between the export- settings and  
  the EXPORT action. Better names to use: output-filename and output-format



Comment 25 Christian Persch 2006-06-20 13:54:19 UTC
(In reply to comment #24)
> here is the highlights of my quick discussion with alex:
> 
> <alex> +  file = g_locale_from_utf8 (gtk_entry_get_text (GTK_ENTRY
> (priv->entry)),
> <alex> +        -1, NULL, NULL, NULL);
> <alex> Surely the filename shouldn't be in locale encoding
> <mclasen> right, it needs to be in filename encoding
Damn, I used the wrong function! I'll fix that.

> - We really don't see the point in going through the uri; 
>   lets keep it a filename for now. 
The point is to keep it open to future support for non-local files (bug 344522). If we keep it filename now we need to change it later and programs need to support both filenames and uris.

> - There is potential for confusion between the export- settings and  
>   the EXPORT action. Better names to use: output-filename and output-format
Ok, I'll change that. 

Comment 26 Christian Persch 2006-06-20 16:03:03 UTC
(In reply to comment #25)
> > - We really don't see the point in going through the uri; 
> >   lets keep it a filename for now. 
> The point is to keep it open to future support for non-local files (bug
> 344522). If we keep it filename now we need to change it later and programs
> need to support both filenames and uris.

Also, filenames have arbitrary encodings while URIs are UTF-8. This simplifies storing/restoring the GktPrintSettings and makes them unambiguous.
Comment 27 Christian Persch 2006-06-20 16:38:43 UTC
Created attachment 67721 [details] [review]
step 1 update 2

Fix to use g_filename_from_utf8 and use OUTPUT instead of EXPORT.
Comment 28 Matthias Clasen 2006-06-20 16:51:31 UTC
ok, looks good. 
I'm willing to accept the argument that uris have a defined encoding.
Can you commit this  ?
Comment 29 Christian Persch 2006-06-20 17:37:26 UTC
2006-06-20  Christian Persch  <chpe@cvs.gnome.org>

        * gtk/gtkprinteroptionwidget.c: (filesave_changed_cb),
        (alternative_set), (construct_widgets): Convert input to filename
        encoding and construct an URI from that.
        * gtk/gtkprintsettings.h: Add OUTPUT_FILE_FORMAT and OUTPUT_URI keys.
        * modules/printbackends/pdf/gtkprintbackendpdf.c: Use those defines.
        Step 1 from bug #339592.
Comment 30 Christian Persch 2006-06-20 17:42:13 UTC
Created attachment 67727 [details] [review]
step 2 updated
Comment 31 Matthias Clasen 2006-06-20 18:04:50 UTC
Looks good, go ahead
Comment 32 Christian Persch 2006-06-20 19:23:28 UTC
2006-06-20  Christian Persch  <chpe@cvs.gnome.org>

        * configure.in
        * gtk/Makefile.am
        * modules/printbackends/Makefile.am
        A modules/printbackends/file/.cvsignore
        A modules/printbackends/file/Makefile.am
        A modules/printbackends/file/gtkprintbackendfile.c
        A modules/printbackends/file/gtkprintbackendfile.h
        R modules/printbackends/pdf/*:
        Rename "pdf" backend to "file" backend. Step 2 from bug #339592.

Comment 33 Matthias Clasen 2006-06-20 19:24:53 UTC
Are you going to handle step 3 too, or should I go ahead and do that ?
Comment 34 Christian Persch 2006-06-20 19:26:53 UTC
Created attachment 67735 [details] [review]
step 3

Add print-to-PS option.

I'm hesitating between ALTERNATIVE and PICKONE type for the extra option... both look wrong since they expand vertically since the filesave option has 2 rows... still we can fix that up later.
Comment 35 Matthias Clasen 2006-06-20 20:44:12 UTC
Why are you showing the file format option if there is only one choice ?
I had imagined to only show it if there is more than one choice. Of course,
it would be nice to change the name back to  "Print to PS/PDF" in that case...

Also, why do you treat the can-generate-neither-ps-nor-pdf specially ?
I think we should just expect applications to set the capabilities
correctly. 

Finally, I think it would be a nice touch to change the default output filename
according to the supported formats: output.ps/output.pdf according to
the initially selected format (shouldn't that be initialized from the settings,
btw ? )
Comment 36 Christian Persch 2006-06-20 21:12:42 UTC
(In reply to comment #35)
> Why are you showing the file format option if there is only one choice ?
> I had imagined to only show it if there is more than one choice. Of course,
> it would be nice to change the name back to  "Print to PS/PDF" in that case...
I'll do that.

> Also, why do you treat the can-generate-neither-ps-nor-pdf specially ?
> I think we should just expect applications to set the capabilities
> correctly. 
The (neither GENERATE_PS nor GENERATE_PDF are set) case is not "I'm not going to print anything" case, it's the "I'm going to print to the cairo surface" case, in which we can generate any supported format, PS *and* PDF.

> Finally, I think it would be a nice touch to change the default output filename
> according to the supported formats: output.ps/output.pdf according to
> the initially selected format (shouldn't that be initialized from the settings,
> btw ? )
I'll fix that.

Comment 37 Matthias Clasen 2006-06-21 06:16:25 UTC
(In reply to comment #36)
> (In reply to comment #35)
> > Why are you showing the file format option if there is only one choice ?
> > I had imagined to only show it if there is more than one choice. Of course,
> > it would be nice to change the name back to  "Print to PS/PDF" in that case...
> I'll do that.

I don't think you can, with the current GtkPrinter api, since name is a 
construct-only property.

> > Also, why do you treat the can-generate-neither-ps-nor-pdf specially ?
> > I think we should just expect applications to set the capabilities
> > correctly. 
> The (neither GENERATE_PS nor GENERATE_PDF are set) case is not "I'm not going
> to print anything" case, it's the "I'm going to print to the cairo surface"
> case, in which we can generate any supported format, PS *and* PDF.

Hmm, at least the high-level api sets both GENERATE_PS and GENERATE_PDF,
so it wouldn't need this special case.

Comment 38 Christian Persch 2006-06-21 12:05:53 UTC
(In reply to comment #37)
> > > it would be nice to change the name back to  "Print to PS/PDF" in that case...
> > I'll do that.
> 
> I don't think you can, with the current GtkPrinter api, since name is a 
> construct-only property.
Yes :(

> > > Also, why do you treat the can-generate-neither-ps-nor-pdf specially ?
> > > I think we should just expect applications to set the capabilities
> > > correctly. 
> > The (neither GENERATE_PS nor GENERATE_PDF are set) case is not "I'm not going
> > to print anything" case, it's the "I'm going to print to the cairo surface"
> > case, in which we can generate any supported format, PS *and* PDF.
> 
> Hmm, at least the high-level api sets both GENERATE_PS and GENERATE_PDF,
> so it wouldn't need this special case.

If we take GENERATE_PS/PDF to say "allow the user to print to PS/PDF", then if the application hardcodes these flags, and we add print-to-SVG later (which the print-to-cairo-surface path can easily support with no changes to the application) those apps wouldn't offer this choice even though they do support that... 
Comment 39 Matthias Clasen 2006-06-21 13:20:38 UTC
(In reply to comment #38)
> > Hmm, at least the high-level api sets both GENERATE_PS and GENERATE_PDF,
> > so it wouldn't need this special case.
> 
> If we take GENERATE_PS/PDF to say "allow the user to print to PS/PDF", then if
> the application hardcodes these flags, and we add print-to-SVG later (which the
> print-to-cairo-surface path can easily support with no changes to the
> application) those apps wouldn't offer this choice even though they do support
> that... 

Interesting argument. Although I would expect most print-to-cairo users
to go through the hilevel api, in which case they would get print-to-svg, since
we would update GtkPrintOperation to advertise that capability...

Anyway, if you want to support this NONE==ALL special case, it needs to 
be documented in some way. The docs for GtkPrintCapabilities are in
one of the template files, I forget which.
Comment 40 Christian Persch 2006-06-21 19:13:05 UTC
Created attachment 67805 [details] [review]
step 3 updated
Comment 41 Matthias Clasen 2006-06-21 19:56:47 UTC
I'm  sorry, I actually went ahead already and committed a tweaked  version of your earlier patch...

Really pressed for time today, sorry


Anyway,  I at least took the doc additions from your updated patch.