-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.go
56 lines (46 loc) · 1.1 KB
/
resources.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
package davepdf
import "fmt"
type PdfResources struct {
id int
objects []*PdfObject
}
func (pdf *Pdf) newResources() *PdfResources {
resources := &PdfResources{}
pdf.newObjId()
resources.id = pdf.n
return resources
}
func (pdf *Pdf) writeResources() {
pdf.newObj(pdf.resources.id)
pdf.outln("<<")
// Write fonts
if len(pdf.fonts) > 0 {
pdf.outln(" /Font <<")
for _, font := range pdf.fonts {
pdf.outln(fmt.Sprintf(" /Font-%s %d 0 R", font.family, font.id))
}
pdf.outln(" >>")
}
// Write XObjects
if len(pdf.tplObjIds)+len(pdf.images) > 0 {
pdf.outln(" /XObject <<")
for tplName, id := range pdf.tplObjIds {
pdf.outln(fmt.Sprintf(" %s %d 0 R", tplName, id))
}
for _, image := range pdf.images {
pdf.outln(fmt.Sprintf(" /Image%d %d 0 R", image.id, image.id))
}
pdf.outln(" >>")
}
// Write Shadings
if len(pdf.shadings) > 0 {
pdf.outln(" /Shading <<")
for i := 0; i < len(pdf.shadings); i++ {
shading := pdf.shadings[i]
pdf.outln(fmt.Sprintf(" /Sh%d %d 0 R", 1, shading.id))
}
pdf.outln(" >>")
}
pdf.outln(">>")
pdf.outln("endobj\n")
}