~mendelmaleh/dummy

ref: 55d7475293eaf60ed5d381c1efe1e9af58f98b78 dummy/options.go -rw-r--r-- 1.1 KiB
55d74752Mendel E Wrap dummy.Options 1 year, 2 months 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
package dummy

import (
	"image/color"

	"git.sr.ht/~mendelmaleh/freetype/truetype"
)

type Options struct {
	// image
	Width, Height int
	Mask          string
	Colors        []color.RGBA

	// text
	Text      string
	Font      *truetype.Font
	Size, DPI float64

	// web
	Desc string
}

// to be used only with dopt.Copy(), otherwise the default colors can be changed.
var DefaultOptions = &Options{
	// image
	Width:  200,
	Height: 200,
	Mask:   "plain",
	Colors: []color.RGBA{
		color.RGBA{0, 0, 0, 0xff},
		color.RGBA{0xff, 0xff, 0xff, 0xff},
	},

	// text // default font is set in main after its loaded.
	Size: 80,
	DPI:  72,

	// web
	Desc: "Dummy image generator",
}

// Copy so that the original options don't change (essentially a deep copy).
func (opt Options) Copy() (copt Options) {
	// copy all the fields
	copt = opt

	// deep copy for slices
	copt.Colors = make([]color.RGBA, len(opt.Colors))
	copy(copt.Colors, opt.Colors)

	return copt
}

// Normalize our Options, implement limits and workarounds.
func (opt *Options) Normalize() {
	// limit width to 600 for now
	if opt.Width > 600 {
		opt.Width = 600
	}
}