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 Doug Schepers <do...@schepers.cc> on 2003/09/28 05:47:02 UTC

Setting Style in Batik 1.5?

Hi-

I've been coding with an eye mostly toward ASV, so I'm fairly new to much of
Batik (though I've used things like the font convertor for a while). Forgive
me if I ask dumb or ASV-centric questions. I'm testing some of my code on
Squiggle/Batik1.5, and I've runn into a few errors that I may have taken for
granted in ASV.

I'm wondering why I can't use:
myElement.style.setProperty('fill', 'blue')

I can set style as an attribute, but not as a style property (see sample
[1]); it complains it can't find the setProperty method (see output [2]).

Is this the wrong way to do it? Or is this method simply not supported in
Batik?

Thanks-
-Doug

[1]
<?xml version='1.0' standalone='no'?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
   "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width='100%' height='100%' xmlns='http://www.w3.org/2000/svg'>

   <script type='text/ecmascript'><![CDATA[
      function SetFillStyle(evt)
      {
         //assign value to property
         evt.target.style.setProperty('fill', 'blue');
      }

      function SetFillAttribute(evt)
      {
         //assign value to attribute
         evt.target.setAttributeNS(null, 'fill', 'blue');
      }

   ]]></script>

   <circle cx='25' cy='25' r='20' style='fill:orange; '
onclick='SetFillStyle(evt)'/>
   <circle cx='125' cy='25' r='20' fill='orange'
onclick='SetFillAttribute(evt)'/>

</svg>

[2]
org.mozilla.javascript.EvaluatorException: Can't find method
org.apache.batik.css.dom.CSSOMStyleDeclaration.setProperty(string,string).
(Inline Script; line 5)

at
org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporte
r.java:76)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:591)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:630)
at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:606)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:198)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1191)
at org.mozilla.javascript.gen.c1.call(Inline Script:5)
at
org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:275)
at org.mozilla.javascript.gen.c6.call(<SVG>:1)
at org.mozilla.javascript.gen.c6.exec(<SVG>)
at org.apache.batik.script.rhino.RhinoInterpreter.evaluate(Unknown Source)
at org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(Unknown
Source)
at
org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEv
ent(Unknown Source)
at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown
Source)
at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
at
org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unkno
wn Source)
at
org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unkno
wn Source)
at org.apache.batik.bridge.BridgeEventSupport$Listener.mouseClicked(Unknown
Source)
at org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(Unknown
Source)
at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(Unknown
Source)
at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown
Source)
at org.apache.batik.gvt.event.AWTEventDispatcher.mouseClicked(Unknown
Source)
at org.apache.batik.swing.svg.JSVGComponent$22.run(Unknown Source)
at org.apache.batik.util.RunnableQueue.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Jim Ley <ji...@jibbering.com>.
"Thomas DeWeese" <Th...@Kodak.com> wrote in message
news:3F7830D4.2060808@Kodak.com...
>     In either case they will get an error!

Are you sure, all other implementations of SVG DOM style that I can find do
not error and do change the style with setProperty("a","b",null)  so 3rd
property null does not appear to be an error from implementations (spec
appears unclear to me, it just says string, with the obvious javascript
typeless problem) documentation on use also shows null is appropriate e.g.
the normally excellent ppk's http://www.xs4all.nl/~ppk/js/changess.html

> Are you seriously suggesting that I
> go and write and then maintain several dozen wrapper classes (which will
likely
> slow things down) _just_ so the user sees 'priority can't be null'?

No of course not...  but is it an error?  Adobe and CSV implementors don't
think so, Mozilla, Opera both type convert null to a valid priority.   It's
not a major bug or anything like that, and I do appreciate the difficulty in
the java connection and as it's easy for script people to cope with I
wouldn't recommend spending any time on it - there are bigger priorities.
I'm just not confident that it should be an error.

Jim.




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Jim,

Jim Ley wrote:

> "Thomas DeWeese" <Th...@Kodak.com> wrote in message
> news:3F7776D1.7030304@Kodak.com...
> 
>>Jim Ley wrote:
>>
>>>I don't accept that
>>>Batik is doing the right thing within ECMAScript binding.
>>
>>     Come on Jim, an error is an error :).
> 
> True, but the could point to a deeper problem and I believe it does, because
> javascript didn't necessarily call (string,string) it may have called
> (object,object)
> so you are doing type conversion on some of the parameters passed, why not
> all?

    As I think you are aware all these interfaces are 'proxied' into JavaScript
