diff options
Diffstat (limited to 'test/java/org')
-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"; |