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
|
||||
|
|
|
@ -33,7 +33,6 @@ type Text struct {
|
|||
Style string `xml:",attr,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
/* shared attrs */
|
||||
|
||||
type FillStroke struct {
|
||||
|
@ -42,4 +41,6 @@ type FillStroke struct {
|
|||
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