-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont_spacing.go
116 lines (105 loc) · 2.82 KB
/
font_spacing.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
// Copyright ©2021-2022 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
import (
"strings"
"github.com/ddkwork/toolbox/i18n"
)
// FontSpacing holds the text spacing of a font.
type FontSpacing int32
// Possible values for FontSpacing.
const (
UltraCondensedSpacing FontSpacing = 1 + iota
ExtraCondensedSpacing
CondensedSpacing
SemiCondensedSpacing
StandardSpacing
SemiExpandedSpacing
ExpandedSpacing
ExtraExpandedSpacing
UltraExpandedSpacing
)
// Spacings holds the set of possible FontSpacing values.
var Spacings = []FontSpacing{
UltraCondensedSpacing,
ExtraCondensedSpacing,
CondensedSpacing,
SemiCondensedSpacing,
StandardSpacing,
SemiExpandedSpacing,
ExpandedSpacing,
ExtraExpandedSpacing,
UltraExpandedSpacing,
}
// MarshalText implements the encoding.TextMarshaler interface.
func (s FontSpacing) MarshalText() (text []byte, err error) {
return []byte(s.Key()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (s *FontSpacing) UnmarshalText(text []byte) error {
*s = SpacingFromString(string(text))
return nil
}
// SpacingFromString extracts the FontSpacing from a string.
func SpacingFromString(str string) FontSpacing {
if str == "" {
return StandardSpacing
}
for s := UltraCondensedSpacing; s <= UltraExpandedSpacing; s++ {
if strings.EqualFold(s.Key(), str) {
return s
}
}
return StandardSpacing
}
// Key returns the key that is used when serializing.
func (s FontSpacing) Key() string {
switch s {
case UltraCondensedSpacing:
return "ultra-condensed"
case ExtraCondensedSpacing:
return "extra-condensed"
case CondensedSpacing:
return "condensed"
case SemiCondensedSpacing:
return "semi-condensed"
case SemiExpandedSpacing:
return "semi-expanded"
case ExpandedSpacing:
return "expanded"
case ExtraExpandedSpacing:
return "extra-expanded"
case UltraExpandedSpacing:
return "ultra-expanded"
default:
return "standard"
}
}
func (s FontSpacing) String() string {
switch s {
case UltraCondensedSpacing:
return i18n.Text("Ultra-Condensed")
case ExtraCondensedSpacing:
return i18n.Text("Extra-Condensed")
case CondensedSpacing:
return i18n.Text("Condensed")
case SemiCondensedSpacing:
return i18n.Text("Semi-Condensed")
case SemiExpandedSpacing:
return i18n.Text("Semi-Expanded")
case ExpandedSpacing:
return i18n.Text("Expanded")
case ExtraExpandedSpacing:
return i18n.Text("Extra-Expanded")
case UltraExpandedSpacing:
return i18n.Text("Ultra-Expanded")
default:
return i18n.Text("Standard")
}
}