Bug 689653

Summary: Nested form XObject pdfmarks not working properly
Product: Ghostscript Reporter: Ken Sharp <ken.sharp>
Component: PDF WriterAssignee: Ken Sharp <ken.sharp>
Status: RESOLVED FIXED    
Severity: normal CC: christinedelight.top85, shailesh.mistry
Priority: P4    
Version: master   
Hardware: PC   
OS: Windows NT   
Customer: Word Size: ---
Attachments: patch for base/gdevpdfm.c to fix issue with /SP/BP/EP pdfmarks nested between /BP /EP pdfmarks
patch for nested form XObject pdfmarks
PDF file, produced from testfile given above using patched version of gs (patch=attachment 6857)

Description Ken Sharp 2008-01-15 05:24:30 UTC
The only way currently to get form XObjects from pdfwrite is to use pdfmarks.
When a Form XObject pdfmark is contained within a form XObject pdfmark, the
resulting PDF is incorrect.

Test file:
%!
[ /_objdef {PDFForm} /BBox [0 0 100 100] /BP pdfmark
	[ /_objdef {NestedForm} /BBox [0 0 50 50] /BP pdfmark
		<<
		    	/PatternType 1 
		    	/PaintType 1 
		    	/TilingType 1 
		    	/BBox [ 0 0 50 50 ] 
		    	/XStep 50 
		    	/YStep 50 
			/PaintProc 
			{
				pop
					1 0 0 setrgbcolor
					0 0 moveto 0 50 lineto
					50 50 lineto 50 0 lineto
					0 0 lineto stroke
			}
		>> [1 0 0 1 0 0] makepattern setpattern
		0 0 100 100 rectfill
	[ /EP pdfmark
	[ {NestedForm} /SP pdfmark
[ /EP pdfmark
[ {PDFForm} /SP pdfmark

showpage
Comment 1 Alexander Grahn 2010-10-26 13:19:02 UTC
Created attachment 6833 [details]
patch for base/gdevpdfm.c to fix issue with /SP/BP/EP pdfmarks nested between /BP /EP pdfmarks

IF /SP pdfmark is injected into the definition of a new Form XObject (that is, put between /BP-/EP pdfmarks), the newly created container Form XObject lacks the /XObject entry in its /Resources dictionary.

The proposed patch fixes this bug. It maintains a stack of dictionaries which are filled with the XObject resources referenced in the current context, that is which are referenced (by /SP pdfmark) in the content stream of the Form XObject currently open (opened by the /BP pdfmark). When the current context is closed by an /EP pdfmark the /XObject entry is added to the /Resources dictionary. Hence, /BP-/EP and /SP can now be nested to arbitrary depth into other /BP-/EP pdfmark pairs.

The patch also fixes bug 689883.
Comment 2 Alexander Grahn 2010-11-01 12:31:34 UTC
Created attachment 6857 [details]
patch for nested form XObject pdfmarks

The updated patch is much shorter. A correct PDF will be produced from the given Postscript example. Also fixes bug 689883.
Comment 3 Alexander Grahn 2010-11-03 08:01:28 UTC
Created attachment 6862 [details]
PDF file, produced from testfile given above using patched version of gs (patch=attachment 6857 [details])
Comment 4 Shailesh Mistry 2011-07-25 17:11:39 UTC
Bug still reproducible in Ghostscript 9.03
Comment 5 Ken Sharp 2013-12-03 02:11:39 UTC
Patch (finally!) adopted in commit 3d544d51c3e1d63a2fd115dac23255c966ba0e

Apologies for the length of time its taken to review and adopt this.