Use dasharray and dashoffset attributes in svg context
This commit is contained in:
parent
0b3b26d85f
commit
484fe1caef
2 changed files with 25 additions and 12 deletions
|
@ -81,6 +81,10 @@ func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
|
|||
svgPaths[i].StrokeWidth = toSvgLength(gc.Current.LineWidth)
|
||||
svgPaths[i].StrokeLinecap = gc.Current.Cap.String()
|
||||
svgPaths[i].StrokeLinejoin = gc.Current.Join.String()
|
||||
if len(gc.Current.Dash) > 0 {
|
||||
svgPaths[i].StrokeDasharray = toSvgArray(gc.Current.Dash)
|
||||
svgPaths[i].StrokeDashoffset = toSvgLength(gc.Current.DashOffset)
|
||||
}
|
||||
} else {
|
||||
svgPaths[i].Stroke = "none"
|
||||
}
|
||||
|
@ -105,6 +109,14 @@ func toSvgLength(l float64) string {
|
|||
return fmt.Sprintf("%.4f", l)
|
||||
}
|
||||
|
||||
func toSvgArray(nums []float64) string {
|
||||
arr := make([]string, len(nums))
|
||||
for i, num := range nums {
|
||||
arr[i] = fmt.Sprintf("%.4f", num)
|
||||
}
|
||||
return strings.Join(arr, ",")
|
||||
}
|
||||
|
||||
func toSvgPathDesc(p *draw2d.Path) string { // TODO move elsewhere
|
||||
parts := make([]string, len(p.Components))
|
||||
ps := p.Points
|
||||
|
|
|
@ -11,15 +11,15 @@ import (
|
|||
|
||||
type Svg struct {
|
||||
XMLName xml.Name `xml:"svg"`
|
||||
Xmlns string `xml:"xmlns,attr"`
|
||||
Groups []Group `xml:"g"`
|
||||
Xmlns string `xml:"xmlns,attr"`
|
||||
Groups []Group `xml:"g"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
FillStroke
|
||||
Groups []Group `xml:"g"`
|
||||
Paths []Path `xml:"path"`
|
||||
Texts []Text `xml:"text"`
|
||||
Paths []Path `xml:"path"`
|
||||
Texts []Text `xml:"text"`
|
||||
}
|
||||
|
||||
type Path struct {
|
||||
|
@ -29,17 +29,18 @@ type Path struct {
|
|||
|
||||
type Text struct {
|
||||
FillStroke
|
||||
Text string `xml:",innerxml"`
|
||||
Text string `xml:",innerxml"`
|
||||
Style string `xml:",attr,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
/* shared attrs */
|
||||
|
||||
type FillStroke struct {
|
||||
Fill string `xml:"fill,attr,omitempty"`
|
||||
Stroke string `xml:"stroke,attr,omitempty"`
|
||||
StrokeWidth string `xml:"stroke-width,attr,omitempty"`
|
||||
StrokeLinecap string `xml:"stroke-linecap,attr,omitempty"`
|
||||
StrokeLinejoin string `xml:"stroke-linejoin,attr,omitempty"`
|
||||
}
|
||||
Fill string `xml:"fill,attr,omitempty"`
|
||||
Stroke string `xml:"stroke,attr,omitempty"`
|
||||
StrokeWidth string `xml:"stroke-width,attr,omitempty"`
|
||||
StrokeLinecap string `xml:"stroke-linecap,attr,omitempty"`
|
||||
StrokeLinejoin string `xml:"stroke-linejoin,attr,omitempty"`
|
||||
StrokeDasharray string `xml:"stroke-dasharray,attr,omitempty"`
|
||||
StrokeDashoffset string `xml:"stroke-dashoffset,attr,omitempty"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue