mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Merge pull request #322 from Crzyrndm/serialise_color_tint
Ensure <color tint=...> is correctly serialised as an optional double
This commit is contained in:
commit
3ced259a26
@ -28,6 +28,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <xlnt/xlnt_config.hpp>
|
#include <xlnt/xlnt_config.hpp>
|
||||||
|
#include <xlnt/utils/optional.hpp>
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
|
||||||
@ -284,6 +285,11 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
theme_color& theme();
|
theme_color& theme();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if tint is set
|
||||||
|
/// </summary>
|
||||||
|
bool has_tint() const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the tint of this color.
|
/// Returns the tint of this color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -333,12 +339,12 @@ private:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The tint of this color
|
/// The tint of this color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
double tint_ = 0.0;
|
optional<double> tint_;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not this is an auto color
|
/// Whether or not this is an auto color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool auto__ = false;
|
bool auto_color = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
@ -3032,7 +3032,7 @@ xlnt::color xlsx_consumer::read_color()
|
|||||||
|
|
||||||
if (parser().attribute_present("tint"))
|
if (parser().attribute_present("tint"))
|
||||||
{
|
{
|
||||||
result.tint(parser().attribute("tint", 0.0));
|
result.tint(parser().attribute<double>("tint"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -3345,7 +3345,6 @@ void xlsx_producer::write_color(const xlnt::color &color)
|
|||||||
write_attribute("auto", write_bool(true));
|
write_attribute("auto", write_bool(true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (color.type())
|
switch (color.type())
|
||||||
{
|
{
|
||||||
case xlnt::color_type::theme:
|
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());
|
write_attribute("rgb", color.rgb().hex_string());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (color.has_tint())
|
||||||
|
{
|
||||||
|
write_attribute("tint", serialize_number_to_string(color.tint()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void xlsx_producer::write_start_element(const std::string &name)
|
void xlsx_producer::write_start_element(const std::string &name)
|
||||||
|
@ -225,12 +225,12 @@ color_type color::type() const
|
|||||||
|
|
||||||
bool color::auto_() const
|
bool color::auto_() const
|
||||||
{
|
{
|
||||||
return auto__;
|
return auto_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void color::auto_(bool value)
|
void color::auto_(bool value)
|
||||||
{
|
{
|
||||||
auto__ = value;
|
auto_color = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexed_color& color::indexed() const
|
const indexed_color& color::indexed() const
|
||||||
@ -269,6 +269,11 @@ rgb_color &color::rgb()
|
|||||||
return rgb_;
|
return rgb_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool color::has_tint() const
|
||||||
|
{
|
||||||
|
return tint_.is_set();
|
||||||
|
}
|
||||||
|
|
||||||
void color::tint(double tint)
|
void color::tint(double tint)
|
||||||
{
|
{
|
||||||
tint_ = tint;
|
tint_ = tint;
|
||||||
@ -276,7 +281,7 @@ void color::tint(double tint)
|
|||||||
|
|
||||||
double color::tint() const
|
double color::tint() const
|
||||||
{
|
{
|
||||||
return tint_;
|
return tint_.is_set() ? tint_.get() : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void color::assert_type(color_type t) const
|
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
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user