automatically by Rhino.  It has a fairly complex system to handle these sorts
of type conversions and locate an appropriate underlying method to call (it
is probably worth noting that absent parameters -> 'null' is not one of them).

    I am sure you can construct ecma script functions that would be
impossible to map this way, but due to the LCD nature of the IDL used to
define these interface I don't think it's a likely problem with any of the
DOM interfaces - for example there are _no_ overloaded functions in DOM.

> I don't know of an example stating the behaviour is wrong, but the error
> you're reporting does not exist in ecmascript, ecmascript objects do not
> throw such an error, the spec doesn't indicate it's an error thrown.

    Once again an error is an error - I can understand that as a JavaScript
Purist it might annoy you - but I don't think it is worth so much attention.

> I believe usefully setProperty(a,b,null)  and setProperty(a,b) should behave
> identically in an ecmascript binding.  ecmascript authors should not need to
> know if it's a host provided or native javascript object.

    In either case they will get an error!  Are you seriously suggesting that I
go and write and then maintain several dozen wrapper classes (which will likely
slow things down) _just_ so the user sees 'priority can't be null'?  I really
think I have much better things to do with my time, however if you think this
is _really_ that important contributions are always welcome (it should be
noted that a hard dependency on Rhino would be bad).




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Jim Ley <ji...@jibbering.com>.
"Thomas DeWeese" <Th...@Kodak.com> wrote in message
news:3F7776D1.7030304@Kodak.com...
> Jim Ley wrote:
>> I don't accept that
>> Batik is doing the right thing within ECMAScript binding.
>
>      Come on Jim, an error is an error :).

True, but the could point to a deeper problem and I believe it does, because
javascript didn't necessarily call (string,string) it may have called
(object,object)
so you are doing type conversion on some of the parameters passed, why not
all?

I don't know of an example stating the behaviour is wrong, but the error
you're reporting does not exist in ecmascript, ecmascript objects do not
throw such an error, the spec doesn't indicate it's an error thrown.

I believe usefully setProperty(a,b,null)  and setProperty(a,b) should behave
identically in an ecmascript binding.  ecmascript authors should not need to
know if it's a host provided or native javascript object.

Jim.





---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Jim,

Jim Ley wrote:

> "Doug Schepers" <do...@schepers.cc> wrote in message
> news:037901c38573$2e9e85e0$3828a318@Raven...
> 
>>org.mozilla.javascript.EvaluatorException: Can't find method
>>org.apache.batik.css.dom.CSSOMStyleDeclaration.setProperty(string,string).
>>(Inline Script; line 5)
> 
> Whilst Thomas is absolutely correct that setProperty takes 3 parameters, I
> don't agree that Batik should be erroring here, because ECMAscript has no
> notion of fixed parameters, calling  setProperty("foo","bar",null) is
> identical in ECMAScript to setProperty("foo","bar")  so whilst I would
> accept an error saying that "proirity can't be null", I don't accept that
> Batik is doing the right thing within ECMAScript binding.

     Come on Jim, an error is an error :).

     All these interfaces are defined using IDL and as such they are limited
by the lowest common denominator. What you describe below goes well beyond LCD.

> I'd always argue that null should be type-converted to the empty string if
> the binding expects a string and it should actually work.
> 
> I'd recommend not using CSS though in authoring SVG, as it'll make Basic
> compatibility easier and is reportedly faster in many viewers.

   If you can point to something that suggests the third argument should
be defaulted in languages that support it please let me know, otherwise
giving the error that setProperty doesn't take two strings is fine, IMHO.




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Jim Ley <ji...@jibbering.com>.
"Doug Schepers" <do...@schepers.cc> wrote in message
news:037901c38573$2e9e85e0$3828a318@Raven...
> org.mozilla.javascript.EvaluatorException: Can't find method
> org.apache.batik.css.dom.CSSOMStyleDeclaration.setProperty(string,string).
> (Inline Script; line 5)

