Use line-{width,cap,join} attributes in svg context

This commit is contained in:
Drahoslav 2017-12-24 12:32:29 +01:00
parent ca83e24222
commit 6c0a15c624
3 changed files with 31 additions and 1 deletions

View File

@ -128,6 +128,14 @@ const (
SquareCap
)
func (cap LineCap) String() string {
return map[LineCap]string{
RoundCap: "round",
ButtCap: "cap",
SquareCap: "square",
}[cap]
}
// LineJoin is the style of segments joint
type LineJoin int
@ -140,6 +148,14 @@ const (
MiterJoin
)
func (join LineJoin) String() string {
return map[LineJoin]string{
RoundJoin: "round",
BevelJoin: "bevel",
MiterJoin: "miter",
}[join]
}
// StrokeStyle keeps stroke style attributes
// that is used by the Stroke method of a Drawer
type StrokeStyle struct {

View File

@ -76,9 +76,16 @@ func (gc *GraphicContext) drawPaths (drawType drawType, paths ...*draw2d.Path) {
svgPaths[i].Desc = toSvgPathDesc(path)
if drawType & stroked == stroked {
svgPaths[i].Stroke = toSvgRGBA(gc.Current.StrokeColor)
svgPaths[i].StrokeWidth = toSvgLength(gc.Current.LineWidth)
svgPaths[i].StrokeLinecap = gc.Current.Cap.String()
svgPaths[i].StrokeLinejoin = gc.Current.Join.String()
} else {
svgPaths[i].Stroke = "none"
}
if drawType & filled == filled {
svgPaths[i].Fill = toSvgRGBA(gc.Current.FillColor)
} else {
svgPaths[i].Fill = "none"
}
}
@ -89,7 +96,11 @@ func (gc *GraphicContext) drawPaths (drawType drawType, paths ...*draw2d.Path) {
func toSvgRGBA (c color.Color) string { // TODO move elsewhere
r, g, b, a := c.RGBA()
return fmt.Sprintf("rgba(%v, %v, %v, %v)", r>>8, g>>8, b>>8, float64(a>>8)/255)
return fmt.Sprintf("rgba(%v, %v, %v, %.3f)", r>>8, g>>8, b>>8, float64(a>>8)/255)
}
func toSvgLength (l float64) string {
return fmt.Sprintf("%.4f", l)
}
func toSvgPathDesc (p *draw2d.Path) string { // TODO move elsewhere

View File

@ -39,4 +39,7 @@ type Text struct {
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"`
}