Closed Bug 1916030 Opened 1 year ago Closed 7 months ago

Firefox fails to paint svg-as-an-image, if the svg element has a width or height of 0 and no viewBox

Categories

(Core :: SVG, defect)

defect

Tracking

()

RESOLVED FIXED
139 Branch
Tracking Status
firefox139 --- fixed

People

(Reporter: dholbert, Assigned: dholbert)

References

Details

Attachments

(6 files, 1 obsolete file)

Filing this as the underlying defect behind our WPT failure in bug 1906145.

Essentially, if an SVG image lacks a viewBox, and has a zero-sized width or height, then I think we synthesize a zero-sized viewBox from its width and height, and that means we don't paint anything when the image draws (because we scale up a zero-sized area to fill the image element's bounds, or something like that).

Other browsers do in fact paint in this case, though -- I suspect because they just decline to synthesize a viewBox from the SVG image's height and width, and they instead just use a viewBox based on the area that we're rendering to (the image element), or something along those lines.

Blocks: 1906145
Summary: Firefox fails to paint svg-as-an-image if it has a defined width or height of 0 and no viewBox → Firefox fails to paint svg-as-an-image, if the svg element has a width or height of 0 and no viewBox

In all three testcases, we fail to paint the SVG in the top half of the testcase, whereas other engines reliably paint (when there's area to be painted).

Specifically:

  • Firefox renders the top half with no cyan (i.e. not painting any content from the SVG image)
  • Chromium renders the the top half with cyan backgrounds (for the img elements that are nonzero-sized).
  • WebKit renders the top half with cyan backgrounds. (They also render all the img elements as being nonzero-sized, which disagrees with us and Chrome -- this sizing behavior is probably a WebKit bug).

When fixing this, I plan to include (possibly-evolved-a-bit) versions of those 3 testcases as WPTs, along with similar tests for <embed>, <svg:image>, SVG-as-a-background-image-with-background-size, etc. (in all cases having width and/or height set to 0 on the <svg> element, but nonzero width and/or height on the embedding context).

Try run with implementation changes, but still needing some new tests:
https://treeherder.mozilla.org/jobs?repo=try&revision=1b3d051ece5df8981c7ce4c7271444e7786e3ef0

This patch doesn't change behavior; it's just moving existing logic to a helper
function, so that the next patch in the series can add an additional use of
this helper-function.

As discussed in (ancient) bug 614649: for SVG images that have a specified
'width' and/or 'height' on their root <svg> element, we need to synthesize a
viewBox using that width and/or 'height', in order for the SVG content to scale
up or down to fill an <img> element of a different size (rather than just
rendering at its native resolution into a viewport of that size, padding or
clipping its coordinate space).

But notably, we should not synthesize a viewBox if either 'width' or 'height'
are 0 (or 0%), because a 0-sized viewBox would result in nothing being
painted. That's the main thing that this new testcase is focusing on testing.

Attachment #9479013 - Attachment is obsolete: true
Pushed by dholbert@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4fafa6c67ac8 part 1: Spin off a helper function for testing whether an <svg> element's width & height are both either unset or set to a positive value. r=firefox-svg-reviewers,longsonr https://hg.mozilla.org/integration/autoland/rev/010466b2a459 part 2: Decline to synthesize a viewBox for SVG-as-an-image, if the synthesized viewBox would be zero-sized (which would prevent painting). r=firefox-svg-reviewers,longsonr https://hg.mozilla.org/integration/autoland/rev/081370c77dc9 part 3: Add WPT to test for viewBox synthesis in SVG-as-an-image with specified width and/or height. r=firefox-svg-reviewers,longsonr
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/51992 for changes under testing/web-platform/tests
Status: NEW → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → 139 Branch
Upstream PR merged by moz-wptsync-bot
Blocks: 1960779
Blocks: 1960606
Blocks: 1961245
QA Whiteboard: [qa-triage-done-c140/b139]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: