diff --git a/include/xlnt/cell/text_run.hpp b/include/xlnt/cell/text_run.hpp index 24337d2f..a7dba081 100644 --- a/include/xlnt/cell/text_run.hpp +++ b/include/xlnt/cell/text_run.hpp @@ -25,6 +25,7 @@ #include #include // for XLNT_CLASS, XLNT_FUNCTION +#include namespace xlnt { @@ -38,21 +39,35 @@ public: std::string get_string() const; void set_string(const std::string &string); - + + bool has_size() const; std::size_t get_size() const; + void set_size(std::size_t size); + + bool has_color() const; std::string get_color() const; + void set_color(const std::string &color); + + bool has_font() const; std::string get_font() const; + void set_font(const std::string &font); + + bool has_family() const; std::size_t get_family() const; + void set_family(std::size_t family); + + bool has_scheme() const; std::string get_scheme() const; + void set_scheme(const std::string &scheme); private: std::string string_; - bool has_formatting_ = false; - std::size_t size_; - std::string color_; - std::string font_; - std::size_t family_; - std::string scheme_; + + std::experimental::optional size_; + std::experimental::optional color_; + std::experimental::optional font_; + std::experimental::optional family_; + std::experimental::optional scheme_; }; } // namespace xlnt diff --git a/source/cell/text.cpp b/source/cell/text.cpp index 43a524c2..5c521f42 100644 --- a/source/cell/text.cpp +++ b/source/cell/text.cpp @@ -71,11 +71,40 @@ bool text::operator==(const text &rhs) const if (runs_[i].has_formatting()) { - if (runs_[i].get_color() != rhs.runs_[i].get_color()) return false; - if (runs_[i].get_family() != rhs.runs_[i].get_family()) return false; - if (runs_[i].get_font() != rhs.runs_[i].get_font()) return false; - if (runs_[i].get_scheme() != rhs.runs_[i].get_scheme()) return false; - if (runs_[i].get_size() != rhs.runs_[i].get_size()) return false; + if (runs_[i].has_color() == rhs.runs_[i].has_color() + && runs_[i].has_color() + && runs_[i].get_color() != rhs.runs_[i].get_color()) + { + return false; + } + + if (runs_[i].has_family() == rhs.runs_[i].has_family() + && runs_[i].has_family() + && runs_[i].get_family() != rhs.runs_[i].get_family()) + { + return false; + } + + if (runs_[i].has_font() == rhs.runs_[i].has_font() + && runs_[i].has_font() + && runs_[i].get_font() != rhs.runs_[i].get_font()) + { + return false; + } + + if (runs_[i].has_scheme() == rhs.runs_[i].has_scheme() + && runs_[i].has_scheme() + && runs_[i].get_scheme() != rhs.runs_[i].get_scheme()) + { + return false; + } + + if (runs_[i].has_size() == rhs.runs_[i].has_size() + && runs_[i].has_size() + && runs_[i].get_size() != rhs.runs_[i].get_size()) + { + return false; + } } } diff --git a/source/cell/text_run.cpp b/source/cell/text_run.cpp index 3c0c77aa..dc6df7ae 100644 --- a/source/cell/text_run.cpp +++ b/source/cell/text_run.cpp @@ -45,32 +45,82 @@ void text_run::set_string(const std::string &string) bool text_run::has_formatting() const { - return has_formatting_; + return has_size() || has_color() || has_font() || has_family() || has_scheme(); +} + +bool text_run::has_size() const +{ + return (bool)size_; } std::size_t text_run::get_size() const { - return size_; + return *size_; +} + +void text_run::set_size(std::size_t size) +{ + size_ = size; +} + +bool text_run::has_color() const +{ + return (bool)color_; } std::string text_run::get_color() const { - return color_; + return *color_; +} + +void text_run::set_color(const std::string &color) +{ + color_ = color; +} + +bool text_run::has_font() const +{ + return (bool)font_; } std::string text_run::get_font() const { - return font_; + return *font_; +} + +void text_run::set_font(const std::string &font) +{ + font_ = font; +} + +bool text_run::has_family() const +{ + return (bool)family_; } std::size_t text_run::get_family() const { - return family_; + return *family_; +} + +void text_run::set_family(std::size_t family) +{ + family_ = family; +} + +bool text_run::has_scheme() const +{ + return (bool)scheme_; } std::string text_run::get_scheme() const { - return scheme_; + return *scheme_; +} + +void text_run::set_scheme(const std::string &scheme) +{ + scheme_ = scheme; } } // namespace xlnt diff --git a/source/serialization/shared_strings_serializer.cpp b/source/serialization/shared_strings_serializer.cpp index e50eb654..3dfd0882 100644 --- a/source/serialization/shared_strings_serializer.cpp +++ b/source/serialization/shared_strings_serializer.cpp @@ -37,6 +37,7 @@ xml_document shared_strings_serializer::write_shared_strings(const std::vector +#include +#include + class test_read : public CxxTest::TestSuite { public: diff --git a/source/styles/format.cpp b/source/styles/format.cpp index bc21fe94..4912cc9d 100644 --- a/source/styles/format.cpp +++ b/source/styles/format.cpp @@ -32,10 +32,16 @@ namespace xlnt { format::format() + : formattable(), + parent_(nullptr), + named_style_name_("Normal") { } -format::format(const format &other) : formattable(other) +format::format(const format &other) + : formattable(other), + parent_(other.parent_), + named_style_name_(other.named_style_name_) { } @@ -76,4 +82,9 @@ bool format::has_style() const return !named_style_name_.empty(); } +std::string format::get_style_name() const +{ + return named_style_name_; +} + } // namespace xlnt diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index ef6f6eb8..774e504e 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -749,4 +749,16 @@ const std::vector &workbook::get_formats() const return d_->formats_; } +style &workbook::get_style(const std::string &name) +{ + return *std::find_if(d_->styles_.begin(), d_->styles_.end(), + [&name](const style &s) { return s.get_name() == name; }); +} + +const style &workbook::get_style(const std::string &name) const +{ + return *std::find_if(d_->styles_.begin(), d_->styles_.end(), + [&name](const style &s) { return s.get_name() == name; }); +} + } // namespace xlnt