~mendelmaleh/dummy

ref: b7992e7049cbea825edd717ffdc3e89122e1a0d4 dummy/options.go -rw-r--r-- 954 bytes
b7992e70Mendel E Normalize in server package 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
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
}