简体   繁体   English

为什么 SVG 线/路径相互叠加会产生不同的笔划?

[英]Why do SVG lines/ paths on top of each other create a different stroke?

I am drawing some paths with the same stroke with some significant overlap (dynamically creating and updating a tree).我正在用相同的笔画绘制一些具有显着重叠的路径(动态创建和更新树)。 On the overlapping regions, the stroke looks different (darker as well as thicker -see a) as on the non overlapping regions (- see b).在重叠区域,笔画看起来与在非重叠区域(- 见 b)不同(更深和更粗 - 参见 a)。 The same effect is noticeable with different stroke colors, too.同样的效果在不同的笔触颜色下也很明显。

在此处输入图片说明

Here is the code:这是代码:

 path.p2 { fill: none; stroke: black; stroke-width: 1px; }
 <svg height="500" width="400"> <path class="p2" d="M210 10 V 100 H 300 "/> <path class="p2" d="M210 10 V 120 H 300 "/> <path class="p2" d="M210 10 V 140 H 300 "/> <path class="p2" d="M210 10 V 160 H 300 "/> </svg>

Is there a simple CSS, SVG or javascript fix how to draw these paths (without recalculation of the overlapping regions and creating a new path)?是否有简单的 CSS、SVG 或 javascript 修复如何绘制这些路径(无需重新计算重叠区域并创建新路径)?

As I've commented you may add shape-rendering: crispEdges to path.p2正如我所评论的,您可以将shape-rendering: crispEdges添加到path.p2

MDN Quote: MDN 引用:

crispEdges Indicates that the user agent shall attempt to emphasize the contrast between clean edges of artwork over rendering speed and geometric precision. crispEdges表示用户代理应尝试强调图稿干净边缘之间的对比,而不是渲染速度和几何精度。 To achieve crisp edges, the user agent might turn off anti-aliasing for all lines and curves or possibly just for straight lines which are close to vertical or horizontal.为了获得清晰的边缘,用户代理可能会关闭所有直线和曲线的抗锯齿,或者可能只关闭接近垂直或水平的直线。 Also, the user agent might adjust line positions and line widths to align edges with device pixels.此外,用户代理可能会调整线位置和线宽以将边缘与设备像素对齐。

 svg { outline:1px solid; } path.p2 { fill: none; stroke: black; stroke-width: 1px; shape-rendering: crispEdges; }
 <svg height="500" width="400"> <path class="p2" d="M210 10 V 100 H 300 "/> <path class="p2" d="M210 10 V 120 H 300 "/> <path class="p2" d="M210 10 V 140 H 300 "/> <path class="p2" d="M210 10 V 160 H 300 "/> </svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM