-
Notifications
You must be signed in to change notification settings - Fork 0
/
font.go
55 lines (43 loc) · 1.01 KB
/
font.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 pdflexgo
import (
"fmt"
"github.com/jung-kurt/gofpdf"
)
const DefaultFontSize = 11.0
type FontLoadInformation struct {
fontFamily string
style FontStyle
filePath string
}
func setFont(fpdf *gofpdf.Fpdf, fontFamily string, style FontStyle, size float64) {
_fontFamily, _style := getFontFamilyAndStyle(fontFamily, style)
fpdf.SetFont(_fontFamily, _style, size)
fpdf.SetFontSize(size)
}
func getFontFamilyAndStyle(fontFamily string, style FontStyle) (string, string) {
isStandard := true
switch fontFamily {
case FontFamilyCourier, FontFamilyHelvetica, FontFamilyArial, FontFamilyTime, FontFamilySymbol:
default:
isStandard = false
}
if isStandard {
switch style {
case FontStyleRegular:
style = ""
case FontStyleRegularItalic:
style = "I"
case FontStyleBold:
style = "B"
case FontStyleBoldItalic:
style = "BI"
default:
isStandard = false
}
}
if !isStandard {
fontFamily = fmt.Sprintf("%s!%s", fontFamily, style)
style = ""
}
return fontFamily, string(style)
}