From 735af12e7fc9469d536d1f751a4ca7b6b99dfcfd Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:36:07 +0100 Subject: [PATCH] update LoadFontData: codePoints can now be nil, codepointCount defaults to 95 (like C raylib does) --- raylib/raylib_purego.go | 7 +++++-- raylib/rtext.go | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/raylib/raylib_purego.go b/raylib/raylib_purego.go index 73f83bb..e94af0c 100644 --- a/raylib/raylib_purego.go +++ b/raylib/raylib_purego.go @@ -2900,9 +2900,12 @@ func IsFontReady(font Font) bool { } // LoadFontData - Load font data for further use -func LoadFontData(fileData []byte, fontSize int32, codepoints []rune, typ int32) []GlyphInfo { +func LoadFontData(fileData []byte, fontSize int32, codepoints []rune, codepointCount, typ int32) []GlyphInfo { dataSize := int32(len(fileData)) - codepointCount := int32(len(codepoints)) + // In case no chars count provided, default to 95 + if codepointCount <= 0 { + codepointCount = 95 + } ret := loadFontData(fileData, dataSize, fontSize, codepoints, codepointCount, typ) return unsafe.Slice(ret, codepointCount) } diff --git a/raylib/rtext.go b/raylib/rtext.go index d1ffd2e..1e0c305 100644 --- a/raylib/rtext.go +++ b/raylib/rtext.go @@ -101,12 +101,16 @@ func IsFontReady(font Font) bool { } // LoadFontData - Load font data for further use -func LoadFontData(fileData []byte, fontSize int32, codePoints []int32, typ int32) []GlyphInfo { +func LoadFontData(fileData []byte, fontSize int32, codePoints []rune, codepointCount, typ int32) []GlyphInfo { cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) cdataSize := (C.int)(len(fileData)) cfontSize := (C.int)(fontSize) - ccodePoints := (*C.int)(unsafe.Pointer(&codePoints[0])) - ccodePointCount := (C.int)(len(codePoints)) + ccodePoints := (*C.int)(unsafe.SliceData(codePoints)) + // In case no chars count provided, default to 95 + if codepointCount <= 0 { + codepointCount = 95 + } + ccodePointCount := (C.int)(codepointCount) ctype := (C.int)(typ) ret := C.LoadFontData(cfileData, cdataSize, cfontSize, ccodePoints, ccodePointCount, ctype) v := unsafe.Slice((*GlyphInfo)(unsafe.Pointer(ret)), ccodePointCount)