-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape-plan.go
98 lines (79 loc) · 4.28 KB
/
shape-plan.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
98
package hb
// #include <stdlib.h>
// #include <hb.h>
import "C"
import "unsafe"
// ShapePlan holds a shaping plan.
//
// Shape plans contain information about how HarfBuzz will shape a particular
// text segment, based on the segment's properties and the capabilities in the
// font face in use.
//
// Shape plans can be queried about how shaping will perform, given a set of
// specific input parameters (script, language, direction, features, etc.).
//
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-t
type ShapePlan *C.hb_shape_plan_t
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-create
func ShapePlanCreate(face Face, props *SegmentProperties, userFeatures []Feature, shaperList []string) ShapePlan {
shapers := cStringArray(shaperList)
defer freeStringArray(shapers)
return C.hb_shape_plan_create(face, (*C.hb_segment_properties_t)(unsafe.Pointer(props)), cFeatures(userFeatures), C.uint(len(userFeatures)), &shapers[0])
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-create-cached
func ShapePlanCreateCached(face Face, props *SegmentProperties, userFeatures []Feature, shaperList []string) ShapePlan {
shapers := cStringArray(shaperList)
defer freeStringArray(shapers)
return C.hb_shape_plan_create_cached(face, (*C.hb_segment_properties_t)(unsafe.Pointer(props)), cFeatures(userFeatures), C.uint(len(userFeatures)), &shapers[0])
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-create2
func ShapePlanCreate2(face Face, props *SegmentProperties, userFeatures []Feature, coords []int32, shaperList []string) ShapePlan {
var cCoords *C.int
if len(coords) > 0 {
cCoords = (*C.int)(unsafe.Pointer(&coords[0]))
}
shapers := cStringArray(shaperList)
defer freeStringArray(shapers)
return C.hb_shape_plan_create2(face, (*C.hb_segment_properties_t)(unsafe.Pointer(props)), cFeatures(userFeatures), C.uint(len(userFeatures)), cCoords, C.uint(len(coords)), &shapers[0])
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-create-cached2
func ShapePlanCreateCached2(face Face, props *SegmentProperties, userFeatures []Feature, coords []int32, shaperList []string) ShapePlan {
var cCoords *C.int
if len(coords) > 0 {
cCoords = (*C.int)(unsafe.Pointer(&coords[0]))
}
shapers := cStringArray(shaperList)
defer freeStringArray(shapers)
return C.hb_shape_plan_create_cached2(face, (*C.hb_segment_properties_t)(unsafe.Pointer(props)), cFeatures(userFeatures), C.uint(len(userFeatures)), cCoords, C.uint(len(coords)), &shapers[0])
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-get-empty
func ShapePlanGetEmpty() ShapePlan {
return C.hb_shape_plan_get_empty()
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-reference
func ShapePlanReference(shapePlan ShapePlan) ShapePlan {
return C.hb_shape_plan_reference(shapePlan)
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-destroy
func ShapePlanDestroy(shapePlan ShapePlan) {
C.hb_shape_plan_destroy(shapePlan)
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-set-user-data
func ShapePlanSetUserData(shapePlan ShapePlan, key *UserDataKey, data unsafe.Pointer, destroy DestroyFunc, replace bool) bool {
return C.hb_shape_plan_set_user_data(shapePlan, (*C.hb_user_data_key_t)(key), data, destroy, cBool(replace)) == 1
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-get-user-data
func ShapePlanGetUserData(shapePlan ShapePlan, key *UserDataKey) unsafe.Pointer {
return C.hb_shape_plan_get_user_data(shapePlan, (*C.hb_user_data_key_t)(key))
}
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-execute
func ShapePlanExecute(shapePlan ShapePlan, font Font, buffer Buffer, features []Feature) bool {
return C.hb_shape_plan_execute(shapePlan, font, buffer, cFeatures(features), C.uint(len(features))) == 1
}
// ShapePlanGetShaper returns the shaper from a given shaping plan.
//
// Learn more: https://harfbuzz.github.io/harfbuzz-hb-shape-plan.html#hb-shape-plan-get-shaper
func ShapePlanGetShaper(shapePlan ShapePlan) string {
res := C.hb_shape_plan_get_shaper(shapePlan)
return C.GoString(res)
}