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 Age Bosma <ag...@gmail.com> on 2009/01/06 15:19:38 UTC

Styling issue (presentation attribute vs CSS)

Hi,

Intro: I just started using Batik and I'm relatively new to Java. I'm
using both in Netbeans 6.5. ;-)

Using Batik went quite well so far but I can't seem to figure one
thing out. I hope you can help me out.

Example 1: <circle id="test" cx="25" cy="25" r="20"
style="opacity:0;fill:blue"/>
Example 2: <circle id="test" cx="25" cy="25" r="20" opacity="0"
style="fill:blue"/>

(note the difference in specifying the opacity styling property)

In case of example 1, the following has no effect on the visibility to
the circle while it works as expected (the circle becomes visible) on
example 2:

Element circle = svgDoc.getElementById("test");
circle.setAttributeNS(null, "opacity", "1");

Should this be considered a bug? Shouldn't the CSS property be
overwritten by setting the presentation attribute?
I wasn't able to find anything about style method priority in the SVG
specs but it would seem logical to me that the last set method should
be the one that's used.

Unfortunately I don't have any control over the property style being
used in the SVG file I get. Since more properties could be included in
the style attribute, is it possible to change just the one CSS
property without having to do string (followed by attribute)
replacements on the style attribute? Basically kind of like it's
possible in JavaScript (element.style.property = ...). I was of the
opinion that this was possible in Batik but I can't seem to find out
how.

Yours,

Age Bosma

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


Re: Styling issue (presentation attribute vs CSS)

Posted by Age Bosma <ag...@gmail.com>.
Helder Magalhães wrote:
>> Should this be considered a bug? Shouldn't the CSS property be
>> overwritten by setting the presentation attribute?
>> I wasn't able to find anything about style method priority in the SVG
>> specs but it would seem logical to me that the last set method should
>> be the one that's used.
>
> No, Batik's behavior seems to be the expected according to the
specification:
>   «In general, this means that the presentation attributes have lower
> priority than other CSS style rules specified in author style sheets
> or style attributes.» [1]
>
>

Darn, I must have overlooked that statement.

>
> Hope this helps,
>  Helder Magalhães
>

It does indeed, thank you for all the info!

thomas.deweese@kodak.com wrote:
> Hi Louis-rémi and Age,
> 
> "louis-rémi BABE" <lr...@gmail.com> wrote on 01/06/2009 11:26:32 AM:
> 
>> > Basically kind of like it's
>> > possible in JavaScript (element.style.property = ...). I was of the
>> > opinion that this was possible in Batik but I can't seem to find out
>> > how.
>>
>> This should be possible using the following syntax:
>>
>> element.style.setProperty(''opacity", "1", "");
> 
>    I think he want's to do this in Java code so it would
> be something like:
>  
> ((org.w3c.dom.svg.SVGStylable)element).getStyle().setProperty("opacity",
> "1", "");
> 

This was exactly what I was looking for, many thanks. I'll give it a go
tomorrow.

Yours,

Age

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


Re: Styling issue (presentation attribute vs CSS)

Posted by th...@kodak.com.
Hi Louis-rémi and Age,

"louis-rémi BABE" <lr...@gmail.com> wrote on 01/06/2009 11:26:32 AM:

> > Basically kind of like it's
> > possible in JavaScript (element.style.property = ...). I was of the
> > opinion that this was possible in Batik but I can't seem to find out
> > how.
> 
> This should be possible using the following syntax:
> 
> element.style.setProperty(''opacity", "1", "");

   I think he want's to do this in Java code so it would
be something like:

  ((org.w3c.dom.svg.SVGStylable)element).getStyle().setProperty("opacity", 
"1", "");

> The last argument is for priority: "important" or ""
> 
> Not sure whether there is a getProperty method, you should use 
> getComputedStyle on document's defaultView for that purpose.

   All quite correct.

Re: Styling issue (presentation attribute vs CSS)

Posted by louis-rémi BABE <lr...@gmail.com>.
>
> > Basically kind of like it's
> > possible in JavaScript (element.style.property = ...). I was of the
> > opinion that this was possible in Batik but I can't seem to find out
> > how.
>

This should be possible using the following syntax:

element.style.setProperty(''opacity", "1", "");

The last argument is for priority: "important" or ""

Not sure whether there is a getProperty method, you should use
getComputedStyle on document's defaultView for that purpose.

Re: Styling issue (presentation attribute vs CSS)

Posted by Helder Magalhães <he...@gmail.com>.
> Should this be considered a bug? Shouldn't the CSS property be
> overwritten by setting the presentation attribute?
> I wasn't able to find anything about style method priority in the SVG
> specs but it would seem logical to me that the last set method should
> be the one that's used.

No, Batik's behavior seems to be the expected according to the specification:
  «In general, this means that the presentation attributes have lower
priority than other CSS style rules specified in author style sheets
or style attributes.» [1]


> Unfortunately I don't have any control over the property style being
> used in the SVG file I get.

That's going to be a problem... Jwatt suggested while ago that CSS
attributes were avoided whenever possible [2], possibly also for this
reason - I've fight with this in the past myself... :-|


>  Since more properties could be included in
> the style attribute, is it possible to change just the one CSS
> property without having to do string (followed by attribute)
> replacements on the style attribute?

Not that I'm aware of. Batik does provide a set of CSS manipulation
utility classes, although I'm not sufficiently familiar with them to
redirect you towards the proper location: crawling for
"org.apache.batik.css" in the javadoc [3] may help; also, search for
"useCSS" in the SVG Generator how-to [4] for a few samples and
possible ideas.


> Basically kind of like it's
> possible in JavaScript (element.style.property = ...). I was of the
> opinion that this was possible in Batik but I can't seem to find out
> how.

This seems to be specific to JavaScript-in-HTML or to a browser
(Firefox?), although I haven't investigated further to clarify. In
SVG, you typically manipulate the DOM, either within the SVG scope
using ECMAScript [5] or outside the SVG scope using the framework's
dialect (for Batik, this corresponds to Java [6]). I'm not sure if SVG
by itself has such DOM access to CSS attributes...


> Yours,
> Age Bosma

Hope this helps,
 Helder Magalhães


[1] http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes
[2] http://jwatt.org/svg/authoring/#the-style-attribute
[3] http://xmlgraphics.apache.org/batik/javadoc/
[4] http://xmlgraphics.apache.org/batik/using/svg-generator.html#howToUse
[5] http://xmlgraphics.apache.org/batik/using/scripting/ecmascript.html
[6] http://xmlgraphics.apache.org/batik/using/scripting/java.html

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