Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / CSS

Proprietà CSS `paint-order`

`paint-order` cambia la sequenza di disegno di `fill`, `stroke` e `markers` per forme e testo SVG; `normal` usa tale sequenza predefinita.

Versione: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Sintassi

normal | [ fill || stroke || markers ]

paint-order cambia la sequenza di disegno di fill, stroke e markers per forme e testo SVG; normal usa tale sequenza predefinita.

L’esempio rasterizza due rettangoli SVG e dimostra a livello di pixel che il solo stroke disegna il tratto prima del riempimento: la metà interna del tratto spesso viene coperta dal rosso, mentre quella esterna resta blu.

Grammatica: normal | [ fill || stroke || markers ].

Le operazioni elencate sono eseguite da sinistra a destra e quelle omesse vengono accodate nel normale ordine relativo. La proprietà è ereditata, si applica alla grafica SVG e non cambia la geometria del tratto.

Esempi

<!doctype html><meta charset="utf-8"><svg id="stage" xmlns="http://www.w3.org/2000/svg" width="140" height="80"><rect id="normal" x="20" y="20" width="40" height="40" fill="red" stroke="blue" stroke-width="20"/><rect id="ordered" x="90" y="20" width="40" height="40" fill="red" stroke="blue" stroke-width="20" style="paint-order:stroke"/></svg><pre id="result"></pre><script>const rasterize=svg=>new Promise((resolve,reject)=>{const image=new Image();image.onload=()=>{const canvas=document.createElement('canvas');canvas.width=Number(svg.getAttribute('width'));canvas.height=Number(svg.getAttribute('height'));const context=canvas.getContext('2d');context.drawImage(image,0,0);resolve(context)};image.onerror=()=>reject(new Error('SVG rasterization failed'));image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(new XMLSerializer().serializeToString(svg))});const rgb=(context,x,y)=>[...context.getImageData(x,y,1,1).data].slice(0,3).join(',');(async()=>{const context=await rasterize(stage),normalInner=rgb(context,25,40),orderedInner=rgb(context,95,40),normalOuter=rgb(context,15,40),orderedOuter=rgb(context,85,40),computed=getComputedStyle(ordered).paintOrder;if(normalInner!=='0,0,255'||orderedInner!=='255,0,0'||normalOuter!=='0,0,255'||orderedOuter!=='0,0,255'||computed!=='stroke')throw new Error('paint-order pixel mismatch '+[normalInner,orderedInner,normalOuter,orderedOuter,computed]);result.textContent='inner='+normalInner+'/'+orderedInner+'; outer='+normalOuter+'/'+orderedOuter+'; computed='+computed})().catch(error=>result.textContent='ERROR:'+error.message);</script>

Risultato

inner=0,0,255/255,0,0; outer=0,0,255/0,0,255; computed=stroke

L’esempio rasterizza due rettangoli SVG e dimostra a livello di pixel che il solo `stroke` disegna il tratto prima del riempimento: la metà interna del tratto spesso viene coperta dal rosso, mentre quella esterna resta blu.

Fonti