I have a g
element that contains one or more path
elements. As I mentioned in another question, I scale and translate the g
element by computing a transform
attribute so that it fits on a grid in another part of the canvas.
The calculation is done using the difference between two rectangles, the getBBox()
from the g
element and the rectangle around the grid.
Here is the question -- after I do the transform, I update the contents of the g
element and call getBBox()
again, without removing the transform
. The resulting rectangle appears to be calculated without considering the transform
. I would have expected it to reflect the change. Is this behavior consistent with the SVG specification? How do I get the bounding box of the transformed rectangle?
This, BTW, is in an HTML 5 document running in Firefox 4, if that makes any difference.
Update: Apparently this behavior seems pretty clearly in violation of the specification. From the text here at w3c:
SVGRect getBBox()
Returns the tight bounding box in current user space (i.e., after application of the ‘transform’ attribute, if any) on the geometry of all contained graphics elements, exclusive of stroking, clipping, masking and filter effects). Note that getBBox must return the actual bounding box at the time the method was called, even in case the element has not yet been rendered.
Am I reading this correctly? If so this seems to be an errata in the SVG implementation Firefox uses; I haven't had a chance to try any other. I would file a bug report if someone could point me to where.
question from:
https://stackoverflow.com/questions/6179173/how-is-the-getbbox-svgrect-calculated 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…