// Copyright (c) 2014-2021 Thomas Fussell // Copyright (c) 2010-2015 openpyxl // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include #include #include #include namespace xlnt { /// /// An indexed color encapsulates a simple index to a color in the indexedColors of the stylesheet. /// class XLNT_API indexed_color { public: //TODO: should this be explicit? /// /// Constructs an indexed_color from an index. /// indexed_color(std::size_t index); /// /// Returns the index this color points to. /// std::size_t index() const; /// /// Sets the index to index. /// void index(std::size_t index); private: /// /// The index of this color /// std::size_t index_; }; /// /// A theme color encapsulates a color derived from the theme. /// class XLNT_API theme_color { public: /// /// Constructs a theme_color from an index. /// theme_color(std::size_t index); /// /// Returns the index of the color in the theme this points to. /// std::size_t index() const; /// /// Sets the index of this color to index. /// void index(std::size_t index); private: /// /// The index of the color /// std::size_t index_; }; /// /// An RGB color describes a color in terms of its red, green, blue, and alpha components. /// class XLNT_API rgb_color { public: /// /// Constructs an RGB color from a string in the form \#[aa]rrggbb /// rgb_color(const std::string &hex_string); /// /// Constructs an RGB color from red, green, and blue values in the range 0 to 255 /// plus an optional alpha which defaults to fully opaque. /// rgb_color(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a = 255); /// /// Returns a string representation of this color in the form \#aarrggbb /// std::string hex_string() const; /// /// Returns a byte representing the red component of this color /// std::uint8_t red() const; /// /// Returns a byte representing the red component of this color /// std::uint8_t green() const; /// /// Returns a byte representing the blue component of this color /// std::uint8_t blue() const; /// /// Returns a byte representing the alpha component of this color /// std::uint8_t alpha() const; /// /// Returns the red, green, and blue components of this color separately in an array in that order. /// std::array rgb() const; /// /// Returns the red, green, blue, and alpha components of this color separately in an array in that order. /// std::array rgba() const; private: /// /// The four bytes of this color /// std::array rgba_; }; /// /// Some colors are references to colors rather than having a particular RGB value. /// enum class color_type { indexed, theme, rgb }; /// /// Colors can be applied to many parts of a cell's style. /// class XLNT_API color { public: /// /// Returns the color \#000000 /// static const color black(); /// /// Returns the color \#ffffff /// static const color white(); /// /// Returns the color \#ff0000 /// static const color red(); /// /// Returns the color \#8b0000 /// static const color darkred(); /// /// Returns the color \#00ff00 /// static const color blue(); /// /// Returns the color \#008b00 /// static const color darkblue(); /// /// Returns the color \#0000ff /// static const color green(); /// /// Returns the color \#00008b /// static const color darkgreen(); /// /// Returns the color \#ffff00 /// static const color yellow(); /// /// Returns the color \#cccc00 /// static const color darkyellow(); /// /// Constructs a default color /// color(); /// /// Constructs a color from a given RGB color /// color(const rgb_color &rgb); /// /// Constructs a color from a given indexed color /// color(const indexed_color &indexed); /// /// Constructs a color from a given theme color /// color(const theme_color &theme); /// /// Returns the type of this color /// color_type type() const; /// /// Returns true if this color has been set to auto /// bool auto_() const; /// /// Sets the auto property of this color to value /// void auto_(bool value); /// /// Returns the internal indexed color representing this color. If this is not an RGB color, /// an invalid_attribute exception will be thrown. /// const rgb_color &rgb() const; /// /// Returns the internal indexed color representing this color. If this is not an RGB color, /// an invalid_attribute exception will be thrown. /// rgb_color &rgb(); /// /// Returns the internal indexed color representing this color. If this is not an indexed color, /// an invalid_attribute exception will be thrown. /// const indexed_color &indexed() const; /// /// Returns the internal indexed color representing this color. If this is not an indexed color, /// an invalid_attribute exception will be thrown. /// indexed_color &indexed(); /// /// Returns the internal indexed color representing this color. If this is not a theme color, /// an invalid_attribute exception will be thrown. /// const theme_color &theme() const; /// /// Returns the internal indexed color representing this color. If this is not a theme color, /// an invalid_attribute exception will be thrown. /// theme_color &theme(); /// /// Returns true if tint is set /// bool has_tint() const; /// /// Returns the tint of this color. /// double tint() const; /// /// Sets the tint of this color to tint. Tints lighten or darken an existing color by multiplying the color with the tint. /// void tint(double tint); /// /// Returns true if this color is equivalent to other /// bool operator==(const color &other) const; /// /// Returns true if this color is not equivalent to other /// bool operator!=(const color &other) const; private: /// /// Throws an invalid_attribute exception if the given type is different from this color's type /// void assert_type(color_type t) const; /// /// The type of this color /// color_type type_; /// /// The internal RGB color. Only valid when this color has a type of rgb /// rgb_color rgb_; /// /// The internal RGB color. Only valid when this color has a type of indexed /// indexed_color indexed_; /// /// The internal RGB color. Only valid when this color has a type of theme /// theme_color theme_; /// /// The tint of this color /// optional tint_; /// /// Whether or not this is an auto color /// bool auto_color = false; }; } // namespace xlnt