-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathborder.go
93 lines (78 loc) · 2.07 KB
/
border.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package pdf
import "rogchap.com/skia"
type BorderStyle struct {
Color string
Left float32
Top float32
Right float32
Bottom float32
RadiusTopLeft float32
RadiusTopRight float32
RadiusBottomRight float32
RadiusBottomLeft float32
}
type border struct {
container
style *BorderStyle
}
func defaultBorderStyle() *BorderStyle {
return &BorderStyle{
Color: "#000",
Left: 1,
Top: 1,
Right: 1,
Bottom: 1,
}
}
func (b *border) draw(available size) {
b.container.draw(available)
c := b.canvas()
w, h := available.width, available.height
style := b.style
if style == nil {
style = defaultBorderStyle()
}
paint := skia.NewPaint(parseHexColor(style.Color))
paint.SetStyle(skia.PaintStyleStroke)
paint.SetStrokeCap(skia.StrokeCapSquare)
if style.Top > 0 {
paint.SetStrokeWidth(style.Top)
path := skia.NewPath()
path.MoveTo(0+style.RadiusTopLeft, 0)
path.LineTo(w-style.RadiusTopRight, 0)
if style.RadiusTopRight > 0 {
path.ArcTo(skia.NewRect(w-style.RadiusTopRight*2, 0, w, style.RadiusTopRight*2), -90, 90, false)
}
c.DrawPath(path, paint)
}
if style.Right > 0 {
paint.SetStrokeWidth(style.Right)
path := skia.NewPath()
path.MoveTo(w, style.RadiusTopRight)
path.LineTo(w, h-style.RadiusBottomRight)
if style.RadiusBottomRight > 0 {
path.ArcTo(skia.NewRect(w-style.RadiusBottomRight*2, h-style.RadiusBottomRight*2, w, h), 0, 90, false)
}
c.DrawPath(path, paint)
}
if style.Bottom > 0 {
paint.SetStrokeWidth(style.Bottom)
path := skia.NewPath()
path.MoveTo(w-style.RadiusBottomRight, h)
path.LineTo(style.RadiusBottomLeft, h)
if style.RadiusBottomLeft > 0 {
path.ArcTo(skia.NewRect(0, h-style.RadiusBottomLeft*2, style.RadiusBottomLeft*2, h), 90, 90, false)
}
c.DrawPath(path, paint)
}
if style.Left > 0 {
paint.SetStrokeWidth(style.Left)
path := skia.NewPath()
path.MoveTo(0, h-style.RadiusBottomLeft)
path.LineTo(0, style.RadiusTopLeft)
if style.RadiusTopLeft > 0 {
path.ArcTo(skia.NewRect(0, 0, style.RadiusTopLeft*2, style.RadiusTopLeft*2), 180, 90, false)
}
c.DrawPath(path, paint)
}
}