2019-07-25 19:43:46 +03:00
|
|
|
// Copyright 2017 FoxyUtils ehf. All rights reserved.
|
2017-08-28 20:56:18 -05:00
|
|
|
//
|
2020-08-08 01:01:05 +00:00
|
|
|
// Use of this software package and source code is governed by the terms of the
|
|
|
|
// UniDoc End User License Agreement (EULA) that is available at:
|
|
|
|
// https://unidoc.io/eula/
|
|
|
|
// A trial license code for evaluation can be obtained at https://unidoc.io.
|
2017-08-28 20:56:18 -05:00
|
|
|
|
|
|
|
package color
|
|
|
|
|
2017-09-09 08:24:05 -05:00
|
|
|
import (
|
2019-05-04 11:18:06 +03:00
|
|
|
"github.com/unidoc/unioffice"
|
2017-09-09 08:24:05 -05:00
|
|
|
)
|
2017-08-28 20:56:18 -05:00
|
|
|
|
|
|
|
// Color is a 24 bit color that can be converted to
|
|
|
|
// internal ECMA-376 formats as needed.
|
|
|
|
type Color struct {
|
2017-09-02 21:10:36 -05:00
|
|
|
r, g, b, a uint8
|
2017-08-28 20:56:18 -05:00
|
|
|
isAuto bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGB constructs a new RGB color with a given red, green and blue value.
|
|
|
|
func RGB(r, g, b uint8) Color {
|
2017-09-04 10:50:29 -05:00
|
|
|
return Color{r, g, b, 255, false}
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
|
2018-12-27 15:10:44 +09:00
|
|
|
// RGBA constructs a new RGBA color with a given red, green, blue and alpha
|
|
|
|
// value.
|
|
|
|
func RGBA(r, g, b, a uint8) Color {
|
|
|
|
return Color{r, g, b, a, false}
|
|
|
|
}
|
|
|
|
|
2017-08-28 20:56:18 -05:00
|
|
|
// IsAuto returns true if the color is the 'Auto' type. If the
|
|
|
|
// field doesn't support an Auto color, then black is used.
|
|
|
|
func (c Color) IsAuto() bool {
|
|
|
|
return c.isAuto
|
|
|
|
}
|
|
|
|
|
|
|
|
// AsRGBString is used by the various wrappers to return a pointer
|
|
|
|
// to a string containing a six digit hex RGB value.
|
|
|
|
func (c Color) AsRGBString() *string {
|
2019-05-04 13:54:29 +00:00
|
|
|
return unioffice.Stringf("%02x%02x%02x", c.r, c.g, c.b)
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// AsRGBAString is used by the various wrappers to return a pointer
|
|
|
|
// to a string containing a six digit hex RGB value.
|
|
|
|
func (c Color) AsRGBAString() *string {
|
2019-05-04 13:54:29 +00:00
|
|
|
return unioffice.Stringf("%02x%02x%02x%02x", c.a, c.r, c.g, c.b)
|
2017-08-28 20:56:18 -05:00
|
|
|
}
|