Hi, Change on Fill Rule (nonzero, evenodd) does not update the canvas, unless the point/coordinated of the element is changed then it will update the canvas
Here I attached the sample program to reproduce Here is the bug id: #26879 Best Regards Tonny Kohar -- Sketsa SVG Graphics Editor http://www.kiyut.com
<<attachment: bug_fill_rule.svg>>
/* * BugFillRule.java * * Created on April 29, 2004, 12:57 PM */ package kiyut.bug; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import org.apache.batik.dom.svg.*; import org.apache.batik.bridge.UpdateManager; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; import org.apache.batik.swing.gvt.GVTTreeRendererEvent; import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter; import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; import org.apache.batik.swing.svg.GVTTreeBuilderAdapter; import org.apache.batik.swing.svg.GVTTreeBuilderEvent; import org.apache.batik.util.*; import org.w3c.dom.*; import org.w3c.dom.css.*; import org.w3c.dom.svg.*; /** * * @author tonny */ public class BugFillRule { File file = null; SVGDocument doc; JSVGCanvas canvas; /** Creates a new instance of BugFillRule */ public BugFillRule(String[] args) { if (args[0] == null) { System.out.println("Please enter the svg filename as argument"); System.exit(1); } System.out.println(args[0]); file = new File(args[0]); } /** * @param args the command line arguments */ public static void main(String[] args) { BugFillRule bug = new BugFillRule(args); bug.run(); } public void run() { doc = loadSVGDocument(file); JFrame frame = createFrame(); frame.pack(); frame.setVisible(true); } public SVGDocument loadSVGDocument(File file) { try { String url = file.toURL().toString(); String parser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); SVGDocument svgDocument = f.createSVGDocument(url); return svgDocument; } catch (Exception e) { e.printStackTrace(); return null; } } private JFrame createFrame() { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { buttonActionPerformed(e); } }; JButton gradButton = new JButton("change fill rule"); gradButton.setActionCommand("change_fill_rule"); gradButton.addActionListener(actionListener); JButton rectButton = new JButton("force update"); rectButton.setActionCommand("force_update"); rectButton.addActionListener(actionListener); JPanel buttonPane = new JPanel(); buttonPane.add(gradButton); buttonPane.add(rectButton); canvas = new JSVGCanvas(); canvas.setPreferredSize(new Dimension(400,400)); canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); canvas.setDoubleBufferedRendering(true); canvas.setSVGDocument(doc); // Set the JSVGCanvas listeners. canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() { public void gvtBuildStarted(GVTTreeBuilderEvent e) { System.out.println("Build Started..."); } public void gvtBuildCompleted(GVTTreeBuilderEvent e) { System.out.println("Build Done."); } }); canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { public void gvtRenderingPrepare(GVTTreeRendererEvent e) { System.out.println("Rendering Started..."); } public void gvtRenderingCompleted(GVTTreeRendererEvent e) { System.out.println("Rendering Done."); } }); JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); contentPane.add(canvas,BorderLayout.CENTER); contentPane.add(buttonPane,BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.setContentPane(contentPane); return frame; } private void buttonActionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equalsIgnoreCase("change_fill_rule")) { Runnable runnable = new Runnable() { public void run() { SVGPathElement pathElt = (SVGPathElement)doc.getElementById("star01"); // here is the bug it is not updating canvas SVGStylable svgStylable = (SVGStylable)pathElt; CSSStyleDeclaration cssStyle = svgStylable.getStyle(); String attr = SVGConstants.SVG_FILL_RULE_ATTRIBUTE; String value = cssStyle.getPropertyValue(attr); String newValue; if (value.equalsIgnoreCase(SVGConstants.SVG_NON_ZERO_VALUE)) { newValue = SVGConstants.SVG_EVEN_ODD_VALUE; } else { newValue = SVGConstants.SVG_NON_ZERO_VALUE; } cssStyle.setProperty(attr,newValue, ""); System.out.println("fill rule current: " + value + " --> " + newValue); } }; UpdateManager um = canvas.getUpdateManager(); um.getUpdateRunnableQueue().invokeLater(runnable); canvas.repaint(); } else if (command.equalsIgnoreCase("force_update")) { // bug on batik, unless the point/coordinate of the element is changed, // fill rule won't update the canvas Runnable runnable = new Runnable() { public void run() { SVGPathElement pathElt = (SVGPathElement)doc.getElementById("star01"); SVGPathSegList segList = pathElt.getPathSegList(); SVGPathSeg pathSeg = segList.getItem(0); SVGPathSegMovetoAbs moveTo = (SVGPathSegMovetoAbs)pathSeg; moveTo.setX(moveTo.getX()+1); moveTo.setY(moveTo.getY()+1); } }; UpdateManager um = canvas.getUpdateManager(); um.getUpdateRunnableQueue().invokeLater(runnable); canvas.repaint(); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]