Title: CSS Shapes Module Level 2
Status: ED
Work Status: Exploring
Shortname: css-shapes
Level: 2
Group: csswg
TR: https://www.w3.org/TR/css-shapes-2/
ED: https://drafts.csswg.org/css-shapes-2/
Editor: Rossen Atanassov, Microsoft Corporation, ratan@microsoft.com, w3cid 49885
Editor: Alan Stearns, Adobe Systems, Inc., stearns@adobe.com, w3cid 46659
Abstract: This draft contains the features of CSS relating to wrapping content around and inside shapes. It (implicitly for now) includes and extends the functionality of CSS Shapes Level 1 [[CSS-SHAPES]]. The main points of extension compared to level 1 include additional ways of defining shapes, defining an exclusion area using a shape, and restricting an element's content area using a shape.
Link Defaults: css2 (property) margin, css-display-3 (value) table
This section is not normative.
Level 1 of this specification defined properties
to control the geometry of an element's [=float area=].
This level defines how shapes apply to exclusions.
It also includes a 'shape-inside' property
for applying a shape to an element's content area.
Finally, it defines new ways of specifying shapes for all of these applications.
Value Definitions
This specification follows the CSS property definition conventions from [[!CSS2]]
using the value definition syntax from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the [=CSS-wide keywords=] as their property value.
For readability they have not been repeated explicitly.
Terminology
: exclusion area
:: The area used for excluding inline flow content around an exclusion box.
The [=exclusion area=] is equivalent to the [=border box=] for an exclusion box.
This specification's 'shape-outside' property
can be used to define arbitrary, non-rectangular [=exclusion areas=].
The 'shape-inside' property also defines an [=exclusion area=],
but in this case it is the area outside the shape that inline content avoids.
: float area
:: The area used for wrapping content around a float element.
By default, the float area is the float element's [=margin box=].
This specification's 'shape-outside' property can be used
to define arbitrary, non-rectangular float areas.
: content area
:: The [=content area=] is normally used for layout of the inline flow content of a box.
: direction-agnostic size
:: The [=direction-agnostic size=] of a box is equal to the length of the diagonal of the box,
divided by sqrt(2).
Note: This is a method of averaging the width and height of a box
used by SVG in some cases,
when a percentage of a box's size is desired
but the context doesn't specifically favor the width or the height.
For square boxes, this is the same as the width/height.
Shapes
Shapes define arbitrary geometric contours
around which inline content flows.
The shape-outside property defines the [=float area=] for a float,
and the [=exclusion area=] for an exclusion.
While the ''path()'' function allows reuse of the SVG path syntax
to define more arbitrary shapes than allowed by more specialized shape functions,
it requires writing a path as a single string
(which is not compatible with, for example, building a path piecemeal with ''var()''),
and inherits a number of limitations from SVG,
such as implicitly only allowing the ''px'' unit.
The ''shape()'' function defines a path in the same way,
but does so with more standard CSS syntax,
and allows the full range of CSS functionality,
such as additional units and math functions.
shape() = shape( <<'fill-rule'>>? from <>, <>#)
The <<'fill-rule'>> is interpreted identically to the same argument in ''path()''.
The rest of the arguments define a list of path data commands,
identical to that of an SVG Path,
which the function represents.
The from <> represents the starting point for the first shape-command.
It adds an initial absolute moveto
to the list of path data commands,
with the <> measured from the top-left corner of the [=reference box=].
The sequence of <>s represent
further path data commands.
Each command's starting point is the previous command's ending point.
<> = <> | <> | <> |
<> | <> | <> | close
<> = <>{2}
<> = by | to
<> = move <> <>
<> = line <> <>
<> = [hline | vline] <> <>
<> = curve <> <> via <>{1,2}
<> = smooth <> <> [via <>]?
<> = arc <> <> of <>{1,2}
[ <> || <> || rotate <> ]?
<> = cw | ccw
<> = large | small
<> = <>{2}
Defines a pair of coordinates,
representing a rightward and downward offset, respectively,
from a specified reference point.
Percentages are resolved against the width or height, respectively,
of the [=reference box=].
<> = by | to
Every command can be specified in "absolute" or "relative" coordinates,
determined by their <> component.
''to'' indicates that any <>s in the command
are relative to the top-left corner of the [=reference box=],
while ''by'' indicates that the <>s
are relative to the command's starting point.
Note: In either case, <> values in <>s
are always computed relative to the [=reference box's=] size.
<> = move <> <>
Adds a moveto command
to the list of path data commands,
with an ending point specified by the <>.
This draws nothing,
and merely "moves the pen" for the next command.
Note: This starts a new subpath,
for the purpose of the ''close'' command.
<> = line <> <>
Adds a lineto command
to the list of path data commands,
with an ending point specified by the <>.
This draws a straight line from the command's starting point to its ending point.
<> = [hline | vline] <> <>
Adds a horizontal (for ''hline'') or vertical (for ''vline'')
lineto command
to the list of path data commands.
This is equivalent to a ''line'' command
with the <> given as the horizontal or vertical component, respectively,
of the <>,
and the other component specified appropriately to make the line horizontal or vertical.
<> = curve <> <> via <>{1,2}
Adds a Bézier curve command to the list of path data commands,
ending at the point specified by the first <>.
The via component specifies control points for the curve:
if a single <> is provided,
the command specifies a quadratic curve;
if two <>s are provided,
it specifies a cubic curve.
<> = smooth <> <> [via <>]?
Adds a smooth Bézier curve command to the list of path data commands,
ending at the point specified by the first <>.
The via component specifies control points for the curve:
if it's omitted,
the command specifies a smooth quadratic curve;
if it's provided,
if specifies a smooth cubic curve.
Note: A ''smooth'' command is equivalent to a ''curve'' command
with the first control point automatically specified
as the reflection of the previous curve's second control point
around the starting point,
or as the starting point if the previous path data command wasn't a curve.
This ensures G1 continuity with the previous command,
so the curve appears to smoothly continue from the previous command,
rather than possibly making a sudden direction change.
Add an elliptical arc command
to the list of path data commands,
ending at the point specified by the <>.
The of component specifies the size of the ellipse that the arc is taken from.
The first <> provides the horizontal radius of the ellipse
and the second provides the vertical radius.
Like for <>s,
<> values are resolved against the width or height of the [=reference box=],
as appropriate.
If only one <> is provided,
both radiuses use the provided value.
In that case, <> values are resolved against the [=direction-agnostic size=] of the [=reference box=]
(similar to the ''circle()'' function).
Note that SVG has [[svg2#ArcOutOfRangeParameters|some specific error-handling for the ellipse radiuses]]:
* if the endpoint is the same as the starting point, the command does nothing
* if either radius is zero, the command is equivalent to a <> to the ending point
* if either radius is negative, its absolute value is used instead
* if the radiuses don't describe an ellipse large enough
to intersect both the starting point and ending point
(after rotation by the specified <>),
they are scaled up uniformly until the ellipse is just large enough to reach.
The ellipse described by the specified radiuses defaults to being axis-aligned,
but can be rotated by specifying an <>.
Similar to the ''rotate()'' transform function,
positive angles specify a clockwise rotation,
and negative angles specify a counterclockwise rotation.
If omitted, this defaults to ''0deg''.
The ending point, radiuses, and angle,
taken together,
usually define two possible ellipses
that intersect the starting point and ending point,
and each ellipse can be traced in either direction,
for a total of four possible arcs.
The <> and <> components specify which of these arcs is desired:
* <> can be cw or ccw,
indicating that the arc that is traced around the ellipse clockwise or counter-clockwise from the center, respectively,
must be chosen.
If omitted, this defaults to ''ccw''.
Note: In the SVG arc command, ''cw'' corresponds to the value 1 for the sweep flag, and ''ccw'' to the value 0.
* <> can be large or small,
indicating that the larger or smaller, respectively, of the two possible arcs
must be chosen.
If omitted, this defaults to ''small''.
Note: In the SVG arc command, ''large'' corresponds to the value 1 for the large flag, and ''small'' to the 0.
Note: If the starting and ending points are on exactly opposite sides of the ellipse,
both possible arcs are the same size,
but also there is only one possible ellipse.
In this case, the <> distinguishes which of the two possible arcs will be chosen,
and <> has no effect.
close
Adds a closepath command
to the list of path data commands.
Note: This is similar to a ''line'' command
with its ending point set to the starting point of the subpath.
When specifying a raw shape, they're identical,
but if the path is stroked,
the ending point of the ''close'' command is smoothly joined
with the start of the subpath,
which affects how line-joins and line-caps are rendered.
Interpolating the ''shape()'' Function
''shape()'' and ''path()'' functions can be [=interpolated=] with each other
if their associated list of path data commands is the same length
and has the same commands, in order.
If the starting and ending values are both ''path()'' functions,
the interpolated value is a ''path()'' function;
otherwise it's a ''shape()'' function.
In either case,
the interpolated value must represent the same list of path data commands,
with each command having its numerical components interpolated between the corresponding components of the starting and ending list.
For this purpose, commands are "the same" if they use the same command keyword,
and use the same <> keyword.
For ''curve'' and ''smooth'', they also must have the same number of control points.
If an ''arc'' command has different <> between its starting and ending list,
then the interpolated result uses ''cw'' for any progress value between 0 and 1.
If it has different <> keywords,
then the interpolated result uses ''large'' for any progress value between 0 and 1.
Note: The ''arc'' keyword interpolation rules
are meant to match existing SVG <{path}> interpolation rules.
Referencing SVG shapes
An SVG shape can be referenced using the url() syntax.
The shape can be any
of the SVG basic shapes
or a path element.
...
...
Shapes from Image
Add the final
level 1
section.
Issue: One suggestion
is to define a shape based on an element's rendered content.
This could have security implications.
Issue: Another suggestion
is to add something to an image() function
that determines the relevant pixels to use
(both for defining a shape and for display).
Fetching external shapes
To fetch an external resource for a shape, either an SVG or an image, given a
{{CSSStyleRule}} |rule|,
[=fetch a style resource=] given |rule|'s URL,
with stylesheet being |rule|'s parent CSS style sheet,
destination "image",
CORS mode "cors",
and processResponse being the following steps given [=/response=] |res| and null, failure or
a byte stream |byteStream|:
If |byteStream| is a byte stream,
apply the image or SVG to the appropriate shape-accepting property.
Note: shapes require CORS mode as their effect is detected by the document.
Declaring Shapes
A shape can be declared with the 'shape-outside' property,
with possible modifications from the 'shape-margin' property.
The shape defined by the 'shape-outside' and 'shape-margin' properties
changes the geometry of a float element's [=float area=]
and an exclusion element's [=exclusion area=].
A shape can be declared with the 'shape-inside' property,
with possible modifications from the 'shape-padding' property.
The shape defined by the 'shape-inside' and 'shape-padding' properties
defines an [=exclusion area=]
that contributes to the element's [=wrapping context=].
The 'shape-inside' property applies to all block-level elements.
The red box illustrates an exclusion element's content box,
which is unmodified and subject to normal CSS positioning
(here absolute positioning).
Lorem ipsum dolor sit amet...
The 'shape-outside' Property
Add the final level 1 section
with the change that shape-outside applies to block-level elements
and has an effect if the element is an exclusion.
The 'shape-inside' Property
The 'shape-inside' property adds one or more exclusion areas
to the element's wrapping context.
This modifies the normal rectangular shape of the content area
to a possibly non-rectangular wrapping area.
The exclusion areas are defined by subtracting the shape from the element's content area.
Any part of the shape outside the element's content area has no effect.
Name: shape-inside
Value: auto | outside-shape | [ <> || shape-box ] | <> | display
Initial: auto
Applies To: block-level elements
Inherited: no
Computed Value: computed lengths for <>, the absolute URL for <>, otherwise as specified
Animation type: as defined for <>, otherwise discrete
The values of this property have the following meanings:
auto
The shape is computed based on the content box of the element.
outside-shape
The shape is computed based on
the shape defined by the shape-outside
and shape-margin properties.
<>
The shape is computed based
on the values of one of
''inset()'', ''circle()'', ''ellipse()'' or ''polygon()''.
<>
If the <uri> references an SVG shape element,
that element defines the shape.
Otherwise, if the <uri> references an image,
the shape is extracted and computed
based on the alpha channel
of the specified image.
If the <uri> does not reference
an SVG shape element or an image,
the effect is as if the value ''auto'' had been specified.
display
The shape is computed based on the shape of the display
as described in css-round-display.
The 'shape-inside' property applies to floats.
The 'shape-inside' property may not apply on some elements
such as elements with a computed 'display' value of ''display/table''.
Overflow content avoids
the exclusion area(s) added
by 'shape-inside' and 'shape-padding'
(as well as any other exclusion areas
in the element's wrapping context).
In other words,
overflow continues outside
the rectangular bounds of the element.
Issue: improve the illustration above,
using text to show overflow instead of grey boxes.
When a shape-inside has a definite size
(no percentages used in the shape's definition)
an auto-sized element should use the shape
as a constraint in determining its maximum size.
The shape-image-threshold Property
Add the final
level 1
section with the change that
it applies to both 'shape-inside'
and 'shape-outside'.
The shape-image-source-type Property
Should we add an alpha/luminance switch
to determine which values we use
from the shape-image source?
This could just be a keyword
on the shape-image-threshold property.
Whatever we go with should be compatible
with the alpha/luminance switch from mask sources.
The 'shape-margin' property
Add the final
level 1
section with the change that it applies to exclusions.
The 'shape-padding' Property
The 'shape-padding' property adds padding to a shape-inside.
This defines a new shape where every point
is the specified distance from the shape-inside.
This property takes on positive values only.
Name: shape-padding
Value: <>
Initial: 0
Applies To: block-level elements
Inherited: no
Percentages: refer to the inline size of the containing block
Computed Value: computed <> value
Animation type: by computed value
<>
Sets the padding of the shape to the specified value.
Note: The 'shape-padding' property only affects layout of content
inside the element it applies to
while the 'shape-margin' property only affects layout of content
outside the element.
Privacy Considerations
No new privacy considerations have been reported on this specification.
Security Considerations
No new security considerations have been reported on this specification.