The example uses direct setting of the x, y coordinates. Your example text node has a transform attribute. You will likely need to transform the background rectangle also.
On Mon, Dec 21, 2009 at 4:49 PM, dao <dao.ho...@gmail.com> wrote: > that quick!! > > but the rect does not fits my locatable... it has not the right size and is > stucked on the top left corner of my canvas... > > any idea? > > > On Mon, Dec 21, 2009 at 9:44 PM, jonathan wood <jonathanshaww...@gmail.com > > wrote: > >> Sorry for the very incomplete code clipping. This is from a test case I >> sent to the list a few days ago...nabble, etc will likely yield the entire >> file >> >> .....here is a better cut: >> >> >> SVGRect bbox = >> ((SVGLocatable)textNode).getBBox(); >> >> Element rect = >> doc.getElementById("my-bg-rect"); >> if (rect == null) { >> rect = >> doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "rect"); >> rect.setAttributeNS(null, "id", >> "my-bg-rect"); >> rect.setAttributeNS(null, "fill", >> "#CCDDFF"); >> rect.setAttributeNS(null, "stroke", >> "#000000"); >> rect.setAttributeNS(null, >> "stroke-width", "3"); >> } >> >> rect.setAttributeNS(null, "x", "" + >> (bbox.getX() - 10) ); >> rect.setAttributeNS(null, "y", "" + >> (bbox.getY() - 10) ); >> rect.setAttributeNS(null, "width", "" + >> (bbox.getWidth() + 20) ); >> rect.setAttributeNS(null, "height", "" + >> (bbox.getHeight() + 20) ); >> >> doc.getDocumentElement().insertBefore(rect, textNode); >> >> >> >> >> >> On Mon, Dec 21, 2009 at 3:41 PM, jonathan wood < >> jonathanshaww...@gmail.com> wrote: >> >>> SVGRect bbox = >>> ((SVGLocatable)textNode).getBBox(); >>> >>> Element rect = >>> doc.getElementById("my-bg-rect"); >>> if (rect == null) { >>> rect = >>> doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "rect"); >>> rect.setAttributeNS(null, "id", >>> "my-bg-rect"); >>> rect.setAttributeNS(null, "fill", >>> "#CCDDFF"); >>> rect.setAttributeNS(null, "stroke", >>> "#000000"); >>> rect.setAttributeNS(null, >>> "stroke-width", "3"); >>> >>> } >>> >>> >>> On Mon, Dec 21, 2009 at 3:07 PM, dao <dao.ho...@gmail.com> wrote: >>> >>>> hello, >>>> >>>> I'd like to highlight a text element of my svg file: >>>> >>>> <text transform="matrix(1 0 0 1 433.8965 494.4141)" style="fill:#00FFFF; >>>> font-family:'CourierNewPSMT'; font-size:24;">00.00</text> >>>> >>>> >>>> I cannot see any way to set the background of a text, or to get the box >>>> size to draw a rectangle around it. >>>> >>>> Do you know how I can do this? >>>> >>>> regards >>>> >>>> >>>> -- >>>> Dao Hodac >>>> >>> >>> >> > > > -- > Dao Hodac >