Beispiel #1
0
//TextExtents reports the extents for s.
//The extents describe a user-space rectangle that encloses the "inked" portion
//of the text, as it would be drawn with ShownText.
//Additionally, the x_advance and y_advance values indicate the amount by which
//the current point would be advanced by ShowText.
//
//Note that whitespace characters do not directly contribute to the size
//of the rectangle (extents.Width and extents.Height), but they do contribute
//indirectly by changing the position of non-whitespace characters.
//In particular, trailing whitespace characters are likely to not affect
//the size of the rectangle, though they will affect the AdvanceX and AdvanceY
//values.
//
//Originally cairo_text_extents.
func (c *Context) TextExtents(s string) TextExtents {
	var t C.cairo_text_extents_t
	cs := C.CString(s)
	C.cairo_text_extents(c.c, cs, &t)
	C.free(unsafe.Pointer(cs))
	return XtensionNewTextExtents(t)
}
Beispiel #2
0
func (v *Context) TextExtents(utf8 string) TextExtents {
	cstr := C.CString(utf8)
	defer C.free(unsafe.Pointer(cstr))
	var extents C.cairo_text_extents_t
	C.cairo_text_extents(v.native(), (*C.char)(cstr), &extents)
	return TextExtents{
		XBearing: float64(extents.x_bearing),
		YBearing: float64(extents.y_bearing),
		Width:    float64(extents.width),
		Height:   float64(extents.height),
		XAdvance: float64(extents.x_advance),
		YAdvance: float64(extents.y_advance),
	}
}
Beispiel #3
0
func (self *Surface) TextExtents(text string) *TextExtents {
	cte := C.cairo_text_extents_t{}
	cs := C.CString(text)
	C.cairo_text_extents(self.context, cs, &cte)
	C.free(unsafe.Pointer(cs))
	te := &TextExtents{
		Xbearing: float64(cte.x_bearing),
		Ybearing: float64(cte.y_bearing),
		Width:    float64(cte.width),
		Height:   float64(cte.height),
		Xadvance: float64(cte.x_advance),
		Yadvance: float64(cte.y_advance),
	}
	return te
}
Beispiel #4
0
func (self *Surface) GetTextExtents(text string) *GTextExtents {
	p := C.CString(text)
	e := new(TextExtents)
	C.cairo_text_extents(self.context, p, &(e.extents))
	C.free(unsafe.Pointer(p))

	r := new(GTextExtents)
	r.XBearing = float64(e.extents.x_bearing)
	r.YBearing = float64(e.extents.y_bearing)
	r.Width = float64(e.extents.width)
	r.Height = float64(e.extents.height)
	r.XAdvance = float64(e.extents.x_advance)
	r.YAdvance = float64(e.extents.y_advance)

	return r
}
Beispiel #5
0
// void cairo_text_extents (cairo_t *cr, const char *utf8, cairo_text_extents_t *extents);
func (self *Surface) TextExtents(utf8 string, extents *TextExtents) {
	C.cairo_text_extents(self.context, C.CString(utf8), (*C.cairo_text_extents_t)(unsafe.Pointer(extents)))
}