diff --git a/.travis.yml b/.travis.yml index 23295deb..ebf644c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,4 +56,4 @@ after_success: - if [ "$COMPILER" = "g++-4.9" ]; then cd .. && ./build/bin/xlnt.test ; fi - if [ "$COMPILER" = "g++-4.9" ]; then export OLDWD=$(pwd) ; fi - if [ "$COMPILER" = "g++-4.9" ]; then cd "build/CMakeFiles/xlnt.static.dir$(pwd)" ; pwd ; fi - - if [ "$COMPILER" = "g++-4.9" ]; then coveralls --root $OLDWD --verbose -x ".cpp" --gcov-options '\-p' --exclude include --exclude third-party --exclude tests --exclude samples --exclude benchmarks -E ".*/source/.*/tests/.*" ; fi + - if [ "$COMPILER" = "g++-4.9" ]; then coveralls --root $OLDWD --verbose -x ".cpp" --gcov-options '\-p' --exclude include --exclude third-party --exclude tests --exclude samples --exclude benchmarks -E ".*/source/.*/tests/.*" -E ".*/build/tests/runner-autogen.cpp.*" -E ".*CompilerIdCXX/.*" ; fi diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index 25ed6cb6..7cf3edec 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -80,16 +80,18 @@ public: void set_family(std::size_t family); + bool has_scheme() const; + void set_scheme(const std::string &scheme); + std::string get_scheme() const; + color get_color() const; bool has_family() const; std::size_t get_family() const; - bool has_scheme() const; - protected: std::string to_hash_string() const override; diff --git a/source/detail/style_serializer.cpp b/source/detail/style_serializer.cpp index d3d968d8..fcb94625 100644 --- a/source/detail/style_serializer.cpp +++ b/source/detail/style_serializer.cpp @@ -878,7 +878,7 @@ bool write_fonts(const std::vector &fonts, pugi::xml_node &fonts_nod if (f.has_scheme()) { auto scheme_node = font_node.append_child("scheme"); - scheme_node.append_attribute("val").set_value("minor"); + scheme_node.append_attribute("val").set_value(f.get_scheme().c_str()); } } diff --git a/source/styles/font.cpp b/source/styles/font.cpp index d8c453dd..2a271bc1 100644 --- a/source/styles/font.cpp +++ b/source/styles/font.cpp @@ -145,6 +145,11 @@ bool font::has_scheme() const return has_scheme_; } +std::string font::get_scheme() const +{ + return scheme_; +} + std::string font::to_hash_string() const { std::string hash_string = "font"; diff --git a/source/workbook/tests/test_style_writer.hpp b/source/workbook/tests/test_style_writer.hpp index 4e557069..0e5f3e12 100644 --- a/source/workbook/tests/test_style_writer.hpp +++ b/source/workbook/tests/test_style_writer.hpp @@ -11,22 +11,68 @@ class test_style_writer : public CxxTest::TestSuite { public: - void test_write_number_formats() + bool style_xml_matches(const std::string &expected_string, xlnt::workbook &wb) { - xlnt::workbook wb; - wb.get_active_sheet().get_cell("A1").set_number_format(xlnt::number_format("YYYY")); xlnt::excel_serializer excel_serializer(wb); xlnt::style_serializer style_serializer(excel_serializer.get_stylesheet()); pugi::xml_document observed; style_serializer.write_stylesheet(observed); - pugi::xml_document expected_doc; - std::string expected = - " " + pugi::xml_document expected; + expected.load(expected_string.c_str()); + + auto comparison = Helper::compare_xml(expected.root(), observed.root()); + return (bool)comparison; + } + + void test_write_custom_number_format() + { + xlnt::workbook wb; + wb.get_active_sheet().get_cell("A1").set_number_format(xlnt::number_format("YYYY")); + auto expected = + "" + " " " " - " "; - expected_doc.load(expected.c_str()); - auto diff = Helper::compare_xml(expected_doc.child("numFmts"), observed.child("styleSheet").child("numFmts")); - TS_ASSERT(diff); + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + TS_ASSERT(style_xml_matches(expected, wb)); } void test_simple_styles() @@ -47,20 +93,14 @@ public: xlnt::protection hidden(true, true); ws.get_cell("E1").set_protection(hidden); - xlnt::excel_serializer e(wb); - xlnt::style_serializer serializer(e.get_stylesheet()); - pugi::xml_document xml; - serializer.write_stylesheet(xml); - - TS_ASSERT(Helper::compare_xml(PathHelper::GetDataDirectory("/writer/expected/simple-styles.xml"), xml)); + std::string expected = PathHelper::read_file(PathHelper::GetDataDirectory("/writer/expected/simple-styles.xml")); + TS_ASSERT(style_xml_matches(expected, wb)); } void test_empty_workbook() { xlnt::workbook wb; - xlnt::excel_serializer e(wb); - xlnt::style_serializer serializer(e.get_stylesheet()); - auto expected = + std::string expected = "" " " " " @@ -100,8 +140,78 @@ public: " " " " ""; - pugi::xml_document xml; - serializer.write_stylesheet(xml); - TS_ASSERT(Helper::compare_xml(expected, xml)); + TS_ASSERT(style_xml_matches(expected, wb)); + } + + void test_complex_font() + { + xlnt::font f; + f.set_bold(true); + f.set_color(xlnt::color::red()); + f.set_family(3); + f.set_italic(true); + f.set_name("Consolas"); + f.set_scheme("major"); + f.set_size(21); + f.set_strikethrough(true); + f.set_underline(xlnt::font::underline_style::double_accounting); + + xlnt::workbook wb; + wb.get_active_sheet().get_cell("A1").set_font(f); + + std::string expected = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + TS_ASSERT(style_xml_matches(expected, wb)); } };