简体   繁体   English

SVG和VML路径填充差异

[英]SVG and VML path fill difference

I migrate from VML to SVG. 我从VML迁移到SVG。 There is a problem with the way path is filled. 路径填充方式存在问题。 Here is an example: 这是一个例子:

用VML和SVG绘制的星形

On the left side is star drawn with VML, and on the right with SVG. 左侧是用VML绘制的星形,右侧是SVG绘制的星形。 Source code for VML (works only in IE): VML的源代码(仅在IE中有效):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
    <style> v\:* { behavior: url(#default#VML); }</style >
</head>
<body>
    <div style="width:300; height:270;">
        <v:shape fillcolor="blue" strokecolor="red" coordorigin="0 0" coordsize="300 270"
            strokeweight="2" style="position:relative; top:20; left:20; width:300; height:270" 
            path="m150,20 l240,240 l30,90 l270,90 l60,240 x e">
        </v:shape>
    </div>
</body>

Source code for SVG: SVG的源代码:

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <svg width="300" height="270">
            <path d="M150,20 L240,240 L30,90 L270,90 L60,240 Z" fill="blue" stroke="red" stroke-width="3"/>
        </svg>
    </body>
</html>

There is obvious difference in filling in the middle of the star. 填充恒星中间存在明显差异。 I prefer VML style. 我更喜欢VML风格。 Is there a ways to do it with SVG? 有没有办法用SVG做到这一点?

Sure, you just want an evenodd fill-rule 当然,您只需要一个偶数填充规则

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <svg width="300" height="270">
            <path d="M150,20 L240,240 L30,90 L270,90 L60,240 Z" fill-rule="evenodd" fill="blue" stroke="red" stroke-width="3"/>
        </svg>
    </body>
</html>

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

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