evince cannot render some EPS files

Bug #1242678 reported by epii on 2013-10-21
82
This bug affects 14 people
Affects Status Importance Assigned to Milestone
Evince
Expired
Medium
libspectre
Confirmed
Medium
evince (Ubuntu)
Medium
Unassigned
Trusty
Medium
Unassigned
libspectre (Ubuntu)
High
Unassigned
Trusty
High
Unassigned

Bug Description

I upgraded to Ubuntu Saucy,
evince cannot render EPS files generated by gnuplot.
(Just show an empty page.)

[how to reproduce]

1. Generate an EPS file using gnuplot by executing the following command.
$ gnuplot -e "set terminal postscript; set output 'test.eps'; plot x;"

2. Open the file "test.eps" just created.
$ evince "test.eps"

The following are what evince writes to the terminal.

(evince:24176): EvinceDocument-CRITICAL **: ev_document_get_n_pages: assertion 'EV_IS_DOCUMENT (document)' failed

(evince:24176): Gtk-WARNING **: drawing failure for widget `EvView': invalid matrix (not invertible)

(evince:24176): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion 'width > 0 && height > 0' failed

(evince:24176): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion 'width > 0 && height > 0' failed

3. Then evince just shows an empty (white) page.

===

If i rotate 90 or -90 degree by pressing Ctrl+Left or Ctrl+Right key,
evince can show this file correctly.

===

Okular, GIMP, inkscape and gs can show this EPS file.
(may be rotated 90 degree, however)

[Impact]

With the default viewer for PostrScript and EPS files, many files do not display and produce errors/warnings. Users usually do not know that they can visualize these files by rotating the page and rotated it is also not in a very useful orientation.

[Test Case]

Display the attached EPS file with evince or follow the steps under "how to reproduce" above. Rotate the page via Ctrl+Left or Ctrl+Right and the image is only visible for two of the four orientations. Withe the proposed package the problem get solved. The image is visible in all the four orientations.

[Regression Potential]

Low, as tested with various files and reviewed by several upstream developers.

ProblemType: Bug
DistroRelease: Ubuntu 13.10
Package: evince 3.10.0-0ubuntu2
ProcVersionSignature: Ubuntu 3.11.0-12.19-generic 3.11.3
Uname: Linux 3.11.0-12-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 2.12.5-0ubuntu2
Architecture: amd64
Date: Mon Oct 21 21:23:15 2013
InstallationDate: Installed on 2013-09-07 (44 days ago)
InstallationMedia: Ubuntu 13.04 "Raring Ringtail" - Release amd64 (20130424)
MarkForUpload: True
SourcePackage: evince
UpgradeStatus: Upgraded to saucy on 2013-10-04 (16 days ago)

epii (epii) wrote :
epii (epii) wrote :

i will attach the EPS file which causes this bug.

Changed in evince:
importance: Unknown → Medium
status: Unknown → New
Changed in evince (Ubuntu):
importance: Undecided → Low
status: New → Triaged

I've also experienced this bug. Rotation ±90° makes visible, and 0° is always invisible, with the following stderr:
(evince:19353): Gtk-WARNING **: drawing failure for widget `EvView': invalid matrix (not invertible)

Sebastien Bacher (seb128) wrote :

Seems like it could be an issue in ghostscript (upstream bug state that downgrading it fixes the issue). Till, could you have a look if that's a gs issue/maybe report it upstream if that's one?

no longer affects: ghostscript (Ubuntu)
Changed in evince (Ubuntu):
assignee: nobody → Till Kamppeter (till-kamppeter)
M S Bhaskar (mithipatisiva9) wrote :

yes. i read in ubuntu forums also. There also it is mentioned that it is a bug in ghostscript.

Changed in ghostscript (Ubuntu):
assignee: nobody → Till Kamppeter (till-kamppeter)
Changed in evince (Ubuntu):
assignee: Till Kamppeter (till-kamppeter) → nobody
Changed in ghostscript (Ubuntu):
importance: Undecided → Low
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in ghostscript (Ubuntu):
status: New → Confirmed
Till Kamppeter (till-kamppeter) wrote :

Another test file showing the problem is attached to the duplicate bug 1272120.

Till Kamppeter (till-kamppeter) wrote :

Could you somehow find out the Ghostscript command lines (or parameter lists for libgs calls) for both the non-working unrotated case and the working rotated case? Could you also find out the actual files sent to Ghostscript for rendering? To post an upstream bug report at Ghostscript (http://bugs.ghostscript.com/) I would need a way to reproduce the problem by a pure Ghostscript command line.

epii (epii) wrote :

Evince uses libspectre (http://www.freedesktop.org/wiki/Software/libspectre/)
as a backend library for postscript rendering.
See "libspectre/spectre-device.c", L215-264.

Download full text (5.3 KiB)

bhaskar@brainiac:m1struct_fac$ evince M1_fraction_transformed_vs_time.eps

(evince:4207): EvinceDocument-CRITICAL **: ev_document_get_n_pages:
assertion 'EV_IS_DOCUMENT (document)' failed

(evince:4207): EvinceView-CRITICAL **: ev_pixbuf_cache_get_selection_list:
assertion 'EV_IS_PIXBUF_CACHE (pixbuf_cache)' failed

(evince:4207): EvinceView-CRITICAL **: ev_pixbuf_cache_set_selection_list:
assertion 'EV_IS_PIXBUF_CACHE (pixbuf_cache)' failed

this is what i get in the terminal for evince for the rotated version.

for the non rotated version I get the following message

(evince:4207): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion
'width > 0 && height > 0' failed

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion
'width > 0 && height > 0' failed

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4207): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)
bhaskar@brainiac:m1struct_fac$ evince M1_fraction_transformed_vs_time.eps

