Example #1
0
// RenderTo32Bit renders a string using the bitmapped font to a non-antialised
// string to a 32-bit buffer with the given color. It returns the width of the
// string.
func (s *Font) RenderTo32Bit(
	str string, col color.Color, x, y int, target gfx.Surface32Bit) (xAdvance float64) {
	col32 := target.MapColor(col)
	for _, ch := range str {
		if !s.valid(ch) {
			continue
		}

		g := s.glyphs[int(ch)-s.startChar]

		s.render32BitChar(ch, col32, x+int(xAdvance), y, target)

		xAdvance += float64(g.xAdvance)
	}
	return
}
Example #2
0
func (s *Font) render32BitChar(
	ch rune, color uint32, x, y int, target gfx.Surface32Bit) {
	if !s.valid(ch) {
		return
	}

	g := s.glyphs[int(ch)-s.startChar]

	x += int(g.xOff)
	y += int(g.yOff)

	tPix := target.Pixels32()

	tRect := target.Bounds()

	for gy := 0; gy <= int(g.y1-g.y0); gy++ {
		tPos := x + (y+gy)*target.Pitch32()
		gPos := (gy+int(g.y0))*s.Pitch() + int(g.x0)

		for gx := 0; gx <= int(g.x1-g.x0); gx++ {
			if s.pixels[gPos+gx] >= 0x80 && image.Pt(x+gx, y+gy).In(tRect) {
				tPix[tPos+gx] = color
			}
		}
	}
}