git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

font/plan9font/plan9font_test.go (1.4K)

 1 // Copyright 2016 The Go Authors. All rights reserved.
 2 // Use of this source code is governed by a BSD-style
 3 // license that can be found in the LICENSE file.
 4 
 5 package plan9font
 6 
 7 import (
 8 	"image"
 9 	"io/ioutil"
10 	"path"
11 	"path/filepath"
12 	"testing"
13 
14 	"golang.org/x/image/font"
15 )
16 
17 func TestMetrics(t *testing.T) {
18 	readFile := func(name string) ([]byte, error) {
19 		return ioutil.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
20 	}
21 	data, err := readFile("unicode.7x13.font")
22 	if err != nil {
23 		t.Fatal(err)
24 	}
25 	face, err := ParseFont(data, readFile)
26 	if err != nil {
27 		t.Fatal(err)
28 	}
29 	want := font.Metrics{Height: 832, Ascent: 704, Descent: 128, XHeight: 704, CapHeight: 704,
30 		CaretSlope: image.Point{X: 0, Y: 1}}
31 	if got := face.Metrics(); got != want {
32 		t.Errorf("unicode.7x13.font: Metrics: got %v, want %v", got, want)
33 	}
34 	subData, err := readFile("7x13.0000")
35 	if err != nil {
36 		t.Fatal(err)
37 	}
38 	subFace, err := ParseSubfont(subData, 0)
39 	if err != nil {
40 		t.Fatal(err)
41 	}
42 	if got := subFace.Metrics(); got != want {
43 		t.Errorf("7x13.0000: Metrics: got %v, want %v", got, want)
44 	}
45 }
46 
47 func BenchmarkParseSubfont(b *testing.B) {
48 	subfontData, err := ioutil.ReadFile(filepath.FromSlash("../testdata/fixed/7x13.0000"))
49 	if err != nil {
50 		b.Fatal(err)
51 	}
52 	b.ResetTimer()
53 	for i := 0; i < b.N; i++ {
54 		if _, err := ParseSubfont(subfontData, 0); err != nil {
55 			b.Fatal(err)
56 		}
57 	}
58 }