Closed
Bug 520506
Opened 16 years ago
Closed 15 years ago
Incorrect text getBBox in SVG
Categories
(Core :: SVG, defect)
Core
SVG
Tracking
()
RESOLVED
FIXED
| Tracking | Status | |
|---|---|---|
| status1.9.2 | --- | beta5-fixed |
People
(Reporter: vincent_hardy, Assigned: longsonr)
Details
Attachments
(2 files, 3 obsolete files)
|
17.23 KB,
application/zip
|
Details | |
|
2.44 KB,
patch
|
jwatt
:
review+
beltzner
:
approval1.9.2+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
In Firefox, getBBox on text elements returns the text's visual bounds, and does not account for the text's ascent and descent. From the SVG specification, section 7.11
(http://www.w3.org/TR/SVG/coords.html#ObjectBoundingBox), the full
glyph cell should be accounted for:
"For 'text' elements, for the purposes of the bounding box calculation, each
glyph is treated as a separate graphics element. The calculations assume that
all glyphs occupy the full glyph cell. For example, for horizontal text, the
calculations assume that each glyph extends vertically to the full ascent and
descent values for the font."
Reproducible: Always
Steps to Reproduce:
1. var elt = getElementById("myTextElementId"); // e.g., text with "Hello world"
var elt2 = getElementById("myOtherTextElementId"); // e.g., text with "The quick brown fox"
2. var bbox = elt.getBBox();
var bbox2 = elt2.getBBox();
3. alert(bbox.height + " / " + bbox2.height)
Actual Results:
The text's bounding box is the tight bounds around the text content.
Expected Results:
Account for the full font's descent/ascent.
| Assignee | ||
Comment 1•16 years ago
|
||
It would be great if you could attach a complete testcase using the Add an attachment facility.
| Reporter | ||
Comment 2•16 years ago
|
||
The file contains text-bbox.svg and text-bbox.js to reproduce the issue, along with text-bbox.png to show the expected bbox.
| Assignee | ||
Comment 3•15 years ago
|
||
Assignee: nobody → longsonr
Status: UNCONFIRMED → NEW
Ever confirmed: true
| Assignee | ||
Comment 4•15 years ago
|
||
Attachment #412456 -
Attachment is obsolete: true
Comment 5•15 years ago
|
||
What's the problem with AddBoundingBoxesToPath in this case?
| Assignee | ||
Comment 6•15 years ago
|
||
AddBoundingBoxesToPath gives you the extents of the full glyph cell assuming that each glyph extends vertically to the full ascent and descent values for the font. AddCharactersToPath gives you the actual extent of the character.
For getBBox according to the spec reference in comment 0 we want the former. For the covered region we want something as small as possible for best performance, hence the latter is more appropriate.
| Assignee | ||
Comment 7•15 years ago
|
||
AddBoundingBoxesToPath gives you the extents of the full glyph cell assuming that each glyph extends vertically to the full ascent and descent values for the font. AddCharactersToPath gives you the actual extent of the character.
For getBBox according to the spec reference in comment 0 we want the former. For the covered region we want something as small as possible for best performance, hence the latter is more appropriate.
| Assignee | ||
Comment 8•15 years ago
|
||
Attachment #412457 -
Attachment is obsolete: true
Attachment #412460 -
Flags: review?(jwatt)
Comment 9•15 years ago
|
||
Ah, yes indeed. I misread your patch initially and thought you were changing AddBoundingBoxesToPath to AddCharactersToPath throughout, which of course would make no sense to solve this bug. :-)
I'm not sure about changing to AddCharactersToPath for covered region calculations. I think we probably won't save much in terms of invalidation area, and unfortunately it adds a fair bit to the expense of the calculation of the area itself. Or do you disagree?
| Assignee | ||
Comment 10•15 years ago
|
||
Unfortunately some characters in some fonts extend outside the bounding box (bug 525095 has an example). However I probably should address that bug there.
Attachment #412460 -
Attachment is obsolete: true
Attachment #412792 -
Flags: review?(jwatt)
Attachment #412460 -
Flags: review?(jwatt)
Comment 11•15 years ago
|
||
So changing to AddCharactersToPath for covered region calculation would fix some artifact bugs? :-(
Updated•15 years ago
|
Attachment #412792 -
Flags: review?(jwatt) → review+
Comment 12•15 years ago
|
||
Comment on attachment 412792 [details] [diff] [review]
patch
Anyway, this patch looks great for this bug. r=jwatt
| Assignee | ||
Comment 13•15 years ago
|
||
Status: NEW → RESOLVED
Closed: 15 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Comment 14•15 years ago
|
||
Comment on attachment 412792 [details] [diff] [review]
patch
Requesting approval1.9.2. Fixes a common complaint, standards compliance issue, with one line patch exercising a path we already exercise in another way. Very safe.
Attachment #412792 -
Flags: approval1.9.2?
Comment 15•15 years ago
|
||
Comment on attachment 412792 [details] [diff] [review]
patch
a192=beltzner
Attachment #412792 -
Flags: approval1.9.2? → approval1.9.2+
Comment 16•15 years ago
|
||
status1.9.2:
--- → final-fixed
You need to log in
before you can comment on or make changes to this bug.
Description
•