Closed Bug 1778774 Opened 2 years ago Closed 1 year ago

SVG width/height in rem causes incorrect warning in the console

Categories

(Core :: SVG, defect)

Firefox 104
defect

Tracking

()

RESOLVED DUPLICATE of bug 1287054

People

(Reporter: 326374, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

Steps to reproduce:

Use the rem unit in the width/height attributes of <svg>.

Example SVG file:

<svg xmlns="http://www.w3.org/2000/svg" width="1rem" height="1rem"/>

Example HTML file:

<!DOCTYPE html>
<svg width="1rem" height="1rem"/>

Actual results:

Got warning in the console

Expected results:

No warning

Most other units seem to cause the same warnings: ch, cap, Q, ic, vb, vi, vw, vh, vmin, vmax and their small/large/dynamic counterparts. All of them seem to work, though.

I believe that support for these units was implemented in bug 1383650.

Attached image Example SVG file
Attached file Example HTML file

Thanks! I can reproduce.

I believe that support for these units was implemented in bug 1383650.

Thanks, that's helpful. --> Adding a dependency on that bug.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Depends on: 1383650
Ever confirmed: true

Looks like SVGAnimatedLength.cpp GetUnitTypeForString is failing to match when we look up the unit (while parsing the value).

It's failing because the unit isn't listed in unitMap:
https://searchfox.org/mozilla-central/rev/1ce190047b9556c3c10ab4de70a0e61d893e2954/dom/svg/SVGAnimatedLength.cpp#65

static const nsStaticAtom* const unitMap[] = {
    nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
    nullptr, /* SVG_LENGTHTYPE_NUMBER */
    nsGkAtoms::percentage,
    nsGkAtoms::em,
    nsGkAtoms::ex,
    nsGkAtoms::px,
    nsGkAtoms::cm,
    nsGkAtoms::mm,
    nsGkAtoms::in,
    nsGkAtoms::pt,
    nsGkAtoms::pc};

Maybe (?) it's as simple as just adding the new unit values to that unitMap?

I suspect our current implementation (a vestige from before bug 1383650) is based on this spec text from SVG1.1 (which has an allow-list of allowed units):
https://www.w3.org/TR/SVG11/types.html#DataTypeLength

When a <length> is used in an SVG presentation attribute, the syntax must match the following pattern:
length ::= number ("em" | "ex" | "px" | "in" | "cm" | "mm" | "pt" | "pc" | "%")?

But SVG2 section 7.8 defers to CSS for the definition of width (including syntax, etc):
https://www.w3.org/TR/SVG2/geometry.html#Sizing
...and there's additional text deferring to CSS for units here:
https://www.w3.org/TR/SVG2/coords.html#Units

Blocks: svg2

longsonr, maybe you'd be interested to work on this? (Not sure if it's as trivial as I think in comment 5, but hopefully a quick and easy win.)

Flags: needinfo?(longsonr)

You can't just add a unit, you have to add code to process that unit. bug 1836995 adds support for q units although since they are absolute units (i.e. they don't depend on some external property such as font size or display width) they are somewhat easier.

Flags: needinfo?(longsonr)
Status: NEW → RESOLVED
Closed: 1 year ago
Duplicate of bug: 1287054
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: