Can strokes be used as part of clip-paths in SVGs?

前端 未结 1 528
北荒
北荒 2021-01-19 17:05

I am in the middle of writing SVG output from MuPDF, and I\'ve run up against what seems to be a limitation in the capabilities of SVG. I thought I\'d ask here in case this

相关标签:
1条回答
  • 2021-01-19 17:59

    Clip-paths in svg are meant to be just the shape, not the traits of the shape, so in other words you'll not get the stroke included. What you can do is use a mask instead, setting the stroke of the path in the mask to white.

    Here's an example:

    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 600 600">
      <defs>
        <mask id="m0" maskUnits="userSpaceOnUse" x="0" y="0" width="600" height="600">
          <path fill="none" stroke="white" stroke-width="5" d="M 150 300 L 80 300 L 80 370 L 150 370" />
        </mask>
      </defs>
    
      <path stroke-width="12" fill="none" stroke="#0000ff" d="M 150 300 L 80 300 L 80 370 L 150 370 " />
      <g mask="url(#m0)">
        <rect fill="yellow" x="0" y="0" width="600" height="600" />
      </g>
    </svg>
    
    0 讨论(0)
提交回复
热议问题