package xvdoc import ( "bytes" "encoding/json" ) type styleRect struct { x, y int dx, dy int styles []string } func (s *styleRect) UnmarshalJSON(src []byte) (err error) { dec := json.NewDecoder(bytes.NewReader(src)) var t json.Token for dec.More() && err == nil { if t, err = dec.Token(); err == nil { if _, check := t.(json.Delim); !check { switch t.(string) { case "x": err = dec.Decode(&s.x) case "y": err = dec.Decode(&s.y) case "dx": err = dec.Decode(&s.dx) case "dy": err = dec.Decode(&s.dy) case "styles": err = dec.Decode(&s.styles) default: err = dec.Decode(new(interface{})) } } } } return } ////////////////////////////////////////////////////////////////// type rectMerge struct { x, y int dx, dy int } func (s *rectMerge) UnmarshalJSON(src []byte) (err error) { dec := json.NewDecoder(bytes.NewReader(src)) var t json.Token for dec.More() && err == nil { if t, err = dec.Token(); err == nil { if _, check := t.(json.Delim); !check { switch t.(string) { case "x": err = dec.Decode(&s.x) case "y": err = dec.Decode(&s.y) case "dx": err = dec.Decode(&s.dx) case "dy": err = dec.Decode(&s.dy) default: err = dec.Decode(new(interface{})) } } } } return } ////////////////////////////////////////////////////////////// type rectWidths struct { x, dx int width float64 } func (s *rectWidths) UnmarshalJSON(src []byte) (err error) { dec := json.NewDecoder(bytes.NewReader(src)) var t json.Token for dec.More() && err == nil { if t, err = dec.Token(); err == nil { if _, check := t.(json.Delim); !check { switch t.(string) { case "x": err = dec.Decode(&s.x) case "dx": err = dec.Decode(&s.dx) case "width": err = dec.Decode(&s.width) default: err = dec.Decode(new(interface{})) } } } } return }