You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Erik Bunn <eb...@basen.net> on 2006/09/21 10:45:04 UTC
Identifying SVG DOM node equivalents in GVT
Is there a way of identifying the counterpart of an id'ed SVG node in
a GVT tree?
I'll expound; I may be approaching SVG from a different direction
than some.
An artist designs an appealing SVG icon for a steam engine. He
publishes it in my system, informing me that within the SVG document,
the color of SVG node 'foo' indicates operational status (green ==
good, red == broken), and that the rotation angle of SVG node 'bar'
indicates temperature and should be between 0 and 180 degrees.
I currently load the icon as an SVG DOM tree. I look up nodes 'foo'
and 'bar', and, performing some nasty attribute manipulations,
programmatically inject the current engine status and boiler
temperature values measured from my favorite steam engine into the
DOM. (Identifying the nodes intended for manipulation is relatively
easy using JXPath, but changing SVG element attributes like this is
just stupid.)
If I could identify those same graphical elements in the transformed
GVT tree, I could just use the nice GraphicsNode API for the
transformations. However, while I imagine that there's a strong
correlation between GVT branches and SVG DOM branches, I don't see
anything like id's being offered at the API level on the GVT side.
Hmm. Or should I stick to the SVG DOM side? Looks like I could use
org.w3c.dom.svg.SVGLocatable.getTransform() and
CSSStylableElement.setComputedStyleMap() to fill most of my needs,
with a little type casting after the JXPath lookup.
Sorry if these are elementary questions, still trying to find my
integration points to the library;
//ebu
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Modifying CSS via SVGStylable: null CSSEngine?
Posted by Erik Bunn <eb...@basen.net>.
Thomas,
> Yes, you need to boot the CSS and SVG DOM's before you use them
> (from the Wiki):
> http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom
Argh - for all my googling, somehow I didn't hit this.
Keeping things light-weight makes complete sense, now that I know why.
> This might in theory just boot the CSS DOM, which might
> be faster/lighter but also totally unknown territory.
It's based on what DocumentLoader does, but I'll definitely refactor
toward safe ground.
>> I've just given the clone the same instance as 'doc' use;
>> not sure if this is good.)
>
> Same instance of what? The UserAgent and DOM Impl would be fine
> everything else will cause you trouble eventually.
The CSSEngine. This will get factored out, although it seems to work
for the simple style manipulation I'm doing here.
Thank you!
//erik
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Modifying CSS via SVGStylable: null CSSEngine?
Posted by th...@kodak.com.
Hi Erik,
Erik Bunn <eb...@basen.net> wrote on 09/26/2006 03:36:34 AM:
> On Sep 21, 2006, at 13:16 , thomas.deweese@kodak.com 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.)
Yes, you need to boot the CSS and SVG DOM's before you use them
(from the Wiki):
http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom
> Is there something obvious I'm missing when I assume the above should
> just work?
Yes, initially we just give you the Core DOM. If you want to
the SVG DOM (SVGLocatable, etc) or CSS DOM (SVGStylable) you
need to bring them up (they add significant weight to the dom
and useful stuff can be done without them, of course more useful
stuff can be done with them ;).
It would be nice if we brought these API's up the first time
you hit them but we would have to assume an awful lot of stuff
and people might think it was weird that we potentially read a
bunch of files (i.e. style sheets, script etc) when you ask for
the bounding box of something....
> 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 );
This might in theory just boot the CSS DOM, which might
be faster/lighter but also totally unknown territory.
> (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.
Yes, any copies will need to have the SVG/CSS Dom's brought up.
Since you are going to be rendering them anyway you need to build
the GVT tree (which boots the SVG and CSS DOM) so there isn't really
additional work here.
> I've just given the clone the same instance as 'doc' use;
> not sure if this is good.)
Same instance of what? The UserAgent and DOM Impl would be fine
everything else will cause you trouble eventually.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Modifying CSS via SVGStylable: null CSSEngine?
Posted by Erik Bunn <eb...@basen.net>.
In my continuing series...
On Sep 21, 2006, at 13:16 , thomas.deweese@kodak.com 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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: org.apache.batik.transcoder.TranscoderException: null
Posted by Archie Cobbs <ar...@dellroad.org>.
Martin Constantine wrote:
> The following is the end-result of a problem I'm having with Batik
> (getting to the root of this takes a fair amount of explanation so
> please bare with me if the post seems lacking):
>
>
> Caused by: org.apache.batik.transcoder.TranscoderException: null
> Enclosed Exception:
> The URI "data:image/jpg;base64,
> /9j/4AAQSkZJRgABAQAAAQABAAD//gAuSW50ZWwoUikgSlBFRyBMaWJyYXJ5LCB2
>
> ... lots more lines of image bits...
>
> bbr/AJ+Zv+/h oAPtt1/z8zf9/DQAfbbr/n5m/wC/hoAiuL26+yzf6TN9xv8AlofSgAD/2Q=="
> on element <image> can't be opened because:
> URL data in unsupported format or corrupt
This might be the same problem as described in this bug:
http://issues.apache.org/bugzilla/show_bug.cgi?id=40091
That bug is still open.
In any case, I have an unverified hunch that this might also simply
be a different side effect of this bug:
http://issues.apache.org/bugzilla/show_bug.cgi?id=40167
which is already fixed in SVN and for which there is a simple fix.
Can you try applying the patch in Bug #41067 to your version of
Batik and seeing if it solves the problem?
Thanks,
-Archie
__________________________________________________________________________
Archie Cobbs * CTO, Awarix * http://www.awarix.com
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: org.apache.batik.transcoder.TranscoderException: null
Posted by Martin Constantine <ma...@lecture123.com>.
Looks like the upgrade did the trick. Thanks a million!!
Martin
thomas.deweese@kodak.com wrote:
> Hi Martin,
>
> Martin Constantine <ma...@lecture123.com> wrote on 09/26/2006 03:48:56
> AM:
>
>
>> Some context:
>>
>> OS = Windows XP Sp2
>> JRE/JDK = 1.5.0_08
>> Batik version = 1.5.1
>>
>
> Well you might try upgrading to release 1.6 it fixed quite
> a number of bugs from 1.5.1. Or else you might try either the
> branches/svg11 (stable branch) or trunk version of Batik.
> The 1.5.1 release is quite old at this point...
>
>
>> What's very strange is that this code sequence always works when I run
>>
> from my
>
>> IDE (netbeans) and always barfs when I run from the command line (via a
>>
> bat
>
>> file). If anyone can shed some light on this behaviour, I would greatly
>> appreciate it. Please also don't hesitate to request further info.
>>
>
> The above makes me think that it might be a classpath/JDK issue.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
Re: org.apache.batik.transcoder.TranscoderException: null
Posted by th...@kodak.com.
Hi Martin,
Martin Constantine <ma...@lecture123.com> wrote on 09/26/2006 03:48:56
AM:
> Some context:
>
> OS = Windows XP Sp2
> JRE/JDK = 1.5.0_08
> Batik version = 1.5.1
Well you might try upgrading to release 1.6 it fixed quite
a number of bugs from 1.5.1. Or else you might try either the
branches/svg11 (stable branch) or trunk version of Batik.
The 1.5.1 release is quite old at this point...
> What's very strange is that this code sequence always works when I run
from my
> IDE (netbeans) and always barfs when I run from the command line (via a
bat
> file). If anyone can shed some light on this behaviour, I would greatly
> appreciate it. Please also don't hesitate to request further info.
The above makes me think that it might be a classpath/JDK issue.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
org.apache.batik.transcoder.TranscoderException: null
Posted by Martin Constantine <ma...@lecture123.com>.
Hi,
The following is the end-result of a problem I'm having with Batik
(getting to the root of this takes a fair amount of explanation so
please bare with me if the post seems lacking):
Caused by: org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
The URI "data:image/jpg;base64,
/9j/4AAQSkZJRgABAQAAAQABAAD//gAuSW50ZWwoUikgSlBFRyBMaWJyYXJ5LCB2
... lots more lines of image bits...
bbr/AJ+Zv+/h oAPtt1/z8zf9/DQAfbbr/n5m/wC/hoAiuL26+yzf6TN9xv8AlofSgAD/2Q=="
on element <image> can't be opened because:
URL data in unsupported format or corrupt
at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
at
edu.rutgers.elearning.util.SVGRasterizer.rasterizeSVG(SVGRasterizer.java:178)**
... 3 more
**I broke down the code in SVGRasterizer.java in the listing below. The
exception actually occurs at line 11 below.
Some context:
OS = Windows XP Sp2
JRE/JDK = 1.5.0_08
Batik version = 1.5.1
Here is the sequence of calls that yield the exception:
1 String parser = XMLResourceDescriptor.getXMLParserClassName();
2 SAXSVGDocumentFactory svgFactory = new
SAXSVGDocumentFactory(parser);
3 SVGDocument doc = (SVGDocument) svgFactory.createDocument(url);
4 TranscoderInput input = new TranscoderInput(doc);
5 BufferedImageTranscoder transcoder = new
BufferedImageTranscoder();
6 BufferedImage img = null;
try{
7 SVGRasterizer rasterizer = new SVGRasterizer();
8 transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH,
new Float(size.getWidth()));
9 transcoder.addTranscodingHint(ImageTranscoder.KEY_HEIGHT,
new Float(size.getHeight()));
10 TranscoderInput input = new TranscoderInput(doc);
11 transcoder.transcode(input, null);
12 img = transcoder.getBufferedImage();
}catch(Exception ioe){
13 ioe.printStackTrace();
}
Prior to this code running, a single-slide PowerPoint is converted
successfully to an svg document, which loads in both IE and FireFox
without any problem. This document is loaded into the "doc" variable
above at line 3. The program barfs out the exception at line 11.
What's very strange is that this code sequence /always/ works when I run
from my IDE (netbeans) and always barfs when I run from the command line
(via a bat file). If anyone can shed some light on this behaviour, I
would greatly appreciate it. Please also don't hesitate to request
further info. Thanks in advance.
Martin
Solved - Re: Identifying SVG DOM node equivalents in GVT
Posted by Erik Bunn <eb...@basen.net>.
On Sep 22, 2006, at 19:06 , Erik Bunn wrote:
> Hm. What are the prerequisites to using the SVGLocatable transforms?
> Should I be able to add an element and transform it like this?
>
> // ...load SVGDocument...
> Element g = svgDocument.createElementNS
> ( SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_G_TAG );
> someElement.appendChild( g );
> SVGMatrix xform = SVGLocatableSupport.getCTM( g );
> xform.translate( 42.0f, 42.0f );
> // ...proceed to rendering...
>
>
> This produces a NullPointerException in the anonymous SVGMatrix
> implementation by SVGLocatableSupport.getCTM() - the 'g' I created
> doesn't have an SVGContext yet. I suppose I'm skipping essential
> steps... Do I need to build a GVT first, or do some sort of update?
Further digging brought me to what I surmise is the right way:
SVGTransformList transformList = ((SVGTransformable)
someElement).getTransform().getBaseVal();
SVGSVGElement svg = mySVGDocument.getRootElement();
SVGTransform xform = svg.createSVGTransform();
xform.setTranslate( 42.0f, 42.0f );
transformList.appendItem( xform );
Somehow, when trying to figure out Batik processing, I seem to zero
in on interestingly named methods in all the wrong classes, and to
make shaky assumptions. Ah, well, this part is solved, now onward;
//ebu
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Identifying SVG DOM node equivalents in GVT
Posted by Erik Bunn <eb...@basen.net>.
On Sep 21, 2006, at 13:16 , thomas.deweese@kodak.com wrote:
> And yes the SVGLocatable interface is the right interface
> for querying and manipulating the transform. Also don't be
> afraid to insert additional grouping elements to adjust the
> transform.
Hm. What are the prerequisites to using the SVGLocatable transforms?
Should I be able to add an element and transform it like this?
// ...load SVGDocument...
Element g = svgDocument.createElementNS
( SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_G_TAG );
someElement.appendChild( g );
SVGMatrix xform = SVGLocatableSupport.getCTM( g );
xform.translate( 42.0f, 42.0f );
// ...proceed to rendering...
This produces a NullPointerException in the anonymous SVGMatrix
implementation by SVGLocatableSupport.getCTM() - the 'g' I created
doesn't have an SVGContext yet. I suppose I'm skipping essential
steps... Do I need to build a GVT first, or do some sort of update?
Thanks,
//ebu
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Identifying SVG DOM node equivalents in GVT
Posted by th...@kodak.com.
Hi Erik,
Erik Bunn <eb...@basen.net> wrote on 09/21/2006 04:45:04 AM:
> Is there a way of identifying the counterpart of an id'ed SVG node in
> a GVT tree?
You can use 'BridgeContext.getGraphicsNode(Element e)' to
get the peer of an Element. For this to work you need to set
the BridgeContext to 'dynamic' mode
"BridgeContext.setDynamicState(DYNAMIC)" before building
the GVT tree.
> I'll expound; I may be approaching SVG from a different direction
> than some.
>
> An artist designs an appealing SVG icon for a steam engine. He
> publishes it in my system, informing me that within the SVG document,
> the color of SVG node 'foo' indicates operational status (green ==
> good, red == broken), and that the rotation angle of SVG node 'bar'
> indicates temperature and should be between 0 and 180 degrees.
>
> I currently load the icon as an SVG DOM tree. I look up nodes 'foo'
> and 'bar', and, performing some nasty attribute manipulations,
> programmatically inject the current engine status and boiler
> temperature values measured from my favorite steam engine into the
> DOM. (Identifying the nodes intended for manipulation is relatively
> easy using JXPath, but changing SVG element attributes like this is
> just stupid.)
>
> If I could identify those same graphical elements in the transformed
> GVT tree, I could just use the nice GraphicsNode API for the
> transformations. However, while I imagine that there's a strong
> correlation between GVT branches and SVG DOM branches, I don't see
> anything like id's being offered at the API level on the GVT side.
>
> Hmm. Or should I stick to the SVG DOM side? Looks like I could use
> org.w3c.dom.svg.SVGLocatable.getTransform() and
> CSSStylableElement.setComputedStyleMap() to fill most of my needs,
> with a little type casting after the JXPath lookup.
I would fairly strongly suggest that you use the SVG DOM.
I would avoid 'setComputedStyleMap' you should be able to use
SVGStylable.getStyle().setProperty(String prop, String val, String
priority)
(most/all SVG elements implement SVGStylable, you can simply
pass "" for priority).
And yes the SVGLocatable interface is the right interface
for querying and manipulating the transform. Also don't be
afraid to insert additional grouping elements to adjust the
transform.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org