Skip to content

Commit dba7168

Browse files
dirkschulzesvgeesus
authored andcommitted
Add multiple mask layers back to the spec. Add mask-composite property.
1 parent c2f3079 commit dba7168

5 files changed

Lines changed: 272 additions & 40 deletions

File tree

css-masking-1/Overview.src.html

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ <h2 id="placement">Module interactions</h2>
7676

7777
The compositing model follows the SVG compositing model [[!SVG11]]: First the element is styled under absence of filter effects, masking, clipping and opacity. Then the element and its descendants are drawn on a temporary canvas. In a last step the following effects are applied to the element in order: filter effects [[FILTER-EFFECTS]], clipping, masking and opacity.
7878

79+
This specification allows compositing multiple mask layers with the Porter Duff compositing operators defined in CSS Compositing and Blending [[!COMPOSITING-1]].
80+
7981
The terms <i>object bounding box</i> and <i>stroke bounding box</i> follow the definitions in SVG 2 [[!SVG2]].
8082

8183
<h2 id="values">Values</h2>
@@ -344,7 +346,7 @@ <h3 id="the-mask-image">Mask Image Source: the 'mask-image' property</h3>
344346

345347
<pre class='propdef'>
346348
Name: mask-image
347-
Value: <<mask-reference>>
349+
Value: <<mask-reference>>#
348350
Initial: none
349351
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
350352
Inherited: no
@@ -367,16 +369,20 @@ <h3 id="the-mask-image">Mask Image Source: the 'mask-image' property</h3>
367369
</dd>
368370
<dt>none</dt>
369371
<dd>
370-
A value of ''none'' counts as an image layer but does not mask the element.
372+
A value of ''none'' counts as a transparent black image layer.
371373
</dd>
372374
</dl>
373375

374376
A computed value of other than ''none'' results in the creation of a <a spec="css21">stacking context</a> [[!CSS21]] the same way that CSS 'opacity' [[CSS3COLOR]] does for values other than ''1''.
375377

376-
A mask reference that is an empty image (zero width or zero height), that fails to download, is not a reference to an <a element>mask</a> element, is non-existent, or that cannot be displayed (e.g. because it is not in a supported image format) is ignored. It still counts as an image layer but does not mask the element.
378+
A mask reference that is an empty image (zero width or zero height), that fails to download, is not a reference to an <a element>mask</a> element, is non-existent, or that cannot be displayed (e.g. because it is not in a supported image format) still counts as an image layer of transparent black.
377379

378380
See the section <a href="#MaskValues">“Mask processing”</a> for how to process a mask image.
379381

382+
Note: A value of ''none'' in a list of <<mask-reference>>s may influence the masking operation depending on the used compositing operator specified by 'mask-composite'.
383+
384+
Note: A <<mask-source>> counts as mask layer and can be combined in a repeatable <<mask-reference>> list with <<image>> or further <<mask-source>> list items.
385+
380386
Note: An element can also be masked with 'mask-box-source'. See 'mask-box-source' for the interaction of that property with 'mask-image'.
381387