Whilst Thomas is absolutely correct that setProperty takes 3 parameters, I
don't agree that Batik should be erroring here, because ECMAscript has no
notion of fixed parameters, calling  setProperty("foo","bar",null) is
identical in ECMAScript to setProperty("foo","bar")  so whilst I would
accept an error saying that "proirity can't be null", I don't accept that
Batik is doing the right thing within ECMAScript binding.

I'd always argue that null should be type-converted to the empty string if
the binding expects a string and it should actually work.

I'd recommend not using CSS though in authoring SVG, as it'll make Basic
compatibility easier and is reportedly faster in many viewers.

Jim.




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Thomas DeWeese <Th...@Kodak.com>.
Doug Schepers wrote:

> Thank you, Thomas.
> 
> Batik's strict compliance to the Specs is really keeping me on my toes! I'm
> very glad that this viewer exists, in part because I'm such it raises the
> compliance bar for other viewers, and forces lazy authors like myself to use
> good coding practices.
> 
> This worked admirably in both Squiggle and ASV3/6p; Corel balked at the
> style accessor, so I'm not sure there.
> 
> I did a simple experiment, setting the parent group style to "fill:red
> !important", but it did not override the style of the fill in the child
> circle... how does the priority work in such an instance?

   To be honest I am not a CSS guru.  Taking a quick look at CSS2 this seems
to mostly be a stylesheet thing.  So if you had a stylesheet that said
text { fill:green }

   But your content had : <text style="fill:blue">...

   Your text would be blue, but if the style sheet said:

text { fill:green ! important }

   The text should be green.  I don't think this figures into inheritance.
   See the attached file.

> I'm curious to know if anyone has compiled a list of "gotchas" between ASV
> and Batik?

   Not that I am aware of but contributions are welcome (they could
be FAQ entries or a standalone document).

> Thanks-
> -Doug
> 
> Thomas DeWeese" wrote:
> 
>>Hi Doug,
>>
>>    Take a look at the CSS DOM specification, in particular:
>>
>>
> 
> http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleDeclaration-setProperty
> 
>>     setProperty takes three arguments not two.  The third is priority,
>>this is typically "important" (override everything) or "" (normal
> 
> priority -
> 
>>which is used most commonly).
>>
>>Doug Schepers wrote:
>>
>>
>>>Hi-
>>>
>>>I've been coding with an eye mostly toward ASV, so I'm fairly new to
> 
> much of
> 
>>>Batik (though I've used things like the font convertor for a while).
> 
> Forgive
> 
>>>me if I ask dumb or ASV-centric questions. I'm testing some of my code
> 
> on
> 
>>>Squiggle/Batik1.5, and I've runn into a few errors that I may have taken
> 
> for
> 
>>>granted in ASV.
>>>
>>>I'm wondering why I can't use:
>>>myElement.style.setProperty('fill', 'blue')
>>>
>>>I can set style as an attribute, but not as a style property (see sample
>>>[1]); it complains it can't find the setProperty method (see output
> 
> [2]).
> 
>>>Is this the wrong way to do it? Or is this method simply not supported
> 
> in
> 
>>>Batik?
>>>
>>>Thanks-
>>>-Doug
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 


Re: Setting Style in Batik 1.5?

Posted by Doug Schepers <do...@schepers.cc>.
Thank you, Thomas.

Batik's strict compliance to the Specs is really keeping me on my toes! I'm
very glad that this viewer exists, in part because I'm such it raises the
compliance bar for other viewers, and forces lazy authors like myself to use
good coding practices.

This worked admirably in both Squiggle and ASV3/6p; Corel balked at the
style accessor, so I'm not sure there.

I did a simple experiment, setting the parent group style to "fill:red
!important", but it did not override the style of the fill in the child
circle... how does the priority work in such an instance?

I'm curious to know if anyone has compiled a list of "gotchas" between ASV
and Batik?

Thanks-
-Doug

