From 9d60c5fa32604c49e5cd0b6dc6013ab243ef34c0 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Thu, 11 May 2017 19:48:43 +0200
Subject: [PATCH] improve Atlas creation time 2-3 times

---
 text/atlas.go | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/text/atlas.go b/text/atlas.go
index 5e7b07f..c7e189e 100644
--- a/text/atlas.go
+++ b/text/atlas.go
@@ -1,6 +1,7 @@
 package text
 
 import (
+	"fmt"
 	"image"
 	"image/draw"
 	"sort"
@@ -197,15 +198,16 @@ func makeMapping(face font.Face, runes []rune, padding, width fixed.Int26_6) (ma
 	dot := fixed.P(0, 0)
 
 	for _, r := range runes {
-		// face.Glyph gives more useful results for drawing than face.GlyphBounds
-		dr, _, _, advance, ok := face.Glyph(fixed.P(0, 0), r)
+		b, advance, ok := face.GlyphBounds(r)
 		if !ok {
+			fmt.Println(r)
 			continue
 		}
 
+		// this is important for drawing, artifacts arise otherwise
 		frame := fixed.Rectangle26_6{
-			Min: fixed.P(dr.Min.X, dr.Min.Y),
-			Max: fixed.P(dr.Max.X, dr.Max.Y),
+			Min: fixed.P(b.Min.X.Floor(), b.Min.Y.Floor()),
+			Max: fixed.P(b.Max.X.Ceil(), b.Max.Y.Ceil()),
 		}
 
 		dot.X -= frame.Min.X
-- 
GitLab