In my continuing series...
On Sep 21, 2006, at 13:16 , [EMAIL PROTECTED] wrote:
I would avoid 'setComputedStyleMap' you should be able to use
SVGStylable.getStyle().setProperty(String prop, String val, String
priority)
It took me a while to get this to work: I had to manually force a
CSSEngine to my parsed SVGDocument, otherwise Batik throws an NPE.
Can anyone point out what goes wrong in the following? (The following
is just a synopsis of my code, as always, but checked for consistency
with the actual implementation.)
// 1. Load a document; docReader is provided and gives us a
valid SVG document.
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory
( parser );
factory.setValidating( false );
// *) See commentary below
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
SVGDocument doc = factory.createSVGDocument( svgNS,
docReader );
// 2. Locate an element and modify CSS.
Element knownStylable = doc.getElementById
( "element_with_style" );
CSSStyleDeclaration styles = ((SVGStylable)
knownStylable).getStyle();
styles.setProperty( CSSConstants.CSS_DISPLAY_PROPERTY,
CSSConstants.CSS_NONE_VALUE, "" );
Done like this, the last line causes an NPE to be thrown; the
CSSEngine of the document is null. (I can compile Batik with debug
and check the exact location, if required.)
Is there something obvious I'm missing when I assume the above should
just work?
One way of forcing functionality is to add the following at *) :
SVGDOMImplementation di = (SVGDOMImplementation)
m_factory.getDOMImplementation( "1.1" );
UserAgent ua = new UserAgentAdapter();
BridgeContext bc = new BridgeContext( ua );
di.createCSSEngine( (SVGOMDocument)doc, bc );
(To complicate matters, I actually tend to clone 'doc' and play with
the copy. In that case, I will have to manually set the CSSEngine of
the copy, as well. I've just given the clone the same instance as
'doc' use; not sure if this is good.)
I'm using Batik 1.6.
Hints appreciated; thanks!
//ebu
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]