-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.go
73 lines (60 loc) · 1.82 KB
/
functions.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
package davepdf
import (
"fmt"
"strings"
)
type FunctionType = int
const (
FunctionType0 FunctionType = 0
FunctionType2 = 2
FunctionType3 = 3
FunctionType4 = 4
)
type PdfFunction struct {
id int
Type FunctionType
Domain []float64
Size []int
Encode []float64
BitsPerSample int
Range []float64
Decode []float64
Bounds []float64
Functions []*PdfFunction
C0 []float64
C1 []float64
N float64
}
func (pdf *Pdf) NewFunction() *PdfFunction {
function := &PdfFunction{}
pdf.newObjId()
function.id = pdf.n
pdf.functions = append(pdf.functions, function)
return function
}
func (pdf *Pdf) writeFunctions() {
for _, function := range pdf.functions {
childFuncs := ""
for _, childFunc := range function.Functions {
childFuncs += fmt.Sprintf("%d 0 R ", childFunc.id)
}
// Trim leading space
childFuncs = strings.TrimSpace(childFuncs)
pdf.newObj(function.id)
pdf.outln("<<")
pdf.outln(fmt.Sprintf(" /FunctionType %d", function.Type))
pdf.outln(fmt.Sprintf(" /Domain [%f %f]", function.Domain[0], function.Domain[1]))
if function.Type == FunctionType3 {
pdf.outln(fmt.Sprintf(" /Functions [%s]", childFuncs))
pdf.outln(fmt.Sprintf(" /Bounds [%f]", function.Bounds[0]))
pdf.outln(fmt.Sprintf(" /Encode [%f %f %f %f]", function.Encode[0], function.Encode[1], function.Encode[2], function.Encode[3]))
}
if function.Type == FunctionType2 {
pdf.outln(fmt.Sprintf(" /C0 [%f %f %f %f]", function.C0[0], function.C0[1], function.C0[2], function.C0[3]))
pdf.outln(fmt.Sprintf(" /C1 [%f %f %f %f]", function.C1[0], function.C1[1], function.C1[2], function.C1[3]))
pdf.outln(fmt.Sprintf(" /N %f", function.N))
}
pdf.outln(">>")
pdf.outln("endobj\n")
}
}