-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathface.go
47 lines (37 loc) · 948 Bytes
/
face.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
package writer
import (
"io"
"github.com/haashemi/go-harfbuzz/hb"
)
// Just to make sure if [Face] implements [io.Closer].
var _ io.Closer = &Face{}
// Face holds a harfbuzz Face object.
type Face struct {
io.Closer
blob hb.Blob
face hb.Face
}
// Close destroys the harfbuzz Blob and Face objects and frees the memory.
func (f *Face) Close() error {
hb.FaceDestroy(f.face)
hb.BlobDestroy(f.blob)
return nil
}
// NewFace returns a newly initialized harfbuzz Face object from “data” bytes.
func NewFace(data []byte) *Face {
blob := hb.BlobCreate(data, hb.MemoryModeDuplicate, nil, nil)
face := hb.FaceCreate(blob, 0)
return &Face{
blob: blob,
face: face,
}
}
// NewFaceFromFile returns a newly initialized harfbuzz Face object from “filename” file.
func NewFaceFromFile(filename string) *Face {
blob := hb.BlobCreateFromFile(filename)
face := hb.FaceCreate(blob, 0)
return &Face{
blob: blob,
face: face,
}
}