Closed Bug 1258270 Opened 8 years ago Closed 5 years ago

Support calc() on stroke-width, stroke-dasharray and stroke-dashoffset

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1218257

People

(Reporter: boris, Unassigned)

References

(Blocks 2 open bugs, )

Details

(Keywords: dev-doc-needed)

Bug 594933 implemented calc() on line-height and Bug 1218257 will implement calc() on stroke-dashoffset. We still need calc() on stroke-width and stroke-dasharray.
Summary: Support calc() to stroke-width and stroke-dasharray → Support calc() on stroke-width and stroke-dasharray
Blocks: css-values-3
We'd like to support calc() on properties that accept <number> values, so in this bug, I think we should implement these items:
1. stroke-dasharray:
   The property value of stroke-dasharray is "none | <dasharray>", and
   "<dasharray>" is "[ <length> | <percentage> | <number> ]#*" [1].
   In this bug, I think we could add calc() into <dasharray>, so it'd be like this:
   "[ <length> | <percentage> | <number> | <calc()> ]#*".

2. stroke-width:
   The spec [2] says, the value of stroke-width is "<percentage> | <length>", and
   I don't see the <number> in it, so I'm not sure if implementing calc() in stroke-width is acceptable.
   However, CSS-value-3 [3] says "It can be used wherever <length>, <frequency>, <angle>,
   <time>, <number>, or <integer> values are allowed.", so I think we still could support calc() on stroke-width.
   Let the value of stroke-width be "<percentage> | <length> | <calc()>".

[1] https://svgwg.org/svg2-draft/painting.html#DataTypeDasharray
[2] https://svgwg.org/svg2-draft/painting.html#StrokeWidth
[3] https://drafts.csswg.org/css-values-3/#calc-notation
Assignee: nobody → boris.chiou
Status: NEW → ASSIGNED
Part of the reason these are interesting is that SVG properties allow raw numbers (meaning pixels) in place of lengths.  See the CSS_PROPERTY_NUMBERS_ARE_PIXELS flag.  The other property that does this is stroke-dashoffset (bug 1218257).  So the calc() code for these properties needs to treat <number> values as pixel lengths, but only in the appropriate places.

For all three properties, there would be a stored calc() in the style structs.  So it's possible this transformation could happen relatively late -- which is different from the way <number> works normally for these properties (converted relatively early).

I haven't thought about the problem enough to think about what I think the best solution is, but happy to discuss further later.  (I'm in a meeting now, though, so just writing a brief comment.)
Summary: Support calc() on stroke-width and stroke-dasharray → Support calc() on stroke-width, stroke-dasharray and stroke-dashoffset
Assignee: boris.chiou → nobody
Status: ASSIGNED → NEW
I'm working on other bugs in this quarter, so remove the assignee.
Priority: -- → P3
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE

I see this was closed as a dupe of bug #1218257 (marked fixed in v67) yet I tested on v72.0.2 stable and setting a calc value for stroke-width doesn't appear to change it, instead falling back to the default 1 stroke-width.

Eg: using embedded CSS within an SVG and applying stroke-width: calc(2 * 4); to a path doesn't affect its stroke-width, yet does in Chromium which additionally supports utilizing CSS variables for stroke-width with calc (as it seems to for everything else I've encountered).

It works if you properly specify the unit, like: calc(2px * 4).

Also, chrome doesn't seem to behave as I'd expect either: stroke-width: calc(2 * 2); does parse, but it gives me a computed value of 2px instead of 4px. It gives me 0px in Safari. stroke-width: calc(2px * 2) works as I'd expect in all browsers.

It's unclear to me if that case is working as per spec or not, seems to me like numbers are ambiguous in calc() expressions like that.

I'll file bugs in other browsers / the spec to hopefully get them to behave like Firefox does.

I filed https://github.com/w3c/csswg-drafts/issues/4874 and bugs for other browsers as linked above.

Using CSS variables seems to work as expected here too, if there are units specified.

You need to log in before you can comment on or make changes to this bug.