MCPcopy
hub / github.com/tdewolff/canvas / String

Method String

util.go:175–191  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

173type CSSColor color.RGBA
174
175func (color CSSColor) String() string {
176 if color.A == 255 {
177 buf := make([]byte, 7)
178 buf[0] = '#'
179 hex.Encode(buf[1:], []byte{color.R, color.G, color.B})
180 if buf[1] == buf[2] && buf[3] == buf[4] && buf[5] == buf[6] {
181 buf[2] = buf[3]
182 buf[3] = buf[5]
183 buf = buf[:4]
184 }
185 return string(buf)
186 } else if color.A == 0 {
187 return "rgba(0,0,0,0)"
188 }
189 a := float64(color.A) / 255.0
190 return fmt.Sprintf("rgba(%d,%d,%d,%v)", int(float64(color.R)/a), int(float64(color.G)/a), int(float64(color.B)/a), dec(a))
191}
192
193func rgbaColor(col color.Color) color.RGBA {
194 r, g, b, a := col.RGBA()

Callers

nothing calls this directly

Calls 2

decTypeAlias · 0.70
EncodeMethod · 0.65

Tested by

no test coverage detected