forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
font_obj.go
65 lines (54 loc) · 1.4 KB
/
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
57
58
59
60
61
62
63
64
65
package gopdf
import (
"fmt"
"io"
)
//FontObj font obj
type FontObj struct {
Family string
//Style string
//Size int
IsEmbedFont bool
indexObjWidth int
indexObjFontDescriptor int
indexObjEncoding int
Font IFont
CountOfFont int
}
func (f *FontObj) init(funcGetRoot func() *GoPdf) {
f.IsEmbedFont = false
//me.CountOfFont = -1
}
func (f *FontObj) write(w io.Writer, objID int) error {
baseFont := f.Family
if f.Font != nil {
baseFont = f.Font.GetName()
}
io.WriteString(w, "<<\n")
fmt.Fprintf(w, " /Type /%s\n", f.getType())
io.WriteString(w, " /Subtype /TrueType\n")
fmt.Fprintf(w, " /BaseFont /%s\n", baseFont)
if f.IsEmbedFont {
io.WriteString(w, " /FirstChar 32 /LastChar 255\n")
fmt.Fprintf(w, " /Widths %d 0 R\n", f.indexObjWidth)
fmt.Fprintf(w, " /FontDescriptor %d 0 R\n", f.indexObjFontDescriptor)
fmt.Fprintf(w, " /Encoding %d 0 R\n", f.indexObjEncoding)
}
io.WriteString(w, ">>\n")
return nil
}
func (f *FontObj) getType() string {
return "Font"
}
// SetIndexObjWidth sets the width of a font object.
func (f *FontObj) SetIndexObjWidth(index int) {
f.indexObjWidth = index
}
// SetIndexObjFontDescriptor sets the font descriptor.
func (f *FontObj) SetIndexObjFontDescriptor(index int) {
f.indexObjFontDescriptor = index
}
// SetIndexObjEncoding sets the encoding.
func (f *FontObj) SetIndexObjEncoding(index int) {
f.indexObjEncoding = index
}