Esempio n. 1
0
func glyph(face font.Face, char rune, dot fixed.Point26_6) (dr image.Rectangle, mask image.Image, maskp image.Point) {
	var ok bool

	if dr, mask, maskp, _, ok = face.Glyph(dot, char); !ok {
		dr, mask, maskp, _, _ = face.Glyph(dot, utf8.RuneError)
	}

	return
}
Esempio n. 2
0
func (p *glyphPage) add(face fnt.Face, r rune) bool {
	if _, found := p.entries[r]; found {
		panic("Glyph already added to glyph page")
	}

	b, mask, maskp, _, _ := face.Glyph(fixed.Point26_6{}, r)
	bounds := math.CreateRect(b.Min.X, b.Min.Y, b.Max.X, b.Max.Y)

	w, h := bounds.Size().WH()
	x, y := p.nextPoint.X, p.nextPoint.Y

	if x+w > p.size.W {
		// Row full, start new line
		x = 0
		y += p.rowHeight + glyphPadding
		p.rowHeight = 0
	}

	if y+h > p.size.H {
		return false // Page full
	}

	draw.Draw(p.image, image.Rect(x, y, x+w, y+h), mask, maskp, draw.Src)

	p.entries[r] = glyphEntry{
		offset: math.Point{X: x, Y: y}.Sub(bounds.Min),
		bounds: bounds,
	}
	p.nextPoint = math.Point{X: x + w + glyphPadding, Y: y}
	if h > p.rowHeight {
		p.rowHeight = h
	}
	p.tex = nil

	return true
}