1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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
- }
|