Use fill-rule attribute in svg context

This commit is contained in:
Drahoslav 2017-12-24 16:05:15 +01:00
parent d297a025cd
commit 6d31bfac59
3 changed files with 21 additions and 6 deletions

View file

@ -28,6 +28,13 @@ func toSvgArray(nums []float64) string {
return strings.Join(arr, ",")
}
func toSvgFillRule(rule draw2d.FillRule) string {
return map[draw2d.FillRule]string{
draw2d.FillRuleEvenOdd: "evenodd",
draw2d.FillRuleWinding: "nonzero",
}[rule]
}
func toSvgPathDesc(p *draw2d.Path) string {
parts := make([]string, len(p.Components))
ps := p.Points

View file

@ -8,6 +8,7 @@ import (
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dbase"
"image"
"strings"
)
const ()
@ -71,15 +72,17 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) {
func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
paths = append(paths, gc.Current.Path)
svgPaths := make([]Path, len(paths))
svgPath := Path{}
group := Group{}
group := Group{
Paths: svgPaths,
}
svgPathsDesc := make([]string, len(paths))
// multiple pathes has to be joined to single svg path description
// because fill-rule wont work for whole group
for i, path := range paths {
svgPaths[i].Desc = toSvgPathDesc(path)
svgPathsDesc[i] = toSvgPathDesc(path)
}
svgPath.Desc = strings.Join(svgPathsDesc, " ")
if drawType&stroked == stroked {
group.Stroke = toSvgRGBA(gc.Current.StrokeColor)
@ -94,8 +97,11 @@ func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
if drawType&filled == filled {
group.Fill = toSvgRGBA(gc.Current.FillColor)
group.FillRule = toSvgFillRule(gc.Current.FillRule)
}
group.Paths = []Path{svgPath}
gc.svg.Groups = append(gc.svg.Groups, group)
}

View file

@ -37,7 +37,9 @@ type Text struct {
/* shared attrs */
type FillStroke struct {
Fill string `xml:"fill,attr,omitempty"`
Fill string `xml:"fill,attr,omitempty"`
FillRule string `xml:"fill-rule,attr,omitempty"`
Stroke string `xml:"stroke,attr,omitempty"`
StrokeWidth string `xml:"stroke-width,attr,omitempty"`
StrokeLinecap string `xml:"stroke-linecap,attr,omitempty"`