aboutsummaryrefslogtreecommitdiffstats
path: root/pkgid.go
blob: f90a33b80bdf87b6ee08a8ce3b106e5567bb0610 (plain) (blame)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package lulu

import (
	"bytes"
	"encoding"
	"fmt"
)

//go:generate go run github.com/yawnak/string-enumer -t TrimSize -t ColorType -t Quality -t Binding -t Paper -t Finish -t Linen -t Foil --text -o ./pkgid_gen.go .

// PkgId is a pod_package_id which represents the manufacturing options
// of a printable.
type PkgId struct {
	TrimSize
	ColorType
	Quality
	Binding
	Paper
	Finish
	Linen
	Foil
}

func (p PkgId) String() string {
	return fmt.Sprintf("%s.%s.%s.%s.%s.%s%s%s", p.TrimSize, p.ColorType, p.Quality, p.Binding, p.Paper, p.Finish, p.Linen, p.Foil)
}

func (p PkgId) MarshalText() ([]byte, error) {
	return []byte(p.String()), nil
}

func (p *PkgId) UnmarshalText(text []byte) error {
	s := string(text)
	parts := bytes.Split(text, []byte("."))
	if len(parts) != 6 {
		return fmt.Errorf("malformed pod_package_id %q: has %d dot-separated fields; want 6", s, len(parts))
	}
	cover := parts[5]
	if len(cover) != 3 {
		return fmt.Errorf("malformed pod_package_id %q: finish/linen/foil suffix must be 3 characters", s)
	}

	for i, field := range []encoding.TextUnmarshaler{&p.TrimSize, &p.ColorType, &p.Quality, &p.Binding, &p.Paper} {
		if err := field.UnmarshalText(parts[i]); err != nil {
			return err
		}
	}
	for i, field := range []encoding.TextUnmarshaler{&p.Finish, &p.Linen, &p.Foil} {
		if err := field.UnmarshalText([]byte{cover[i]}); err != nil {
			return err
		}
	}
	return nil
}

// TrimSize is the final dimensions of the pages after the bleed margins
// are trimmed off.
type TrimSize string

const (
	Pocketbook        TrimSize = "0425X0687"
	Novella           TrimSize = "0500X0800"
	Digest            TrimSize = "0550X0850"
	A5                TrimSize = "0583X0827"
	UsTrade           TrimSize = "0600X0900"
	Royal             TrimSize = "0614X0921"
	Comic             TrimSize = "0663X1025"
	SmallSquare       TrimSize = "0750X0750"
	Executive         TrimSize = "0700X1000"
	CrownQuatro       TrimSize = "0744X0968"
	Square            TrimSize = "0850X0850"
	A4                TrimSize = "0827X1169"
	UsLetter          TrimSize = "0850X1100"
	Landscape         TrimSize = "0900X0700"
	UsLetterLandscape TrimSize = "1100X0850"
	A4Landscape       TrimSize = "1169X0827"
)

// ColorType is the color mode of the printer.
type ColorType string

const (
	Mono  ColorType = "BW"
	Color ColorType = "FC"
)

// Quality is the print quality.
type Quality string

const (
	Premium  Quality = "PRE"
	Standard Quality = "STD"
)

type Binding string

const (
	Perfect      Binding = "PB"
	Coil         Binding = "CO"
	SaddleStitch Binding = "SS"
	CaseWrap     Binding = "CW"
	LinenWrap    Binding = "LW"
	WireO        Binding = "WO"
)

// Paper is the weight/thickness and hue of the paper.
type Paper string

const (
	P60UncoatedWhite Paper = "060UW444"
	P60UncoatedCream Paper = "060UC444"
	P70CoatedWhite   Paper = "070CW460"
	P80CoatedWhite   Paper = "080CW444"
	P100CoatedWhite  Paper = "100CW"
)

// Finish is the surface finish of the cover.
type Finish string

const (
	Gloss       Finish = "G"
	Matte       Finish = "M"
	Unlaminated Finish = "U"
)

// Linen is the color of the linen-wrapped cover, if applicable.
type Linen string

const (
	RedLinen           Linen = "R"
	NavyLinen          Linen = "N"
	BlackLinen         Linen = "B"
	GrayLinen          Linen = "G"
	TanLinen           Linen = "T"
	ForestLinen        Linen = "F"
	InteriorCoverPrint Linen = "I"
	NoLinen            Linen = "X"
)

// Foil is the color of the foil stamping, if applicable.
type Foil string

const (
	GoldFoil  Foil = "G"
	BlackFoil Foil = "B"
	WhiteFoil Foil = "W"
	NoFoil    Foil = "X"
)