improve Atlas creation time 2-3 times

This commit is contained in:
faiface 2017-05-11 19:48:43 +02:00
parent cce26f0a51
commit 9d60c5fa32
1 changed files with 6 additions and 4 deletions

View File

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