<fileset dir="${test.dir}/java">
<include name="META-INF/**"/>
<include name="**/*.xml"/>
+ <include name="**/*.fo"/>
</fileset>
<fileset dir="${build.dir}/test-gensrc">
<include name="**/*.xml"/>
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
class EventProducerCollector {
private static final String CLASSNAME_EVENT_PRODUCER = EventProducer.class.getName();
- private static final Map PRIMITIVE_MAP;
+ private static final Map<String, Class<?>> PRIMITIVE_MAP;
static {
- Map m = new java.util.HashMap();
+ Map <String, Class<?>> m = new java.util.HashMap<String, Class<?>>();
m.put("boolean", Boolean.class);
m.put("byte", Byte.class);
m.put("char", Character.class);
}
private DocletTagFactory tagFactory;
- private List models = new ArrayList();
+ private List<EventModel> models = new java.util.ArrayList<EventModel>();
/**
* Creates a new EventProducerCollector.
throws EventConventionException, ClassNotFoundException {
JavaClass clazz = method.getParentClass();
//Check EventProducer conventions
- if (!method.getReturns().isVoid()) {
+ if (!method.getReturnType().isVoid()) {
throw new EventConventionException("All methods of interface "
+ clazz.getFullyQualifiedName() + " must have return type 'void'!");
}
if (params.length > 1) {
for (int j = 1, cj = params.length; j < cj; j++) {
JavaParameter p = params[j];
- Class type;
+ Class<?> type;
JavaClass pClass = p.getType().getJavaClass();
if (p.getType().isPrimitive()) {
- type = (Class)PRIMITIVE_MAP.get(pClass.getName());
+ type = PRIMITIVE_MAP.get(pClass.getName());
if (type == null) {
throw new UnsupportedOperationException(
"Primitive datatype not supported: " + pClass.getName());
* Returns the event model that has been accumulated.
* @return the event model.
*/
- public List getModels() {
+ public List<EventModel> getModels() {
return this.models;
}
</fo:simple-page-master>
</fo:layout-master-set>
]]></source>
- <p>The no-operation extension element can only occur within a simple-page-master.
- Multiple no-operation extension elements within a simple-page-master are allowed.
- The name attribute is mandatory.
+ <p>The no-operation extension element can appear as child of
+ simple-page-master (appears after "Begin Page" BPG),
+ page-sequence (appears after "Begin Named Page Group" BNG
+ and declarations (appears after "Begin Document" BDT).
+ Multiple no-operation extension elements inside the same formatting object are allowed.
+ Each NOP will appear right after the respective "Begin" field indicated above even if it
+ is specified as the last child under its parent. However, the order inside the parent
+ will be maintained.
+ The name attribute is mandatory but will not appear inside the AFP stream.
</p>
</section>
<section id="afp-invoke-medium-map">
* byte data
*/
public void createNoOperation(String content) {
- currentPage.createNoOperation(content);
+ if (currentPage != null) {
+ currentPage.createNoOperation(content);
+ } else if (currentPageGroup != null) {
+ currentPageGroup.createNoOperation(content);
+ } else {
+ document.createNoOperation(content);
+ }
}
/**
currentPageGroup.endPageGroup();
tleSequence = currentPageGroup.getTleSequence();
document.addPageGroup(currentPageGroup);
- document.writeToStream(outputStream);
currentPageGroup = null;
}
+ document.writeToStream(outputStream); //Flush objects
}
/**
// }
/** {@inheritDoc} */
+ @Override
public void writeToStream(OutputStream os) throws IOException {
if (!started) {
writeStart(os);
}
/** {@inheritDoc} */
+ @Override
protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os)
throws IOException {
writeObjects(objects, os, false);
* @return true if this object can be written
*/
protected boolean canWrite(AbstractAFPObject obj) {
- if (obj instanceof AbstractPageObject) {
+ if (obj instanceof Completable) {
return ((Completable)obj).isComplete();
}
else {
import java.io.OutputStream;
import org.apache.fop.afp.AFPConstants;
+import org.apache.fop.afp.Completable;
import org.apache.fop.afp.util.BinaryUtils;
/**
* No Operation structured fields, no semantics should be attached to
* the data carried by the No Operation structured field in interchange
*/
-public class NoOperation extends AbstractAFPObject {
+public class NoOperation extends AbstractAFPObject implements Completable {
/** Up to 32759 bytes of data with no architectural definition */
private static final int MAX_DATA_LEN = 32759;
data[1] = rl1[0];
data[2] = rl1[1];
- // Structured field ID for a TLE
+ // Structured field ID for a NOP
data[3] = (byte) 0xD3;
data[4] = (byte) 0xEE;
data[5] = (byte) 0xEE;
os.write(data);
}
+ /** {@inheritDoc} */
+ public boolean isComplete() {
+ return true; //always complete
+ }
+
+ /** {@inheritDoc} */
+ public void setComplete(boolean complete) {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return "NOP: " + content.substring(0, Math.min(64, content.length()));
+ }
+
}
\ No newline at end of file
<message key="rule.childOfSPM">The element must be a child of fo:simple-page-master.</message>
<message key="rule.childOfDeclarations">The element must be a child of fo:declarations.</message>
<message key="rule.childOfSPMorDeclarations">The element must be a child of fo:declarations or fo:simple-page-master.</message>
+ <message key="rule.childOfSPMorPSorDeclarations">The element must be a child of fo:declarations, fo:simple-page-master or fo:page-sequence.</message>
<message key="rule.childOfInstreamForeignObjectorExternalGraphic">The element must be a child of fo:instream-foreign-object or fo:external-graphic.</message>
<message key="rule.childOfPageSequence">The element must be a child of fo:page-sequence.</message>
<message key="rule.childOfPageSequenceOrSPM">The element must be a child of fo:page-sequence or fo:simple-page-master.</message>
private DataStream dataStream;
/** the map of page segments */
- private Map/*<String,PageSegmentDescriptor>*/pageSegmentMap
- = new java.util.HashMap/*<String,PageSegmentDescriptor>*/();
+ private Map<String, PageSegmentDescriptor> pageSegmentMap
+ = new java.util.HashMap<String, PageSegmentDescriptor>();
/** Medium Map referenced on previous page **/
private String lastMediumMap;
- private static final int LOC_ELSEWHERE = 0;
- private static final int LOC_FOLLOWING_PAGE_SEQUENCE = 1;
- private static final int LOC_IN_PAGE_HEADER = 2;
+ private static enum Location {
+ ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER
+ }
- private int location = LOC_ELSEWHERE;
+ private Location location = Location.ELSEWHERE;
/** the shading mode for filled rectangles */
private AFPShadingMode shadingMode = AFPShadingMode.COLOR;
}
/** {@inheritDoc} */
+ @Override
public void setDefaultFontInfo(FontInfo fontInfo) {
FontManager fontManager = getUserAgent().getFactory().getFontManager();
FontCollection[] fontCollections = new FontCollection[] {
}
/** {@inheritDoc} */
+ @Override
public void startDocument() throws IFException {
super.startDocument();
try {
}
}
+
+ /** {@inheritDoc} */
+ @Override
+ public void startDocumentHeader() throws IFException {
+ super.startDocumentHeader();
+ this.location = Location.IN_DOCUMENT_HEADER;
+ }
+
/** {@inheritDoc} */
+ @Override
public void endDocumentHeader() throws IFException {
+ super.endDocumentHeader();
+ this.location = Location.ELSEWHERE;
}
/** {@inheritDoc} */
+ @Override
public void endDocument() throws IFException {
try {
this.dataStream.endDocument();
} catch (IOException ioe) {
throw new IFException("I/O error in startPageSequence()", ioe);
}
- this.location = LOC_FOLLOWING_PAGE_SEQUENCE;
+ this.location = Location.FOLLOWING_PAGE_SEQUENCE;
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public void startPage(int index, String name, String pageMasterName, Dimension size)
throws IFException {
- this.location = LOC_ELSEWHERE;
+ this.location = Location.ELSEWHERE;
paintingState.clear();
AffineTransform baseTransform = getBaseTransform();
}
/** {@inheritDoc} */
+ @Override
public void startPageHeader() throws IFException {
super.startPageHeader();
- this.location = LOC_IN_PAGE_HEADER;
+ this.location = Location.IN_PAGE_HEADER;
}
/** {@inheritDoc} */
+ @Override
public void endPageHeader() throws IFException {
- this.location = LOC_ELSEWHERE;
+ this.location = Location.ELSEWHERE;
super.endPageHeader();
}
AFPPageSetup aps = (AFPPageSetup)extension;
String element = aps.getElementName();
if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) {
- if (this.location != LOC_IN_PAGE_HEADER
- && this.location != LOC_FOLLOWING_PAGE_SEQUENCE) {
+ switch (this.location) {
+ case FOLLOWING_PAGE_SEQUENCE:
+ case IN_PAGE_HEADER:
+ String name = aps.getName();
+ String value = aps.getValue();
+ dataStream.createTagLogicalElement(name, value);
+ break;
+ default:
throw new IFException(
"TLE extension must be in the page header or between page-sequence"
+ " and the first page: " + aps, null);
}
- String name = aps.getName();
- String value = aps.getValue();
- dataStream.createTagLogicalElement(name, value);
+ } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
+ switch (this.location) {
+ case IN_DOCUMENT_HEADER:
+ case FOLLOWING_PAGE_SEQUENCE:
+ case IN_PAGE_HEADER:
+ String content = aps.getContent();
+ if (content != null) {
+ dataStream.createNoOperation(content);
+ }
+ break;
+ default:
+ throw new IFException(
+ "NOP extension must be in the document header, the page header"
+ + " or between page-sequence"
+ + " and the first page: " + aps, null);
+ }
} else {
- if (this.location != LOC_IN_PAGE_HEADER) {
+ if (this.location != Location.IN_PAGE_HEADER) {
throw new IFException(
"AFP page setup extension encountered outside the page header: " + aps,
null);
String source = apse.getValue();
String uri = apse.getResourceSrc();
pageSegmentMap.put(source, new PageSegmentDescriptor(name, uri));
- } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
- String content = aps.getContent();
- if (content != null) {
- dataStream.createNoOperation(content);
- }
}
}
} else if (extension instanceof AFPPageOverlay) {
AFPPageOverlay ipo = (AFPPageOverlay)extension;
- if (this.location != LOC_IN_PAGE_HEADER) {
+ if (this.location != Location.IN_PAGE_HEADER) {
throw new IFException(
"AFP page overlay extension encountered outside the page header: " + ipo,
null);
dataStream.createIncludePageOverlay(overlay, ipo.getX(), ipo.getY());
}
} else if (extension instanceof AFPInvokeMediumMap) {
- if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE
- && this.location != LOC_IN_PAGE_HEADER) {
+ if (this.location != Location.FOLLOWING_PAGE_SEQUENCE
+ && this.location != Location.IN_PAGE_HEADER) {
throw new IFException(
"AFP IMM extension must be between page-sequence"
* @return the page segment descriptor or null if there's no page segment for the given URI
*/
PageSegmentDescriptor getPageSegmentNameFor(String uri) {
- return (PageSegmentDescriptor)pageSegmentMap.get(uri);
+ return pageSegmentMap.get(uri);
}
}
}
/** {@inheritDoc} */
+ @Override
protected void startOfNode() throws FOPException {
super.startOfNode();
if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(getLocalName())) {
"rule.childOfPageSequenceOrSPM");
}
} else {
- if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) {
+ if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER
+ && parent.getNameId() != Constants.FO_PAGE_SEQUENCE
+ && parent.getNameId() != Constants.FO_DECLARATIONS) {
invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
- "rule.childOfSPM");
+ "rule.childOfSPMorPSorDeclarations");
}
}
}
/** {@inheritDoc} */
+ @Override
protected void characters(char[] data, int start, int length,
PropertyList pList, Locator locator) throws FOPException {
StringBuffer sb = new StringBuffer();
}
/** {@inheritDoc} */
+ @Override
public void processNode(String elementName, Locator locator,
Attributes attlist, PropertyList propertyList)
throws FOPException {
}
/** {@inheritDoc} */
+ @Override
protected ExtensionAttachment instantiateExtensionAttachment() {
return new AFPPageSetup(getLocalName());
}
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="JM" type="add">
+ Allow afp:no-operation to also appear under fo:page-sequence and fo:declarations.
+ </action>
<action context="Code" dev="AD" type="fix" fixes-bug="50635" due-to="mkoegler.AT.auto.tuwien.ac.at">
Bugfix: fix issue in RenderPagesModel.checkPreparedPages() where the same page-sequence
is potentially started multiple times.
import org.apache.fop.image.loader.batik.ImageLoaderTestCase;
import org.apache.fop.image.loader.batik.ImagePreloaderTestCase;
import org.apache.fop.intermediate.IFMimickingTestCase;
+import org.apache.fop.render.afp.AFPTestSuite;
import org.apache.fop.render.extensions.prepress.PageBoundariesTest;
import org.apache.fop.render.extensions.prepress.PageScaleTest;
import org.apache.fop.render.pdf.PDFAConformanceTestCase;
import org.apache.fop.render.pdf.PDFCMapTestCase;
import org.apache.fop.render.pdf.PDFEncodingTestCase;
import org.apache.fop.render.pdf.PDFsRGBSettingsTestCase;
+import org.apache.fop.render.ps.PSTestSuite;
import org.apache.fop.render.rtf.RichTextFormatTestSuite;
import org.apache.fop.traits.MinOptMaxTest;
suite.addTest(new TestSuite(PDFCMapTestCase.class));
suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class));
suite.addTest(new TestSuite(DejaVuLGCSerifTest.class));
+ suite.addTest(AFPTestSuite.suite());
+ suite.addTest(PSTestSuite.suite());
suite.addTest(RichTextFormatTestSuite.suite());
suite.addTest(new TestSuite(ImageLoaderTestCase.class));
suite.addTest(new TestSuite(ImagePreloaderTestCase.class));
--- /dev/null
+/*
+ * 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;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+import java.util.MissingResourceException;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+
+/**
+ * Abstract base class for rendering (output) verification tests.
+ */
+public abstract class AbstractRenderingTestCase extends TestCase {
+
+ private static final Map<String, String> MIME_MAP = new java.util.HashMap<String, String>();
+
+ static {
+ MIME_MAP.put(MimeConstants.MIME_PDF, ".pdf");
+ MIME_MAP.put(MimeConstants.MIME_POSTSCRIPT, ".ps");
+ MIME_MAP.put(MimeConstants.MIME_AFP, ".afp");
+ }
+
+ /** the JAXP TransformerFactory */
+ protected TransformerFactory tFactory = TransformerFactory.newInstance();
+ /** the FopFactory */
+ protected FopFactory fopFactory = FopFactory.newInstance();
+
+ /**
+ * Renders a test file.
+ * @param ua the user agent (with override set!)
+ * @param resourceName the resource name for the FO file
+ * @param suffix a suffix for the output filename
+ * @param outputFormat MIME type of the requested output format
+ * @return the output file
+ * @throws Exception if an error occurs
+ */
+ protected File renderFile(FOUserAgent ua, String resourceName, String suffix,
+ String outputFormat) throws Exception {
+ String extension = MIME_MAP.get(outputFormat);
+ assert extension != null;
+ File outputFile = new File("build/test-results/" + resourceName + suffix + extension);
+ File outputDir = outputFile.getParentFile();
+ FileUtils.forceMkdir(outputDir);
+
+ // Prepare input file
+ InputStream in = getClass().getResourceAsStream(resourceName);
+ if (in == null) {
+ throw new MissingResourceException(resourceName + " not found in resources",
+ getClass().getName(), null);
+ }
+ try {
+ Source src = new StreamSource(in);
+
+ // Create output file
+ OutputStream out = new java.io.FileOutputStream(outputFile);
+ out = new java.io.BufferedOutputStream(out);
+ try {
+ Fop fop = fopFactory.newFop(outputFormat, ua, out);
+ SAXResult res = new SAXResult(fop.getDefaultHandler());
+
+ Transformer transformer = tFactory.newTransformer();
+ transformer.transform(src, res);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ return outputFile;
+ }
+
+}
--- /dev/null
+/*
+ * 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.afp;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for FOP's AFP output.
+ */
+public class AFPTestSuite {
+
+ /**
+ * Builds the test suite
+ * @return the test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test suite for AFP output");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(NoOperationTestCase.class));
+ //$JUnit-END$
+ return suite;
+ }
+}
--- /dev/null
+/*
+ * 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.afp;
+
+import java.io.File;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRenderingTestCase;
+
+/**
+ * Abstract base class for AFP verification tests.
+ */
+abstract class AbstractAFPTestCase extends AbstractRenderingTestCase {
+
+ /**
+ * Renders a test file.
+ * @param ua the user agent (with override set!)
+ * @param resourceName the resource name for the FO file
+ * @param suffix a suffix for the output filename
+ * @return the output file
+ * @throws Exception if an error occurs
+ */
+ protected File renderFile(FOUserAgent ua, String resourceName, String suffix)
+ throws Exception {
+ return renderFile(ua, resourceName, suffix, MimeConstants.MIME_AFP);
+ }
+
+
+}
--- /dev/null
+/*
+ * 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.afp;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.afp.AFPConstants;
+import org.apache.fop.afp.parser.MODCAParser;
+import org.apache.fop.afp.parser.UnparsedStructuredField;
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Tests generation of afp:no-operation (NOPs).
+ */
+public class NoOperationTestCase extends AbstractAFPTestCase {
+
+ /**
+ * Tests afp:no-operation.
+ * @throws Exception if an error occurs
+ */
+ public void testNoOperation() throws Exception {
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+ File outputFile = renderFile(ua, "nops.fo", "");
+
+ InputStream in = new java.io.FileInputStream(outputFile);
+ try {
+ MODCAParser parser = new MODCAParser(in);
+ UnparsedStructuredField field = skipTo(parser, 0xD3A8A8); //Begin Document
+
+ //NOP in fo:declarations
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:declarations", getNopText(field));
+
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3A8AD, field.getSfTypeID()); //Begin Named Page Group
+
+ //NOPs in fo:page-sequence
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:page-sequence: start", getNopText(field));
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:page-sequence: end", getNopText(field));
+
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3A8AF, field.getSfTypeID()); //Begin Page
+
+ field = skipTo(parser, 0xD3A9C9); //End Active Environment Group
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:simple-page-master: first", getNopText(field));
+
+ field = skipTo(parser, 0xD3A9C9); //End Active Environment Group
+ field = parser.readNextStructuredField();
+ assertEquals(0xD3EEEE, field.getSfTypeID());
+ assertEquals("fo:simple-page-master: rest", getNopText(field));
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+ int counter = 0;
+ in = new java.io.FileInputStream(outputFile);
+ try {
+ MODCAParser parser = new MODCAParser(in);
+ while (true) {
+ UnparsedStructuredField field = parser.readNextStructuredField();
+ if (field == null) {
+ break;
+ }
+ if (field.getSfTypeID() == 0xD3EEEE) {
+ counter++;
+ }
+ }
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ assertEquals(6, counter); //decl, 2 * ps, 3 * page/spm
+ }
+
+ private String getNopText(UnparsedStructuredField field) throws UnsupportedEncodingException {
+ byte[] data = field.getData();
+ String text = new String(data, AFPConstants.EBCIDIC_ENCODING);
+ return text;
+ }
+
+ private UnparsedStructuredField skipTo(MODCAParser parser, int typeID) throws IOException {
+ UnparsedStructuredField field = null;
+ do {
+ field = parser.readNextStructuredField();
+ if (field.getSfTypeID() == typeID) {
+ return field;
+ }
+ } while (field != null);
+ Assert.fail("Structured field not found: " + Integer.toHexString(typeID));
+ return null;
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:afp="http://xmlgraphics.apache.org/fop/extensions/afp">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="first" page-height="10.5cm" page-width="14.85cm" margin="2cm">
+ <afp:no-operation name="spm">fo:simple-page-master: first</afp:no-operation>
+ <fo:region-body margin-top="2em "/>
+ <fo:region-before extent="2em"/>
+ </fo:simple-page-master>
+ <fo:simple-page-master master-name="rest" page-height="10.5cm" page-width="14.85cm" margin="2cm">
+ <afp:no-operation name="spm">fo:simple-page-master: rest</afp:no-operation>
+ <fo:region-body margin-top="2em "/>
+ <fo:region-before extent="2em"/>
+ </fo:simple-page-master>
+ <fo:page-sequence-master master-name="main">
+ <fo:repeatable-page-master-alternatives>
+ <fo:conditional-page-master-reference master-reference="first" page-position="first"/>
+ <fo:conditional-page-master-reference master-reference="rest"/>
+ </fo:repeatable-page-master-alternatives>
+ </fo:page-sequence-master>
+ </fo:layout-master-set>
+
+ <fo:declarations>
+ <afp:no-operation name="declarations">fo:declarations</afp:no-operation>
+ </fo:declarations>
+
+ <fo:page-sequence master-reference="main" id="doc1">
+ <afp:no-operation name="ps">fo:page-sequence: start</afp:no-operation>
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block>Page 1</fo:block>
+ <fo:block>Page 1</fo:block>
+ <fo:block break-after="page"></fo:block>
+ <fo:block>Page 2</fo:block>
+ <fo:block>Page 2</fo:block>
+ <fo:block break-after="page"></fo:block>
+ <fo:block>Page 3</fo:block>
+ <fo:block>Page 3</fo:block>
+ </fo:flow>
+ <afp:no-operation name="ps">fo:page-sequence: end</afp:no-operation>
+ </fo:page-sequence>
+</fo:root>
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.MissingResourceException;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.xmlgraphics.ps.PSResource;
import org.apache.xmlgraphics.ps.dsc.DSCException;
import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRenderingTestCase;
/**
* Abstract base class for PostScript verification tests.
*/
-public abstract class AbstractPostScriptTestCase extends TestCase {
-
- /** the JAXP TransformerFactory */
- protected TransformerFactory tFactory = TransformerFactory.newInstance();
- /** the FopFactory */
- protected FopFactory fopFactory = FopFactory.newInstance();
+public abstract class AbstractPostScriptTestCase extends AbstractRenderingTestCase {
/**
* Renders a test file.
*/
protected File renderFile(FOUserAgent ua, String resourceName, String suffix)
throws Exception {
- File outputFile = new File("build/test-results/" + resourceName + suffix + ".ps");
- File outputDir = outputFile.getParentFile();
- FileUtils.forceMkdir(outputDir);
-
- // Prepare input file
- InputStream in = getClass().getResourceAsStream(resourceName);
- if (in == null) {
- throw new MissingResourceException(resourceName + " not found in resources",
- getClass().getName(), null);
- }
- try {
- Source src = new StreamSource(in);
-
- // Create PostScript
- OutputStream out = new java.io.FileOutputStream(outputFile);
- out = new java.io.BufferedOutputStream(out);
- try {
- Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, ua, out);
- SAXResult res = new SAXResult(fop.getDefaultHandler());
-
- Transformer transformer = tFactory.newTransformer();
- transformer.transform(src, res);
- } finally {
- IOUtils.closeQuietly(out);
- }
- } finally {
- IOUtils.closeQuietly(in);
- }
- return outputFile;
+ return renderFile(ua, resourceName, suffix, MimeConstants.MIME_POSTSCRIPT);
}
/**
gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
+ gotoDSCComment(parser, DSCConstants.BEGIN_RESOURCE);
PSResource form2 = new PSResource(PSResource.TYPE_FORM, "FOPForm:2");
checkResourceComment(parser, DSCConstants.BEGIN_RESOURCE, form2);
--- /dev/null
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for FOP's PostScript output.
+ */
+public class PSTestSuite {
+
+ /**
+ * Builds the test suite
+ * @return the test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test suite for PostScript output");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(ImageHandlingTestCase.class));
+ suite.addTest(new TestSuite(ResourceOptimizationTestCase.class));
+ //$JUnit-END$
+ return suite;
+ }
+}
= (DSCCommentDocumentSuppliedResources)gotoDSCComment(parser,
DSCConstants.DOCUMENT_SUPPLIED_RESOURCES);
Set resources = supplied.getResources();
- assertEquals(4, resources.size());
+ assertEquals(5, resources.size());
assertTrue(resources.contains(form1));
assertTrue("Expected barcode.eps as supplied resource",
resources.contains(new PSResource(PSResource.TYPE_FILE,