Beispiel #1
0
// 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
}
Beispiel #2
0
// Returns the metrics (dimensions) of a glyph.
//
// Return values are:
//   minx, maxx, miny, maxy, advance, err
//
// For more information on glyph metrics, visit
// http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
func (f *Font) GlyphMetrics(ch uint16) (int, int, int, int, int, error) {
	minx := C.int(0)
	maxx := C.int(0)
	miny := C.int(0)
	maxy := C.int(0)
	advance := C.int(0)
	err := C.TTF_GlyphMetrics(f.cfont, C.Uint16(ch), &minx, &maxx, &miny, &maxy, &advance)
	if int(err) != 0 {
		return int(minx), int(maxx), int(miny), int(maxy), int(advance), sdl.NewSDLError()
	}
	return int(minx), int(maxx), int(miny), int(maxy), int(advance), nil
}