From eb8f9e82d215f6daae9a0702063b0ab86ef859b3 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Mon, 10 Aug 2015 12:13:36 +0000 Subject: [PATCH] FOP-2473: SVG text using filters not shown git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1695041 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/pdf/PDFImageHandlerSVG.java | 3 +- .../fop/render/ps/PSImageHandlerSVG.java | 15 ++++++++- .../fop/render/ps/ImageHandlingTestCase.java | 33 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java index fac9f4005..d2f05106f 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java @@ -49,6 +49,7 @@ import org.apache.fop.render.ImageHandler; import org.apache.fop.render.ImageHandlerUtil; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; +import org.apache.fop.render.ps.PSImageHandlerSVG; import org.apache.fop.svg.PDFAElementBridge; import org.apache.fop.svg.PDFBridgeContext; import org.apache.fop.svg.PDFGraphics2D; @@ -85,7 +86,7 @@ public class PDFImageHandlerSVG implements ImageHandler { GVTBuilder builder = new GVTBuilder(); //Controls whether text painted by Batik is generated using text or path operations - boolean strokeText = false; + boolean strokeText = PSImageHandlerSVG.shouldStrokeText(imageSVG.getDocument().getChildNodes()); //TODO connect with configuration elsewhere. BridgeContext ctx = new PDFBridgeContext(ua, diff --git a/src/java/org/apache/fop/render/ps/PSImageHandlerSVG.java b/src/java/org/apache/fop/render/ps/PSImageHandlerSVG.java index 6d277f2f0..c679d7d75 100644 --- a/src/java/org/apache/fop/render/ps/PSImageHandlerSVG.java +++ b/src/java/org/apache/fop/render/ps/PSImageHandlerSVG.java @@ -103,7 +103,7 @@ public class PSImageHandlerSVG implements ImageHandler { PSImageUtils.writeImage(encoder, imgDim, imgDescription, targetRect, cm, gen, ri, mi.getMaskColor()); } else { //Controls whether text painted by Batik is generated using text or path operations - boolean strokeText = false; + boolean strokeText = shouldStrokeText(imageSVG.getDocument().getChildNodes()); //TODO Configure text stroking SVGUserAgent ua = new SVGUserAgent(context.getUserAgent(), @@ -327,6 +327,19 @@ public class PSImageHandlerSVG implements ImageHandler { return opacityFound; } + public static boolean shouldStrokeText(NodeList childNodes) { + for (int i = 0; i < childNodes.getLength(); i++) { + Node curNode = childNodes.item(i); + if (shouldStrokeText(curNode.getChildNodes())) { + return true; + } + if ("text".equals(curNode.getLocalName())) { + return curNode.getAttributes().getNamedItem("filter") != null; + } + } + return false; + } + /** {@inheritDoc} */ public int getPriority() { return 400; diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java index 02e96806f..3c05e9ad7 100644 --- a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java +++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java @@ -18,18 +18,27 @@ /* $Id$ */ package org.apache.fop.render.ps; + +import java.awt.Rectangle; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import org.junit.Test; +import org.w3c.dom.Document; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.apache.commons.io.IOUtils; +import org.apache.batik.anim.dom.SAXSVGDocumentFactory; + +import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; import org.apache.xmlgraphics.ps.DSCConstants; +import org.apache.xmlgraphics.ps.PSGenerator; import org.apache.xmlgraphics.ps.PSResource; import org.apache.xmlgraphics.ps.dsc.DSCException; import org.apache.xmlgraphics.ps.dsc.DSCParser; @@ -39,6 +48,8 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCCommentTitle; import org.apache.xmlgraphics.ps.dsc.events.DSCEvent; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; +import org.apache.fop.fonts.FontInfo; import org.apache.fop.render.intermediate.IFContext; /** @@ -159,4 +170,26 @@ public class ImageHandlingTestCase extends AbstractPostScriptTest { return sb.toString(); } + @Test + public void testPSImageHandlerSVG() throws IOException { + FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent(); + String svg = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Hello SVG with FOP\n" + + ""; + SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(null); + Document doc = factory.createDocument(null, IOUtils.toInputStream(svg)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + new PSImageHandlerSVG().handleImage( + new PSRenderingContext(ua, new PSGenerator(bos), new FontInfo()), + new ImageXMLDOM(null, doc, ""), + new Rectangle()); + assertTrue(bos.toString().contains("/DataSource Data")); + } } -- 2.39.5