Пример #1
0
// adjust the font to fit within a width
func (f *FW) fitwidth(width, adj int, s string) {
	f.tw = openvg.TextWidth(s, f.font, f.fontsize)
	for f.tw > openvg.VGfloat(width) {
		f.fontsize -= adj
		f.tw = openvg.TextWidth(s, f.font, f.fontsize)
	}
}
Пример #2
0
// textwrap draws text at location, wrapping at the specified width
func textwrap(x, y, w openvg.VGfloat, s string, font string, size int, leading, factor openvg.VGfloat, color string) {
	openvg.FillColor(color)
	wordspacing := openvg.TextWidth("M", font, size)
	words := strings.Split(s, " ")
	xp := x
	yp := y
	edge := x + w
	for i := 0; i < len(words); i++ {
		tw := openvg.TextWidth(words[i], font, size)
		openvg.Text(xp, yp, words[i], font, size)
		xp += tw + (wordspacing * factor)
		if xp > edge {
			xp = x
			yp -= leading
		}

	}
}
Пример #3
0
// textwrap draws text at location, wrapping at the specified width
func textwrap(x, y, w openvg.VGfloat, s string, font string, fs, leading, factor openvg.VGfloat) {
	size := int(fs)
	if font == "mono" {
		factor = 1.0
	}
	wordspacing := openvg.TextWidth("m", font, size)
	words := strings.FieldsFunc(s, whitespace)
	xp := x
	yp := y
	edge := x + w
	for _, s := range words {
		tw := openvg.TextWidth(s, font, size)
		openvg.Text(xp, yp, s, font, size)
		xp += tw + (wordspacing * factor)
		if xp > edge {
			xp = x
			yp -= leading
		}
	}
}