Two exactly same SVG paths not drawn exactly the same way

六眼飞鱼酱① 提交于 2019-12-13 15:06:28

问题


I'm drawing two exactly same paths on top of each other to an SVG canvas. The path behind can be seen even though the other path should hide it. Here's the SVG:

<svg viewBox="0 0 100 100">
    <!-- BLUE PATH -->
    <path id="blue" d="M 50,50 m 0,-48 a 48,48 0 1 1 0,96 a 48,48 0 1 1 0,-96" stroke="blue" stroke-width="4" fill-opacity="0" style="stroke-dasharray: 302px, 302px; stroke-dashoffset: 0px;"></path>

    <!-- YELLOW PATH -->
    <path id="yellow" d="M 50,50 m 0,-48 a 48,48 0 1 1 0,96 a 48,48 0 1 1 0,-96" stroke="yellow" stroke-width="4" fill-opacity="0" style="stroke-dasharray: 302px, 302px; stroke-dashoffset: 120px;"></path>
</svg>

Here's how it looks:

You can test this in JSFiddle: http://jsfiddle.net/k0xxp6g9/1/

The blue path can be slightly seen "leaking" from behind the yellow line. I think this has something to do with anti-aliasing. Setting shape-rendering="crispEdges" to SVG hides the issue, but lines are not smooth anymore.

How can I fix this so that blue path would not "leak" behind the yellow path? I wouldn't want to make blue path any thinner than the yellow one.


回答1:


You are seeing the effects of antialiasing.

The proper fix would be to only draw the partial arc of blue where it is visible.



来源:https://stackoverflow.com/questions/30002698/two-exactly-same-svg-paths-not-drawn-exactly-the-same-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!