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.
Created attachment 2345 [details] rotate_error.zip input test file and results from gs and adobe conversion to pdf.
reproduced with head.
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.
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.
Created attachment 2352 [details] patch.txt A suggested patch is being tested now.
Patch to HEAD : http://ghostscript.com/pipermail/gs-cvs/2006-July/006676.html