This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
value_typography.go
133 lines (115 loc) · 2.79 KB
/
value_typography.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package property
import (
"github.com/mitchellh/mapstructure"
)
var ValueTypeTypography = ValueType("typography")
type Typography struct {
FontFamily *string `json:"fontFamily" mapstructure:"fontFamily"`
FontWeight *string `json:"fontWeight" mapstructure:"fontWeight"`
FontSize *int `json:"fontSize" mapstructure:"fontSize"`
Color *string `json:"color" mapstructure:"color"`
TextAlign *TextAlign `json:"textAlign" mapstructure:"textAlign"`
Bold *bool `json:"bold" mapstructure:"bold"`
Italic *bool `json:"italic" mapstructure:"italic"`
Underline *bool `json:"underline" mapstructure:"underline"`
}
func (t *Typography) Clone() *Typography {
if t == nil {
return nil
}
return &Typography{
FontFamily: t.FontFamily,
FontWeight: t.FontWeight,
FontSize: t.FontSize,
Color: t.Color,
TextAlign: t.TextAlign,
Bold: t.Bold,
Italic: t.Italic,
Underline: t.Underline,
}
}
type TextAlign string
const (
TextAlignLeft TextAlign = "left"
TextAlignCenter TextAlign = "center"
TextAlignRight TextAlign = "right"
TextAlignJustify TextAlign = "justify"
TextAlignJustifyAll TextAlign = "justify_all"
)
func TextAlignFrom(t string) (TextAlign, bool) {
switch TextAlign(t) {
case TextAlignLeft:
return TextAlignLeft, true
case TextAlignCenter:
return TextAlignCenter, true
case TextAlignRight:
return TextAlignRight, true
case TextAlignJustify:
return TextAlignJustify, true
case TextAlignJustifyAll:
return TextAlignJustifyAll, true
}
return TextAlign(""), false
}
func TextAlignFromRef(t *string) *TextAlign {
if t == nil {
return nil
}
var t2 TextAlign
switch TextAlign(*t) {
case TextAlignLeft:
t2 = TextAlignLeft
case TextAlignCenter:
t2 = TextAlignCenter
case TextAlignRight:
t2 = TextAlignRight
case TextAlignJustify:
t2 = TextAlignJustify
case TextAlignJustifyAll:
t2 = TextAlignJustifyAll
default:
return nil
}
return &t2
}
func (t TextAlign) String() string {
return string(t)
}
func (t *TextAlign) StringRef() *string {
if t == nil {
return nil
}
t2 := string(*t)
return &t2
}
type typePropertyTypography struct{}
func (*typePropertyTypography) I2V(i interface{}) (interface{}, bool) {
if v, ok := i.(Typography); ok {
return v, true
}
if v, ok := i.(*Typography); ok {
if v != nil {
return *v, true
}
return nil, false
}
v := Typography{}
if err := mapstructure.Decode(i, &v); err == nil {
return v, true
}
return nil, false
}
func (*typePropertyTypography) V2I(v interface{}) (interface{}, bool) {
return v, true
}
func (*typePropertyTypography) Validate(i interface{}) bool {
_, ok := i.(Typography)
return ok
}
func (v *Value) ValueTypography() (vv Typography, ok bool) {
if v == nil {
return
}
vv, ok = v.Value().(Typography)
return
}