(evince:4230): EvinceDocument-CRITICAL **: ev_document_get_n_pages:
assertion 'EV_IS_DOCUMENT (document)' failed

(evince:4230): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4230): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4230): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion
'width > 0 && height > 0' failed

(evince:4230): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion
'width > 0 && height > 0' failed

(evince:4230): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4230): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

(evince:4230): Gtk-WARNING **: drawing failure for widget `EvView': invalid
matrix (not invertible)

i'm sending the corresponding file as an attachment

On Sat, Jan 25, 2014 at 2:33 AM, Till Kamppeter
<email address hidden>wrote:

> Could you somehow find out the Ghostscript command lines (or parameter
> lists for libgs calls) for both the non-working unrotated case and the
> working rotated case? Could you also find out the actual files sent to
> Ghostscript for rendering? To post an upstream bug report at Ghostscript
> (http://bugs.ghostscript.com/) I would need a way to reproduce the
> problem by a pure Ghostscript command line.
>
> --
> You received this bug notification because ...

Read more...

Seb (or someone else who knows about the internals of evince), can you derive from these console messages whether Ghostscript gets called at all in these situation or whether they occur due to failing Ghostscript?

Sebastien Bacher (seb128) wrote :

@Till: evince uses libspectre which uses libgs (I think), the ghostscript command line doesn't get called but the library used if from the same source

seb, thanks for the hint. By adding a debug fprintf() line to libspectre/spectre-device.c of the libspectre source package and rebuilding the package I could discover the Ghostscript command line equivalent to the libgs call used in libspectre. It is

gs -dMaxBitmap=10000000 -dSAFER -dNOPAUSE -dNOPAGEPROMPT -P- -sDEVICE=display -dTextAlphaBits=4 -dGraphicsAlphaBits=2 -g402x574 -r57,428571x57,400000 -dDisplayFormat=6359172 -sDisplayHandle=16#7f974c00d6f0 -c '<< /Orientation 3 >> setpagedevice .locksafe' -f ~/Documents/M_1_no_of_ppts.eps

Unfortunately, one cannot simply call this on the command line, as the "display" output device is used and this seems to send a bitmap to a specified, existing X window. When rotating the image, only the resolution and size values change in the command line and also the value after "/Orientation". Odd orientations (3, 1) do not display in evince, even orientations (2, 0) do.

To run an isolated command line as similar as possible, I tried the "x11" device:

gs -dMaxBitmap=10000000 -dSAFER -P- -sDEVICE=x11 -dTextAlphaBits=4 -dGraphicsAlphaBits=2 -g402x574 -r57,428571x57,400000 -c '<< /Orientation 3 >> setpagedevice .locksafe' -f ~/Documents/M_1_no_of_ppts.eps

Here the file displayed with all 4 orientations, but the output as wrong for the odd orientations. For the odd orientations we expect the output in landscape orientation, but it appears here also in portrait, so all 4 orientations give portrait output. So something seems to be wrong with how Ghostscript treats this file.

Reported to Ghostscript upstream as

http://bugs.ghostscript.com/show_bug.cgi?id=694979

Sebastien Bacher (seb128) wrote :

Thanks Till, good work debugging that issue/reporting it to the ghostscript upstream bug tracker!

Changed in ghostscript (Ubuntu):
status: Confirmed → Triaged
Achim Behrens (k1l) wrote :

i am effected, too with saucy.
any workaround so far to use evince like it should? downgrade libspectre?

epii (epii) wrote :

downgrade ghostscript, ghostscript-x, libgs9 and libgs9-common.

The Ghostscript developers did not consider this as a Ghostscript bug, see the upstream bug report

http://bugs.ghostscript.com/show_bug.cgi?id=694979

They consider the input EPS file from gnuplot) broken. So we should move this bug report to gnuplot ...

Changed in evince (Ubuntu):
status: Triaged → Invalid
Changed in ghostscript (Ubuntu):
status: Triaged → Invalid
Anton Gladky (gladky-anton) wrote :

I am not able to reproduce the bug. But, sorry, on Debian Jessie. I do not have any Ubuntu for the moment.

Anton, Gnuplot Debian maintainer.

M S Bhaskar (mithipatisiva9) wrote :

very unfortunate...
because. the same file could be opened in a previous version of evince. If
it was broken, that shouldn't have been possible. I don't think its a
problem with gnuplot.

On Thu, Mar 13, 2014 at 6:09 PM, Till Kamppeter
<email address hidden>wrote:

> The Ghostscript developers did not consider this as a Ghostscript bug,
> see the upstream bug report
>
> http://bugs.ghostscript.com/show_bug.cgi?id=694979
>
> They consider the input EPS file from gnuplot) broken. So we should move
> this bug report to gnuplot ...
>
>
> ** Also affects: gnuplot (Ubuntu)
> Importance: Undecided
> Status: New
>
> ** Changed in: evince (Ubuntu)
> Status: Triaged => Invalid
>
> ** Changed in: ghostscript (Ubuntu)
> Status: Triaged => Invalid
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1271446).
> https://bugs.launchpad.net/bugs/1242678
>
> Title:
> evince cannot render some EPS files
>
> Status in Evince document viewer:
> New
> Status in GS-GPL - GPL Ghostscript:
> Unknown
> Status in "evince" package in Ubuntu:
> Invalid
> Status in "ghostscript" package in Ubuntu:
> Invalid
> Status in "gnuplot" package in Ubuntu:
> New
>
> Bug description:
> I upgraded to Ubuntu Saucy,
> evince cannot render EPS files generated by gnuplot.
> (Just show an empty page.)
>
>
> [how to reproduce]
>
> 1. Generate an EPS file using gnuplot by executing the following command.
> $ gnuplot -e "set terminal postscript; set output 'test.eps'; plot x;"
>
> 2. Open the file "test.eps" just created.
> $ evince "test.eps"
>
> The following are what evince writes to the terminal.
>
> (evince:24176): EvinceDocument-CRITICAL **: ev_document_get_n_pages:
> assertion 'EV_IS_DOCUMENT (document)' failed
>
> (evince:24176): Gtk-WARNING **: drawing failure for widget `EvView':
> invalid matrix (not invertible)
>
> (evince:24176): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface:
> assertion 'width > 0 && height > 0' failed
>
> (evince:24176): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface:
> assertion 'width > 0 && height > 0' failed
>
> 3. Then evince just shows an empty (white) page.
>
> ===
>
> If i rotate 90 or -90 degree by pressing Ctrl+Left or Ctrl+Right key,
> evince can show this file correctly.
>
> ===
>
> Okular, GIMP, inkscape and gs can show this EPS file.
> (may be rotated 90 degree, however)
>
> ProblemType: Bug
> DistroRelease: Ubuntu 13.10
> Package: evince 3.10.0-0ubuntu2
> ProcVersionSignature: Ubuntu 3.11.0-12.19-generic 3.11.3
> Uname: Linux 3.11.0-12-generic x86_64
> NonfreeKernelModules: nvidia
> ApportVersion: 2.12.5-0ubuntu2
> Architecture: amd64
> Date: Mon Oct 21 21:23:15 2013
> InstallationDate: Installed on 2013-09-07 (44 days ago)
> InstallationMedia: Ubuntu 13.04 "Raring Ringtail" - Release amd64
> (20130424)
> MarkForUpload: True
> SourcePackage: evince
> UpgradeStatus: Upgraded to saucy on 2013-10-04 (16 days ago)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/evince/+bug/1242678/+subscriptions
>

