~sbinet/star-tex

ref: 01f50749024c419b3b1800893d74a02994b9ecbb star-tex/font/pkf/font_test.go -rw-r--r-- 1.3 KiB
01f50749Sebastien Binet {cmd/pk2bm,font/pkf}: first import 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright ©2021 The star-tex Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package pkf

import (
	"testing"

	"star-tex.org/x/tex/font/fixed"
	"star-tex.org/x/tex/kpath"
)

func TestFont(t *testing.T) {
	ctx := kpath.New()
	for _, tc := range []struct {
		name      string
		numglyphs int
		design    fixed.Int12_20
		chksum    uint32
	}{
		{
			name:      "fonts/pk/ljfour/public/cm/dpi600/cmr10.pk",
			numglyphs: 128,
			design:    10485760,
			chksum:    1274110073,
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			f, err := ctx.Open(tc.name)
			if err != nil {
				t.Fatalf("could not open PK file: %+v", err)
			}
			defer f.Close()

			fnt, err := Parse(f)
			if err != nil {
				t.Fatalf("could not parse PK file: %+v", err)
			}

			if got, want := fnt.DesignSize(), tc.design; got != want {
				t.Fatalf("invalid design size: got=%v, want=%v", got, want)
			}

			if got, want := fnt.Checksum(), tc.chksum; got != want {
				t.Fatalf("invalid checksum: got=%v, want=%v", got, want)
			}

			if got, want := fnt.NumGlyphs(), tc.numglyphs; got != want {
				t.Fatalf("invalid number of glyphs: got=%d, want=%d", got, want)
			}

			for i := 0; i < fnt.NumGlyphs(); i++ {
				g := fnt.GlyphAt(i)
				g.unpack()
			}
		})
	}
}