Exemplo n.º 1
0
// Return the width and height of the rendered UTF-8 text.
//
// Return values are (width, height, err) where err is 0 for success, -1 on any error.
func (f *Font) SizeUTF8(text string) (int, int, int) {
	w := C.int(0)
	h := C.int(0)
	s := C.CString(text)
	err := C.TTF_SizeUTF8(f.cfont, s, &w, &h)
	return int(w), int(h), int(err)
}
Exemplo n.º 2
0
Arquivo: ttf.go Projeto: beoran/fungo
// Get the dimensions of a rendered string of text. Works for UTF-8 encoded text.
// returns w and h in that order
func TTFTextSize(font *C.TTF_Font, text string) (int, int) {
	var w, h int
	ctext := cstr(text)
	defer ctext.free()
	pw := cintptr(&w)
	ph := cintptr(&h)
	C.TTF_SizeUTF8(font, ctext, pw, ph)
	return w, h
}
Exemplo n.º 3
0
Arquivo: ttf.go Projeto: krig/Go-SDL2
// Return the width and height of the rendered UTF-8 text.
//
// Return values are (width, height, err)
func (f *Font) SizeUTF8(text string) (int, int, error) {
	w := C.int(0)
	h := C.int(0)
	s := C.CString(text)
	err := C.TTF_SizeUTF8(f.cfont, s, &w, &h)
	if int(err) != 0 {
		return int(w), int(h), sdl.NewSDLError()
	}
	return int(w), int(h), nil
}
Exemplo n.º 4
0
// SizeUTF8 (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_40.html#SEC40)
func (f *Font) SizeUTF8(text string) (int, int, error) {
	_text := C.CString(text)
	defer C.free(unsafe.Pointer(_text))
	var w C.int
	var h C.int
	result := C.TTF_SizeUTF8(f.f, _text, &w, &h)
	if result == 0 {
		return int(w), int(h), nil
	}
	return int(w), int(h), GetError()
}
Exemplo n.º 5
0
Arquivo: ttf.go Projeto: willemvds/sdl
func (f *Font) SizeUTF8(text string) (int, int, error) {
	w := C.int(0)
	h := C.int(0)
	ctext := C.CString(text)
	res := C.TTF_SizeUTF8(f.c, ctext, &w, &h)
	var err error
	if res != 0 {
		err = getError()
	}
	return int(w), int(h), err
}
Exemplo n.º 6
0
Arquivo: ttf.go Projeto: Zwobot/Go-SDL
// Return the width and height of the rendered UTF-8 text.
//
// Return values are (width, height, err) where err is 0 for success, -1 on any error.
func (f *Font) SizeUTF8(text string) (int, int, int) {
	sdl.GlobalMutex.Lock() // Because the underlying C code is fairly complex
	f.mutex.Lock()         // Use a write lock, because 'C.TTF_Size*' may update font's internal caches

	w := C.int(0)
	h := C.int(0)
	s := C.CString(text)
	err := C.TTF_SizeUTF8(f.cfont, s, &w, &h)

	sdl.GlobalMutex.Unlock()
	f.mutex.Unlock()

	return int(w), int(h), int(err)
}