Created attachment 96165
Rotate documents correctly

I've tried to rotate a PostScript file from https://bugzilla.redhat.com/show_bug.cgi?id=1031838 in evince and the rotation was not quite correct. It doesn't show anything for 90° and 270°, just warnings about matrices. So I've tested this also with some other PostScript files and I've seen that the rotation doesn't work for any of them.

I've prepared a patch which performs the rotation by inserting command "rotate" to the PostScript program right after %%EndSetup and adjusting of offsets accordingly. I've tested the patch for rendering of slices and it works. But I'm not entirely sure whether it will work in every situation.

Marek

Sebastien Bacher (seb128) wrote :

Till, it seems like ghostscript upstream suggested that the /Orientation use is buggy there, if that option is used by libspectre should that be consider a bug there and should be changed to use '90 rotate' or such? Could you maybe investigate that/report a bug on https://bugs.freedesktop.org/enter_bug.cgi?product=libspectre

affects: evince (Ubuntu) → libspectre (Ubuntu)
Changed in libspectre (Ubuntu):
importance: Low → High
status: Invalid → Triaged
Sebastien Bacher (seb128) wrote :

In fact it's already reported with a patch on https://bugs.freedesktop.org/show_bug.cgi?id=76450

The issue reported there seems to be also what makes evince fails to render some eps files on e.g recent Ubuntu versions

That has been reported on
https://bugzilla.gnome.org/show_bug.cgi?id=710957
https://bugs.launchpad.net/libspectre/+bug/1242678
http://bugs.ghostscript.com/show_bug.cgi?id=694979

The ghostscript bugs has details

"...
Basically, this isn't a bug. If you want to rotate an EPS you absolutely should NOT be doing so by using /Orientation, which is a media selection parameter. You should instead use '90 rotate' or similar to set up the CTM before you render the EPS."

@Marek: I tried your patch on some of the files from the Ubuntu bug, e.g https://bugs.launchpad.net/libspectre/+bug/1242678/+attachment/3886169/+files/test.eps ... it fixes the "nothing is displayed" but the orientation seems wrong (rotated from 90° compared to gs and 180° compared to what portrait should be (e.g axis/labels are wrong)). Not sure if that's a bug in the documents or in the change though

Sebastien Bacher (seb128) wrote :

The patch from upstream fixes the "no content displayed" but the orientation seems wrong, i've added a comment on the report, let's wait for an update/upstream code review

Changed in libspectre:
importance: Unknown → Medium
status: Unknown → Confirmed
Changed in gnuplot (Ubuntu Trusty):
status: New → Invalid
importance: Undecided → Low
Sebastien Bacher (seb128) wrote :

Till accepted to have a look/test the upstream suggested patch, assigning the bug to him, thanks Till!

Changed in libspectre (Ubuntu):
assignee: nobody → Till Kamppeter (till-kamppeter)

Seb, I think we should wait for Marek's reaction to your comment on the Freedesktop bug. Ghostscript is probably correct.

