forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subfont_descriptor_obj.go
61 lines (52 loc) · 2.19 KB
/
subfont_descriptor_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
package gopdf
import (
"bytes"
"fmt"
"github.com/signintech/gopdf/fontmaker/core"
)
//SubfontDescriptorObj pdf subfont descriptorObj object
type SubfontDescriptorObj struct {
buffer bytes.Buffer
PtrToSubsetFontObj *SubsetFontObj
indexObjPdfDictionary int
}
func (s *SubfontDescriptorObj) init(func() *GoPdf) {}
func (s *SubfontDescriptorObj) getType() string {
return "SubFontDescriptor"
}
func (s *SubfontDescriptorObj) getObjBuff() *bytes.Buffer {
return &s.buffer
}
func (s *SubfontDescriptorObj) build() error {
ttfp := s.PtrToSubsetFontObj.GetTTFParser()
s.buffer.WriteString("<<\n")
s.buffer.WriteString("/Type /FontDescriptor\n")
s.buffer.WriteString(fmt.Sprintf("/Ascent %d\n", DesignUnitsToPdf(ttfp.Ascender(), ttfp.UnitsPerEm())))
s.buffer.WriteString(fmt.Sprintf("/CapHeight %d\n", DesignUnitsToPdf(ttfp.CapHeight(), ttfp.UnitsPerEm())))
s.buffer.WriteString(fmt.Sprintf("/Descent %d\n", DesignUnitsToPdf(ttfp.Descender(), ttfp.UnitsPerEm())))
s.buffer.WriteString(fmt.Sprintf("/Flags %d\n", ttfp.Flag()))
s.buffer.WriteString(fmt.Sprintf("/FontBBox [%d %d %d %d]\n",
DesignUnitsToPdf(ttfp.XMin(), ttfp.UnitsPerEm()),
DesignUnitsToPdf(ttfp.YMin(), ttfp.UnitsPerEm()),
DesignUnitsToPdf(ttfp.XMax(), ttfp.UnitsPerEm()),
DesignUnitsToPdf(ttfp.YMax(), ttfp.UnitsPerEm()),
))
s.buffer.WriteString(fmt.Sprintf("/FontFile2 %d 0 R\n", s.indexObjPdfDictionary+1))
s.buffer.WriteString(fmt.Sprintf("/FontName /%s\n", CreateEmbeddedFontSubsetName(s.PtrToSubsetFontObj.GetFamily())))
s.buffer.WriteString(fmt.Sprintf("/ItalicAngle %d\n", ttfp.ItalicAngle()))
s.buffer.WriteString("/StemV 0\n")
s.buffer.WriteString(fmt.Sprintf("/XHeight %d\n", DesignUnitsToPdf(ttfp.XHeight(), ttfp.UnitsPerEm())))
s.buffer.WriteString(">>\n")
return nil
}
//SetIndexObjPdfDictionary set PdfDictionary pointer
func (s *SubfontDescriptorObj) SetIndexObjPdfDictionary(index int) {
s.indexObjPdfDictionary = index
}
//SetPtrToSubsetFontObj set SubsetFont pointer
func (s *SubfontDescriptorObj) SetPtrToSubsetFontObj(ptr *SubsetFontObj) {
s.PtrToSubsetFontObj = ptr
}
func DesignUnitsToPdf(val int64, unitsPerEm uint64) int64 {
return core.Round(float64(float64(val) * 1000.00 / float64(unitsPerEm)))
}