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 Nirmesh Desai <nd...@autonomy.com> on 2008/08/19 00:01:51 UTC

bbox on text node in onload javascript

 

I am unable to get the bbox from text node in javascript function call
at onload of svg element.

 

Would there be another way to have the bbox accessed before have the svg
displayed?

 

Thanks in advance...

 

Nirmesh.


RE: bbox on text node in onload javascript

Posted by th...@kodak.com.
Hi Nirmesh,

"Nirmesh Desai" <nd...@autonomy.com> wrote on 08/20/2008 03:19:40 PM:

>  function updateVisualization(evt)
>  {
>         //some code for inits etc...
>         itemLabelTextView1 = templateText.cloneNode(true);
>         itemLabelTextPath1 = templateTextPath.cloneNode(true);
> itemLabelTextPath1.appendChild(document.createTextNode('someText'));
>         itemLabelTextView1.appendChild(itemLabelTextPath1);
> 
>      var bbox = itemLabelTextView1.getBBox();

[...]

> The bbox remained null with the timeout approach.

   The problem is that the element is not part of the
rendering tree. This can have many implications on the
calculation of the bounding box, so I'm not entirely
sure what other implementations are returning.  Batik
simply won't return a bbox unless the element is part
of the rendering tree (that includes not returning
a bbox for elements that have display='none' things
in the '<defs>' section, etc).

   If you append it to some element in the rendering
tree (even if it's just temporary) then getBBox will work.
Obviously depending on where you attach it the bbox might
vary (CSS property inheritance and selectors being one 
major variable, but also things like percentage units).

RE: bbox on text node in onload javascript

Posted by Nirmesh Desai <nd...@autonomy.com>.
Here is a simple description ..

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     onload="loadsvgcaller(evt);">

<script type="text/ecmascript"> <![CDATA[


function loadsvgcaller(evt) {
 window.setTimeout("updateVisualization();",1000);
}


 function updateVisualization(evt)
 {
        //some code for inits etc...
        itemLabelTextView1 = templateText.cloneNode(true);
        itemLabelTextPath1 = templateTextPath.cloneNode(true);
        itemLabelTextPath1.appendChild(document.createTextNode('someText'));
        itemLabelTextView1.appendChild(itemLabelTextPath1);
          
	  var bbox = itemLabelTextView1.getBBox();
	  var bboxWidth = bbox.width;
	  var bboxHeight = height;

          // bbox is null even with the timeout trick.. 

	  //further use bbox width, height to manipulate element positions

 };

  ]]> </script>

    	  <text font-family="Verdana" fill="blue" id='templateText'>
        <textPath xlink:href="#templateTextPathDef"                     id='templateTextPath'></textPath>
</text>
</svg>


The bbox remained null with the timeout approach.

Thanks,
Nirmesh.

-----Original Message-----
From: Helder Magalhães [mailto:helder.magalhaes@gmail.com] 
Sent: Wednesday, August 20, 2008 6:36 AM
To: batik-users@xmlgraphics.apache.org
Subject: Re: bbox on text node in onload javascript

> I am unable to get the bbox from text node in javascript function call at
> onload of svg element.

Using a onload event hander the SVG should work: the SVG document is
already displayed. There are a number of known issues with some SVG
implementations (such as Firefox [1], at least for version 2) while
attempting to compute bounding boxes before the SVG document is
displayed (for example, in a script which will be immediately
evaluated when available, before the document is actually displayed).

Which Batik version are you using? Can you attach a reduced test case
for your experienced behavior? Does it still occur if you use the
"setTimeout" trick [1]? If not, then the SVG wiki page should be
updated in order to state that the "setTimeout" trick also applies to
Batik version X (the one you are using).

Hope this helps,

 Helder Magalhães

[1] http://wiki.svg.org/GetBBox#Firefox_Support

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



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


Re: bbox on text node in onload javascript

Posted by Helder Magalhães <he...@gmail.com>.
> I am unable to get the bbox from text node in javascript function call at
> onload of svg element.

Using a onload event hander the SVG should work: the SVG document is
already displayed. There are a number of known issues with some SVG
implementations (such as Firefox [1], at least for version 2) while
attempting to compute bounding boxes before the SVG document is
displayed (for example, in a script which will be immediately
evaluated when available, before the document is actually displayed).

Which Batik version are you using? Can you attach a reduced test case
for your experienced behavior? Does it still occur if you use the
"setTimeout" trick [1]? If not, then the SVG wiki page should be
updated in order to state that the "setTimeout" trick also applies to
Batik version X (the one you are using).

Hope this helps,

 Helder Magalhães

[1] http://wiki.svg.org/GetBBox#Firefox_Support

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