Example #1
0
func (atlas *FontAtlas) Draw(text string, b Bounds) {
	m := atlas.Face.Metrics()
	w := pow2(font.MeasureString(atlas.Face, text).Ceil())
	h := pow2(m.Ascent.Ceil() + m.Descent.Ceil())
	if w > 2048 {
		w = 2048
	}
	if h > 2048 {
		h = 2048
	}
	b.Max.X = b.Min.X + float32(w)
	b.Max.Y = b.Min.Y + float32(h)

	rendered := image.NewRGBA(image.Rect(0, 0, w, h))
	drawer := font.Drawer{
		Dst:  rendered,
		Src:  image.Black,
		Face: atlas.Face,
	}
	drawer.Dot = fixed.P(0, m.Ascent.Ceil())
	drawer.DrawString(text)

	atlas.draw(rendered, b)
}
Example #2
0
func (atlas *FontAtlas) Measure(text string) (size Point) {
	m := atlas.Face.Metrics()
	size.X = float32(font.MeasureString(atlas.Face, text).Ceil())
	size.Y = float32(m.Ascent.Ceil() + m.Descent.Ceil())
	return size
}