Use fill-rule attribute in svg context
This commit is contained in:
parent
d297a025cd
commit
6d31bfac59
3 changed files with 21 additions and 6 deletions
|
@ -28,6 +28,13 @@ func toSvgArray(nums []float64) string {
|
||||||
return strings.Join(arr, ",")
|
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 {
|
func toSvgPathDesc(p *draw2d.Path) string {
|
||||||
parts := make([]string, len(p.Components))
|
parts := make([]string, len(p.Components))
|
||||||
ps := p.Points
|
ps := p.Points
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/llgcode/draw2d"
|
"github.com/llgcode/draw2d"
|
||||||
"github.com/llgcode/draw2d/draw2dbase"
|
"github.com/llgcode/draw2d/draw2dbase"
|
||||||
"image"
|
"image"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ()
|
const ()
|
||||||
|
@ -71,15 +72,17 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) {
|
||||||
func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
|
func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
|
||||||
paths = append(paths, gc.Current.Path)
|
paths = append(paths, gc.Current.Path)
|
||||||
|
|
||||||
svgPaths := make([]Path, len(paths))
|
svgPath := Path{}
|
||||||
|
group := Group{}
|
||||||
|
|
||||||
group := Group{
|
svgPathsDesc := make([]string, len(paths))
|
||||||
Paths: svgPaths,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// multiple pathes has to be joined to single svg path description
|
||||||
|
// because fill-rule wont work for whole group
|
||||||
for i, path := range paths {
|
for i, path := range paths {
|
||||||
svgPaths[i].Desc = toSvgPathDesc(path)
|
svgPathsDesc[i] = toSvgPathDesc(path)
|
||||||
}
|
}
|
||||||
|
svgPath.Desc = strings.Join(svgPathsDesc, " ")
|
||||||
|
|
||||||
if drawType&stroked == stroked {
|
if drawType&stroked == stroked {
|
||||||
group.Stroke = toSvgRGBA(gc.Current.StrokeColor)
|
group.Stroke = toSvgRGBA(gc.Current.StrokeColor)
|
||||||
|
@ -94,8 +97,11 @@ func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
|
||||||
|
|
||||||
if drawType&filled == filled {
|
if drawType&filled == filled {
|
||||||
group.Fill = toSvgRGBA(gc.Current.FillColor)
|
group.Fill = toSvgRGBA(gc.Current.FillColor)
|
||||||
|
group.FillRule = toSvgFillRule(gc.Current.FillRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.Paths = []Path{svgPath}
|
||||||
|
|
||||||
gc.svg.Groups = append(gc.svg.Groups, group)
|
gc.svg.Groups = append(gc.svg.Groups, group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,9 @@ type Text struct {
|
||||||
/* shared attrs */
|
/* shared attrs */
|
||||||
|
|
||||||
type FillStroke struct {
|
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"`
|
Stroke string `xml:"stroke,attr,omitempty"`
|
||||||
StrokeWidth string `xml:"stroke-width,attr,omitempty"`
|
StrokeWidth string `xml:"stroke-width,attr,omitempty"`
|
||||||
StrokeLinecap string `xml:"stroke-linecap,attr,omitempty"`
|
StrokeLinecap string `xml:"stroke-linecap,attr,omitempty"`
|
||||||
|
|
Loading…
Reference in a new issue