|
List Info
Thread: Position problem for group element
|
|
| Position problem for group element |

|
2006-04-25 12:17:25 |
Hi All,
I have created a group element "port" in my
external defs.svg and instanced it
in my application using "use" element with
"x" and "y" attributes. But if I
tried to get the position "use" elements
position, it's returning (0,0). It's
not giving "x" and "y" attributes
which was set by me.
Declaration in defs.svg:
<g id = "portset">
<rect x="0" y="0"
fill="#AEADAE" stroke="black"
stroke-width="0.25" width="53"
height="17"/>
.
.
.
</g>
Accessing code in my Application:
Element g2 = doc.createElementNS(svgNS, "g");
g2.setAttributeNS(null, "id",
"group2");
Element use2 = doc.createElementNS(svgNS,
"use");
use2.setAttributeNS(null, "id",
"use2");
use2.setAttributeNS
(XLINK_NAMESPACE_URI, "xlink:href",
"file:///C:/xx/de.svg#portset");
use2.setAttributeNS(null, "x",
"10");
use2.setAttributeNS(null, "y",
"10");
g2.appendChild(use2);
.
.
.
SVGLocatable recPos = (SVGLocatable)use2;
SVGRect posRect = re.getBBox();
System.out.println("X::" + posRect.getX());
System.out.println("Y::" + posRect.getY());
Can anyone please clarify my problem?
Thanks,
Selva
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
| Position problem for group element |

|
2006-04-25 12:34:36 |
Hi Selva,
news <news sea.gmane.org> wrote on 04/25/2006
08:17:25 AM:
> I have created a group element "port" in my
external defs.svg and
instanced it
> in my application using "use" element with
"x" and "y" attributes. But
if I
> tried to get the position "use" elements
position, it's returning (0,0).
It's
> not giving "x" and "y"
attributes which was set by me.
> Accessing code in my Application:
>
> Element g2 = doc.createElementNS(svgNS,
"g");
> g2.setAttributeNS(null, "id",
"group2");
> Element use2 = doc.createElementNS(svgNS,
"use");
> use2.setAttributeNS(null, "id",
"use2");
> use2.setAttributeNS
> (XLINK_NAMESPACE_URI, "xlink:href",
"file:///C:/xx/de.svg#portset");
> use2.setAttributeNS(null, "x",
"10");
> use2.setAttributeNS(null, "y",
"10");
> g2.appendChild(use2);
[...]
> SVGLocatable recPos = (SVGLocatable)use2;
> SVGRect posRect = re.getBBox();
^^
Presumably this is meant to be 'recPos'?
> Can anyone please clarify my problem?
For any element that establishes a viewport (use is one
of them)
the 'x' and 'y' attributes are used to construct a
'translate' transform.
When you ask for the bbox you get it in the local coordinate
system of
the element, which has the transform already applied. What
you probably
want is the bbox of the use element in the parent's
coordinate system.
This is most easily accomplished using the
getTransformToElement
method
to get the transform from the use element to it's parent.
Then you can
map the corner points of the rect (or any single point) by
using
SVGPoint.matrixTransform(SVGMatrix). You can construct an
SVGPoint by
calling 'createSVGPoint' on an SVGSVGElement.
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
| Position problem for group element |

|
2006-04-25 12:34:36 |
Hi Selva,
news <news sea.gmane.org> wrote on 04/25/2006
08:17:25 AM:
> I have created a group element "port" in my
external defs.svg and
instanced it
> in my application using "use" element with
"x" and "y" attributes. But
if I
> tried to get the position "use" elements
position, it's returning (0,0).
It's
> not giving "x" and "y"
attributes which was set by me.
> Accessing code in my Application:
>
> Element g2 = doc.createElementNS(svgNS,
"g");
> g2.setAttributeNS(null, "id",
"group2");
> Element use2 = doc.createElementNS(svgNS,
"use");
> use2.setAttributeNS(null, "id",
"use2");
> use2.setAttributeNS
> (XLINK_NAMESPACE_URI, "xlink:href",
"file:///C:/xx/de.svg#portset");
> use2.setAttributeNS(null, "x",
"10");
> use2.setAttributeNS(null, "y",
"10");
> g2.appendChild(use2);
[...]
> SVGLocatable recPos = (SVGLocatable)use2;
> SVGRect posRect = re.getBBox();
^^
Presumably this is meant to be 'recPos'?
> Can anyone please clarify my problem?
For any element that establishes a viewport (use is one
of them)
the 'x' and 'y' attributes are used to construct a
'translate' transform.
When you ask for the bbox you get it in the local coordinate
system of
the element, which has the transform already applied. What
you probably
want is the bbox of the use element in the parent's
coordinate system.
This is most easily accomplished using the
getTransformToElement
method
to get the transform from the use element to it's parent.
Then you can
map the corner points of the rect (or any single point) by
using
SVGPoint.matrixTransform(SVGMatrix). You can construct an
SVGPoint by
calling 'createSVGPoint' on an SVGSVGElement.
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
[1-3]
|
|