-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.go
80 lines (67 loc) · 1.34 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
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
package davepdf
type PdfFont struct {
id int
family string
}
func (pdf *Pdf) newFont() *PdfFont {
font := &PdfFont{}
pdf.newObjId()
font.id = pdf.n
pdf.fonts = append(pdf.fonts, font)
return font
}
func (pdf *Pdf) SetFontFamily(fontFamily string) {
validFonts := []string{
"Times-Roman",
"Times-Bold",
"Times-Italic",
"Times-BoldItalic",
"Courier",
"Courier-Bold",
"Courier-Oblique",
"Courier-BoldOblique",
"Helvetica",
"Helvetica-Bold",
"Helvetica-Oblique",
"Helvetica-BoldOblique",
"Symbol",
"ZapfDingbats"}
valid := false
for _, font := range validFonts {
if font == fontFamily {
valid = true
break
}
}
if !valid {
panic("Invalid font: " + fontFamily)
}
found := false
for _, font := range pdf.fonts {
if font.family == fontFamily {
pdf.fontFamily = "/Font-" + font.family
found = true
break
}
}
if !found {
font := pdf.newFont()
font.family = fontFamily
pdf.fontFamily = "/Font-" + font.family
}
}
func (pdf *Pdf) SetFontSize(fontSize int) {
pdf.fontSize = fontSize
}
func (pdf *Pdf) writeFonts() {
for _, font := range pdf.fonts {
pdf.newObj(font.id)
pdf.outln("<<")
pdf.outln(" /Type /Font")
pdf.outln(" /Subtype /Type1")
pdf.outln(" /Name /Font-" + font.family)
pdf.outln(" /BaseFont /" + font.family)
pdf.outln(">>")
pdf.outln("endobj\n")
}
}