~sbinet/star-tex

ref: 01f50749024c419b3b1800893d74a02994b9ecbb star-tex/font/pkf/cmd.go -rw-r--r-- 2.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// 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 (
	"star-tex.org/x/tex/internal/iobuf"
)

// Cmd is a PK command.
type Cmd interface {
	opcode() opCode
	Name() string

	read(r *iobuf.Reader)
}

type CmdXXX1 struct {
	Value []byte
}

func (CmdXXX1) opcode() opCode { return opXXX1 }
func (CmdXXX1) Name() string   { return "pk_xxx1" }
func (cmd *CmdXXX1) read(r *iobuf.Reader) {
	_ = r.ReadU8()
	n := int(r.ReadU8())
	cmd.Value = r.ReadBuf(n)
}

type CmdXXX2 struct {
	Value []byte
}

func (CmdXXX2) opcode() opCode { return opXXX2 }
func (CmdXXX2) Name() string   { return "pk_xxx2" }
func (cmd *CmdXXX2) read(r *iobuf.Reader) {
	_ = r.ReadU8()
	n := int(r.ReadU16())
	cmd.Value = r.ReadBuf(n)
}

type CmdXXX3 struct {
	Value []byte
}

func (CmdXXX3) opcode() opCode { return opXXX3 }
func (CmdXXX3) Name() string   { return "pk_xxx3" }
func (cmd *CmdXXX3) read(r *iobuf.Reader) {
	_ = r.ReadU8()
	n := int(r.ReadU24())
	cmd.Value = r.ReadBuf(n)
}

type CmdXXX4 struct {
	Value []byte
}

func (CmdXXX4) opcode() opCode { return opXXX4 }
func (CmdXXX4) Name() string   { return "pk_xxx4" }
func (cmd *CmdXXX4) read(r *iobuf.Reader) {
	_ = r.ReadU8()
	n := int(r.ReadU32())
	cmd.Value = r.ReadBuf(n)
}

type CmdYYY struct {
	Value uint32
}

func (CmdYYY) opcode() opCode { return opYYY }
func (CmdYYY) Name() string   { return "pk_yyy" }
func (cmd *CmdYYY) read(r *iobuf.Reader) {
	_ = r.ReadU8()
	cmd.Value = r.ReadU32()
}

type CmdPost struct{}

func (CmdPost) opcode() opCode { return opPost }
func (CmdPost) Name() string   { return "pk_post" }
func (CmdPost) read(r *iobuf.Reader) {
	_ = r.ReadU8()
}

type CmdNOP struct{}

func (CmdNOP) opcode() opCode { return opNOP }
func (CmdNOP) Name() string   { return "pk_nop" }
func (CmdNOP) read(r *iobuf.Reader) {
	_ = r.ReadU8()
}

type CmdPre struct {
	Version  uint8
	Msg      string
	Design   uint32
	Checksum uint32
	Hppp     uint32
	Vppp     uint32
}

func (CmdPre) opcode() opCode { return opPre }
func (CmdPre) Name() string   { return "pk_pre" }
func (cmd *CmdPre) read(r *iobuf.Reader) {
	_ = r.ReadU8()
	cmd.Version = r.ReadU8()
	n := int(r.ReadU8())
	cmd.Msg = string(r.ReadBuf(n))
	cmd.Design = r.ReadU32()
	cmd.Checksum = r.ReadU32()
	cmd.Hppp = r.ReadU32()
	cmd.Vppp = r.ReadU32()
}

var (
	_ Cmd = (*CmdXXX1)(nil)
	_ Cmd = (*CmdXXX2)(nil)
	_ Cmd = (*CmdXXX3)(nil)
	_ Cmd = (*CmdXXX4)(nil)
	_ Cmd = (*CmdYYY)(nil)
	_ Cmd = (*CmdPost)(nil)
	_ Cmd = (*CmdNOP)(nil)
	_ Cmd = (*CmdPre)(nil)
)