-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions.go
48 lines (37 loc) · 1018 Bytes
/
instructions.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
package davepdf
import "fmt"
type PdfInstruction struct {
code string
comments string
}
type PdfInstructions struct {
instructions []*PdfInstruction
}
func (ins *PdfInstructions) add(code string, comments string) {
in := &PdfInstruction{code: code, comments: comments}
ins.instructions = append(ins.instructions, in)
}
func (ins *PdfInstructions) String() string {
result := ""
maxLen := 0
for i := 0; i < len(ins.instructions); i++ {
// Get instruction
instruction := ins.instructions[i]
// Set max length
if len(instruction.code) > maxLen {
maxLen = len(instruction.code)
}
}
for i := 0; i < len(ins.instructions); i++ {
// Get instruction
instruction := ins.instructions[i]
// Append result
result += fmt.Sprintf("%-"+fmt.Sprintf("%d", maxLen+2)+"s %% %s\n", instruction.code, instruction.comments)
}
return result
}
func (pdf *Pdf) newInstructions() *PdfInstructions {
result := &PdfInstructions{}
result.instructions = make([]*PdfInstruction, 0)
return result
}