Open Bug 1783729 Opened 2 years ago Updated 2 years ago

SVGGraphicsElement.getBBox sometimes depends on parent transform

Categories

(Core :: SVG, defect)

Firefox 103
defect

Tracking

()

People

(Reporter: edemaine, Unassigned)

Details

Attachments

(3 files)

Attached file getbbox.html

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Steps to reproduce:

  1. Open attached getbbox.html
  2. Look in console.

Actual results:

Reported width and height differ substantially, roughly 5x.

untransformed : 0 -44.66666793823242 25 55.33333206176758
transformed : 0 -43.333335876464844 5 10.666666984558105

Expected results:

I expect the reported width and height to be the same / similar, according to the spec and MDN which says that getBBox "does not account for any transformation applied to the element or its parents".

On Chrome, I get:

untransformed : 0 -44.80000305175781 25.066667556762695 55.466670989990234
transformed : -2.6666667461395264 -45.333335876464844 29.33333396911621 56

Chrome seems to be messing up the x coordinates and width a bit, but the change is "only" 16%, compared to 500%.

When I change the rendered character to   (which is what I actually need), Chrome gets identical metrics, and Firefox remains 5-6x off.

If I add a viewBox (e.g. viewBox="0 0 1 1") to the <svg> element, then everything works again...

The Bugbug bot thinks this bug should belong to the 'Core::SVG' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → SVG
Product: Firefox → Core

We adjust the font sizing on when you make things small to try to make things more legible.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → INVALID

I understand that you tweak font sizes a bit (Chrome clearly does this too, hence the 16% difference), but should I really be expecting the width and heights to be off by a factor of 5? This is not at all an accurate bounding box for the rendered text in the element's own coordinate frame.

I'm attaching in getbbox3.html an improved demo of the bug that renders the bounding box returned by getBBox in the same coordinate frame. In Firefox, it bears no relation to the rendered text, while in Chrome, it looks right.

Attached image screenshot.png

Here's a screenshot with Chrome's behavior on the left and Firefox's behavior on the right. I expect the red rectangles to surround the rendered xs.

Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: