Bug 688793

Summary: document pages rotated with Ghostscript, not with Acrobat
Product: Ghostscript Reporter: Ralph Giles <ralph.giles>
Component: GeneralAssignee: leonardo <leonardo>
Status: NOTIFIED FIXED    
Severity: normal    
Priority: P2    
Version: 8.50   
Hardware: PC   
OS: Linux   
Customer: 242 Word Size: ---
Attachments: patch.txt

Description Ralph Giles 2006-07-12 09:08:22 UTC
Customer complains that after converting ps to pdf with Ghostscript 8.50, the
output displays rotated (landscape instead of portrait for a portrait page).
Converting the same file with Acrobat results in the correct orientation.
Comment 1 Ralph Giles 2006-07-12 09:14:25 UTC
Created attachment 2345 [details]
rotate_error.zip

input test file and results from gs and adobe conversion to pdf.
Comment 2 Ralph Giles 2006-07-12 09:40:13 UTC
reproduced with head.
Comment 3 Ralph Giles 2006-07-12 10:21:09 UTC
The document only sets ViewerOrientation, but we're only looking at Orientation
and PageOrientation. We must handle this comment properly, especially as it
takes precedence over the other two.

In the meantime, we fall back to detecting the predominant text direction, which
fails to get the correct orientation for this particular file (reasonably; it's
a graph with more text along the vertical axes). This behaviour can be disabled
by passing -dAutoRotatePages=/None to Ghostscript, but this is not a general
solution.

Calling setorientation in the pagedevice from postscript is the most definitive
fix. Also, getting the ps driver to set Orientation or PageOrientation would
probably also fix it with current Ghostscript.
Comment 4 Raph Levien 2006-07-12 10:55:04 UTC
My analysis:

There are two issues here. First, the document-global viewing_orientation info
isn't being copied into the page-specific info. The following patch seems to me
to be the right thing to do.

Index: src/gdevpdf.c
===================================================================
--- src/gdevpdf.c       (revision 6725)
+++ src/gdevpdf.c       (working copy)
@@ -858,6 +858,9 @@
     page->dsc_info = pdev->page_dsc_info;
     if (page->dsc_info.orientation < 0)
        page->dsc_info.orientation = pdev->doc_dsc_info.orientation;
+    if (page->dsc_info.viewing_orientation < 0)
+       page->dsc_info.viewing_orientation =
+           pdev->doc_dsc_info.viewing_orientation;
     if (page->dsc_info.bounding_box.p.x >= page->dsc_info.bounding_box.q.x ||
        page->dsc_info.bounding_box.p.y >= page->dsc_info.bounding_box.q.y
        )

Second, when the inferred text rotation and the dsc orientation can't match
(i.e. are off by an odd multiple of 90 degrees), precedence is given to the text
rotation. The comment reads: "If not combinable, prefer text rotation". This
logic was committed in svn rev 2836.

My recommendation: apply the patch above, and reverse the precedence so that if
both dsc orientation is set and text rotation is inferred, use the dsc value.
See also bug 687800 for a test case to try.
Comment 5 leonardo 2006-07-13 13:35:50 UTC
Created attachment 2352 [details]
patch.txt

A suggested patch is being tested now.
Comment 6 leonardo 2006-07-13 14:36:39 UTC
Patch to HEAD :
http://ghostscript.com/pipermail/gs-cvs/2006-July/006676.html