Bug 60982

Summary: Page size detected incorrectly
Product: libspectre Reporter: Germán Poo-Caamaño <gpoo+bfdo>
Component: generalAssignee: Carlos Garcia Campos <carlosgc>
Status: RESOLVED MOVED QA Contact: Carlos Garcia Campos <carlosgc>
Severity: normal    
Priority: medium CC: markus.kramer
Version: unspecified   
Hardware: Other   
OS: All   
URL: https://bugzilla.gnome.org/show_bug.cgi?id=346160
Whiteboard:
i915 platform: i915 features:
Attachments: PS test case
Another test case
Another test case /PageSize inside %%BeginSetup
LibSpectre ignores the A4 in setpagedevice
LibSpectre reads the A4 "structuring comments"

Description Germán Poo-Caamaño 2013-02-17 01:05:17 UTC
Created attachment 74958 [details]
PS test case

This bug was reported a long time ago in https://bugzilla.gnome.org/show_bug.cgi?id=346160

The page size is reported as letter when it should be A4.

In the test case reported, spectre_page_get_size returns 612x792, but it should be 592x842.

The document does not have PageBoundingBox, PageOrientation, PageMedia nor PaperSize.  IIRC, it is defined in:

/Forms-A4 {/pageheight 842 def 1 dict dup /PageSize [595 842] put
    systemdict /setpagedevice known {dup setpagedevice} if
    /Top-margin 816 def p} def

and then:

% Document starts here

Forms-A4 Point-10cpi Normal-font newfont
Forms-A4  Normal-font newfont  Normal-font newfont  Normal-font newfont  Point-17cpi newfont p
%%Page: 1 1

If I use ps2pdf to convert the document, and then open the PDF with evince, the page size is A4 (as expected).
Comment 1 Germán Poo-Caamaño 2013-02-17 01:18:10 UTC
Created attachment 74959 [details]
Another test case

Here is another test case.  In this case, there is a definition of /PageSize in the line 290 of the document after BeginFeature.

This was also reported in Gnome's Bugzilla: https://bugzilla.gnome.org/show_bug.cgi?id=598868
Comment 2 Germán Poo-Caamaño 2013-02-25 18:25:55 UTC
Created attachment 75522 [details]
Another test case /PageSize inside %%BeginSetup

Another test case reported in https://bugzilla.gnome.org/show_bug.cgi?id=694636

I removed the content, but the page size definition still is there in the line 72.
Comment 3 Markus 2014-07-26 19:17:26 UTC
Created attachment 103517 [details]
LibSpectre ignores the A4 in setpagedevice
Comment 4 Markus 2014-07-26 19:18:28 UTC
Created attachment 103518 [details]
LibSpectre reads the A4 "structuring comments"
Comment 5 Markus 2014-07-26 19:20:14 UTC
Hello,

to research this case, I have created and attached a very small test document (4corners_A4.ps). In fact the only test being tested is  

      << /PageSize [595 842] >> setpagedevice

These numbers specify A4, but Evince does render the page as Letter.
The content of the page are four lines pointing into the corners of A4, to recognize the page size easily. 

I have read libspectre/ps.c (the C source code file) and found that libspectre ignores (does not parse) code like  << /PageSize [x y] >> setpagedevice

Instead, for the Page Size, libspectre relies on “document structuring comments”  (starting with %%).

I find this far from optimal, because comments are the only source of PageSize information, while there is a language feature that is ignored, and there are PostScript documents and generators that are unaware of these comments. This is confusing.


The two “structuring comment” blocks below are needed to convince libspectre of A4, I found by trial and error. The code is in the second attachment (4corners_A4_libspectre.ps). I am very surprised that a missing %%Page comment even generates a Syntax error.

I would like to suggest that reading the page size from  << /PageSize [x y] >> setpagedevice” would make libspectre a more robust library. 

Who is the current maintainer of the code?

Best regards,
Markus




BLOCK 1 ------ at the beginning of the document

%%BoundingBox: 0 0 595 842
%%Orientation: Portrait
%%PageOrder: Ascend
%%DocumentMedia: 595 842
%%DocumentPaperSizes: a4
%%EndComments

%%BeginDefaults
%%PageBoundingBox: 0 0 595 842
%%PageOrientation: Portrait
%%EndDefaults

%%BeginSetup
%%PageBoundingBox: 0 0 595 842
%%PaperOrientation: Portrait
%%PaperSize: a4
%%EndSetup



BLOCK 2 ------ at each page
%%Page 1
Comment 6 GitLab Migration User 2018-10-12 21:36:39 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/libspectre/libspectre/issues/17.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.