Author: gadams
Date: Sun May 27 17:39:49 2012
New Revision: 1343072
URL: http://svn.apache.org/viewvc?rev=1343072&view=rev
Log:
Add extension to place code just before PostScript %PageTrailer. Submitted by
Luis Bernardo.
Added:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java
xmlgraphics/fop/trunk/status.xml
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java?rev=1343072&r1=1343071&r2=1343072&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
Sun May 27 17:39:49 2012
@@ -26,6 +26,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -57,6 +58,7 @@ import org.apache.fop.render.intermediat
import org.apache.fop.render.intermediate.IFPainter;
import org.apache.fop.render.ps.extensions.PSCommentAfter;
import org.apache.fop.render.ps.extensions.PSCommentBefore;
+import org.apache.fop.render.ps.extensions.PSPageTrailerCodeBefore;
import org.apache.fop.render.ps.extensions.PSSetPageDevice;
import org.apache.fop.render.ps.extensions.PSSetupCode;
@@ -98,10 +100,11 @@ public class PSDocumentHandler extends A
private PSPageDeviceDictionary pageDeviceDictionary;
/** This is a collection holding all document header comments */
- private Collection[] comments = new Collection[3];
+ private Collection[] comments = new Collection[4];
private static final int COMMENT_DOCUMENT_HEADER = 0;
private static final int COMMENT_DOCUMENT_TRAILER = 1;
private static final int COMMENT_PAGE_TRAILER = 2;
+ private static final int PAGE_TRAILER_CODE_BEFORE = 3;
/**
* Default constructor.
@@ -443,8 +446,9 @@ public class PSDocumentHandler extends A
/** {@inheritDoc} */
public void startPageTrailer() throws IFException {
- super.startPageTrailer();
try {
+ writeExtensions(PAGE_TRAILER_CODE_BEFORE);
+ super.startPageTrailer();
gen.writeDSCComment(DSCConstants.PAGE_TRAILER);
} catch (IOException ioe) {
throw new IFException("I/O error in startPageTrailer()", ioe);
@@ -526,6 +530,11 @@ public class PSDocumentHandler extends A
comments[targetCollection] = new java.util.ArrayList();
}
comments[targetCollection].add(extension);
+ } else if (extension instanceof PSPageTrailerCodeBefore) {
+ if (comments[PAGE_TRAILER_CODE_BEFORE] == null) {
+ comments[PAGE_TRAILER_CODE_BEFORE] = new ArrayList();
+ }
+ comments[PAGE_TRAILER_CODE_BEFORE].add(extension);
}
} catch (IOException ioe) {
throw new IFException("I/O error in handleExtensionObject()", ioe);
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java?rev=1343072&r1=1343071&r2=1343072&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java
Sun May 27 17:39:49 2012
@@ -41,6 +41,7 @@ public class PSExtensionElementMapping e
foObjs = new java.util.HashMap<String, Maker>();
foObjs.put(PSSetupCodeElement.ELEMENT, new PSSetupCodeMaker());
foObjs.put(PSPageSetupCodeElement.ELEMENT, new
PSPageSetupCodeMaker());
+ foObjs.put(PSPageTrailerCodeBefore.ELEMENT, new
PSPageTrailerCodeBeforeMaker());
foObjs.put(PSSetPageDeviceElement.ELEMENT, new
PSSetPageDeviceMaker());
foObjs.put(PSCommentBefore.ELEMENT, new PSCommentBeforeMaker());
foObjs.put(PSCommentAfter.ELEMENT, new PSCommentAfterMaker());
@@ -59,6 +60,12 @@ public class PSExtensionElementMapping e
}
}
+ static class PSPageTrailerCodeBeforeMaker extends ElementMapping.Maker {
+ public FONode make(FONode parent) {
+ return new PSPageTrailerCodeBeforeElement(parent);
+ }
+ }
+
static class PSSetPageDeviceMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new PSSetPageDeviceElement(parent);
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java?rev=1343072&r1=1343071&r2=1343072&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java
Sun May 27 17:39:49 2012
@@ -53,6 +53,7 @@ public class PSExtensionHandler extends
lastAttributes = new AttributesImpl(attributes);
handled = false;
if (localName.equals(PSSetupCode.ELEMENT)
+ || localName.equals(PSPageTrailerCodeBefore.ELEMENT)
|| localName.equals(PSSetPageDevice.ELEMENT)
|| localName.equals(PSCommentBefore.ELEMENT)
|| localName.equals(PSCommentAfter.ELEMENT)) {
@@ -84,6 +85,8 @@ public class PSExtensionHandler extends
this.returnedObject = new PSCommentBefore(content.toString());
} else if (PSCommentAfter.ELEMENT.equals(localName)) {
this.returnedObject = new PSCommentAfter(content.toString());
+ } else if (PSPageTrailerCodeBefore.ELEMENT.equals(localName)) {
+ this.returnedObject = new
PSPageTrailerCodeBefore(content.toString());
}
}
content.setLength(0); //Reset text buffer (see characters())
Added:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java?rev=1343072&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java
(added)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java
Sun May 27 17:39:49 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps.extensions;
+
+
+public class PSPageTrailerCodeBefore extends PSExtensionAttachment {
+
+ /** The element name */
+ protected static final String ELEMENT = "ps-page-trailer-code-before";
+
+ /**
+ * Default constructor
+ * @param content the actual comment
+ */
+ public PSPageTrailerCodeBefore(String content) {
+ super(content);
+ }
+
+ /**
+ * Constructor
+ */
+ public PSPageTrailerCodeBefore() {
+ super();
+ }
+
+ /**
+ * @return element name
+ */
+ protected String getElement() {
+ return ELEMENT;
+ }
+
+}
Added:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java?rev=1343072&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java
(added)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java
Sun May 27 17:39:49 2012
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps.extensions;
+
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+
+/**
+ * Comment before element
+ */
+public class PSPageTrailerCodeBeforeElement extends AbstractPSCommentElement {
+
+ /** the element name */
+ protected static final String ELEMENT = "ps-page-trailer-code-before";
+
+ /**
+ * Main constructor
+ * @param parent parent node
+ */
+ public PSPageTrailerCodeBeforeElement(FONode parent) {
+ super(parent);
+ }
+
+ /**
+ * @return local name
+ * @see org.apache.fop.fo.FONode#getLocalName()
+ */
+ public String getLocalName() {
+ return PSPageTrailerCodeBefore.ELEMENT;
+ }
+
+ /**
+ * @return instance of its extension attachment object
+ */
+ protected ExtensionAttachment instantiateExtensionAttachment() {
+ return new PSPageTrailerCodeBefore();
+ }
+}
Modified: xmlgraphics/fop/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1343072&r1=1343071&r2=1343072&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Sun May 27 17:39:49 2012
@@ -63,6 +63,9 @@
documents. Example: the fix of marks layering will be such a case when
it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Renderers" dev="GA" type="fix" fixes-bug="53295"
due-to="Luis Bernardo">
+ Add extension to place code just before PostScript %PageTrailer.
+ </action>
<action context="Renderers" dev="GA" type="fix" fixes-bug="53294"
due-to="Robert Meyer">
Fix invalid PostScript file being created when font-size is 0.
</action>
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java?rev=1343072&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java
(added)
+++
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java
Sun May 27 17:39:49 2012
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.render.ps.extensions.PSPageTrailerCodeBefore;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class PSRenderingUtilTestCase {
+
+ private final String content = "<< /MyEntry 0 >> command";
+ private final PSPageTrailerCodeBefore ptcb = new
PSPageTrailerCodeBefore(content);
+ private final PSGenerator gen = mock(PSGenerator.class);
+
+ @Test
+ public void testWriteEnclosedExtensionAttachment() throws IOException {
+ PSRenderingUtil.writeEnclosedExtensionAttachment(gen, ptcb);
+ verify(gen).writeln(content);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]