// 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 { /// /// The pattern of pixels upon which the corresponding pattern fill will be displayed /// enum class XLNT_API pattern_fill_type { none, solid, mediumgray, darkgray, lightgray, darkhorizontal, darkvertical, darkdown, darkup, darkgrid, darktrellis, lighthorizontal, lightvertical, lightdown, lightup, lightgrid, lighttrellis, gray125, gray0625 }; /// /// Represents a fill which colors the cell based on a foreground and /// background color and a pattern. /// class XLNT_API pattern_fill { public: /// /// Constructs a default pattern fill with a none pattern and no colors. /// pattern_fill(); /// /// Returns the pattern used by this fill /// pattern_fill_type type() const; /// /// Sets the pattern of this fill and returns a reference to it. /// pattern_fill &type(pattern_fill_type new_type); /// /// Returns the optional foreground color of this fill /// optional foreground() const; /// /// Sets the foreground color and returns a reference to this pattern. /// pattern_fill &foreground(const color &foreground); /// /// Returns the optional background color of this fill /// optional background() const; /// /// Sets the foreground color and returns a reference to this pattern. /// pattern_fill &background(const color &background); /// /// Returns true if this pattern fill is equivalent to other. /// bool operator==(const pattern_fill &other) const; /// /// Returns true if this pattern fill is not equivalent to other. /// bool operator!=(const pattern_fill &other) const; private: /// /// The type of this pattern_fill /// pattern_fill_type type_ = pattern_fill_type::none; /// /// The optional foreground color /// optional foreground_; /// /// THe optional background color /// optional background_; }; /// /// Enumerates the types of gradient fills /// enum class XLNT_API gradient_fill_type { linear, path }; /// /// Encapsulates a fill which transitions between colors at particular "stops". /// class XLNT_API gradient_fill { public: /// /// Constructs a default linear fill /// gradient_fill(); /// /// Returns the type of this gradient fill /// gradient_fill_type type() const; // Type /// /// Sets the type of this gradient fill /// gradient_fill &type(gradient_fill_type new_type); // Degree /// /// Sets the angle of the gradient in degrees /// gradient_fill °ree(double degree); /// /// Returns the angle of the gradient /// double degree() const; // Left /// /// Returns the distance from the left where the gradient starts. /// double left() const; /// /// Sets the distance from the left where the gradient starts. /// gradient_fill &left(double value); // Right /// /// Returns the distance from the right where the gradient starts. /// double right() const; /// /// Sets the distance from the right where the gradient starts. /// gradient_fill &right(double value); // Top /// /// Returns the distance from the top where the gradient starts. /// double top() const; /// /// Sets the distance from the top where the gradient starts. /// gradient_fill &top(double value); // Bottom /// /// Returns the distance from the bottom where the gradient starts. /// double bottom() const; /// /// Sets the distance from the bottom where the gradient starts. /// gradient_fill &bottom(double value); // Stops /// /// Adds a gradient stop at position with the given color. /// gradient_fill &add_stop(double position, color stop_color); /// /// Deletes all stops from the gradient. /// gradient_fill &clear_stops(); /// /// Returns all of the gradient stops. /// std::unordered_map stops() const; /// /// Returns true if the gradient is equivalent to other. /// bool operator==(const gradient_fill &other) const; /// /// Returns true if the gradient is not equivalent to other. /// bool operator!=(const gradient_fill &right) const; private: /// /// The type of gradient /// gradient_fill_type type_ = gradient_fill_type::linear; /// /// The angle of the gradient /// double degree_ = 0; /// /// THe left distance /// double left_ = 0; /// /// THe right distance /// double right_ = 0; /// /// The top distance /// double top_ = 0; /// /// The bottom distance /// double bottom_ = 0; /// /// The gradient stops and colors /// std::unordered_map stops_; }; /// /// Enumerates the possible fill types /// enum class XLNT_API fill_type { pattern, gradient }; /// /// Describes the fill style of a particular cell. /// class XLNT_API fill { public: /// /// Helper method for the most common use case, setting the fill color of a cell to a single solid color. /// The foreground and background colors of a fill are not the same as the foreground and background colors /// of a cell. When setting a fill color in Excel, a new fill is created with the given color as the fill's /// fgColor and index color number 64 as the bgColor. This method creates a fill in the same way. /// static fill solid(const color &fill_color); /// /// Constructs a fill initialized as a none-type pattern fill with no /// foreground or background colors. /// fill(); /// /// Constructs a fill initialized as a pattern fill based on the given pattern. /// fill(const pattern_fill &pattern); /// /// Constructs a fill initialized as a gradient fill based on the given gradient. /// fill(const gradient_fill &gradient); /// /// Returns the fill_type of this fill depending on how it was constructed. /// fill_type type() const; /// /// Returns the gradient fill represented by this fill. /// Throws an invalid_attribute exception if this is not a gradient fill. /// class gradient_fill gradient_fill() const; /// /// Returns the pattern fill represented by this fill. /// Throws an invalid_attribute exception if this is not a pattern fill. /// class pattern_fill pattern_fill() const; /// /// Returns true if left is exactly equal to right. /// bool operator==(const fill &other) const; /// /// Returns true if left is not exactly equal to right. /// bool operator!=(const fill &other) const; private: /// /// The type of this fill /// fill_type type_ = fill_type::pattern; /// /// The internal gradient fill if this is a gradient fill type /// xlnt::gradient_fill gradient_; /// /// The internal pattern fill if this is a pattern fill type /// xlnt::pattern_fill pattern_; }; } // namespace xlnt