Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445package theme
import ( "math" "testing"
"gioui.org/font" "gioui.org/text" "golang.org/x/image/math/fixed")
// TestFonts checks the embedded faces load as four weights of Noto Sans.func TestFonts(t *testing.T) { weights := map[font.Weight]bool{} for _, f := range Fonts() { if f.Font.Typeface != uiFamily { t.Errorf("embedded face %q, want %q", f.Font.Typeface, uiFamily) } weights[f.Font.Weight] = true } for _, w := range []font.Weight{font.Normal, font.Medium, font.SemiBold, font.Bold} { if !weights[w] { t.Errorf("no %v weight among %v", w, weights) } }}
// TestWeights checks that bolder UI text really is bolder: a font that// offered only one weight, as a variable font does in Gio, would shape every// weight the same.func TestWeights(t *testing.T) { s := NewShaper() width := func(face font.Typeface, w font.Weight) fixed.Int26_6 { s.LayoutString(text.Parameters{Font: font.Font{Typeface: face, Weight: w}, PxPerEm: fixed.I(20), MaxWidth: math.MaxInt32, MaxLines: 1}, "Wwwwwwwwww") var adv fixed.Int26_6 for g, ok := s.NextGlyph(); ok; g, ok = s.NextGlyph() { adv += g.Advance } return adv } if regular, bold := width(UIFace, font.Normal), width(UIFace, font.Bold); bold <= regular { t.Errorf("UI face: bold is %v wide, regular %v", bold, regular) }}