Ensure <color tint=...> is correctly serialised as an optional double

This commit is contained in:
Crzyrndm 2018-07-28 14:44:49 +12:00
parent 94faf01b72
commit ade8cf3b6c
4 changed files with 26 additions and 8 deletions

View File

@ -28,6 +28,7 @@
#include <string>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/utils/optional.hpp>
namespace xlnt {
@ -284,6 +285,11 @@ public:
/// </summary>
theme_color& theme();
/// <summary>
/// Returns true if tint is set
/// </summary>
bool has_tint() const;
/// <summary>
/// Returns the tint of this color.
/// </summary>
@ -333,12 +339,12 @@ private:
/// <summary>
/// The tint of this color
/// </summary>
double tint_ = 0.0;
optional<double> tint_;
/// <summary>
/// Whether or not this is an auto color
/// </summary>
bool auto__ = false;
bool auto_color = false;
};
} // namespace xlnt

View File

@ -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<double>("tint"));
}
return result;

View File

@ -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)

View File

@ -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;
}