aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-12-17 15:01:21 +0000
committerJeremias Maerki <jeremias@apache.org>2008-12-17 15:01:21 +0000
commitd142add7467c21615699a3799626e6c66563c08d (patch)
tree24f03071dc7341f353dcb3c556c48d68e0431848 /test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
parent3beeea67b665a3fdd6331f8c6fb99d24dc683f78 (diff)
downloadxmlgraphics-fop-d142add7467c21615699a3799626e6c66563c08d.tar.gz
xmlgraphics-fop-d142add7467c21615699a3799626e6c66563c08d.zip
Added getUserAgent() to IFDocumentHandler (implemented by all implementations already).
Full image support for PSPainter. PostScript output now uses the ImageHandler facility (IF and renderer) for both inline (ImageHandler interface) and form image production (PSImageHandler interface). No more hard-coded image flavor list. Resource optimization extended so images that are only used once are inlined to lower memory requirements in the PostScript VM. Added test cases using Commons' DSC parser to verify the new functionality. Added IFDocumentHandler override possibility in FOUserAgent (just like for FOEventHandler and Renderer). Subject support for PDF output. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@727405 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java')
-rw-r--r--test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java188
1 files changed, 188 insertions, 0 deletions
diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
new file mode 100644
index 000000000..51c4dc301
--- /dev/null
+++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
@@ -0,0 +1,188 @@
+/*
+ * 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.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.PSResource;
+import org.apache.xmlgraphics.ps.dsc.DSCException;
+import org.apache.xmlgraphics.ps.dsc.DSCParser;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPage;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentTitle;
+import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Tests the image handling in PostScript output.
+ */
+public class ImageHandlingTestCase extends AbstractPostScriptTestCase {
+
+ /**
+ * Tests JPEG handling with the {@link PSRenderer}.
+ * @throws Exception if an error occurs
+ */
+ public void testJPEGImageWithRendererLevel3() throws Exception {
+ innerTestJPEGImageWithRenderer(3);
+ }
+
+ /**
+ * Tests JPEG handling with the {@link PSRenderer}.
+ * @throws Exception if an error occurs
+ */
+ public void testJPEGImageWithRendererLevel2() throws Exception {
+ innerTestJPEGImageWithRenderer(2);
+ }
+
+ /**
+ * Tests JPEG handling with the {@link PSDocumentHandler}.
+ * @throws Exception if an error occurs
+ */
+ public void testJPEGImageWithIFLevel3() throws Exception {
+ innerTestJPEGImageWithIF(3);
+ }
+
+ /**
+ * Tests JPEG handling with the {@link PSDocumentHandler}.
+ * @throws Exception if an error occurs
+ */
+ public void testJPEGImageWithIFLevel2() throws Exception {
+ innerTestJPEGImageWithIF(2);
+ }
+
+ private void innerTestJPEGImageWithRenderer(int level) throws Exception {
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+ PSRenderer renderer = new PSRenderer();
+ renderer.setUserAgent(ua);
+ PSRenderingUtil psUtil = renderer.getPSUtil();
+ psUtil.setLanguageLevel(level);
+ psUtil.setOptimizeResources(true);
+ ua.setRendererOverride(renderer);
+
+ // Prepare output file
+ File outputFile = renderFile(ua, "ps-jpeg-image.fo", "-rend-l" + psUtil.getLanguageLevel());
+ verifyPostScriptFile(outputFile, psUtil.getLanguageLevel());
+ }
+
+ private void innerTestJPEGImageWithIF(int level) throws Exception {
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+ PSDocumentHandler handler = new PSDocumentHandler();
+ handler.setUserAgent(ua);
+ PSRenderingUtil psUtil = handler.getPSUtil();
+ psUtil.setLanguageLevel(level);
+ psUtil.setOptimizeResources(true);
+ ua.setDocumentHandlerOverride(handler);
+
+ // Prepare output file
+ File outputFile = renderFile(ua, "ps-jpeg-image.fo", "-if-l" + psUtil.getLanguageLevel());
+ verifyPostScriptFile(outputFile, psUtil.getLanguageLevel());
+ }
+
+ private void verifyPostScriptFile(File psFile, int level)
+ throws IOException, DSCException {
+ InputStream in = new java.io.FileInputStream(psFile);
+ in = new java.io.BufferedInputStream(in);
+ try {
+ DSCParser parser = new DSCParser(in);
+
+ DSCCommentPages pages = (DSCCommentPages)gotoDSCComment(parser, DSCConstants.PAGES);
+ assertEquals(1, pages.getPageCount());
+
+ //Skip procsets and encoding
+ 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);
+ DSCCommentTitle title = (DSCCommentTitle)parser.nextEvent().asDSCComment();
+ assertEquals("image/jpeg test/resources/images/bgimg300dpi.jpg", title.getTitle());
+
+ String resourceContent = getResourceContent(parser);
+
+ if (level == 3) {
+ assertContains(resourceContent, "/FOPForm:2");
+ assertContains(resourceContent, "/DCTDecode filter");
+ assertContains(resourceContent, "/ReusableStreamDecode filter");
+ } else {
+ assertContains(resourceContent, "/FOPForm:2");
+ assertContains(resourceContent, "/DCTDecode filter");
+ assertAbsent(resourceContent, "/ReusableStreamDecode filter");
+ }
+
+ //---=== Page 1 ===---
+ DSCCommentPage page = (DSCCommentPage)gotoDSCComment(parser, DSCConstants.PAGE);
+ assertEquals(1, page.getPagePosition());
+
+ PSResource form1 = new PSResource(PSResource.TYPE_FORM, "FOPForm:1");
+ checkResourceComment(parser, DSCConstants.BEGIN_RESOURCE, form1);
+ title = (DSCCommentTitle)parser.nextEvent().asDSCComment();
+ assertEquals("image/jpeg test/resources/images/bgimg72dpi.jpg", title.getTitle());
+ resourceContent = getResourceContent(parser);
+
+ if (level == 3) {
+ assertContains(resourceContent, "/FOPForm:1");
+ assertContains(resourceContent, "/DCTDecode filter");
+ assertContains(resourceContent, "/ReusableStreamDecode filter");
+ } else {
+ assertContains(resourceContent, "/FOPForm:1");
+ assertContains(resourceContent, "/DCTDecode filter");
+ assertAbsent(resourceContent, "/ReusableStreamDecode filter");
+ }
+
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ private void assertMatches(String text, String regex) {
+ assertTrue("Text didn't match '" + regex + "'", text.matches(regex));
+ }
+
+ private void assertContains(String text, String searchString) {
+ assertTrue("Text doesn't contain '" + searchString + "'", text.indexOf(searchString) >= 0);
+ }
+
+ private void assertAbsent(String text, String searchString) {
+ assertTrue("Text contains '" + searchString + "'", text.indexOf(searchString) < 0);
+ }
+
+ private String getResourceContent(DSCParser parser) throws IOException, DSCException {
+ StringBuffer sb = new StringBuffer();
+ while (parser.hasNext()) {
+ DSCEvent event = parser.nextEvent();
+ if (event.isLine()) {
+ sb.append(event.asLine().getLine()).append('\n');
+ } else if (event.isDSCComment()) {
+ if (DSCConstants.END_RESOURCE.equals(event.asDSCComment().getName())) {
+ break;
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+}