(In reply to comment #1)
> The issue reported there seems to be also what makes evince fails to render
> some eps files on e.g recent Ubuntu versions
>
> That has been reported on
> https://bugzilla.gnome.org/show_bug.cgi?id=710957
> https://bugs.launchpad.net/libspectre/+bug/1242678
> http://bugs.ghostscript.com/show_bug.cgi?id=694979
>
> The ghostscript bugs has details
>
> "...
> Basically, this isn't a bug. If you want to rotate an EPS you absolutely
> should NOT be doing so by using /Orientation, which is a media selection
> parameter. You should instead use '90 rotate' or similar to set up the CTM
> before you render the EPS."
>
> @Marek: I tried your patch on some of the files from the Ubuntu bug, e.g
> https://bugs.launchpad.net/libspectre/+bug/1242678/+attachment/3886169/
> +files/test.eps ... it fixes the "nothing is displayed" but the orientation
> seems wrong (rotated from 90° compared to gs and 180° compared to what
> portrait should be (e.g axis/labels are wrong)). Not sure if that's a bug in
> the documents or in the change though

I think that the problem is in evince. It sets wrong angle for rendering with spectre_render_context_set_rotation() from my point of view. evince rotates to left by setting new angle to "original_angle - 90". If you reverse the value passed by evince to libspectre (360 - angle) then it works as expected.

Seb, can you do an appropriate patch on evince and report a bug upstream?

Changed in evince (Ubuntu):
assignee: nobody → Sebastien Bacher (seb128)
importance: Undecided → Medium

Seb, it seems that the bug is in evince, but easy to fix, according to Marek in the Freedesktop bug report:

----------
I think that the problem is in evince. It sets wrong angle for rendering with spectre_render_context_set_rotation() from my point of view. evince rotates to left by setting new angle to "original_angle - 90". If you reverse the value passed by evince to libspectre (360 - angle) then it works as expected.
----------

@Till, yes using https://bugzilla.gnome.org/show_bug.cgi?id=710957 seems fine to me.

@Marek, do you plan to follow up with the evince team about that rotation issue?
It seems like both libspectre and evince need to be updated together to give a correct result there

@Carlos, what do you think about those changes?

(In reply to comment #5)
> @Marek, do you plan to follow up with the evince team about that rotation
> issue?
> It seems like both libspectre and evince need to be updated together to give
> a correct result there

Sure, I can continue on this in evince too. I'll try look for a solution.

Comment on attachment 96165
Rotate documents correctly

Review of attachment 96165:
-----------------------------------------------------------------

Thanks for the patch!

::: libspectre/spectre-device.c
@@ +206,5 @@
> return SPECTRE_STATUS_RENDER_ERROR;
> }
>
> + scaled_width = (int) ((width * rc->x_scale) + 0.5);
> + scaled_height = (int) ((height * rc->y_scale) + 0.5);

I think it would be clearer if we set these values depending on the orientation, and then we just use scale_width, scaled_height below.

@@ +226,5 @@
> rc->text_alpha_bits);
> args[arg++] = graph_alpha = _spectre_strdup_printf ("-dGraphicsAlphaBits=%d",
> rc->graphic_alpha_bits);
> +
> + if (rc->orientation == 0 || rc->orientation == 2) {

Don't use magic numbers here, use NONE and LANDSCAPE instead.

@@ +232,5 @@
> + args[arg++] = resolution = _spectre_strdup_printf ("-r%fx%f",
> + rc->x_scale * rc->x_dpi,
> + rc->y_scale * rc->y_dpi);
> + }
> + else {

} else {

::: libspectre/spectre-gs.c
@@ +237,5 @@
>
> + switch (rotation) {
> + default:
> + tmp_xoffset = xoffset + x;
> + tmp_yoffset = yoffset + y;

I don't think we need the tmp_ variables, we can just modify the existing xoffset/yoffset.

@@ +277,5 @@
> doc->endsetup))
> return FALSE;
>
> + if (rotation != 0) {
> + set = _spectre_strdup_printf ("%d rotate", rotation);

Where does this end up? After the setup and before the pages? Isn't it recommended to apply the rotation after the translation? I think we could move this to spectre_gs_process, after the translate. We pass the rotation to spectre_gs_process and when it's != NONE we inject the rotate command there. What do you think?

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in evince (Ubuntu Trusty):
status: New → Confirmed
Changed in evince (Ubuntu):
status: New → Confirmed

Created attachment 99100
Rotate documents correctly

Thank you for the review.

(In reply to comment #7)
> Comment on attachment 96165 [details] [review]
> Rotate documents correctly
>
> Review of attachment 96165 [details] [review]:
> -----------------------------------------------------------------
>
> Thanks for the patch!
>
> ::: libspectre/spectre-device.c
> @@ +206,5 @@
> > return SPECTRE_STATUS_RENDER_ERROR;
> > }
> >
> > + scaled_width = (int) ((width * rc->x_scale) + 0.5);
> > + scaled_height = (int) ((height * rc->y_scale) + 0.5);
>
> I think it would be clearer if we set these values depending on the
> orientation, and then we just use scale_width, scaled_height below.

Done.

> @@ +226,5 @@
> > rc->text_alpha_bits);
> > args[arg++] = graph_alpha = _spectre_strdup_printf ("-dGraphicsAlphaBits=%d",
> > rc->graphic_alpha_bits);
> > +
> > + if (rc->orientation == 0 || rc->orientation == 2) {
>
> Don't use magic numbers here, use NONE and LANDSCAPE instead.

Done.

> @@ +232,5 @@
> > + args[arg++] = resolution = _spectre_strdup_printf ("-r%fx%f",
> > + rc->x_scale * rc->x_dpi,
> > + rc->y_scale * rc->y_dpi);
> > + }
> > + else {
>
> } else {

Done.

> ::: libspectre/spectre-gs.c
> @@ +237,5 @@
> >
> > + switch (rotation) {
> > + default:
> > + tmp_xoffset = xoffset + x;
> > + tmp_yoffset = yoffset + y;
>
> I don't think we need the tmp_ variables, we can just modify the existing
> xoffset/yoffset.

I removed them but I had to reintroduce them back because of the next item.

> @@ +277,5 @@
> > doc->endsetup))
> > return FALSE;
> >
> > + if (rotation != 0) {
> > + set = _spectre_strdup_printf ("%d rotate", rotation);
>
> Where does this end up? After the setup and before the pages?

Yes, it ends up there.

> Isn't it recommended to apply the rotation after the translation? I think we could
> move this to spectre_gs_process, after the translate. We pass the rotation
> to spectre_gs_process and when it's != NONE we inject the rotate command
> there. What do you think?

I moved it there.

Unfortunately I've found a PostScript file on which the patch doesn't work. It shows the file with the original rotation for each rotation. It is due to "setpagedevice" and "PageSize" are employed there (see next attachment). I'm not sure what to do with it yet.

Regards

Marek

Created attachment 99101
The problematic PostScript file.

Created attachment 99156
Rotate documents correctly

This patch solves the problem with the problematic PostScript file for me but it is kind of a hack. It replaces occurrences of "setpagedevice" with "pop " so that its parameters don't influence the rendering to the "display" device. I have looked into PostScript LANGUAGE REFERENCE and it seems to me that the parameters which are set by "setpagedevice" are not important for rendering to "display" device (but I'm not really sure here).

