forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlyphRanges.go
32 lines (26 loc) · 918 Bytes
/
GlyphRanges.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
package imgui
// #include "wrapper/Types.h"
import "C"
import "unsafe"
// GlyphRanges describes a list of Unicode ranges; 2 value per range, values are inclusive.
// Standard ranges can be queried from FontAtlas.GlyphRanges*() functions.
type GlyphRanges uintptr
// EmptyGlyphRanges is one that does not contain any ranges.
const EmptyGlyphRanges GlyphRanges = 0
func (glyphs GlyphRanges) handle() C.IggGlyphRanges {
return C.IggGlyphRanges(glyphs)
}
type glyphRange struct{ from, to uint16 }
func (glyphs GlyphRanges) extract() (result []glyphRange) {
if glyphs == 0 {
return
}
rawSlice := ptrToUint16Slice(unsafe.Pointer(glyphs.handle()))
index := 0
// iterate until end of list or an arbitrary paranoia limit, should the list not be proper.
for (rawSlice[index] != 0) && (index < 1000) {
result = append(result, glyphRange{from: rawSlice[index+0], to: rawSlice[index+1]})
index += 2
}
return
}