382388
<div class="example">
@@ -387,11 +393,13 @@ <h3 id="the-mask-image">Mask Image Source: the 'mask-image' property</h3>
387393
div { mask-image: url(resources.svg#mask2) }</code></pre>
388394
</div>
389395

396+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-image' interacts with other comma-separated mask properties to form each mask image layer.
397+
390398
<h3 id="the-mask-type">Mask Image Interpretation: the 'mask-type' property</h3>
391399

392400
<pre class='propdef'>
393401
Name: mask-type
394-
Value: <<source-type>>
402+
Value: <<source-type>>#
395403
Initial: auto
396404
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
397405
Inherited: no
@@ -445,11 +453,13 @@ <h3 id="the-mask-type">Mask Image Interpretation: the 'mask-type' property</h3>
445453
&lt;rect width="200" height="200" fill="green"/&gt;</code></pre>
446454
</div>
447455

456+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-type' interacts with other comma-separated mask properties to form each mask image layer.
457+
448458
<h3 id="the-mask-repeat">Tiling Mask Images: The 'mask-repeat' property</h3>
449459

450460
<pre class='propdef'>
451461
Name: mask-repeat
452-
Value: <<repeat-style>>
462+
Value: <<repeat-style>>#
453463
Initial: no-repeat
454464
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
455465
Inherited: no
@@ -480,18 +490,20 @@ <h3 id="the-mask-repeat">Tiling Mask Images: The 'mask-repeat' property</h3>
480490
</div>
481491
</div>
482492

493+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-repeat' interacts with other comma-separated mask properties to form each mask image layer.
494+
483495
<h3 id="the-mask-position">Positioning Mask Images: the 'mask-position' property</h3>
484496

485497
<pre class='propdef'>
486498
Name: mask-position
487-
Value: <<position>>
499+
Value: <<position>>#
488500
Initial: center
489501
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
490502
Inherited: no
491503
Percentages: refer to size of <i>mask painting area</i> <em>minus</em> size of mask image; see text 'background-position' [[!CSS3BG]]
492504
Computed value: Consisting of: two keywords representing the origin and two offsets from that origin, each given as an absolute length (if given a <<length>>), otherwise as a percentage.
493505
Media: visual
494-
Animatable: as <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-simple-list">simple list</a> of <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-lpcalc">length, percentage, or calc
506+
Animatable: as <a href="http://www.w3.org/TR/css3-transitions/#animtype-repeatable-list">repeatable list</a> of <a href="http://www.w3.org/TR/css3-transitions/#animtype-simple-list">simple list</a> of <a href="http://www.w3.org/TR/css3-transitions/#animtype-lpcalc">length, percentage, or calc
495507
</pre>
496508

497509
See the 'background-position' property [[!CSS3BG]] for the definitions of the property values.
@@ -513,11 +525,13 @@ <h3 id="the-mask-position">Positioning Mask Images: the 'mask-position' property
513525
<pre><code class=css>mask-position: right 3em bottom 10px</code></pre>
514526
</div>
515527

528+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-position' interacts with other comma-separated mask properties to form each mask image layer.
529+
516530
<h3 id="the-mask-clip">Masking Area: the 'mask-clip' property</h3>
517531

518532
<pre class='propdef'>
519533
Name: mask-clip
520-
Value: <<geometry-box>> | no-clip
534+
Value: [ <<geometry-box>> | no-clip ]#
521535
Initial: border-box
522536
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
523537
Inherited: no
@@ -576,11 +590,13 @@ <h3 id="the-mask-clip">Masking Area: the 'mask-clip' property</h3>
576590

577591
For elements with associated CSS layout box, the values <a value for=mask-clip>fill-box</a>, <a value for=mask-clip>stroke-box</a> and <a value for=mask-clip>view-box</a> compute to the initial value of 'mask-clip'.
578592

593+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-clip' interacts with other comma-separated mask properties to form each mask image layer.
594+
579595
<h3 id="the-mask-origin">Positioning Area: the 'mask-origin' property</h3>
580596

581597
<pre class='propdef'>
582598
Name: mask-origin
583-
Value: <<geometry-box>>
599+
Value: <<geometry-box>>#
584600
Initial: border-box
585601
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
586602
Inherited: no
@@ -635,29 +651,83 @@ <h3 id="the-mask-origin">Positioning Area: the 'mask-origin' property</h3>
635651

636652
Note: If 'mask-clip' is <a value for=mask-origin>padding-box</a>, 'mask-origin' is <a value for=mask-origin>border-box</a>, 'mask-position' is ''top left'' (the initial value), and the element has a non-zero border, then the top and left of the mask image will be clipped.
637653

654+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-origin' interacts with other comma-separated mask properties to form each mask image layer.
655+
638656
<h3 id="the-mask-size">Sizing Mask Images: the 'mask-size' property</h3>
639657

640658
<pre class='propdef'>
641659
Name: mask-size
642-
Value: <<bg-size>>
660+
Value: <<bg-size>>#
643661
Initial: border-box
644662
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
645663
Inherited: no
646664
Percentages: n/a
647665
Computed value: as specified, but with lengths made absolute
648666
Media: visual
649-
Animatable: as <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-simple-list">simple list</a> of <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-lpcalc">length, percentage, or calc</a> (<span class="note">This means keyword values are not animatable.</span>)
667+
Animatable: as <a href="http://www.w3.org/TR/css3-transitions/#animtype-repeatable-list">repeatable list</a> of <a href="http://www.w3.org/TR/css3-transitions/#animtype-simple-list">simple list</a> of <a href="http://www.w3.org/TR/css3-transitions/#animtype-lpcalc">length, percentage, or calc</a> (<span class="note">This means keyword values are not animatable.</span>)
650668
</pre>
651669

652670
Specifies the size of the mask images.
653671

654672
See 'background-size' property [[!CSS3BG]] for the definitions of the property values.
655673

674+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-size' interacts with other comma-separated mask properties to form each mask image layer.
675+
676+
<h3 id="the-mask-composite">Compositing mask layers: the 'mask-composite' property</h3>
677+
678+
<pre class='propdef'>
679+
Name: mask-composite
680+
Value: <<composite-mode>>#
681+
Initial: source-over
682+
Applies to: All elements. In SVG, it applies to <a>container elements</a> without the <a>'defs'</a> element and all <a>graphics elements</a>
683+
Inherited: no
684+
Percentages: n/a
685+
Computed value: as specified
686+
Media: visual
687+
Animatable: no
688+
</pre>
689+
690+
Defines a Porter Duff compositing operator for each mask layer [[!COMPOSITING-1]].
691+
692+
A specified compositing operator defines the compositing operation for the current mask layer with the immediate mask layer below it. If there is no further mask layer, the compositing operator must be ignored. Mask layers must not composite with the element's content or the content behind the element, instead they must act as if they are rendered into an isolated group.
693+
694+
<div class=example>
695+
An example of the initial compositing operator <em>source-over</em>. Both mask layers will be drawn on top of each other. The result will be used to mask the content of the element.
696+
697+
<pre><code class=css>
698+
mask-image: circle.svg, rect.svg;
699+
mask-composite: source-over;
700+
</code></pre>
701+
<img src="images/mask-source-over.svg" width="665" height="260" alt="Example of source-over compositing of mask layers">
702+
</div>
703+
704+
<div class=example>
705+
An example of the compositing operator <em>destination-in</em>. The top layer “masks” the mask layer below. Just areas where both, <code>circle.svg</code> and <code>rect.svg</code> are visible will be used as mask.
706+
707+
<pre><code class=css>
708+
mask-image: circle.svg, rect.svg;
709+
mask-composite: destination-in;
710+
</code></pre>
711+
<img src="images/mask-destination-in.svg" width="665" height="260" alt="Example of destination-in compositing of mask layers">
712+
</div>
713+
714+
<div class=example>
715+
An example of the compositing operator <em>xor</em>. The resulting mask will be the visible areas of <code>circle.svg</code> and <code>rect.svg</code> where both do NOT overlap.
716+
717+
<pre><code class=css>
718+
mask-image: circle.svg, rect.svg;
719+
mask-composite: xor;
720+
</code></pre>
721+
<img src="images/mask-xor.svg" width="665" height="260" alt="Example of xor compositing of mask layers">
722+
</div>
723+
724+
See the section <a href="#layering">“Layering multiple mask images”</a> for how 'mask-composite' interacts with other comma-separated mask properties to form each mask image layer.
725+
656726
<h3 id="the-mask">Mask Shorthand: the 'mask' property</h3>
657727

658728
<pre class='propdef'>
659729
Name: mask
660-
Value: <<mask-layer>>
730+
Value: <<mask-layer>>#
661731
Initial: see individual properties
662732
Applies to: All elements. In SVG, it applies to <a>container elements</a> excluding the <a>'defs'</a> element and all <a>graphics elements</a>
663733
Inherited: no
@@ -668,7 +738,7 @@ <h3 id="the-mask">Mask Shorthand: the 'mask' property</h3>
668738
</pre>
669739

670740
<pre class=prod><dfn>&lt;mask-layer></dfn> = <<mask-reference>> <<source-type>>? || <<position>> [ / <<bg-size>> ]? ||
671-
<<repeat-style>> || <<geometry-box>> || [ <<geometry-box>> | no-clip ]</pre>
741+
<<repeat-style>> || <<geometry-box>> || [ <<geometry-box>> | no-clip ] || <<composite-mode>></pre>
672742

673743
If one <<geometry-box>> value is present then it sets both 'mask-origin' and 'mask-clip' to that value. If two <<geometry-box>> values are present, then the first sets 'mask-origin' and the second 'mask-clip'.
674744

@@ -718,6 +788,14 @@ <h4 id="MaskValues">Mask processing</h4>
718788

719789
Note: Masks with repeating mask image tiles may have an offset to each other. The space between the mask images is treated as a transparent black mask.
720790

791+
<h4 id="layering">Layering Multiple Mask Images</h4>
792+
793+
The mask of a box can have multiple layers. The number of layers is determined by the number of comma-separated values for the 'mask-image' property. A value of ''none'' in a list of values with other <<mask-reference>>s still creates a layer.
794+
795+
See <a href="http://www.w3.org/TR/css3-background/#layering">Layering Multiple Background Images</a> [[!CSS3BG]].
796+
797+
All mask images are transformed to alpha masks (if necessary see <a href="#MaskValue">Mask processing</a>) and combined by compositing taking the compositing operators specified by 'mask-composite' into account.
798+
721799
<h2 id="box-masks">Box Masks</h2>
722800

723801
With 'mask-box' an image can be split into nine pieces: four corners, four edges and the middle piece as demonstrated in the figure below.
Lines changed: 28 additions & 0 deletions
Loading
Lines changed: 27 additions & 0 deletions
Loading

css-masking-1/images/mask-xor.svg

Lines changed: 33 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)