From 1c1d63498aeee268b7aaa6e8e20b6ea88492445b Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sun, 24 Jun 2018 17:31:05 +1200 Subject: [PATCH] Parsing headerFotter block of test sheet correctly --- include/xlnt/styles/font.hpp | 5 +++- .../header_footer/header_footer_code.cpp | 23 ++++++++++++++++++- source/styles/font.cpp | 8 ++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index b428ae8a..b5b12fdc 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -242,7 +242,10 @@ public: /// /// Returns true if left is not exactly equal to right. /// - bool operator!=(const font &other) const; + bool operator!=(const font &other) const + { + return !operator==(other); + } private: friend class style; diff --git a/source/detail/header_footer/header_footer_code.cpp b/source/detail/header_footer/header_footer_code.cpp index 6479cd42..301c922c 100644 --- a/source/detail/header_footer/header_footer_code.cpp +++ b/source/detail/header_footer/header_footer_code.cpp @@ -360,6 +360,11 @@ std::array, 3> decode_header_footer(const std::s case hf_code::text_single_underline: { + if (!current_run.second.is_set()) + { + current_run.second = xlnt::font(); + } + current_run.second.get().underline(font::underline_style::single); break; } @@ -533,7 +538,23 @@ std::string encode_header_footer(const rich_text &t, header_footer::location whe ss << run.second.get().size(); encoded.append(ss.str()); } - + if (run.second.get().underlined()) + { + switch (run.second.get().underline()) + { + case font::underline_style::single: + case font::underline_style::single_accounting: + encoded.append("&U"); + break; + case font::underline_style::double_: + case font::underline_style::double_accounting: + encoded.append("&E"); + break; + default: + case font::underline_style::none: + break; + } + } if (run.second.get().has_color()) { encoded.push_back('&'); diff --git a/source/styles/font.cpp b/source/styles/font.cpp index 0c5e6982..35c278ed 100644 --- a/source/styles/font.cpp +++ b/source/styles/font.cpp @@ -29,8 +29,6 @@ namespace xlnt { font::font() - : name_("Calibri"), - size_(12.0) { } @@ -156,7 +154,11 @@ font &font::name(const std::string &name) std::string font::name() const { - return name_.get(); + if (name_.is_set()) + { + return name_.get(); + } + return "Calibri"; } bool font::has_color() const