Marek

I'm not a PostScript expert either.

Yes, you can replace setpagedevice with pop. It is not clear to me how your patch is doing this. Something like "/setpagedevice { pop } bind def" should work.

(In reply to comment #12)
> Yes, you can replace setpagedevice with pop. It is not clear to me how your
> patch is doing this. Something like "/setpagedevice { pop } bind def" should
> work.

Thanks Adrian. It seems Marek submitted the same patch again instead of the updated one.

Created attachment 99331
Rotate documents correctly

(In reply to comment #13)
> (In reply to comment #12)
> > Yes, you can replace setpagedevice with pop. It is not clear to me how your
> > patch is doing this. Something like "/setpagedevice { pop } bind def" should
> > work.

Thank you.

> It seems Marek submitted the same patch again instead of the updated one.

You are right, I somehow selected wrong file, I'm sorry. The attached patch is the right one with the hint from Adrian incorporated (I also tried to pass it as a "-c" option to gs but it didn't work).

Comment on attachment 99331
Rotate documents correctly

Review of attachment 99331:
-----------------------------------------------------------------

This looks good to me, except the confusing NONE/LANDSCAPE thing. Adrian, does the PostScript part looks good to you?

::: libspectre/spectre-device.c
@@ +206,4 @@
> return SPECTRE_STATUS_RENDER_ERROR;
> }
>
> + if (rc->orientation == NONE || rc->orientation == LANDSCAPE) {

Why NONE and LANDSCAPE? shouldn't we invert width/height when orientation is LANDSCAPE and SEASCAPE? Ah, I know what's going on, you are using the internal values of the parser (my fault, I think I suggested it) but rc->orientation is actually a SpectreOrientation enum value, so you should use SPECTRE_ORIENTATION_PORTRAIT || SPECTRE_ORIENTATION_REVERSE_PORTRAIT that are 0 and 2 like NONE and LANDSCAPE in the internal parser.

@@ +269,4 @@
> args[arg++] = "-dNOPLATFONTS";
>
> if (rc->width != -1 && rc->height != -1) {
> + if (rc->orientation == NONE || rc->orientation == LANDSCAPE) {

Same here.

(In reply to comment #15)
> Adrian, does the PostScript part looks good to you?

Looks good.

Created attachment 100723
Rotate documents correctly

Hi,

I'm sorry for my late response, I was super busy with something else.

(In reply to comment #15)
> Comment on attachment 99331 [details] [review]
> Rotate documents correctly
>
> Review of attachment 99331 [details] [review]:
> -----------------------------------------------------------------
>
> This looks good to me, except the confusing NONE/LANDSCAPE thing. Adrian,
> does the PostScript part looks good to you?
>
> ::: libspectre/spectre-device.c
> @@ +206,4 @@
> > return SPECTRE_STATUS_RENDER_ERROR;
> > }
> >
> > + if (rc->orientation == NONE || rc->orientation == LANDSCAPE) {
>
> Why NONE and LANDSCAPE? shouldn't we invert width/height when orientation is
> LANDSCAPE and SEASCAPE? Ah, I know what's going on, you are using the
> internal values of the parser (my fault, I think I suggested it) but
> rc->orientation is actually a SpectreOrientation enum value, so you should
> use SPECTRE_ORIENTATION_PORTRAIT || SPECTRE_ORIENTATION_REVERSE_PORTRAIT
> that are 0 and 2 like NONE and LANDSCAPE in the internal parser.
>
> @@ +269,4 @@
> > args[arg++] = "-dNOPLATFONTS";
> >
> > if (rc->width != -1 && rc->height != -1) {
> > + if (rc->orientation == NONE || rc->orientation == LANDSCAPE) {
>
> Same here.

My brain was probably on a vacation :). I've fixed this so that it uses the SPECTRE_ORIENTATION_PORTRAIT and SPECTRE_ORIENTATION_REVERSE_PORTRAIT.

Regards

Marek

(In reply to comment #17)
> Created attachment 100723 [details] [review]
> Rotate documents correctly
>
> Hi,
>
> I'm sorry for my late response, I was super busy with something else.

No problem!

> (In reply to comment #15)
> > Comment on attachment 99331 [details] [review] [review]
> > Rotate documents correctly
> >
> > Review of attachment 99331 [details] [review] [review]:
> > -----------------------------------------------------------------
> >
> > This looks good to me, except the confusing NONE/LANDSCAPE thing. Adrian,
> > does the PostScript part looks good to you?
> >
> > ::: libspectre/spectre-device.c
> > @@ +206,4 @@
> > > return SPECTRE_STATUS_RENDER_ERROR;
> > > }
> > >
> > > + if (rc->orientation == NONE || rc->orientation == LANDSCAPE) {
> >
> > Why NONE and LANDSCAPE? shouldn't we invert width/height when orientation is
> > LANDSCAPE and SEASCAPE? Ah, I know what's going on, you are using the
> > internal values of the parser (my fault, I think I suggested it) but
> > rc->orientation is actually a SpectreOrientation enum value, so you should
> > use SPECTRE_ORIENTATION_PORTRAIT || SPECTRE_ORIENTATION_REVERSE_PORTRAIT
> > that are 0 and 2 like NONE and LANDSCAPE in the internal parser.
> >
> > @@ +269,4 @@
> > > args[arg++] = "-dNOPLATFONTS";
> > >
> > > if (rc->width != -1 && rc->height != -1) {
> > > + if (rc->orientation == NONE || rc->orientation == LANDSCAPE) {
> >
> > Same here.
>
> My brain was probably on a vacation :). I've fixed this so that it uses the
> SPECTRE_ORIENTATION_PORTRAIT and SPECTRE_ORIENTATION_REVERSE_PORTRAIT.

:-)

> Regards
>
> Marek

Pushed to git master, thanks!

Changed in evince (Ubuntu):
status: Confirmed → Invalid
assignee: Sebastien Bacher (seb128) → nobody
Changed in evince (Ubuntu Trusty):
status: Confirmed → Invalid

The attached debdiff is a backport of the upstream patch to the Utopic package of libspectre and it fixes the problem for the attched test.eps file and the file attached to the upstream bug report.

Changed in libspectre (Ubuntu):
status: Triaged → In Progress
tags: added: patch

Seb, can you please upload the fixed libspectre to Utopic? Thanks.

Changed in libspectre (Ubuntu):
assignee: Till Kamppeter (till-kamppeter) → Sebastien Bacher (seb128)

Update for the debdiff, with "utopic" in the changelog.

debdiff for SRU for Trusty. Tested successfully on Trusty. Seb, could you upload this, too. Thanks.

Changed in libspectre (Ubuntu Trusty):
status: Triaged → In Progress

Thanks Marek! Do you still plan to look at the evince side as well (since the rotation seems to still be wrong when using it, as mentioned in previous comments)

Sebastien Bacher (seb128) wrote :

thanks, uploaded to utopic and trusty

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libspectre - 0.2.7-2ubuntu2

---------------
libspectre (0.2.7-2ubuntu2) utopic; urgency=medium

  * fix-document-rotation.patch: Some PostScript and EPS files do not
    get displayed by evince when rotated by 90 or 270 degrees. This is
    due to a bug in libspectre fixed by this upstream patch
    (LP: #1242678, Freedesktop bug #76450).
 -- Till Kamppeter <email address hidden> Tue, 10 Jun 2014 22:13:44 +0200

Changed in libspectre (Ubuntu):
status: In Progress → Fix Released
Changed in libspectre (Ubuntu):
assignee: Sebastien Bacher (seb128) → nobody

A fixed package for Trusty got uploaded to trusty-proposed. As soon as this package gets approved, instructions for installing it for testing get posted here. Please follow the instructions and test them, as your feedback is required for the package to make it into the official updates for Trusty.

description: updated
Changed in libspectre:
status: Confirmed → Fix Released

(In reply to comment #19)
> Thanks Marek! Do you still plan to look at the evince side as well (since
> the rotation seems to still be wrong when using it, as mentioned in previous
> comments)

Hi Sebastien,

thank you for reminding me this. I'll look at that but not now since I have several tasks I have to finish before I can jump on this.
Maybe at the end of the next week.

Regards

Marek

I've been trying this and I'm getting the opposite results, the attached ps file is rotated without the patch but nothing is rendered when rotated with the patch.

(In reply to comment #20)
> (In reply to comment #19)
> > Thanks Marek! Do you still plan to look at the evince side as well (since
> > the rotation seems to still be wrong when using it, as mentioned in previous
> > comments)
>
> Hi Sebastien,
>
> thank you for reminding me this. I'll look at that but not now since I have
> several tasks I have to finish before I can jump on this.
> Maybe at the end of the next week.

I've filled a bug for this here: https://bugzilla.gnome.org/show_bug.cgi?id=731786. A patch is attached there which solves it for me.

(In reply to comment #21)
> I've been trying this and I'm getting the opposite results, the attached ps
> file is rotated without the patch but nothing is rendered when rotated with
> the patch.

I've just tried it with evince from master with patched libspectre and it works for me as expected :(.

Marek

Hello epii, or anyone else affected,

Accepted libspectre into trusty-proposed. The package will build now and be available at http://launchpad.net/ubuntu/+source/libspectre/0.2.7-2ubuntu1.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in libspectre (Ubuntu Trusty):
status: In Progress → Fix Committed
tags: added: verification-needed
Mathew Hodson (mathew-hodson) wrote :

I tested libspectre1 0.2.7-2ubuntu1.1 in trusty-proposed, and I was able to open the test.eps file.

tags: added: verification-done
removed: verification-needed

(In reply to comment #22)
> (In reply to comment #20)
> > (In reply to comment #19)
> > > Thanks Marek! Do you still plan to look at the evince side as well (since
> > > the rotation seems to still be wrong when using it, as mentioned in previous
> > > comments)
> >
> > Hi Sebastien,
> >
> > thank you for reminding me this. I'll look at that but not now since I have
> > several tasks I have to finish before I can jump on this.
> > Maybe at the end of the next week.
>
> I've filled a bug for this here:
> https://bugzilla.gnome.org/show_bug.cgi?id=731786. A patch is attached there
> which solves it for me.
>
>
> (In reply to comment #21)
> > I've been trying this and I'm getting the opposite results, the attached ps
> > file is rotated without the patch but nothing is rendered when rotated with
> > the patch.
>
> I've just tried it with evince from master with patched libspectre and it
> works for me as expected :(.

Maybe it has to do with the gs version?

$ gs --version
9.05

From Debian testing.

epii (epii) wrote :

Thanks Till, Sebastien and other contributors!

I enabled proposed repository and tested the new libspectre build.

The documents are shown now, but the rotation is incorrect (upside down).
So I marked as "verification-failed".

I examined your debdiff file and I realized that the following fact causes a new issue.
Ghostscript consideres "+90deg rotation" as "rotate 90deg CLOCKWISE"
but PostScript considers "+90deg rotation" as "rotate 90 deg COUNTER-CLOCKWISE".
So you should change the sign when you pass a rotation angle as a PostScript command.

I will attach a new patch file fixing this issue.
Can you review my patch?

tags: added: verification-failed
removed: verification-done
epii (epii) wrote :
Sebastien Bacher (seb128) wrote :

@epil: thanks, but that's not an issue with this change, evince needs to be fixed, see the upstream bug or https://bugzilla.gnome.org/show_bug.cgi?id=731786 for details.

I'm marking it back as verification-done, the fix is correct for the library and having documents opening with an incorrect rotation is better than having them not loading.

We are going to upload a fixed evince as well, once upstream is happy with the change

tags: added: verification-done
removed: verification-failed
Sebastien Bacher (seb128) wrote :

(note that your change might be correct, but the right place to discuss that approach would be on the freedesktop or GNOME bugs)

Here we need to agree with libspectre and evince upstream. The libspectre patch proposed for the SRU is from this upstream bug

https://bugs.freedesktop.org/show_bug.cgi?id=76450

but they also tell that an additional fix on evince is needed, supplied as a patch on this bug

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

To follow this, we should post a second SRU for evince (and let this go to -updates).

epii (epii) wrote :

Oh, sorry i didn't read the upstream discussion. Now I understand your points.
I will eagerly wait for the evince's patch :(

Adolfo Jayme (fitojb) wrote :

As a change to evince is still needed, let's mark its part Triaged.

Changed in evince (Ubuntu):
status: Invalid → Triaged
Changed in evince (Ubuntu Trusty):
status: Invalid → Triaged
no longer affects: gnuplot (Ubuntu)
no longer affects: gnuplot (Ubuntu Trusty)
no longer affects: ghostscript (Ubuntu)
no longer affects: ghostscript (Ubuntu Trusty)

(In reply to comment #23)
> (In reply to comment #22)
> > (In reply to comment #20)
> > > (In reply to comment #19)
> > > > Thanks Marek! Do you still plan to look at the evince side as well (since
> > > > the rotation seems to still be wrong when using it, as mentioned in previous
> > > > comments)
> > >
> > > Hi Sebastien,
> > >
> > > thank you for reminding me this. I'll look at that but not now since I have
> > > several tasks I have to finish before I can jump on this.
> > > Maybe at the end of the next week.
> >
> > I've filled a bug for this here:
> > https://bugzilla.gnome.org/show_bug.cgi?id=731786. A patch is attached there
> > which solves it for me.
> >
> >
> > (In reply to comment #21)
> > > I've been trying this and I'm getting the opposite results, the attached ps
> > > file is rotated without the patch but nothing is rendered when rotated with
> > > the patch.
> >
> > I've just tried it with evince from master with patched libspectre and it
> > works for me as expected :(.
>
> Maybe it has to do with the gs version?
>
> $ gs --version
> 9.05
>
> From Debian testing.

I've just tried it with the ghostscript 9.05 and the documents are rotated in opposite direction compared to the libspectre without the patch but it renders the documents correctly otherwise.
I'll prepare a patch which will change the direction of rotation.

Created attachment 101589
Change direction of rotation

The promised patch.

Changed in libspectre:
status: Fix Released → Confirmed

The verification of the Stable Release Update for libspectre has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libspectre - 0.2.7-2ubuntu1.1

---------------
libspectre (0.2.7-2ubuntu1.1) trusty; urgency=medium

  * fix-document-rotation.patch: Some PostScript and EPS files do not
    get displayed by evince when rotated by 90 or 270 degrees. This is
    due to a bug in libspectre fixed by this upstream patch
    (LP: #1242678, Freedesktop bug #76450).
 -- Till Kamppeter <email address hidden> Tue, 10 Jun 2014 22:13:44 +0200

Changed in libspectre (Ubuntu Trusty):
status: Fix Committed → Fix Released

The attachment "libspectre_0.2.7-2ubuntu1_0.2.7-2ubuntu2.debdiff" seems to be a debdiff. The ubuntu-sponsors team has been subscribed to the bug report so that they can review and hopefully sponsor the debdiff. If the attachment isn't a patch, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are member of the ~ubuntu-sponsors, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issue please contact him.]

Could somebody review the new patch there?

(In reply to comment #25)
> Created attachment 101589 [details] [review]
> Change direction of rotation
>
> The promised patch.

I'm not sure this should be done here or in evince. Libspectre should do what the PS spec says, if evince wants the opposite, evince should do the conversion. Or am I misunderstanding the patch?

(In reply to comment #27)
> (In reply to comment #25)
> > Created attachment 101589 [details] [review] [review]
> > Change direction of rotation
> >
> > The promised patch.
>
> I'm not sure this should be done here or in evince. Libspectre should do
> what the PS spec says, if evince wants the opposite, evince should do the
> conversion. Or am I misunderstanding the patch?

in any case we should document the expected behaviour in the documentation of spectre_render_context_get/set_rotation

hum, https://bugs.launchpad.net/bugs/1348384 is a new bug that claims that the change that got commited to git creates some bg issues on some documents... should that be a new bug report or discussed here as well?

we can discuss them here, if this patch has caused regressions we might revert it if we don't find a new solution for the regressions.

Changed in evince:
importance: Medium → Unknown
status: New → Unknown

Created attachment 105606
send setpagedevice

I've just bisected where the behaviour changes. I found that placing a setpagedevice to the place of where Orientation was originally set helps. But I still don't know why.

Created attachment 105607
minimal version of the reproducer

(In reply to comment #31)
> Created attachment 105606 [details] [review]
> send setpagedevice
>
> I've just bisected where the behaviour changes. I found that placing a
> setpagedevice to the place of where Orientation was originally set helps.
> But I still don't know why.

Maybe the page needs some kind of initialization which is performed in setpagedevice. I've just tried to place there just "erasepage" and it works too.

Still doesn't work here, it seems to rotate the first page only of a multipage document.

I've reverted the patch in master for now, until we find a proper solution.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package evince - 3.13.91-0ubuntu1

---------------
evince (3.13.91-0ubuntu1) utopic; urgency=medium

  * New upstream version (lp: #1367769):
    - Do not open single page pdfs in dual mode by default (lp: #256445)
    - Set the window title for empty windows to make sure it's exposed
      to accessibility (lp: #704928)
    - Close the window when CTRL+w shortcut is used in presentation
      mode, instead of turning the screen white (lp #1289581)
    - Keep the scroll position when switching between continuous and
      non continuous mode (lp: #276749)
    - Fix rotation direction in DJVU backend (lp: #1242678)
    - Better handling of hi-dpi screen (lp: #1287915)
    - Make <Ctrl>Home/End scroll to the start/end of the document
      (lp: #1279387)
    - New Preserve Zoom Feature (lp: #286218)
  * debian/control:
    - drop libsm build-depends, that has been deprecated upstream
    - build-depends on libgnome-desktop-3-dev
    - updated gtk requirement
  * debian/libevdocument3-4.symbols, debian/libevview3-3.symbols:
    - updated for the new version
  * debian/patches/gnome_icon_theme.patch:
    - use old gnome-icon-theme name until we update that component
  * debian/patches/gtk_no_gesture.patch:
    - revert use of gtk gesture until we get gtk 3.13 (new in that version)
  * debian/patches/traditional_menu_bar.patch:
    - use traditionnal menubars under Unity (the gmenumodel work has been
      commited upstream but not the menubar changes)
  * debian/patches/unity_normal_titlebar.patch:
    - use traditionnal menubars out of gnome-shell
  * debian/rules:
    - disable libgnome support in the gtk build
  * Resynchronize on Debian
  * debian/apparmor-profile:
  * debian/apparmor-profile.abstraction:
  * debian/evince.apport:
  * debian/evince-common.dirs:
    - Ubuntu apparmor profile
  * debian/control:
    - Build-Depend on dh-apparmor and libgrip-dev
    - Suggests on apparmor
  * debian/rules:
    - install apparmor files
  * debian/patches/11_grip_gestures.patch:
    - supports pinch to zoom, rotate, and drag gestures
  * Changes deprecated with that version
  * debian/rules:
    - save some space by not shipping the synctex screencast.
      (the video is not included in the new upstream version)
 -- Sebastien Bacher <email address hidden> Mon, 15 Sep 2014 12:46:26 +0200

Changed in evince (Ubuntu):
status: Triaged → Fix Released

(In reply to Carlos Garcia Campos from comment #35)
> I've reverted the patch in master for now, until we find a proper solution.

Do you know when a new tarball is planned including this and other fixes? Thanks

(In reply to Pacho Ramos from comment #36)
> (In reply to Carlos Garcia Campos from comment #35)
> > I've reverted the patch in master for now, until we find a proper solution.
>
> Do you know when a new tarball is planned including this and other fixes?
> Thanks

No plans, but I can make a new release once this problem is fixed, for example.

(In reply to Carlos Garcia Campos from comment #34)
> Still doesn't work here, it seems to rotate the first page only of a
> multipage document.

I can not reproduce this. Could you point me to a document which triggers this problem?

Created attachment 111047
erase page before its drawing

This patch is simplified version of the one with setpagedevice, it just erase the page instead of calling whole setpagedevice.

Hi,

the problem we are trying to fix here was introduced by this ghostscript commit: http://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=7a8612112478196d8f047a556fdbb15d17aec7d0 (Add PSFitPage and FitPage options to allow fitting PS files to a page).
It is present in ghostscript since 9.08.

Created attachment 111925
Rotate documents correctly

I've prepared a simple patch which also solves this problem. It just rotates what we get from ghostscript at pixel level. It takes more time than rendering it directly to the format we want but it works.
I'm just not sure about slice rendering. Should the result be slice from rotated page or rotated slice from page?

*** Bug 87588 has been marked as a duplicate of this bug. ***

Changed in evince (Ubuntu Trusty):
importance: Undecided → Medium
affects: gs-gpl → ubuntu-translations
Changed in ubuntu-translations:
importance: Unknown → Undecided
status: Unknown → New
no longer affects: ubuntu-translations

could anyone review the suggested fix there?

Carlos, any hope of getting a review on Marek latest patch ?

Created attachment 120955
This files result eventually in a pixman crash

Hi,

this rotation issue seems to be also causing a crash in pixman in some cases:

  https://bugs.freedesktop.org/show_bug.cgi?id=87588

I am attaching a file which makes the crash reproducible here.

BTW another test-case for the invalid rotation is the output of kxbprint, reproducible like this:

  xkbprint :0.0 keyboard.ps
  evince keyboard.ps

The latter sometimes crashes and sometimes don't, at least on my system.

Ciao ciao,
   Antonio

As far as I remember the fix only worked for some versions of GS. Anyway, I'll try to find some time too look at this in detail again.

Changed in evince:
importance: Unknown → Medium
status: Unknown → Expired
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.