forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strhelper.go
49 lines (44 loc) · 1.05 KB
/
strhelper.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
package gopdf
import (
"math/big"
"strings"
)
//StrHelperGetStringWidth get string width
func StrHelperGetStringWidth(str string, fontSize int, ifont IFont) float64 {
w := 0
bs := []byte(str)
i := 0
max := len(bs)
for i < max {
w += ifont.GetCw()[bs[i]]
i++
}
return float64(w) * (float64(fontSize) / 1000.0)
}
//CreateEmbeddedFontSubsetName create Embedded font (subset font) name
func CreateEmbeddedFontSubsetName(name string) string {
name = strings.Replace(name, " ", "+", -1)
name = strings.Replace(name, "/", "+", -1)
return name
}
//ReadShortFromByte read short from byte array
func ReadShortFromByte(data []byte, offset int) (int64, int) {
buff := data[offset : offset+2]
num := big.NewInt(0)
num.SetBytes(buff)
u := num.Uint64()
var v int64
if u >= 0x8000 {
v = int64(u) - 65536
} else {
v = int64(u)
}
return v, 2
}
//ReadUShortFromByte read ushort from byte array
func ReadUShortFromByte(data []byte, offset int) (uint64, int) {
buff := data[offset : offset+2]
num := big.NewInt(0)
num.SetBytes(buff)
return num.Uint64(), 2
}