Hello,
I want to paint a SVG directly on a Graphics2D, without creating first a BufferedImage. Therefore I
used the GraphicsNodes paint()-method. But it doesn't work with SVGs using filter - the result looks ugly. Using the StaticRenderer instead works fine, but I don't want to use that. Why doesn't it work?
Here my SVG:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="500" viewBox="0 0 450 500">
<defs>
<filter id="dropShadow" filterUnits="objectBoundingBox" width="1.4" height="1.4">
<feGaussianBlur in="SourceAlpha" stdDeviation="4" />
<feOffset dx="4" dy="4" />
<feComponentTransfer result="shadow">
<feFuncA type="linear" slope=".5" intercept="0" />
</feComponentTransfer>
</filter>
</defs>
<rect x="0" y="0" width="100%" height="100%" style="fill:gold" />
<g style="font-size:128; text-anchor:middle;">
<text x="50%" y="35%" style="filter:url(#dropShadow)">Batik</text>
<text x="50%" y="35%" style="fill:rgb(172,20,20)">Batik</text>
</g>
</svg>
My code:
public class Test
{
public static void main(String[] args) {
new Test();
}
public Test() {
String url = "file:/mySVG.svg";
try {
loadDocument(url);
buildGVTTree();
} catch (Exception e) {
e.printStackTrace();
}
JFrame f = new JFrame("Batik");
JPanel p = new MyPanel();
f.getContentPane().add(p);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setSize(400, 400);
f.setVisible(true);
} protected void loadDocument(String url) throws IOException {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory fact = new SAXSVGDocumentFactory(parser);
doc = fact.createSVGDocument(url);
}
protected void buildGVTTree() {
UserAgent agent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(agent);
bridgeContext = new BridgeContext(agent, loader);
bridgeContext.setDynamicState(BridgeContext.DYNAMIC);
gvtRoot = new GVTBuilder().build(bridgeContext, doc);
} class MyPanel extends JPanel
{
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
if (gvtRoot != null) {
gvtRoot.paint(g2d);
}
}
}
private GraphicsNode gvtRoot;
private SVGDocument doc;
private BridgeContext bridgeContext;
}Thanks for helping me!
Stephan M�ller
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
