-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutline.go
76 lines (65 loc) · 1.42 KB
/
outline.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
74
75
76
package freetype
/*
#cgo pkg-config: freetype2
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
*/
import "C"
import (
"reflect"
"unsafe"
)
type Outline struct {
handle C.FT_Outline
}
// number of contours in glyph
func (o *Outline) NumContours() int {
return int(o.handle.n_contours)
}
// number of points in the glyph
func (o *Outline) NumPoints() int {
return int(o.handle.n_points)
}
// the outline's points
func (o *Outline) Points() []Vector {
size := o.NumPoints()
header := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(o.handle.points)),
Len: size,
Cap: size,
}
return *(*[]Vector)(unsafe.Pointer(&header))
}
// the points flags
func (o *Outline) Tags() []byte {
size := o.NumPoints()
header := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(o.handle.tags)),
Len: size,
Cap: size,
}
return *(*[]byte)(unsafe.Pointer(&header))
}
// the contour end points
func (o *Outline) Contours() []int16 {
size := o.NumContours()
header := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(o.handle.contours)),
Len: size,
Cap: size,
}
return *(*[]int16)(unsafe.Pointer(&header))
}
// outline masks
func (o *Outline) Flags() int {
return int(o.handle.flags)
}
// functions
func (o *Outline) Render(library *Library, params *RasterParams) error {
errno := C.FT_Outline_Render(library.handle, &o.handle, ¶ms.handle)
if errno != 0 {
return GetError(errno)
}
return nil
}