Merge pull request #253 from roipoussiere/fix-newatlas

tests and fixes faiface#123, SIGSEGV on text.NewAtlas if glyph absent
This commit is contained in:
Alex R. Delp 2020-08-22 09:49:59 -07:00 committed by GitHub
commit 65ff420b25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,6 @@
package text
import (
"fmt"
"image"
"image/draw"
"sort"
@ -60,8 +59,9 @@ func NewAtlas(face font.Face, runeSets ...[]rune) *Atlas {
))
for r, fg := range fixedMapping {
dr, mask, maskp, _, _ := face.Glyph(fg.dot, r)
draw.Draw(atlasImg, dr, mask, maskp, draw.Src)
if dr, mask, maskp, _, ok := face.Glyph(fg.dot, r); ok {
draw.Draw(atlasImg, dr, mask, maskp, draw.Src)
}
}
bounds := pixel.R(
@ -203,7 +203,6 @@ func makeMapping(face font.Face, runes []rune, padding, width fixed.Int26_6) (ma
for _, r := range runes {
b, advance, ok := face.GlyphBounds(r)
if !ok {
fmt.Println(r)
continue
}

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/faiface/pixel/text"
"golang.org/x/image/font/inconsolata"
)
func TestAtlas7x13(t *testing.T) {
@ -22,3 +23,7 @@ func TestAtlas7x13(t *testing.T) {
}
}
}
func TestAtlasInconsolata(t *testing.T) {
text.NewAtlas(inconsolata.Regular8x16, text.ASCII)
}