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 Bibek Sahu <sc...@dodds.net> on 2004/02/10 21:51:31 UTC

getting calculated property (fill/weight/etc.)

Howdy all,

How do I get the calculated property associated with an element?  For
example, suppose I have the code:

<tspan id="outer" fill="red" style="font-style:italic"> this is <tspan
id="inner" style="font-weight:bold">bold</tspan>. </tspan>



Now, that whole chunk of text should be in red-italics, and only the world
"bold" (in tspan "inner") should be in boldface.  So suppose I have the
SVGTSpanElement whose id="inner": how would I find the color it should be
rendered in?  The style (italics)?  [This is from inside my Java code, so
I also have access to the GVT tree, etc.]

I've tried using SVGStylable.getPresentationAttribute(DOMString), but I
keep getting DOMExceptions:

cssValue = org.apache.batik.dom.svg.SVGStylableElement$PresentationAttributeValue@1a8fb1b
getProperty: caught DOMException: code=11
org.w3c.dom.DOMException:
        at org.apache.batik.dom.svg.SVGStylableElement$PresentationAttributeValue.getValue(Unknown Source)
        at org.apache.batik.css.dom.CSSOMValue.getCssText(Unknown Source)
        at org.globalcircle.svg.SVGUtils.getProperty(SVGUtils.java:277)
        at org.globalcircle.svg.modehandlers.TextModeHandler.updateCaret(TextModeHandler.java:133)
        at org.globalcircle.svg.modehandlers.TextModeHandler.setCaretPosition(TextModeHandler.java:113)
        at org.globalcircle.svg.modehandlers.TextModeHandler$1.handleEvent(TextModeHandler.java:167)
        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(Unknown Source)
        at org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unknown 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$17.run(Unknown Source)
        at org.apache.batik.util.RunnableQueue.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:534)
        caretPosition=9, weight=bold, style=, fill=null, stroke=null, stroke-width=null, color=null


(this is using the CVS version of Batik)


I notice that interface CSSValue only has one method of potential-value to
me: "String getCSSText()"... which is the one throwing the exception...


Ideas?  Suggestions?

Thanks!
- Bibek


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


Re: getting calculated property (fill/weight/etc.)

Posted by Bibek Sahu <sc...@dodds.net>.
That seems to do the trick.  Thanks!

- Bibek


On Wed, 11 Feb 2004, Cameron McCormack wrote:

> Hi Bibek.
>
> Bibek Sahu:
> > How do I get the calculated property associated with an element?  For
> > example, suppose I have the code:
>
> > ...
>
> > I've tried using SVGStylable.getPresentationAttribute(DOMString), but I
> > keep getting DOMExceptions:
>
> getPresentationAttribute returns a CSSValue that represents the actual
> XML presentation attribute, not the computed style property.  What you
> really want to do is get the computed style declaration and then get
> the individual properties from that.
>
>   Element e = ...;
>   SVGElement svg = (SVGElement) e.getOwnerDocument().getDocumentElement();
>   CSSStyleDeclaration style = svg.getComputedStyle(e, null);
>   // then you can get properties by string value...
>   String value = style.getPropertyValue("fill");
>   // ...or by CSSValue
>   CSSValue value = style.getPropertyCSSValue("fill");
>
> Cameron
>
> --
> Cameron McCormack
> |  Web: http://mcc.id.au/
> |  ICQ: 26955922


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


Re: getting calculated property (fill/weight/etc.)

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Hi Bibek.

Bibek Sahu:
> How do I get the calculated property associated with an element?  For
> example, suppose I have the code:

> ...

> I've tried using SVGStylable.getPresentationAttribute(DOMString), but I
> keep getting DOMExceptions:

getPresentationAttribute returns a CSSValue that represents the actual
XML presentation attribute, not the computed style property.  What you
really want to do is get the computed style declaration and then get
the individual properties from that.

  Element e = ...;
  SVGElement svg = (SVGElement) e.getOwnerDocument().getDocumentElement();
  CSSStyleDeclaration style = svg.getComputedStyle(e, null);
  // then you can get properties by string value...
  String value = style.getPropertyValue("fill");
  // ...or by CSSValue
  CSSValue value = style.getPropertyCSSValue("fill");

Cameron

-- 
Cameron McCormack
|  Web: http://mcc.id.au/
|  ICQ: 26955922

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