Luka
Luka

Reputation: 3089

SVG and VML path fill difference

I migrate from VML to SVG. There is a problem with the way path is filled. Here is an example:

star drawn with VML and SVG

On the left side is star drawn with VML, and on the right with SVG. Source code for VML (works only in 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:

<!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. Is there a ways to do it with SVG?

Upvotes: 0

Views: 1468

Answers (1)

Robert Longson
Robert Longson

Reputation: 124089

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>

Upvotes: 3

Related Questions