User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050509 Firefox/1.0+
getBBox method does not work for text element, throwing an exception, and as a
consequence, getComputedTextLength returns 0 every time for any text elements.
Error: uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIDOMSVGLocatable.getBBox]"
nresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://somesite/test_text_getBBox.svg :: g_onload :: line 14" data: no
where somesite is the site name where you put attached file with test
Steps to Reproduce:
1. Open attached file
2. Text "This is a text" appears
Alert boxes does not appear
Two alert boxes, first with results of getBBox, second with result of
getComputedTextLength should appear. Second alert box should have non-zero
value as a text length.
Created attachment 183136 [details]
This is a main test file for this bug.
getBBox is implemented - it's just failing to run because the onload is fired
before the frames are constructed. You can see this if you call your g_onload()
with a onclick handler on the <test> element.
So, when call to getBBox (I am more interested in non-zero result of
getComputedTextLength for the purpose of text layout) is valid? ASV3 for IE
works even at onload time. On the other hand, Mozilla's getBBox does not work
on freshly created text elements even after onload. I suspect it does not
measure text before actually drawing it, which is unfortunate. What possible
workaround could be - e.g. creating new transparent element, pushing drawing
queue somehow (waiting), then measuring?
I'm not necessarily saying our behavior is correct, just what was causing it.
Can you direct me to an appropriate section of SVG spec? I did not find
anything about timing (or, more correctly, order?) of events and
methods/attributes. Or is it in more general DOM specs?
I do not claim that Adobe's behaviour is correct either, it is just much more
convenient from the DOM user's point of view. Otherwise it is hard to arrange
text elements nicely, because you don't have means to measure text and adjust
it in a cross-platfrom way (except using loadable fonts, which I am very
reluctant to use for several reasons, not last of them is lack of hinting), so
you are forced to rely on some run-time measurements.
So, do you believe that this issue is worth resolving?
Our behavior should be fixed, but I think the solution will involve a lot of effort.
(In reply to comment #3)
> What possible
> workaround could be - e.g. creating new transparent element, pushing drawing
> queue somehow (waiting), then measuring?
You may be able to get it to work by calling forceRedraw() before you ask for the length or bbox (http:/
/www.w3.org/TR/SVG/struct.html#InterfaceSVGSVGElement). I'm not sure it'll work in this case but it
was the workaround when other implementations had the same bug.
Doesn't work, unfortunately.
I inserted in my example two lines of code just before reference to getBBox:
var svgs = document.getElementsByTagName("svg")
with no desirable effect.
Though, after once being shown the text node becomes fully functional, so if
you don't need to measure text while onload is processed, but only later, the
work around looks like following: place some text with proper style and
nonsense coordinates (opacity=0 does not help - not implemented in Mozilla,
visibility=hidden will break even ASV3 - no need to display, no way to
measure ;-) under correct transform like this:
<text id="measure" x="-10000" y="-10000"> </text>
Space between <text> and </text> is important, otherwise there will
be no child node with data created.
Then if you need to measure a piece of text:
measureNode = document.getElementById("measure")
measureNode.firstChild.data = someText
w = measureNode.getComputedTextLength()
This one works cross-platform.
*** Bug 295589 has been marked as a duplicate of this bug. ***
Increasing the severity. This is causing problems for a lot of people and we don't have a workaround.
Speaking of workarounds, there is one that works for me so far: to trigger the redrawing procedures by function that gets called by setTimeout(myRedrawFc, 0).
(I do apologize for such an OT post, but there might be more desperate people just as I was.)
The bug is still present in Firefox 3.0 Alpha 1: Grand Paradiso (Gecko 1.9a1). When is this bug going to be at least assigned?
I don't want to be annoying, but I wonder if someone is working on this problem? .getBBox() is a very important method and many people use it from onload scripts. Firefox is the only browser/UA failing when getBBox() is called "onload".
I would really appreciate if this problem could be fixed in the near future (at least before FF3 is released).
*** Bug 373252 has been marked as a duplicate of this bug. ***
In FF3 a7pre the testcase produces two alerts, and no errors.
I can confirm that this bug is now fixed in FF3 a7pre (already worked in a5pre).
This is really good news
Created attachment 279788 [details]
Empty <g> element still throws exception error.
The bug is still there when the element is a valid node but is empty.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007090504 Minefield/3.0a8pre
Comment 17 is a different bug and has nothing to do with onload. Please raise a new bug for it i.e. GetBBox does not work with empty elements.