diff options
author | Jeremias Maerki <jeremias@apache.org> | 2008-01-25 08:26:54 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2008-01-25 08:26:54 +0000 |
commit | 8b281b7c15488402a4dd30d41c4d8e2359e92140 (patch) | |
tree | bd2dac64d3fe25c238ccbf6152c0ccbe8bcb21cc /test/java | |
parent | 4b75aa4cd571bb6d8bee5a6c6fe581e3b20618c4 (diff) | |
download | xmlgraphics-fop-8b281b7c15488402a4dd30d41c4d8e2359e92140.tar.gz xmlgraphics-fop-8b281b7c15488402a4dd30d41c4d8e2359e92140.zip |
Added support for DOMSource to Preloader SVG so a URI Resolver can be written that provides the SVG as a W3C SVG DOM.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@615144 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
-rw-r--r-- | test/java/org/apache/fop/image/loader/batik/ImagePreloaderTestCase.java | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/test/java/org/apache/fop/image/loader/batik/ImagePreloaderTestCase.java b/test/java/org/apache/fop/image/loader/batik/ImagePreloaderTestCase.java index b14dd1fb8..9406ed65c 100644 --- a/test/java/org/apache/fop/image/loader/batik/ImagePreloaderTestCase.java +++ b/test/java/org/apache/fop/image/loader/batik/ImagePreloaderTestCase.java @@ -21,8 +21,19 @@ package org.apache.fop.image.loader.batik; import java.io.IOException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; + import junit.framework.TestCase; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.batik.dom.svg.SVGDOMImplementation; + import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.ImageManager; @@ -30,7 +41,6 @@ import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.image.loader.batik.ImageWMF; /** * Tests for bundled image preloader implementations. @@ -89,6 +99,50 @@ public class ImagePreloaderTestCase extends TestCase { assertEquals(100000, info.getSize().getHeightMpt()); } + public void testSVGWithDOM() throws Exception { + String uri = "my:SVGImage"; + FOUserAgent userAgent = fopFactory.newFOUserAgent(); + + userAgent.setURIResolver(new URIResolver() { + + public Source resolve(String href, String base) throws TransformerException { + if (href.startsWith("my:")) { + DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); + String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; + Document doc = impl.createDocument(svgNS, "svg", null); + Element element = doc.getDocumentElement(); + element.setAttribute("viewBox", "0 0 20 20"); + element.setAttribute("width", "20pt"); + element.setAttribute("height", "20pt"); + + Element rect = doc.createElementNS(svgNS, "rect"); + rect.setAttribute("x", "5"); + rect.setAttribute("y", "5"); + rect.setAttribute("width", "10"); + rect.setAttribute("height", "10"); + element.appendChild(rect); + + DOMSource src = new DOMSource(doc); + return src; + } else { + return null; + } + } + + }); + + ImageManager manager = fopFactory.getImageManager(); + ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext()); + assertNotNull("ImageInfo must not be null", info); + assertEquals(MimeConstants.MIME_SVG, info.getMimeType()); + assertEquals(uri, info.getOriginalURI()); + assertEquals(20, info.getSize().getWidthPx()); //100 = default viewport size + assertEquals(20, info.getSize().getHeightPx()); + assertEquals(userAgent.getSourceResolution(), info.getSize().getDpiHorizontal(), 0.1); + assertEquals(20000, info.getSize().getWidthMpt()); + assertEquals(20000, info.getSize().getHeightMpt()); + } + public void testWMF() throws Exception { String uri = "test/resources/images/testChart.wmf"; |