-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
55 lines (46 loc) · 1.12 KB
/
options.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
package writer
import "golang.org/x/text/unicode/bidi"
// DefaultOptions contains the recommended default options
var DefaultOptions = Options{
Bidi: true,
Features: DefaultFeatures,
}
// Options holds the features used to modify, shape, and write the text.
type Options struct {
Bidi bool
Features []Feature // Feature are the OpenType feature you want to enable.
// TODO: Features maybe should be a struct instead of a slice?
}
// bidiText converts a bi-directional text logically to visually.
func bidiText(in string) (out string, err error) {
p := bidi.Paragraph{}
_, err = p.SetString(in)
if err != nil {
return
}
o, err := p.Order()
if err != nil {
return
}
mainDirection := p.Direction()
for i := 0; i < o.NumRuns(); i++ {
r := o.Run(i)
switch r.Direction() {
case bidi.LeftToRight:
if mainDirection == bidi.LeftToRight {
out += r.String()
} else {
out += bidi.ReverseString(r.String())
}
case bidi.RightToLeft:
if mainDirection == bidi.RightToLeft {
out += r.String()
} else {
out += bidi.ReverseString(r.String())
}
default:
out += r.String()
}
}
return
}