Skip to content

Commit 7b42df0

Browse files
committed
[css-borders-4] Define border/shadow rendering
1 parent 5af5799 commit 7b42df0

File tree

2 files changed

+454
-5
lines changed

2 files changed

+454
-5
lines changed

css-borders-4/Overview.bs

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,74 @@ as well as account for sharp edges and overlaps.
361361
Issue: 'border-radius' already handles *adjacent* corners overlapping by shrinking the radiuses proportionally.
362362
A negative ''superellipse()'' parameter allows for *opposite* corners to sometimes overlap, and needs additional restrictions defined.
363363

364-
Issue <a href="https://github.com/w3c/csswg-drafts/issues/11610">#11610</a>: check if we need additional rendering restrictions.
364+
<h5 id=corner-shape-border-rendering>
365+
Effect of 'corner-shape' on border rendering</h5>
366+
367+
When rendering a [=border=] for a box that has a 'border-radius' and a 'corner-shape'
368+
the inner border follows the curve of the outer shape, with a nearly consistent distance from the outer path throughout,
369+
or a linearly increasing distance if the 'border-width' at the different edges is different.
370+
371+
<div algorithm="adjust-border-inner-path-for-corner-shape">
372+
To compute the <dfn>adjusted untrimmed inner top-left corner starting point</dfn>:
373+
374+
1. Let |s| be the [=superellipse parameter=] of the element's 'corner-top-left-shape'.
375+
1. Let |w| be the [=used value=] of the element's 'border-left-width'.
376+
1. If |s| is equal or greater than 1, return <code>|w|, 0</code>.
377+
1. If |s| is equal or less than -1, return <code>0, -|w|</code>.
378+
1. Let |k| be <code>0.5<sup>|s|</sup></code>.
379+
1. Let |normalizedHalfCorner| be <code>0.5<sup>|k|</sup></code>.
380+
1. Let |offset| be <code>2 - &radic;2</code>.
381+
1. Let |adjustedX| be <code>max(0, 2 * |normalizedHalfCorner| - |offset|)</code>.
382+
1. Let |adjustedY| be <code>max(0, 2 * (1 - |normalizedHalfCorner|) - |offset|)</code>.
383+
1. Return <code>|adjustedX|, |adjustedY|</code>.
384+
</div>
385+
386+
<div algorithm="corner-shape-path">
387+
To compute the inner path of a corner:
388+
389+
1. Let |adjustedX|, |adjustedY| be the result of the [=adjusted untrimmed inner top-left corner starting point=] steps,
390+
modified to consider the corresponding 'border-width' and 'corner-shape' values at the start and end of a path`.
391+
1. Create a path based on the [=canonical superellipse formula=], with the outer corner as the center, starting from |adjustedX| and ending at |adjustedY|.
392+
User agents MAY create an approximation of this path rather than try to follow the formula precisely, for performance reasons.
393+
1. Trim the resulting path so that it starts at a point that has a 'border-width' distance from the outer.
394+
</div>
395+
396+
<div class=note>
397+
The superellipse quadrant is scaled so that:
398+
* Its center stays at the outer corner.
399+
* Its start and end point are perpendicular to the outer starting point.
400+
* Its distance from the outer curve is the corresponding 'border-width'.
401+
402+
This is illustrated in the following chart:
403+
<figure>
404+
<img src="images/corner-shape-border.svg"
405+
width="840" height="840"
406+
style="background: white; padding: 8px;"
407+
title="Border rendering with corner-shape"
408+
alt="Border rendering with corner-shape">
409+
<figcaption>Illustration of border path computation based on 'corner-shape'.
410+
</figcaption>
411+
</figure>
412+
413+
</div>
414+
415+
<h5 id=corner-shape-border-rendering>
416+
Effect of 'corner-shape' on 'box-shadow' rendering</h5>
417+
418+
When rendering the 'box-shadow' of an element that has a 'corner-shape', the 'border-radius' of the rendered shadow is adjusted to account for the spread.
419+
The resulting shape looks like a scaled version of the original shape, as if the shadow is at a distance in the z direction.
420+
This is accomplished by computing the per-dimension scale given the spread, and applying that scale on each of radii separately.
421+
422+
<div algorithm="corner-shape-box-shadow-adjustment">
423+
To scale the 'border-radius' value based on the 'box-shadow' |spread|:
424+
1. Let |width| be the element's [=border box=]'s width.
425+
1. Let |height| be the element's [=border box=]'s height.
426+
1. Let |newWidth| be <code>|width| + |spread| * 2</code>.
427+
1. Let |newHeight| be <code>|height| + |spread| * 2</code>.
428+
1. Let |horizontalScale| be |newWidth|/|width|.
429+
1. Let |verticalScale| be |newHeight|/|height|.
430+
1. Scale the 'border-radius' values by |horizontalScale|, |verticalScale|.
431+
</div>
365432

366433
<h4 id=corner-shape-value>
367434
'corner-shape' values</h4>
@@ -415,10 +482,10 @@ Issue <a href="https://github.com/w3c/csswg-drafts/issues/11610">#11610</a>: che
415482

416483
<figure>
417484
<img src="images/superellipse-param.svg"
418-
width="320" height="240"
419-
style="background: white; padding: 8px;"
420-
title="rendering of different superellipse parameter values"
421-
alt="Rendering of different superellipse parameter values.">
485+
width="320" height="240"
486+
style="background: white; padding: 8px;"
487+
title="rendering of different superellipse parameter values"
488+
alt="Rendering of different superellipse parameter values.">
422489
<figcaption>
423490
Rendering examples of different ''superellipse()'' values.
424491
</figcaption>

0 commit comments

Comments
 (0)