-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrasterparams.go
97 lines (80 loc) · 2.33 KB
/
rasterparams.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package freetype
/*
#cgo pkg-config: freetype2
#include <ft2build.h>
#include FT_FREETYPE_H
void ftRasterParamsGraySpansCB(FT_Raster_Params* params);
*/
import "C"
import (
"reflect"
"unsafe"
)
const (
RasterFlagDefault int = C.FT_RASTER_FLAG_DEFAULT
RasterFlagAA int = C.FT_RASTER_FLAG_AA
RasterFlagDirect int = C.FT_RASTER_FLAG_DIRECT
RasterFlagClip int = C.FT_RASTER_FLAG_CLIP
)
type RasterParams struct {
handle C.FT_Raster_Params
graySpanFunc SpanFunc
}
func NewRasterParams() *RasterParams {
return &RasterParams{handle: C.FT_Raster_Params{}}
}
// The target bitmap.
func (params *RasterParams) Target() *Bitmap {
return &Bitmap{*params.handle.target}
}
func (params *RasterParams) SetTarget(target *Bitmap) {
params.handle.target = &target.handle
}
func (params *RasterParams) Source() unsafe.Pointer {
return params.handle.source
}
func (params *RasterParams) SetSource(source *interface{}) {
params.handle.source = unsafe.Pointer(source)
}
// The rendering flags.
func (params *RasterParams) Flags() int {
return int(params.handle.flags)
}
func (params *RasterParams) SetFlags(flags int) {
params.handle.flags = C.int(flags)
}
func (params *RasterParams) GraySpans() SpanFunc {
return params.graySpanFunc
}
func (params *RasterParams) SetGraySpans(f SpanFunc) {
params.handle.user = unsafe.Pointer(¶ms.handle)
rasterParams[¶ms.handle] = params
params.graySpanFunc = f
C.ftRasterParamsGraySpansCB(¶ms.handle)
}
var rasterParams map[*C.FT_Raster_Params]*RasterParams = make(map[*C.FT_Raster_Params]*RasterParams)
//export goRasterParamsGraySpans
func goRasterParamsGraySpans(y, count C.FT_Int, spans *C.FT_Span, user unsafe.Pointer) {
c := int(count)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(spans)),
Len: c,
Cap: c,
}
goSlice := *(*[]C.FT_Span)(unsafe.Pointer(&hdr))
s := make([]Span, c)
for i := range goSlice {
s[i] = Span{goSlice[i]}
}
params := rasterParams[(*C.FT_Raster_Params)(user)]
params.graySpanFunc(int(y), c, s)
}
// An optional clipping box. It is only used in direct rendering mode.
// Note that coordinates here should be expressed in integer pixels
// (and not in 26.6 fixed-point units)
func (params *RasterParams) ClipBox() *BBox {
return &BBox{params.handle.clip_box}
}
func (params *RasterParams) SetClipBox(bbox *BBox) {
params.handle.clip_box = bbox.handle
}