Hi Michael,
"Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on
03/09/2006 08:43:55 AM:
> Thanks, that makes some sense. It might be helpful in a future release
of
> Batik to have these methods throw something other than an NPE. Since
the
> SVGStyable object is not null, I can't test for that.
In this case probably the right thing is 'getStyle' to return null...
> Ideally for a utility function "isVisible()", I'd like to try
> using the SVGStylable element and if that fails, pull the attribute off
the
> Element as normal.
You understand that this really isn't a very accurate test. If you
go and insert the element in the tree under something that has
visibility="hidden"
it's visibility will 'suddenly' change to hidden.
> I have the same problem with the SVGMatrix on an Element rendered
offscreen; I
> don't know it's broken until I call getA()
Once again it should really check if it has a graphic element and if
not
it should return null. There is a bit of question what the 'right' answer
is
in a case like:
var g = doc.createElementNS(svgNS, "g");
var m = g.getCTM();
doc.getRootElement().appendChild(g);
System.err.println("CTM A: " + m.getA());
There is some indication that this should work. Also you can
imagine the slight inverse:
var g = doc.getElementById("foo"); // get element from doc
var m = g.getCTM(); // currently in doc.
g.parentNode.removeChild(g);
System.err.println("CTM A: " + m.getA());
All this confusion is related to the fact that the return value
from most of the SVG DOM methods are 'live':
var g = doc.getElementById("foo"); // get element from doc
var m = g.getCTM(); // currently in doc.
System.err.println("CTM A Before: " + m.getA()); // result a
g.setAttributeNS(null, "transform", "scale(10)");
System.err.println("CTM A After: " + m.getA()); // result 10*a!
> or something on the SVGMatrix and
> I'm forced to catch an NPE. Not a big deal; just a "code smell" if you
will.
Sure I understand, hopefully the above gives you a feel for the
'problems' we have ;)
> Is there any way to ask a specific element if it's been rendered?
What you really want to know is if it is in the 'rendering tree'.
The short answer is not really. You can come close by walking it's
parent tree and see if it is terminated with the value of
getOwnerDocument.
But there are some complications like:
<g display="none">
<rect display="inline" .../> <!-- still isn't in display
tree... -->
</g>
Similarly:
<foo:blah display="inline">
<rect display="inline" .../> <!-- isn't displayed since child
of 'foreign' element -->
</foo:blah>
> Hi Michael,
>
> I think the element has to be 'part of the document' for styling to
> work properly (otherwise the cascade is wonky).
> So you will need to append it to the Document (preferably where it will
be
> rendered) before querying style info
> otherwise it could inherit values other than the CSS 'defaults'.
>
> "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on
> 03/08/2006 02:09:45 PM:
>
> > OK, long time getting to it, but I'm finally messing with this
> > SVGStylable interface. When I take an SVG element and try to cast it
to
> > an SVGStylable, everything works. It seems that calling getStyle()
> > results in an NPE if no style attribute currently exists. In some
> > cases, it breaks even if it does exist!
> >
> > I try to create a "layer" in my document and default it to being
> > visible:
> >
> > element = svgDocument.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
> > SVGConstants.SVG_G_TAG);
> > element.setAttribute(Constants.PNTR_EVTS_ATTR,
> > SVGConstants.SVG_NONE_VALUE);
> > SVGStylable stylable = (SVGStylable) element;
> >
> > // This causes an NPE!
> > stylable.getStyle().setProperty("visibility", "visible", "");
> >
> > // So I try this instead...
> > element.setAttribute(Constants.STYLE_ATTR,Constants.VISIBILITY_ATTR +
":
> > " + Constants.VISIBLE_VALUE);
> >
> > // Which works until I try to check its visibility elsewhere:
> > public static boolean isVisible(Element element) {
> > SVGStylable stylable = (SVGStylable) element;
> >
> > // NPE here again.
> > String visible =
> >
> > stylable.getStyle().getPropertyValue(Constants.VISIBILITY_ATTR);
> >
> > return visible.equalsIgnoreCase(Constants.VISIBLE_VALUE);
> > }
> >
> > Any help?
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, December 22, 2005 7:47 PM
> > To: [email protected]
> > Subject: RE: Seemingly simple question...
> >
> > Hi Michael,
> >
> > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote
on
> >
> > 12/22/2005 04:13:34 PM:
> >
> > > OK, well in that case, working with CSS won't be so bad. Now on the
> > SAC
> > > page, they have their own implementation, and they also say that
Batik
> > > has an implementation. What kind of object is "e" where you can
call
> > > getStyle() on it? Do you use the Batik 1.2 SAC or the standalone
SAC
> > > 1.3?
> >
> > 'e' is any 'graphics' SVG Element from the DOM.
> >
> > e = document.getElementById("myG");
> >
> > You will want to cast it to a 'org.w3c.dom.svg.SVGStylable'
> > interface.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail:
[EMAIL PROTECTED]
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail:
[EMAIL PROTECTED]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> [attachment "winmail.dat" deleted by Thomas E. DeWeese/449433/EKC]
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]