Add serialization tests for SVG unitless length values

RESOLVED FIXED in Firefox 55

Status

()

enhancement
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: jeremychen, Assigned: jeremychen)

Tracking

unspecified
mozilla55
Points:
---

Firefox Tracking Flags

(firefox55 fixed)

Details

()

Attachments

(1 attachment)

There're 3 SVG properties that accept SVG unitless length, stroke-width, stroke-dasharray, and stroke-dashoffset [1]. We should compute and store them as a factor number instead of rounding them to pixels. Although we compute and store them correctly, I just found that We don't have that kind of tests yet. So I'd like to add some tests for them.

I'll start with adding some small factor numbers to these three properties, and see how it goes.


[1] http://searchfox.org/mozilla-central/search?q=symbol:M_8b66591b5a234643ab62b847a70746707a32d04b&redirect=false
I also notice that get the computed value of a SVG unitless length value is a bit different between Firefox, Chrome, and Safari.

Try

getComputedStyle(document.getElementById('svg1')).strokeWidth

with the following examle:

<svg xmlns="http://www.w3.org/2000/svg"> <rect width="100%" height="100%" fill="lime"/> <circle id="svg1" cx="0" cy="0" r=".0008" fill="none" stroke="blue" stroke-width=".0002" transform="translate(180, 300) scale(100000, 100000)"/> </svg>

For an unitless length, such like the stroke-width in the following svg example:

<svg xmlns="http://www.w3.org/2000/svg">
  <rect width="100%" height="100%" fill="lime"/>
  <circle id="svg1" cx="0" cy="0" r=".0008" fill="none" stroke="blue" stroke-width=".0002" transform="translate(180, 300) scale(100000, 100000)"/>
</svg>

The getComputedStyle() API would return

0.0002 on Firefox
0.0002px on Chrome
0.00019999999494757503px on Safari.

Although there's a slice precision diff between Chrome and Safari, the main difference is that Firefox does not return the "px" unit for unitless length, whereas the others do. From the spec [1], it's not clear to me which one is the right behavior.

Filed https://github.com/w3c/svgwg/issues/319 for this.


[1] https://svgwg.org/svg2-draft/types.html#__svg__SVGLength__SVG_LENGTHTYPE_NUMBER
Try in comment 2 looks fine. Upload patch and ask for review then.
Comment hidden (mozreview-request)

Comment 6

2 years ago
mozreview-review
Comment on attachment 8871651 [details]
Bug 1367977 - add serialization tests for SVG unitless length values.

https://reviewboard.mozilla.org/r/143168/#review146856

::: commit-message-5d6fe:4
(Diff revision 1)
> +Bug 1367977 - add serialization tests for SVG unitless length values.
> +
> +Add small factor numbers as valid values for SVG unitless length values,
> +so we could ensure that an unitless length can not be rounded accidentally

s/an unitless/a unitless/
s/can not/will not/
Attachment #8871651 - Flags: review?(cam) → review+
Comment hidden (mozreview-request)

Comment 8

2 years ago
Pushed by jichen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/ab6539ba5d37
add serialization tests for SVG unitless length values. r=heycam

Comment 9

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/ab6539ba5d37
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.