forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cid_font_obj.go
56 lines (47 loc) · 1.56 KB
/
cid_font_obj.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 gopdf
import (
"bytes"
"fmt"
)
type CIDFontObj struct {
buffer bytes.Buffer
PtrToSubsetFontObj *SubsetFontObj
indexObjSubfontDescriptor int
}
func (ci *CIDFontObj) init(funcGetRoot func() *GoPdf) {
}
func (ci *CIDFontObj) build() error {
ci.buffer.WriteString("<<\n")
ci.buffer.WriteString(fmt.Sprintf("/BaseFont /%s\n", CreateEmbeddedFontSubsetName(ci.PtrToSubsetFontObj.GetFamily())))
ci.buffer.WriteString("/CIDSystemInfo\n")
ci.buffer.WriteString("<<\n")
ci.buffer.WriteString(" /Ordering (Identity)\n")
ci.buffer.WriteString(" /Registry (Adobe)\n")
ci.buffer.WriteString(" /Supplement 0\n")
ci.buffer.WriteString(">>\n")
ci.buffer.WriteString(fmt.Sprintf("/FontDescriptor %d 0 R\n", ci.indexObjSubfontDescriptor+1)) //TODO fix
ci.buffer.WriteString("/Subtype /CIDFontType2\n")
ci.buffer.WriteString("/Type /Font\n")
characterToGlyphIndex := ci.PtrToSubsetFontObj.CharacterToGlyphIndex
ci.buffer.WriteString("/W [")
for _, v := range characterToGlyphIndex {
width := ci.PtrToSubsetFontObj.GlyphIndexToPdfWidth(v)
ci.buffer.WriteString(fmt.Sprintf("%d[%d]", v, width))
}
ci.buffer.WriteString("]\n")
ci.buffer.WriteString(">>\n")
return nil
}
func (ci *CIDFontObj) SetIndexObjSubfontDescriptor(index int) {
ci.indexObjSubfontDescriptor = index
}
func (ci *CIDFontObj) getType() string {
return "CIDFont"
}
func (ci *CIDFontObj) getObjBuff() *bytes.Buffer {
//fmt.Printf("%s\n", me.buffer.String())
return &ci.buffer
}
func (ci *CIDFontObj) SetPtrToSubsetFontObj(ptr *SubsetFontObj) {
ci.PtrToSubsetFontObj = ptr
}