|
@@ -2,6 +2,7 @@ package svg
|
|
|
|
|
|
import "encoding/xml"
|
|
|
import "fmt"
|
|
|
+import "github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
|
type CoreAttributes struct {
|
|
|
Chardata string `xml:",chardata"`
|
|
@@ -16,22 +17,17 @@ type Stop struct {
|
|
|
|
|
|
type LinearGradient struct {
|
|
|
CoreAttributes
|
|
|
- Href string `xml:"href,attr"`
|
|
|
- X1 string `xml:"x1,attr"`
|
|
|
- Y1 string `xml:"y1,attr"`
|
|
|
- X2 string `xml:"x2,attr"`
|
|
|
- Y2 string `xml:"y2,attr"`
|
|
|
+ Href string `xml:"href,attr"`
|
|
|
+ Linear
|
|
|
GradientUnits string `xml:"gradientUnits,attr"`
|
|
|
Stop []Stop `xml:"stop"`
|
|
|
}
|
|
|
|
|
|
type RadialGradient struct {
|
|
|
CoreAttributes
|
|
|
- Href string `xml:"href,attr"`
|
|
|
- Cx string `xml:"cx,attr"`
|
|
|
- Cy string `xml:"cy,attr"`
|
|
|
- Fx string `xml:"fx,attr"`
|
|
|
- Fy string `xml:"fy,attr"`
|
|
|
+ Href string `xml:"href,attr"`
|
|
|
+ CxCy
|
|
|
+ FxFy
|
|
|
R string `xml:"r,attr"`
|
|
|
GradientTransform string `xml:"gradientTransform,attr"`
|
|
|
GradientUnits string `xml:"gradientUnits,attr"`
|
|
@@ -47,41 +43,83 @@ type Defs struct {
|
|
|
|
|
|
type Ellipse struct {
|
|
|
CoreAttributes
|
|
|
- Style string `xml:"style,attr"`
|
|
|
- Cx string `xml:"cx,attr"`
|
|
|
- Cy string `xml:"cy,attr"`
|
|
|
- Rx string `xml:"rx,attr"`
|
|
|
- Ry string `xml:"ry,attr"`
|
|
|
+ Style Style `xml:"style,attr"`
|
|
|
+ CxCy
|
|
|
+ Rx string `xml:"rx,attr"`
|
|
|
+ Ry string `xml:"ry,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+type CxCy struct {
|
|
|
+ Cx Length `xml:"cx,attr"`
|
|
|
+ Cy Length `xml:"cy,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+type FxFy struct {
|
|
|
+ Fx Length `xml:"fx,attr"`
|
|
|
+ Fy Length `xml:"fy,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+type XY struct {
|
|
|
+ X Length `xml:"x,attr"`
|
|
|
+ Y Length `xml:"y,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+type X1Y1 struct {
|
|
|
+ X1 Length `xml:"x1,attr"`
|
|
|
+ Y1 Length `xml:"y1,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+type X2Y2 struct {
|
|
|
+ X2 Length `xml:"x2,attr"`
|
|
|
+ Y2 Length `xml:"y2,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+type Linear struct {
|
|
|
+ X1Y1
|
|
|
+ X2Y2
|
|
|
+}
|
|
|
+
|
|
|
+type Tspan struct {
|
|
|
+ CoreAttributes
|
|
|
+ Style Style `xml:"style,attr"`
|
|
|
+ XY
|
|
|
}
|
|
|
|
|
|
type Text struct {
|
|
|
CoreAttributes
|
|
|
Space string `xml:"space,attr"`
|
|
|
- Style string `xml:"style,attr"`
|
|
|
- X string `xml:"x,attr"`
|
|
|
- Y string `xml:"y,attr"`
|
|
|
- Tspan struct {
|
|
|
- CoreAttributes
|
|
|
- Style string `xml:"style,attr"`
|
|
|
- X string `xml:"x,attr"`
|
|
|
- Y string `xml:"y,attr"`
|
|
|
- } `xml:"tspan"`
|
|
|
+ Style Style `xml:"style,attr"`
|
|
|
+ XY
|
|
|
+ Tspan Tspan `xml:"tspan"`
|
|
|
}
|
|
|
|
|
|
type Rect struct {
|
|
|
- Text string `xml:",chardata"`
|
|
|
- Style string `xml:"style,attr"`
|
|
|
- ID string `xml:"id,attr"`
|
|
|
+ CoreAttributes
|
|
|
+ Style Style `xml:"style,attr"`
|
|
|
+ XY
|
|
|
Width string `xml:"width,attr"`
|
|
|
Height string `xml:"height,attr"`
|
|
|
- X string `xml:"x,attr"`
|
|
|
- Y string `xml:"y,attr"`
|
|
|
+}
|
|
|
+
|
|
|
+func (r Rect) Draw(target *ebiten.Image, options *DrawOptions) {
|
|
|
+ p := vector.Path{}
|
|
|
+ fo := vector.FillOptions{Color: r.ToColor("color")}
|
|
|
+ p.MoveTo(r.X, r.Y).LineTo(r.X, r.Y+r.Width).
|
|
|
+ LineTo(r.X+r.Height, r.Y+r.Width).LineTo(r.X+r.Height, r.Y).
|
|
|
+ p.LineTo(r.X, r.Y).Fill(target, fo)
|
|
|
+}
|
|
|
+
|
|
|
+type DrawOptions struct {
|
|
|
+ X float32
|
|
|
+ Y float32
|
|
|
+}
|
|
|
+
|
|
|
+type Drawer interface {
|
|
|
+ Draw(target *ebiten.Image, options *DrawOptions)
|
|
|
}
|
|
|
|
|
|
type Drawable struct {
|
|
|
- *Rect
|
|
|
- *Ellipse
|
|
|
- *Text
|
|
|
+ Drawer
|
|
|
}
|
|
|
|
|
|
func (d *Drawable) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
|