Hi Cameron,
> Sure, you can just use a 'rect' to draw the
background and then display
> the text atop. If you need to make sure that the rect
covers exactly
> the area of the text, you can use some script:
>
> <svg xmlns="http://www.w3.org/2000/svg
"
> version="1.1"
font-size="24" width="400"
height="400">
> <rect id="theTextBackground"
fill="yellow" width="0"
height="0"/>
> <text id="theText"
x="100" y="100">This is some
text.</text>
> <script>
> var r =
document.getElementById("theTextBackground");
> var t =
document.getElementById("theText");
> var bbox = t.getBBox();
> r.setAttributeNS(null, "x", bbox.x);
> r.setAttributeNS(null, "y", bbox.y);
> r.setAttributeNS(null, "width",
bbox.width);
> r.setAttributeNS(null, "height",
bbox.height);
> </script>
> </svg>
getBBox and getComputedTextLength is returning the required
values
after 'Text' Element has added in RootElement. But is it
possible to create
the rectangle while creating the 'Text' Element?
Element text = doc.createElementNS(svgNS,
"text");
Text value =
doc.createTextNode("100.100.10.10");
text.appendChild(value);
text.setAttributeNS(null, "text-decoration",
"none");
text.setAttributeNS(null, "x",
"150");
text.setAttributeNS(null, "y",
"150");
text.setAttributeNS(null, "font-family",
"Arial");
text.setAttributeNS(null, "font-size",
"12");
text.setAttributeNS(null, "width",
"???") //i need to set width here.
Thanks,
Selva
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|