package svg import "encoding/xml" import "fmt" type CoreAttributes struct { Chardata string `xml:",chardata"` ID string `xml:"id,attr"` } type Stop struct { CoreAttributes Style Style `xml:"style,attr"` Offset string `xml:"offset,attr"` } 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"` 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"` R string `xml:"r,attr"` GradientTransform string `xml:"gradientTransform,attr"` GradientUnits string `xml:"gradientUnits,attr"` Stop []Stop `xml:"stop"` } type Defs struct { CoreAttributes LinearGradient []LinearGradient `xml:"linearGradient"` RadialGradient []RadialGradient `xml:"radialGradient"` Drawable []Drawable } 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"` } 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"` } type Rect struct { Text string `xml:",chardata"` Style string `xml:"style,attr"` ID string `xml:"id,attr"` Width string `xml:"width,attr"` Height string `xml:"height,attr"` X string `xml:"x,attr"` Y string `xml:"y,attr"` } type Drawable struct { *Rect *Ellipse *Text } func (d *Drawable) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error { var err error switch start.Name.Local { case "rect": r := Rect{} err = dec.DecodeElement(&r, &start) d.Rect = &r case "ellipse": r := Ellipse{} err = dec.DecodeElement(&r, &start) d.Ellipse = &r case "text": r := Text{} err = dec.DecodeElement(&r, &start) d.Text = &r default: return fmt.Errorf("drawable not supported: %s", start) } return err } type G struct { CoreAttributes Drawable []Drawable `xml:",any"` } type SVG struct { CoreAttributes XMLName xml.Name `xml:"svg"` Width Length `xml:"width,attr"` Height Length `xml:"height,attr"` ViewBox string `xml:"viewBox,attr"` Version string `xml:"version,attr"` Xlink string `xml:"xlink,attr"` Xmlns string `xml:"xmlns,attr"` SVG string `xml:"svg,attr"` Defs []Defs `xml:"defs"` G G `xml:"g"` }