Closed Bug 520506 Opened 16 years ago Closed 15 years ago

Incorrect text getBBox in SVG

Categories

(Core :: SVG, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
status1.9.2 --- beta5-fixed

People

(Reporter: vincent_hardy, Assigned: longsonr)

Details

Attachments

(2 files, 3 obsolete files)

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.
It would be great if you could attach a complete testcase using the Add an attachment facility.
The file contains text-bbox.svg and text-bbox.js to reproduce the issue, along with text-bbox.png to show the expected bbox.
Attached patch patch (obsolete) — Splinter Review
Assignee: nobody → longsonr
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached patch patch (obsolete) — Splinter Review
Attachment #412456 - Attachment is obsolete: true
What's the problem with AddBoundingBoxesToPath in this case?
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.
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.
Attached patch patch (obsolete) — Splinter Review
Attachment #412457 - Attachment is obsolete: true
Attachment #412460 - Flags: review?(jwatt)
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?
Attached patch patchSplinter Review
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)
So changing to AddCharactersToPath for covered region calculation would fix some artifact bugs? :-(
Attachment #412792 - Flags: review?(jwatt) → review+
Comment on attachment 412792 [details] [diff] [review] patch Anyway, this patch looks great for this bug. r=jwatt
Status: NEW → RESOLVED
Closed: 15 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
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 on attachment 412792 [details] [diff] [review] patch a192=beltzner
Attachment #412792 - Flags: approval1.9.2? → approval1.9.2+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: