diff --git a/include/xlnt/styles/color.hpp b/include/xlnt/styles/color.hpp index 24021452..95f457d2 100644 --- a/include/xlnt/styles/color.hpp +++ b/include/xlnt/styles/color.hpp @@ -28,6 +28,7 @@ #include #include +#include namespace xlnt { @@ -284,6 +285,11 @@ public: /// theme_color& theme(); + /// + /// Returns true if tint is set + /// + bool has_tint() const; + /// /// Returns the tint of this color. /// @@ -333,12 +339,12 @@ private: /// /// The tint of this color /// - double tint_ = 0.0; + optional tint_; /// /// Whether or not this is an auto color /// - bool auto__ = false; + bool auto_color = false; }; } // namespace xlnt diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index 2f29e19f..3ac9eb0b 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -3032,7 +3032,7 @@ xlnt::color xlsx_consumer::read_color() if (parser().attribute_present("tint")) { - result.tint(parser().attribute("tint", 0.0)); + result.tint(parser().attribute("tint")); } return result; diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 212b0d89..a683811d 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -3345,7 +3345,6 @@ void xlsx_producer::write_color(const xlnt::color &color) write_attribute("auto", write_bool(true)); return; } - switch (color.type()) { case xlnt::color_type::theme: @@ -3360,6 +3359,10 @@ void xlsx_producer::write_color(const xlnt::color &color) write_attribute("rgb", color.rgb().hex_string()); break; } + if (color.has_tint()) + { + write_attribute("tint", serialize_number_to_string(color.tint())); + } } void xlsx_producer::write_start_element(const std::string &name) diff --git a/source/styles/color.cpp b/source/styles/color.cpp index 141616fc..5eabee70 100644 --- a/source/styles/color.cpp +++ b/source/styles/color.cpp @@ -225,12 +225,12 @@ color_type color::type() const bool color::auto_() const { - return auto__; + return auto_color; } void color::auto_(bool value) { - auto__ = value; + auto_color = value; } const indexed_color& color::indexed() const @@ -269,6 +269,11 @@ rgb_color &color::rgb() return rgb_; } +bool color::has_tint() const +{ + return tint_.is_set(); +} + void color::tint(double tint) { tint_ = tint; @@ -276,7 +281,7 @@ void color::tint(double tint) double color::tint() const { - return tint_; + return tint_.is_set() ? tint_.get() : 0.0; } void color::assert_type(color_type t) const @@ -289,7 +294,11 @@ void color::assert_type(color_type t) const bool color::operator==(const xlnt::color &other) const { - if (type_ != other.type_ || std::fabs(tint_ - other.tint_) != 0.0 || auto__ != other.auto__) + if (type_ != other.type_ || auto_color != other.auto_color) + { + return false; + } + if (tint_.is_set() != other.tint_.is_set() || (tint_.is_set() && std::fabs(tint_.get() - other.tint_.get()) != 0.0)) { return false; }