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].StrokeWidth = toSvgLength(gc.Current.LineWidth)
|
||||||
svgPaths[i].StrokeLinecap = gc.Current.Cap.String()
|
svgPaths[i].StrokeLinecap = gc.Current.Cap.String()
|
||||||
svgPaths[i].StrokeLinejoin = gc.Current.Join.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 {
|
} else {
|
||||||
svgPaths[i].Stroke = "none"
|
svgPaths[i].Stroke = "none"
|
||||||
}
|
}
|
||||||
|
@ -105,6 +109,14 @@ func toSvgLength(l float64) string {
|
||||||
return fmt.Sprintf("%.4f", l)
|
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
|
func toSvgPathDesc(p *draw2d.Path) string { // TODO move elsewhere
|
||||||
parts := make([]string, len(p.Components))
|
parts := make([]string, len(p.Components))
|
||||||
ps := p.Points
|
ps := p.Points
|
||||||
|
|
|
@ -33,7 +33,6 @@ type Text struct {
|
||||||
Style string `xml:",attr,omitempty"`
|
Style string `xml:",attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* shared attrs */
|
/* shared attrs */
|
||||||
|
|
||||||
type FillStroke struct {
|
type FillStroke struct {
|
||||||
|
@ -42,4 +41,6 @@ type FillStroke struct {
|
||||||
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"`
|
||||||
StrokeLinejoin string `xml:"stroke-linejoin,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