style_group.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package xvdoc
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. )
  6. type styleRect struct {
  7. x, y int
  8. dx, dy int
  9. styles []string
  10. }
  11. func (s *styleRect) UnmarshalJSON(src []byte) (err error) {
  12. dec := json.NewDecoder(bytes.NewReader(src))
  13. var t json.Token
  14. for dec.More() && err == nil {
  15. if t, err = dec.Token(); err == nil {
  16. if _, check := t.(json.Delim); !check {
  17. switch t.(string) {
  18. case "x":
  19. err = dec.Decode(&s.x)
  20. case "y":
  21. err = dec.Decode(&s.y)
  22. case "dx":
  23. err = dec.Decode(&s.dx)
  24. case "dy":
  25. err = dec.Decode(&s.dy)
  26. case "styles":
  27. err = dec.Decode(&s.styles)
  28. default:
  29. err = dec.Decode(new(interface{}))
  30. }
  31. }
  32. }
  33. }
  34. return
  35. }
  36. //////////////////////////////////////////////////////////////////
  37. type rectMerge struct {
  38. x, y int
  39. dx, dy int
  40. }
  41. func (s *rectMerge) UnmarshalJSON(src []byte) (err error) {
  42. dec := json.NewDecoder(bytes.NewReader(src))
  43. var t json.Token
  44. for dec.More() && err == nil {
  45. if t, err = dec.Token(); err == nil {
  46. if _, check := t.(json.Delim); !check {
  47. switch t.(string) {
  48. case "x":
  49. err = dec.Decode(&s.x)
  50. case "y":
  51. err = dec.Decode(&s.y)
  52. case "dx":
  53. err = dec.Decode(&s.dx)
  54. case "dy":
  55. err = dec.Decode(&s.dy)
  56. default:
  57. err = dec.Decode(new(interface{}))
  58. }
  59. }
  60. }
  61. }
  62. return
  63. }
  64. //////////////////////////////////////////////////////////////
  65. type rectWidths struct {
  66. x, dx int
  67. width float64
  68. }
  69. func (s *rectWidths) UnmarshalJSON(src []byte) (err error) {
  70. dec := json.NewDecoder(bytes.NewReader(src))
  71. var t json.Token
  72. for dec.More() && err == nil {
  73. if t, err = dec.Token(); err == nil {
  74. if _, check := t.(json.Delim); !check {
  75. switch t.(string) {
  76. case "x":
  77. err = dec.Decode(&s.x)
  78. case "dx":
  79. err = dec.Decode(&s.dx)
  80. case "width":
  81. err = dec.Decode(&s.width)
  82. default:
  83. err = dec.Decode(new(interface{}))
  84. }
  85. }
  86. }
  87. }
  88. return
  89. }