-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathprocset_obj.go
More file actions
132 lines (107 loc) · 2.87 KB
/
procset_obj.go
File metadata and controls
132 lines (107 loc) · 2.87 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package gopdf
import (
"fmt"
"io"
)
// ProcSetObj is a PDF procSet object.
type ProcSetObj struct {
//Font
Relates RelateFonts
RelateColorSpaces RelateColorSpaces
RelateXobjs RelateXobjects
ExtGStates []ExtGS
ImportedTemplateIds map[string]int
getRoot func() *GoPdf
}
func (pr *ProcSetObj) init(funcGetRoot func() *GoPdf) {
pr.getRoot = funcGetRoot
pr.ImportedTemplateIds = make(map[string]int, 0)
pr.ExtGStates = make([]ExtGS, 0)
}
func (pr *ProcSetObj) write(w io.Writer, objID int) error {
content := "<<\n"
content += "\t/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n"
fonts := "\t/Font <<\n"
for _, relate := range pr.Relates {
fonts += fmt.Sprintf("\t\t/F%d %d 0 R\n", relate.CountOfFont+1, relate.IndexOfObj+1)
}
fonts += "\t>>\n"
content += fonts
colorSpaces := "\t/ColorSpace <<\n"
for _, relate := range pr.RelateColorSpaces {
colorSpaces += fmt.Sprintf("\t\t/CS%d %d 0 R\n", relate.CountOfColorSpace+1, relate.IndexOfObj+1)
}
colorSpaces += "\t>>\n"
content += colorSpaces
xobjects := "\t/XObject <<\n"
for _, XObject := range pr.RelateXobjs {
xobjects += fmt.Sprintf("\t\t/I%d %d 0 R\n", XObject.IndexOfObj+1, XObject.IndexOfObj+1)
}
// Write imported template name and their ids
for tplName, objID := range pr.ImportedTemplateIds {
xobjects += fmt.Sprintf("\t\t%s %d 0 R\n", tplName, objID)
}
xobjects += "\t>>\n"
content += xobjects
extGStates := "\t/ExtGState <<\n"
for _, extGState := range pr.ExtGStates {
extGStates += fmt.Sprintf("\t\t/GS%d %d 0 R\n", extGState.Index+1, extGState.Index+1)
}
extGStates += "\t>>\n"
content += extGStates
content += ">>\n"
if _, err := io.WriteString(w, content); err != nil {
return err
}
return nil
}
func (pr *ProcSetObj) getType() string {
return "ProcSet"
}
// RelateFonts is a slice of RelateFont.
type RelateFonts []RelateFont
// IsContainsFamily checks if font family exists.
func (re *RelateFonts) IsContainsFamily(family string) bool {
for _, rf := range *re {
if rf.Family == family {
return true
}
}
return false
}
// IsContainsFamilyAndStyle checks if font with same name and style already exists .
func (re *RelateFonts) IsContainsFamilyAndStyle(family string, style int) bool {
for _, rf := range *re {
if rf.Family == family && rf.Style == style {
return true
}
}
return false
}
// RelateFont is a metadata index for fonts?
type RelateFont struct {
Family string
//etc /F1
CountOfFont int
//etc 5 0 R
IndexOfObj int
Style int // Regular|Bold|Italic
}
type RelateColorSpaces []RelateColorSpace
type RelateColorSpace struct {
Name string
//etc /CS1
CountOfColorSpace int
//etc 5 0 R
IndexOfObj int
}
// RelateXobjects is a slice of RelateXobject.
type RelateXobjects []RelateXobject
// RelateXobject is an index for ???
type RelateXobject struct {
IndexOfObj int
}
// ExtGS is ???
type ExtGS struct {
Index int
}