Bug 689653 - Nested form XObject pdfmarks not working properly
Summary: Nested form XObject pdfmarks not working properly
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Writer (show other bugs)
Version: master
Hardware: PC Windows NT
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-15 05:24 UTC by Ken Sharp
Modified: 2013-12-03 02:11 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
patch for base/gdevpdfm.c to fix issue with /SP/BP/EP pdfmarks nested between /BP /EP pdfmarks (2.95 KB, patch)
2010-10-26 13:19 UTC, Alexander Grahn
Details | Diff
patch for nested form XObject pdfmarks (429 bytes, patch)
2010-11-01 12:31 UTC, Alexander Grahn
Details | Diff
PDF file, produced from testfile given above using patched version of gs (patch=attachment 6857) (3.41 KB, application/pdf)
2010-11-03 08:01 UTC, Alexander Grahn
Details

Note You need to log in before you can comment on or make changes to this bug.
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.