Thomas DeWeese" wrote:
> Hi Doug,
>
>     Take a look at the CSS DOM specification, in particular:
>
>
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleDeclaration-setProperty
>
>      setProperty takes three arguments not two.  The third is priority,
> this is typically "important" (override everything) or "" (normal
priority -
> which is used most commonly).
>
> Doug Schepers wrote:
>
> > Hi-
> >
> > I've been coding with an eye mostly toward ASV, so I'm fairly new to
much of
> > Batik (though I've used things like the font convertor for a while).
Forgive
> > me if I ask dumb or ASV-centric questions. I'm testing some of my code
on
> > Squiggle/Batik1.5, and I've runn into a few errors that I may have taken
for
> > granted in ASV.
> >
> > I'm wondering why I can't use:
> > myElement.style.setProperty('fill', 'blue')
> >
> > I can set style as an attribute, but not as a style property (see sample
> > [1]); it complains it can't find the setProperty method (see output
[2]).
> >
> > Is this the wrong way to do it? Or is this method simply not supported
in
> > Batik?
> >
> > Thanks-
> > -Doug



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Setting Style in Batik 1.5?

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Doug,

    Take a look at the CSS DOM specification, in particular:

http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleDeclaration-setProperty

     setProperty takes three arguments not two.  The third is priority,
this is typically "important" (override everything) or "" (normal priority -
which is used most commonly).

Doug Schepers wrote:

> Hi-
> 
> I've been coding with an eye mostly toward ASV, so I'm fairly new to much of
> Batik (though I've used things like the font convertor for a while). Forgive
> me if I ask dumb or ASV-centric questions. I'm testing some of my code on
> Squiggle/Batik1.5, and I've runn into a few errors that I may have taken for
> granted in ASV.
> 
> I'm wondering why I can't use:
> myElement.style.setProperty('fill', 'blue')
> 
> I can set style as an attribute, but not as a style property (see sample
> [1]); it complains it can't find the setProperty method (see output [2]).
> 
> Is this the wrong way to do it? Or is this method simply not supported in
> Batik?
> 
> Thanks-
> -Doug
> 
> [1]
> <?xml version='1.0' standalone='no'?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
>    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
> <svg width='100%' height='100%' xmlns='http://www.w3.org/2000/svg'>
> 
>    <script type='text/ecmascript'><![CDATA[
>       function SetFillStyle(evt)
>       {
>          //assign value to property
>          evt.target.style.setProperty('fill', 'blue');
>       }
> 
>       function SetFillAttribute(evt)
>       {
>          //assign value to attribute
>          evt.target.setAttributeNS(null, 'fill', 'blue');
>       }
> 
>    ]]></script>
> 
>    <circle cx='25' cy='25' r='20' style='fill:orange; '
> onclick='SetFillStyle(evt)'/>
>    <circle cx='125' cy='25' r='20' fill='orange'
> onclick='SetFillAttribute(evt)'/>
> 
> </svg>
> 
> [2]
> org.mozilla.javascript.EvaluatorException: Can't find method
> org.apache.batik.css.dom.CSSOMStyleDeclaration.setProperty(string,string).
> (Inline Script; line 5)
> 
> at
> org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporte
> r.java:76)
> at org.mozilla.javascript.Context.reportRuntimeError(Context.java:591)
> at org.mozilla.javascript.Context.reportRuntimeError(Context.java:630)
> at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:606)
> at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:198)
> at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1191)
> at org.mozilla.javascript.gen.c1.call(Inline Script:5)
> at
> org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:275)
> at org.mozilla.javascript.gen.c6.call(<SVG>:1)
> at org.mozilla.javascript.gen.c6.exec(<SVG>)
> at org.apache.batik.script.rhino.RhinoInterpreter.evaluate(Unknown Source)
> at org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(Unknown
> Source)
> at
> org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEv
> ent(Unknown Source)
> at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown
> Source)
> at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
> at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
> at
> org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unkno
> wn Source)
> at
> org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unkno
> wn Source)
> at org.apache.batik.bridge.BridgeEventSupport$Listener.mouseClicked(Unknown
> Source)
> at org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(Unknown
> Source)
> at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(Unknown
> Source)
> at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown
> Source)
> at org.apache.batik.gvt.event.AWTEventDispatcher.mouseClicked(Unknown
> Source)
> at org.apache.batik.swing.svg.JSVGComponent$22.run(Unknown Source)
> at org.apache.batik.util.RunnableQueue.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org