diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2010-08-25 16:49:26 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2010-08-25 16:49:26 +0000 |
commit | 59fa281b045e517c5203151a120050d498a104d5 (patch) | |
tree | b1bc9141255ddf2b4565367828ca49b2c490064e /test/java/org/apache/fop | |
parent | 589c8ab356833617014977ab1a7a8ee6c181359a (diff) | |
parent | 26393f0e181ca1c71c83e594fa67cc7c26b49df3 (diff) | |
download | xmlgraphics-fop-59fa281b045e517c5203151a120050d498a104d5.tar.gz xmlgraphics-fop-59fa281b045e517c5203151a120050d498a104d5.zip |
Merged changes from Trunk up to revision 989178
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript@989216 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop')
26 files changed, 271 insertions, 316 deletions
diff --git a/test/java/org/apache/fop/GenericFOPTestCase.java b/test/java/org/apache/fop/GenericFOPTestCase.java index 26053cdad..5b51a34e1 100644 --- a/test/java/org/apache/fop/GenericFOPTestCase.java +++ b/test/java/org/apache/fop/GenericFOPTestCase.java @@ -31,12 +31,13 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.fop.apps.Fop; +import org.xml.sax.InputSource; + 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.util.DigestFilter; -import org.xml.sax.InputSource; /** * Framework for simple regression testing. @@ -76,8 +77,8 @@ public final class GenericFOPTestCase extends TestCase { public void testSimple() throws Exception { final String digestIn = "17bf13298796065f7775db8707133aeb"; final String digestOut = "e2761f51152f6663911e567901596707"; - final String fo = - "<fo:root xmlns:fo='http://www.w3.org/1999/XSL/Format'>" + final String fo + = "<fo:root xmlns:fo='http://www.w3.org/1999/XSL/Format'>" + " <fo:layout-master-set>" + " <fo:simple-page-master master-name='simple'" + " page-height='25cm' page-width='20cm'>" @@ -118,8 +119,8 @@ public final class GenericFOPTestCase extends TestCase { FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); foUserAgent.setCreationDate(new Date(10000)); MessageDigest outDigest = MessageDigest.getInstance("MD5"); - DigestOutputStream out = - new DigestOutputStream(new ByteArrayOutputStream(), outDigest); + DigestOutputStream out + = new DigestOutputStream(new ByteArrayOutputStream(), outDigest); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); InputSource source = new InputSource(new StringReader(fo)); DigestFilter filter = new DigestFilter("MD5"); diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index 281301789..caf75b4b4 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -23,7 +23,6 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.apache.fop.fonts.DejaVuLGCSerifTest; -import org.apache.fop.fonts.TrueTypeAnsiTestCase; import org.apache.fop.image.loader.batik.ImageLoaderTestCase; import org.apache.fop.image.loader.batik.ImagePreloaderTestCase; import org.apache.fop.intermediate.IFMimickingTestCase; @@ -54,7 +53,6 @@ public class StandardTestSuite { suite.addTest(new TestSuite(PDFEncodingTestCase.class)); suite.addTest(new TestSuite(PDFCMapTestCase.class)); suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class)); - suite.addTest(new TestSuite(TrueTypeAnsiTestCase.class)); suite.addTest(new TestSuite(DejaVuLGCSerifTest.class)); suite.addTest(RichTextFormatTestSuite.suite()); suite.addTest(new TestSuite(ImageLoaderTestCase.class)); diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index fd4f879da..0a197722b 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -92,7 +92,7 @@ public class URIResolutionTestCase extends AbstractFOPTestCase { MyURIResolver resolver = new MyURIResolver(withStream); ua.setURIResolver(resolver); - ua.setBaseURL(foFile.getParentFile().toURL().toString()); + ua.setBaseURL(foFile.getParentFile().toURI().toURL().toString()); Document doc = createAreaTree(foFile, ua); @@ -119,7 +119,7 @@ public class URIResolutionTestCase extends AbstractFOPTestCase { FOUserAgent ua = fopFactory.newFOUserAgent(); MyURIResolver resolver = new MyURIResolver(false); ua.setURIResolver(resolver); - ua.setBaseURL(foFile.getParentFile().toURL().toString()); + ua.setBaseURL(foFile.getParentFile().toURI().toURL().toString()); ByteArrayOutputStream baout = new ByteArrayOutputStream(); diff --git a/test/java/org/apache/fop/config/BaseUserConfigTestCase.java b/test/java/org/apache/fop/config/BaseUserConfigTestCase.java index 5c803317e..6ce833312 100644 --- a/test/java/org/apache/fop/config/BaseUserConfigTestCase.java +++ b/test/java/org/apache/fop/config/BaseUserConfigTestCase.java @@ -100,7 +100,7 @@ public abstract class BaseUserConfigTestCase extends BasePDFTestCase { /** * @return user config File */ - abstract protected String getUserConfigFilename(); + protected abstract String getUserConfigFilename(); /* * @see junit.framework.TestCase#getName() diff --git a/test/java/org/apache/fop/events/EventChecker.java b/test/java/org/apache/fop/events/EventChecker.java index 767c590ed..afef11d87 100644 --- a/test/java/org/apache/fop/events/EventChecker.java +++ b/test/java/org/apache/fop/events/EventChecker.java @@ -40,7 +40,7 @@ class EventChecker extends Assert implements EventListener { if (event.getEventID().equals(expectedEventID)) { eventReceived = true; } else { - fail("Unexpected event: id = " + event.getEventID() + ": "+ msg); + fail("Unexpected event: id = " + event.getEventID() + ": " + msg); } } diff --git a/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java b/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java deleted file mode 100644 index 3f98c93f4..000000000 --- a/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.fonts; - -import java.io.File; -import java.io.OutputStream; -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.xml.transform.Result; -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.output.NullOutputStream; - -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.apps.Fop; -import org.apache.fop.apps.FopFactory; -import org.apache.fop.fonts.apps.TTFReader; -import org.apache.fop.render.pdf.PDFRenderer; - -/** - * Tests XML font metrics file generation and usage for WinAnsi mode. - */ -public class TrueTypeAnsiTestCase extends TestCase { - - /** - * Tests a TrueType font in WinAnsi mode. - * @throws Exception if an error occurs - */ - public void testTrueTypeAnsi() throws Exception { - String fontFamily = "Gladiator Bold"; - File ttfFile = new File("./test/resources/fonts/glb12.ttf"); - File workDir = new File("./build/test-results"); - if (!workDir.isDirectory()) { - assertTrue(workDir.mkdirs()); - } - File metricsFile = new File(workDir, ttfFile.getName() + ".xml"); - if (metricsFile.isFile()) { - assertTrue(metricsFile.delete()); - } - - String[] args = new String[] {"-enc", "ansi", - ttfFile.getCanonicalPath(), metricsFile.getCanonicalPath()}; - TTFReader.main(args); - assertTrue(metricsFile.isFile()); - - FopFactory fopFactory = FopFactory.newInstance(); - FOUserAgent ua = fopFactory.newFOUserAgent(); - PDFRenderer renderer = new PDFRenderer(); - renderer.setUserAgent(ua); - List fontList = new java.util.ArrayList(); - List triplets = new java.util.ArrayList(); - triplets.add(new FontTriplet(fontFamily, "normal", Font.WEIGHT_NORMAL)); - EmbedFontInfo font = new EmbedFontInfo( - metricsFile.toURI().toASCIIString(), - true, triplets, - ttfFile.toURI().toASCIIString(), null); - fontList.add(font); - renderer.addFontList(fontList); - - ua.setRendererOverride(renderer); - OutputStream out = new NullOutputStream(); - - Fop fop = fopFactory.newFop(null, ua, out); - - TransformerFactory tFactory = TransformerFactory.newInstance(); - Source src = new StreamSource(new StringReader( - "<root font-family='" + fontFamily + "'>Test!</root>")); - Result res = new SAXResult(fop.getDefaultHandler()); - Transformer transformer = tFactory.newTransformer( - getSourceForResource(this, "fonttest.xsl")); - transformer.transform(src, res); - } - - private static Source getSourceForResource(Object reference, String name) { - URL url = reference.getClass().getResource(name); - if (url == null) { - throw new NullPointerException("Resource not found: " + name); - } - return new StreamSource(url.toExternalForm()); - } - -} diff --git a/test/java/org/apache/fop/fonts/fonttest.xsl b/test/java/org/apache/fop/fonts/fonttest.xsl deleted file mode 100644 index 26c7d72a5..000000000 --- a/test/java/org/apache/fop/fonts/fonttest.xsl +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - xmlns:fo="http://www.w3.org/1999/XSL/Format"> - - <xsl:output method="xml" indent="yes"/> - - <xsl:template match="root"> - <fo:root> - <fo:layout-master-set> - <fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm" - margin="2cm"> - <fo:region-body/> - </fo:simple-page-master> - </fo:layout-master-set> - <fo:page-sequence master-reference="A4"> - <fo:flow flow-name="xsl-region-body"> - <fo:block font-family="{@font-family}"> - <xsl:value-of select="."/> - </fo:block> - </fo:flow> - </fo:page-sequence> - </fo:root> - </xsl:template> -</xsl:stylesheet> diff --git a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java index bfe9018b1..5513a89ab 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java @@ -94,6 +94,6 @@ public abstract class FOTreeUnitTester extends TestCase { foReader.setErrorHandler(fop.getDefaultHandler()); foReader.setEntityResolver(fop.getDefaultHandler()); - foReader.parse(new File("test/fotree/unittests/" + filename).toURL().toExternalForm()); + foReader.parse(new File("test/fotree/unittests/" + filename).toURI().toURL().toExternalForm()); } } diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java index d938a852b..2c0cf8504 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java @@ -116,7 +116,7 @@ public class LayoutEngineTester { //Setup FOP for area tree rendering FOUserAgent ua = effFactory.newFOUserAgent(); - ua.setBaseURL(testFile.getParentFile().toURL().toString()); + ua.setBaseURL(testFile.getParentFile().toURI().toURL().toString()); ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); diff --git a/test/java/org/apache/fop/memory/MemoryEater.java b/test/java/org/apache/fop/memory/MemoryEater.java index a665580ae..337027dc4 100644 --- a/test/java/org/apache/fop/memory/MemoryEater.java +++ b/test/java/org/apache/fop/memory/MemoryEater.java @@ -79,7 +79,7 @@ public class MemoryEater { OutputStream out = new NullOutputStream(); //write to /dev/nul try { FOUserAgent userAgent = fopFactory.newFOUserAgent(); - userAgent.setBaseURL(foFile.getParentFile().toURL().toExternalForm()); + userAgent.setBaseURL(foFile.getParentFile().toURI().toURL().toExternalForm()); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out); Result res = new SAXResult(fop.getDefaultHandler()); diff --git a/test/java/org/apache/fop/memory/Stats.java b/test/java/org/apache/fop/memory/Stats.java index 9e371251d..354952347 100644 --- a/test/java/org/apache/fop/memory/Stats.java +++ b/test/java/org/apache/fop/memory/Stats.java @@ -71,7 +71,7 @@ class Stats { public void dumpFinalStats() { long duration = System.currentTimeMillis() - startTime; System.out.println("Final statistics"); - System.out.println("Pages produced: " +totalPagesProduced); + System.out.println("Pages produced: " + totalPagesProduced); long ppm = 60000 * totalPagesProduced / duration; System.out.println("Average speed: " + ppm + "ppm"); } diff --git a/test/java/org/apache/fop/render/RendererFactoryTest.java b/test/java/org/apache/fop/render/RendererFactoryTest.java index 4a40ac7c1..6b8e8f5f3 100644 --- a/test/java/org/apache/fop/render/RendererFactoryTest.java +++ b/test/java/org/apache/fop/render/RendererFactoryTest.java @@ -33,7 +33,6 @@ import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFDocumentHandler; import org.apache.fop.render.intermediate.IFRenderer; import org.apache.fop.render.pdf.PDFDocumentHandler; -import org.apache.fop.render.pdf.PDFRenderer; import org.apache.fop.render.rtf.RTFHandler; /** @@ -73,29 +72,15 @@ public class RendererFactoryTest extends TestCase { RendererFactory factory = fopFactory.getRendererFactory(); FOUserAgent ua; Renderer renderer; - Renderer overrideRenderer; ua = fopFactory.newFOUserAgent(); renderer = factory.createRenderer(ua, MimeConstants.MIME_PDF); assertTrue(renderer instanceof IFRenderer); - factory.setRendererPreferred(true); //Test legacy setting - ua = fopFactory.newFOUserAgent(); - renderer = factory.createRenderer(ua, MimeConstants.MIME_PDF); - assertTrue(renderer instanceof PDFRenderer); - ua = fopFactory.newFOUserAgent(); renderer = factory.createRenderer(ua, MimeConstants.MIME_FOP_IF); assertTrue(renderer instanceof IFRenderer); - factory.setRendererPreferred(false); - ua = fopFactory.newFOUserAgent(); - overrideRenderer = new PDFRenderer(); - overrideRenderer.setUserAgent(ua); - ua.setRendererOverride(overrideRenderer); - renderer = factory.createRenderer(ua, null); - assertTrue(renderer == overrideRenderer); - ua = fopFactory.newFOUserAgent(); IFDocumentHandler overrideHandler; overrideHandler = new PDFDocumentHandler(); diff --git a/test/java/org/apache/fop/render/pdf/PDFCMapTestCase.java b/test/java/org/apache/fop/render/pdf/PDFCMapTestCase.java index f5d2f84cf..bd5c8ade1 100644 --- a/test/java/org/apache/fop/render/pdf/PDFCMapTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFCMapTestCase.java @@ -27,38 +27,38 @@ import org.apache.fop.pdf.CMapBuilder; /** Simple sanity test of the PDFCmap class */ public class PDFCMapTestCase extends TestCase { + private static final String EOL = "\n"; public void testPDFCMapFillInPDF() throws Exception { - final String EOL = "\n"; - final String expected = - "%!PS-Adobe-3.0 Resource-CMap" + EOL - +"%%DocumentNeededResources: ProcSet (CIDInit)" + EOL - +"%%IncludeResource: ProcSet (CIDInit)" + EOL - +"%%BeginResource: CMap (test)" + EOL - +"%%EndComments" + EOL - +"/CIDInit /ProcSet findresource begin" + EOL - +"12 dict begin" + EOL - +"begincmap" + EOL - +"/CIDSystemInfo 3 dict dup begin" + EOL - +" /Registry (Adobe) def" + EOL - +" /Ordering (Identity) def" + EOL - +" /Supplement 0 def" + EOL - +"end def" + EOL - +"/CMapVersion 1 def" + EOL - +"/CMapType 1 def" + EOL - +"/CMapName /test def" + EOL - +"1 begincodespacerange" + EOL - +"<0000> <FFFF>" + EOL - +"endcodespacerange" + EOL - +"1 begincidrange" + EOL - +"<0000> <FFFF> 0" + EOL - +"endcidrange" + EOL - +"endcmap" + EOL - +"CMapName currentdict /CMap defineresource pop" + EOL - +"end" + EOL - +"end" + EOL - +"%%EndResource" + EOL - +"%%EOF" + EOL + final String expected + = "%!PS-Adobe-3.0 Resource-CMap" + EOL + + "%%DocumentNeededResources: ProcSet (CIDInit)" + EOL + + "%%IncludeResource: ProcSet (CIDInit)" + EOL + + "%%BeginResource: CMap (test)" + EOL + + "%%EndComments" + EOL + + "/CIDInit /ProcSet findresource begin" + EOL + + "12 dict begin" + EOL + + "begincmap" + EOL + + "/CIDSystemInfo 3 dict dup begin" + EOL + + " /Registry (Adobe) def" + EOL + + " /Ordering (Identity) def" + EOL + + " /Supplement 0 def" + EOL + + "end def" + EOL + + "/CMapVersion 1 def" + EOL + + "/CMapType 1 def" + EOL + + "/CMapName /test def" + EOL + + "1 begincodespacerange" + EOL + + "<0000> <FFFF>" + EOL + + "endcodespacerange" + EOL + + "1 begincidrange" + EOL + + "<0000> <FFFF> 0" + EOL + + "endcidrange" + EOL + + "endcmap" + EOL + + "CMapName currentdict /CMap defineresource pop" + EOL + + "end" + EOL + + "end" + EOL + + "%%EndResource" + EOL + + "%%EOF" + EOL ; final StringWriter w = new StringWriter(); diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java index 7f0462a75..72c677a0c 100644 --- a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java +++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java @@ -43,52 +43,22 @@ import org.apache.fop.render.intermediate.IFContext; public class ImageHandlingTestCase extends AbstractPostScriptTestCase { /** - * Tests JPEG handling with the {@link PSRenderer}. + * Tests JPEG handling. * @throws Exception if an error occurs */ - public void testJPEGImageWithRendererLevel3() throws Exception { - innerTestJPEGImageWithRenderer(3); + public void testJPEGImageLevel3() throws Exception { + innerTestJPEGImage(3); } /** - * Tests JPEG handling with the {@link PSRenderer}. + * Tests JPEG handling. * @throws Exception if an error occurs */ - public void testJPEGImageWithRendererLevel2() throws Exception { - innerTestJPEGImageWithRenderer(2); + public void testJPEGImageLevel2() throws Exception { + innerTestJPEGImage(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 { + private void innerTestJPEGImage(int level) throws Exception { FOUserAgent ua = fopFactory.newFOUserAgent(); PSDocumentHandler handler = new PSDocumentHandler(); handler.setContext(new IFContext(ua)); @@ -159,10 +129,6 @@ public class ImageHandlingTestCase extends AbstractPostScriptTestCase { } } - 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); } diff --git a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java index e5b9a4d27..862ad5205 100644 --- a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java +++ b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java @@ -54,28 +54,10 @@ import org.apache.fop.render.intermediate.IFContext; public class ResourceOptimizationTestCase extends AbstractPostScriptTestCase { /** - * Tests resource optimization with the {@link PSRenderer}. + * Tests resource optimization. * @throws Exception if an error occurs */ - public void testResourceOptimizationWithRenderer() throws Exception { - FOUserAgent ua = fopFactory.newFOUserAgent(); - PSRenderer renderer = new PSRenderer(); - renderer.setUserAgent(ua); - // This is the important part: we're enabling resource optimization - renderer.getPSUtil().setOptimizeResources(true); - ua.setRendererOverride(renderer); - - // Prepare output file - File outputFile = renderFile(ua, "ps-resources.fo", - "-rend-l" + renderer.getPSUtil().getLanguageLevel()); - verifyPostScriptFile(outputFile); - } - - /** - * Tests resource optimization with the {@link PSDocumentHandler}. - * @throws Exception if an error occurs - */ - public void testResourceOptimizationWithIF() throws Exception { + public void testResourceOptimization() throws Exception { FOUserAgent ua = fopFactory.newFOUserAgent(); PSDocumentHandler handler = new PSDocumentHandler(); handler.setContext(new IFContext(ua)); diff --git a/test/java/org/apache/fop/threading/AvalonAdapter.java b/test/java/org/apache/fop/threading/AvalonAdapter.java new file mode 100644 index 000000000..bfe0a5010 --- /dev/null +++ b/test/java/org/apache/fop/threading/AvalonAdapter.java @@ -0,0 +1,58 @@ +/* + * 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.threading; + +import org.apache.avalon.framework.logger.Logger; + +import org.apache.fop.events.Event; +import org.apache.fop.events.EventFormatter; +import org.apache.fop.events.EventListener; +import org.apache.fop.events.model.EventSeverity; + +/** + * Redirects events to an Avalon logger. + */ +class AvalonAdapter implements EventListener { + + private final Logger logger; + private String filename; + + public AvalonAdapter(Logger logger, String filename) { + this.logger = logger; + this.filename = filename; + } + + public void processEvent(Event event) { + String msg = EventFormatter.format(event); + EventSeverity severity = event.getSeverity(); + if (severity == EventSeverity.INFO) { + //logger.info(filename + ": " + msg); + } else if (severity == EventSeverity.WARN) { + //logger.warn(filename + ": " + msg); + } else if (severity == EventSeverity.ERROR) { + logger.error(filename + ": " + msg); + } else if (severity == EventSeverity.FATAL) { + logger.fatalError(filename + ": " + msg); + } else { + assert false; + } + } + +}
\ No newline at end of file diff --git a/test/java/org/apache/fop/threading/FOPTestbed.java b/test/java/org/apache/fop/threading/FOPTestbed.java index 737317bec..8424260a9 100644 --- a/test/java/org/apache/fop/threading/FOPTestbed.java +++ b/test/java/org/apache/fop/threading/FOPTestbed.java @@ -56,7 +56,7 @@ public class FOPTestbed extends AbstractLogEnabled private int threads; private File outputDir; private Configuration fopCfg; - private FOProcessor foprocessor; + private Processor foprocessor; private boolean writeToDevNull; private int counter = 0; @@ -74,7 +74,7 @@ public class FOPTestbed extends AbstractLogEnabled for (int i = 0; i < entries.length; i++) { this.taskList.add(new TaskDef(entries[i])); } - this.fopCfg = configuration.getChild("foprocessor"); + this.fopCfg = configuration.getChild("processor"); } /** {@inheritDoc} */ @@ -177,11 +177,11 @@ public class FOPTestbed extends AbstractLogEnabled * Creates a new FOProcessor. * @return the newly created instance */ - public FOProcessor createFOProcessor() { + public Processor createFOProcessor() { try { Class clazz = Class.forName(this.fopCfg.getAttribute("class", "org.apache.fop.threading.FOProcessorImpl")); - FOProcessor fop = (FOProcessor)clazz.newInstance(); + Processor fop = (Processor)clazz.newInstance(); ContainerUtil.enableLogging(fop, getLogger()); ContainerUtil.configure(fop, this.fopCfg); ContainerUtil.initialize(fop); @@ -206,13 +206,15 @@ public class FOPTestbed extends AbstractLogEnabled this.fo = cfg.getAttribute("fo", null); if (this.fo == null) { this.xml = cfg.getAttribute("xml"); - this.xslt = cfg.getAttribute("xslt"); - TransformerFactory factory = TransformerFactory.newInstance(); - Source xsltSource = new StreamSource(new File(xslt)); - try { - this.templates = factory.newTemplates(xsltSource); - } catch (TransformerConfigurationException tce) { - throw new ConfigurationException("Invalid XSLT", tce); + this.xslt = cfg.getAttribute("xslt", null); + if (this.xslt != null) { + TransformerFactory factory = TransformerFactory.newInstance(); + Source xsltSource = new StreamSource(new File(xslt)); + try { + this.templates = factory.newTemplates(xsltSource); + } catch (TransformerConfigurationException tce) { + throw new ConfigurationException("Invalid XSLT", tce); + } } } } @@ -249,9 +251,9 @@ public class FOPTestbed extends AbstractLogEnabled private TaskDef def; private int num; - private FOProcessor fop; + private Processor fop; - public Task(TaskDef def, int num, FOProcessor fop) { + public Task(TaskDef def, int num, Processor fop) { this.def = def; this.num = num; this.fop = fop; diff --git a/test/java/org/apache/fop/threading/FOProcessorImpl.java b/test/java/org/apache/fop/threading/FOProcessorImpl.java index 2b580bbd0..3702d87e7 100644 --- a/test/java/org/apache/fop/threading/FOProcessorImpl.java +++ b/test/java/org/apache/fop/threading/FOProcessorImpl.java @@ -43,16 +43,12 @@ 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.events.Event; -import org.apache.fop.events.EventFormatter; -import org.apache.fop.events.EventListener; -import org.apache.fop.events.model.EventSeverity; /** - * Default implementation of the FOProcessor interface using FOP. + * Default implementation of the {@link Processor} interface using FOP. */ public class FOProcessorImpl extends AbstractLogEnabled - implements FOProcessor, Configurable, Initializable { + implements Processor, Configurable, Initializable { private FopFactory fopFactory = FopFactory.newInstance(); private TransformerFactory factory = TransformerFactory.newInstance(); @@ -83,7 +79,8 @@ public class FOProcessorImpl extends AbstractLogEnabled try { URL url = new URL(src.getSystemId()); String filename = FilenameUtils.getName(url.getPath()); - foUserAgent.getEventBroadcaster().addEventListener(new AvalonAdapter(filename)); + foUserAgent.getEventBroadcaster().addEventListener( + new AvalonAdapter(getLogger(), filename)); } catch (MalformedURLException mfue) { throw new RuntimeException(mfue); } @@ -107,30 +104,4 @@ public class FOProcessorImpl extends AbstractLogEnabled public String getTargetFileExtension() { return this.fileExtension; } - - private class AvalonAdapter implements EventListener { - - private String filename; - - public AvalonAdapter(String filename) { - this.filename = filename; - } - - public void processEvent(Event event) { - String msg = EventFormatter.format(event); - EventSeverity severity = event.getSeverity(); - if (severity == EventSeverity.INFO) { - //getLogger().info(filename + ": " + msg); - } else if (severity == EventSeverity.WARN) { - //getLogger().warn(filename + ": " + msg); - } else if (severity == EventSeverity.ERROR) { - getLogger().error(filename + ": " + msg); - } else if (severity == EventSeverity.FATAL) { - getLogger().fatalError(filename + ": " + msg); - } else { - assert false; - } - } - - } }
\ No newline at end of file diff --git a/test/java/org/apache/fop/threading/IFProcessorImpl.java b/test/java/org/apache/fop/threading/IFProcessorImpl.java new file mode 100644 index 000000000..34873d76b --- /dev/null +++ b/test/java/org/apache/fop/threading/IFProcessorImpl.java @@ -0,0 +1,124 @@ +/* + * 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.threading; + +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.stream.StreamResult; + +import org.xml.sax.ContentHandler; + +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.configuration.Configurable; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.commons.io.FilenameUtils; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; +import org.apache.fop.apps.MimeConstants; +import org.apache.fop.render.intermediate.IFDocumentHandler; +import org.apache.fop.render.intermediate.IFException; +import org.apache.fop.render.intermediate.IFParser; +import org.apache.fop.render.intermediate.IFUtil; + +/** + * Implementation of the {@link Processor} interface that renders IF XML to a final output format. + */ +public class IFProcessorImpl extends AbstractLogEnabled + implements Processor, Configurable, Initializable { + + private FopFactory fopFactory = FopFactory.newInstance(); + private TransformerFactory factory = TransformerFactory.newInstance(); + private String userconfig; + private String mime; + private String fileExtension; + + /** {@inheritDoc} */ + public void configure(Configuration configuration) throws ConfigurationException { + this.userconfig = configuration.getChild("userconfig").getValue(null); + this.mime = configuration.getChild("mime").getValue(MimeConstants.MIME_PDF); + this.fileExtension = configuration.getChild("extension").getValue(".pdf"); + } + + /** {@inheritDoc} */ + public void initialize() throws Exception { + if (this.userconfig != null) { + getLogger().debug("Setting user config: " + userconfig); + fopFactory.setUserConfig(this.userconfig); + } + } + + /** {@inheritDoc} + * @throws IFException */ + public void process(Source src, Templates templates, OutputStream out) + throws org.apache.fop.apps.FOPException, java.io.IOException, IFException { + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); + foUserAgent.setBaseURL(src.getSystemId()); + try { + URL url = new URL(src.getSystemId()); + String filename = FilenameUtils.getName(url.getPath()); + foUserAgent.getEventBroadcaster().addEventListener( + new AvalonAdapter(getLogger(), filename)); + } catch (MalformedURLException mfue) { + throw new RuntimeException(mfue); + } + + //Setup target handler + IFDocumentHandler targetHandler = fopFactory.getRendererFactory().createDocumentHandler( + foUserAgent, mime); + + //Setup fonts + IFUtil.setupFonts(targetHandler); + targetHandler.setResult(new StreamResult(out)); + + try { + Transformer transformer; + if (templates == null) { + transformer = factory.newTransformer(); + } else { + transformer = templates.newTransformer(); + } + IFParser parser = new IFParser(); + ContentHandler contentHandler = parser.getContentHandler(targetHandler, foUserAgent); + Result res = new SAXResult(contentHandler); + transformer.transform(src, res); + } catch (TransformerException e) { + throw new FOPException(e); + } + } + + /** {@inheritDoc} */ + public String getTargetFileExtension() { + return this.fileExtension; + } + +}
\ No newline at end of file diff --git a/test/java/org/apache/fop/threading/FOProcessor.java b/test/java/org/apache/fop/threading/Processor.java index dd663da05..9c86fc382 100644 --- a/test/java/org/apache/fop/threading/FOProcessor.java +++ b/test/java/org/apache/fop/threading/Processor.java @@ -25,9 +25,9 @@ import javax.xml.transform.Source; import javax.xml.transform.Templates; /** - * Represents an FO processor. + * Represents a processor. */ -public interface FOProcessor { +public interface Processor { /** * Process a file. diff --git a/test/java/org/apache/fop/threading/sample.cfg.xml b/test/java/org/apache/fop/threading/sample.cfg.xml index 0be7dc539..a4de0d754 100644 --- a/test/java/org/apache/fop/threading/sample.cfg.xml +++ b/test/java/org/apache/fop/threading/sample.cfg.xml @@ -2,13 +2,13 @@ <config prompt="false"> <threads>2</threads> <output-dir>C:/Dev/FOP/temp/out</output-dir> - <foprocessor class="org.apache.fop.threading.FOProcessorImpl"> + <processor class="org.apache.fop.threading.FOProcessorImpl"> <!-- <userconfig>C:/Dev/FOP/temp/userconfig.xml</userconfig> --> <mime>application/pdf</mime> <extension>.pdf</extension> - </foprocessor> + </processor> <tasks repeat="2"> <task fo="C:/Dev/FOP/temp/helloworld.fo"/> <task xml="C:/Dev/FOP/temp/page-x-of-y.xml" xslt="C:/Dev/FOP/temp/page-x-of-y.xsl"/> diff --git a/test/java/org/apache/fop/traits/BorderPropsTestCase.java b/test/java/org/apache/fop/traits/BorderPropsTestCase.java index 3332d11f2..be7714ba2 100644 --- a/test/java/org/apache/fop/traits/BorderPropsTestCase.java +++ b/test/java/org/apache/fop/traits/BorderPropsTestCase.java @@ -23,10 +23,10 @@ import java.awt.Color; import junit.framework.TestCase; -import org.apache.xmlgraphics.java2d.color.CMYKColorSpace; -import org.apache.xmlgraphics.java2d.color.ColorExt; +import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; import org.apache.fop.fo.Constants; +import org.apache.fop.util.ColorExt; import org.apache.fop.util.ColorUtil; /** @@ -50,7 +50,7 @@ public class BorderPropsTestCase extends TestCase { assertEquals(b1, b2); float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f}; - CMYKColorSpace cmykCs = CMYKColorSpace.getInstance(); + DeviceCMYKColorSpace cmykCs = DeviceCMYKColorSpace.getInstance(); float[] rgb = cmykCs.toRGB(cmyk); col = ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2], "#CMYK", null, cmykCs, cmyk); diff --git a/test/java/org/apache/fop/util/ColorUtilTestCase.java b/test/java/org/apache/fop/util/ColorUtilTestCase.java index 83163c888..aefd2a76a 100644 --- a/test/java/org/apache/fop/util/ColorUtilTestCase.java +++ b/test/java/org/apache/fop/util/ColorUtilTestCase.java @@ -24,8 +24,7 @@ import java.awt.color.ColorSpace; import junit.framework.TestCase; -import org.apache.xmlgraphics.java2d.color.CMYKColorSpace; -import org.apache.xmlgraphics.java2d.color.ColorExt; +import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; @@ -157,7 +156,7 @@ public class ColorUtilTestCase extends TestCase { assertEquals(255, colActual.getRed()); assertEquals(255, colActual.getGreen()); assertEquals(0, colActual.getBlue()); - assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace()); + assertEquals(DeviceCMYKColorSpace.getInstance(), colActual.getColorSpace()); float[] comps = colActual.getColorComponents(null); assertEquals(4, comps.length); assertEquals(0f, comps[0], 0); @@ -172,7 +171,7 @@ public class ColorUtilTestCase extends TestCase { assertEquals(248, colActual.getRed()); assertEquals(199, colActual.getGreen()); assertEquals(172, colActual.getBlue()); - assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace()); + assertEquals(DeviceCMYKColorSpace.getInstance(), colActual.getColorSpace()); comps = colActual.getColorComponents(null); assertEquals(0.0274f, comps[0], 0.001); assertEquals(0.2196f, comps[1], 0.001); @@ -186,7 +185,7 @@ public class ColorUtilTestCase extends TestCase { assertEquals(255, colActual.getRed()); assertEquals(255, colActual.getGreen()); assertEquals(0, colActual.getBlue()); - assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace()); + assertEquals(DeviceCMYKColorSpace.getInstance(), colActual.getColorSpace()); comps = colActual.getColorComponents(null); assertEquals(4, comps.length); assertEquals(0f, comps[0], 0); @@ -201,7 +200,7 @@ public class ColorUtilTestCase extends TestCase { assertEquals(127, colActual.getRed()); assertEquals(127, colActual.getGreen()); assertEquals(127, colActual.getBlue()); - assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace()); + assertEquals(DeviceCMYKColorSpace.getInstance(), colActual.getColorSpace()); comps = colActual.getColorComponents(null); assertEquals(4, comps.length); assertEquals(0f, comps[0], 0); diff --git a/test/java/org/apache/fop/util/DigestFilter.java b/test/java/org/apache/fop/util/DigestFilter.java index 0384b42df..94e8d67d2 100644 --- a/test/java/org/apache/fop/util/DigestFilter.java +++ b/test/java/org/apache/fop/util/DigestFilter.java @@ -43,7 +43,7 @@ import org.xml.sax.helpers.XMLFilterImpl; public class DigestFilter extends XMLFilterImpl { private MessageDigest digest; - private byte value[]; + private byte[] value; private boolean isNamespaceAware; public DigestFilter(String algorithm) throws NoSuchAlgorithmException { @@ -133,7 +133,7 @@ public class DigestFilter extends XMLFilterImpl { */ public void setFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { - if(feature.equals("http://xml.org/sax/features/namespaces")) { + if (feature.equals("http://xml.org/sax/features/namespaces")) { isNamespaceAware = value; } super.setFeature(feature, value); diff --git a/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java b/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java index 0d976219d..678e80e7d 100644 --- a/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java +++ b/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java @@ -122,7 +122,7 @@ public abstract class AbstractPSPDFBitmapProducer extends AbstractBitmapProducer try { FOUserAgent userAgent = fopFactory.newFOUserAgent(); userAgent.setTargetResolution(context.getTargetResolution()); - userAgent.setBaseURL(src.getParentFile().toURL().toString()); + userAgent.setBaseURL(src.getParentFile().toURI().toURL().toString()); File tempOut = new File(context.getTargetDir(), src.getName() + "." + index + "." + getTargetExtension()); diff --git a/test/java/org/apache/fop/visual/BitmapProducerJava2D.java b/test/java/org/apache/fop/visual/BitmapProducerJava2D.java index bd78fd93f..997a75931 100644 --- a/test/java/org/apache/fop/visual/BitmapProducerJava2D.java +++ b/test/java/org/apache/fop/visual/BitmapProducerJava2D.java @@ -70,7 +70,7 @@ public class BitmapProducerJava2D extends AbstractBitmapProducer implements Conf try { FOUserAgent userAgent = fopFactory.newFOUserAgent(); userAgent.setTargetResolution(context.getTargetResolution()); - userAgent.setBaseURL(src.getParentFile().toURL().toString()); + userAgent.setBaseURL(src.getParentFile().toURI().toURL().toString()); File outputFile = new File(context.getTargetDir(), src.getName() + "." + index + ".java2d.png"); |