From f3a7570a7e5429f69465b22f7230d5861568762d Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Thu, 30 Jun 2016 18:47:43 +0530 Subject: [PATCH 1/6] Add extract alignment attributes function to odf helper --- src/liborcus/odf_helper.cpp | 47 +++++++++++++++++++++++++++++++++++++ src/liborcus/odf_helper.hpp | 7 ++++++ 2 files changed, 54 insertions(+) diff --git a/src/liborcus/odf_helper.cpp b/src/liborcus/odf_helper.cpp index f83f8b00f..30ee52a45 100644 --- a/src/liborcus/odf_helper.cpp +++ b/src/liborcus/odf_helper.cpp @@ -69,6 +69,26 @@ odf_underline_style_map::entry odf_underline_style_entries[] = { MDDS_ASCII("wave"), spreadsheet::underline_t::wave} }; +typedef mdds::sorted_string_map odf_horizontal_alignment_map; + +odf_horizontal_alignment_map::entry odf_horizontal_alignment_entries[] = +{ + { MDDS_ASCII("center"), spreadsheet::hor_alignment_t::center}, + { MDDS_ASCII("end"), spreadsheet::hor_alignment_t::right}, + { MDDS_ASCII("justified"), spreadsheet::hor_alignment_t::justified}, + { MDDS_ASCII("start"), spreadsheet::hor_alignment_t::left} +}; + +typedef mdds::sorted_string_map odf_vertical_alignment_map; + +odf_vertical_alignment_map::entry odf_vertical_alignment_entries[] = +{ + { MDDS_ASCII("bottom"), spreadsheet::ver_alignment_t::bottom}, + { MDDS_ASCII("justified"), spreadsheet::ver_alignment_t::justified}, + { MDDS_ASCII("middle"), spreadsheet::ver_alignment_t::middle}, + { MDDS_ASCII("top"), spreadsheet::ver_alignment_t::top} +}; + bool is_valid_hex_digit(const char& character, orcus::spreadsheet::color_elem_t& val) { if ('0' <= character && character <= '9') @@ -167,6 +187,33 @@ orcus::spreadsheet::underline_t odf_helper::extract_underline_style(const orcus: return underline_style; } +bool odf_helper::extract_hor_alignment_style(const orcus::pstring& value, spreadsheet::hor_alignment_t& alignment) +{ + odf_horizontal_alignment_map horizontal_alignment_map(odf_horizontal_alignment_entries, + ORCUS_N_ELEMENTS(odf_horizontal_alignment_entries), + spreadsheet::hor_alignment_t::unknown); + + alignment = horizontal_alignment_map.find(value.get(), value.size()); + + if (alignment == spreadsheet::hor_alignment_t::unknown) + return false; + + return true; +} + +bool odf_helper::extract_ver_alignment_style(const orcus::pstring& value, spreadsheet::ver_alignment_t& alignment) +{ + odf_vertical_alignment_map vertical_alignment_map(odf_vertical_alignment_entries, + ORCUS_N_ELEMENTS(odf_vertical_alignment_entries), + spreadsheet::ver_alignment_t::unknown); + alignment = vertical_alignment_map.find(value.get(), value.size()); + + if (alignment == spreadsheet::ver_alignment_t::unknown) + return false; + + return true; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/src/liborcus/odf_helper.hpp b/src/liborcus/odf_helper.hpp index e022412e0..b0ba5108a 100644 --- a/src/liborcus/odf_helper.hpp +++ b/src/liborcus/odf_helper.hpp @@ -40,6 +40,13 @@ public: static orcus::spreadsheet::underline_width_t extract_underline_width(const orcus::pstring& value); static orcus::spreadsheet::underline_t extract_underline_style(const orcus::pstring& value); + + static bool extract_hor_alignment_style(const orcus::pstring& value, + spreadsheet::hor_alignment_t& alignment); + + static bool extract_ver_alignment_style(const orcus::pstring& value, + spreadsheet::ver_alignment_t& alignment); + }; } -- GitLab From 10fc0437a9e08e4e31bcab01efb96e7289f75f65 Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Thu, 23 Jun 2016 10:40:05 +0530 Subject: [PATCH 2/6] Add case for vertical alignment to the parser and related functions for it --- src/liborcus/odf_styles_context.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp index 752f7faa4..5d047862d 100644 --- a/src/liborcus/odf_styles_context.cpp +++ b/src/liborcus/odf_styles_context.cpp @@ -119,6 +119,7 @@ class text_prop_attr_parser : std::unary_function spreadsheet::underline_t m_underline_style; spreadsheet::underline_type_t m_underline_type; + public: text_prop_attr_parser() : m_bold(false), m_italic(false), m_color(false), m_underline_is_text_color(false), m_underline(false), @@ -241,7 +242,9 @@ public: m_hidden(false), m_formula_hidden(false), m_print_content(false), - m_cell_protection(false) + m_cell_protection(false), + m_ver_alignment(spreadsheet::ver_alignment_t::unknown), + m_has_ver_alignment(false) {} private: @@ -259,6 +262,9 @@ private: border_map_type m_border_style_dir_pair; + spreadsheet::ver_alignment_t m_ver_alignment; + bool m_has_ver_alignment; + public: void operator() (const xml_token_attr_t& attr) @@ -355,6 +361,9 @@ public: m_locked = true; } } + case XML_vertical_align: + m_has_ver_alignment = odf_helper::extract_ver_alignment_style(attr.value, m_ver_alignment); + break; default: ; } @@ -383,6 +392,8 @@ public: { return m_border_style_dir_pair; } + bool has_ver_alignment() const { return m_has_ver_alignment;} + const spreadsheet::ver_alignment_t& get_ver_alignment() const { return m_ver_alignment;} }; -- GitLab From f1a2a2e5a60ecfe5712ab7292630bf4e4547d437 Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Thu, 23 Jun 2016 10:45:30 +0530 Subject: [PATCH 3/6] Add paragraph properties parser class --- src/liborcus/odf_styles_context.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp index 5d047862d..7fe3698b7 100644 --- a/src/liborcus/odf_styles_context.cpp +++ b/src/liborcus/odf_styles_context.cpp @@ -397,6 +397,35 @@ public: }; +class paragraph_prop_attr_parser : std::unary_function +{ + spreadsheet::hor_alignment_t m_hor_alignment; + bool m_has_hor_alignment; + +public: + paragraph_prop_attr_parser(): + m_hor_alignment(spreadsheet::hor_alignment_t::unknown), + m_has_hor_alignment(false) + {} + + void operator() (const xml_token_attr_t& attr) + { + if (attr.ns == NS_odf_fo) + { + switch (attr.name) + { + case XML_text_align: + m_has_hor_alignment = odf_helper::extract_hor_alignment_style(attr.value, m_hor_alignment); + break; + default: + ; + } + } + } + bool has_hor_alignment() const { return m_has_hor_alignment;} + const spreadsheet::hor_alignment_t& get_hor_alignment() const { return m_hor_alignment;} +}; + } style_value_converter::style_value_converter() -- GitLab From 112c98c2a702df970c6ec8d765c18077504fd1fa Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Thu, 23 Jun 2016 10:46:53 +0530 Subject: [PATCH 4/6] Import odf vertical and horizontal alignment --- src/liborcus/odf_styles_context.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp index 7fe3698b7..6c4d1d5e8 100644 --- a/src/liborcus/odf_styles_context.cpp +++ b/src/liborcus/odf_styles_context.cpp @@ -550,7 +550,14 @@ void styles_context::start_element(xmlns_id_t ns, xml_token_t name, const std::v xml_element_expected(parent, NS_odf_style, XML_style); break; case XML_paragraph_properties: + { xml_element_expected(parent, NS_odf_style, XML_style); + paragraph_prop_attr_parser func; + func = std::for_each(attrs.begin(), attrs.end(), func); + if (func.has_hor_alignment()) + mp_styles->set_xf_horizontal_alignment(func.get_hor_alignment()); + + } break; case XML_text_properties: { @@ -669,6 +676,10 @@ void styles_context::start_element(xmlns_id_t ns, xml_token_t name, const std::v mp_styles->set_cell_print_content(func.is_print_content()); mp_styles->set_cell_formula_hidden(func.is_formula_hidden()); } + + if (func.has_ver_alignment()) + mp_styles->set_xf_vertical_alignment(func.get_ver_alignment()); + size_t cell_protection_id = mp_styles->commit_cell_protection(); switch (m_current_style->family) { -- GitLab From 958dc0012dd90acf2b261859f41c8d017bdbd47d Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Thu, 23 Jun 2016 11:15:03 +0530 Subject: [PATCH 5/6] Add test for odf text alignment --- src/liborcus/odf_styles_context_test.cpp | 15 ++++++++++++++- test/ods/styles/cell-styles.xml | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/liborcus/odf_styles_context_test.cpp b/src/liborcus/odf_styles_context_test.cpp index 95d57971a..b90fc994c 100644 --- a/src/liborcus/odf_styles_context_test.cpp +++ b/src/liborcus/odf_styles_context_test.cpp @@ -49,7 +49,7 @@ void test_odf_fill(orcus::spreadsheet::import_styles &styles) void test_odf_border(orcus::spreadsheet::import_styles &styles) { - assert(styles.get_border_count() == 8); + assert(styles.get_border_count() == 9); /* Test that border style applies to all the sides when not specified */ const orcus::spreadsheet::cell_style_t* style = find_cell_style_by_name("Name1", &styles); @@ -269,6 +269,18 @@ void test_odf_number_formatting(orcus::spreadsheet::import_styles& styles) cell_number_format = styles.get_number_format(number_format); assert(cell_number_format->format_string.str() == "[>=0]0.00;[RED]-0.00"); +} + +void test_odf_text_alignment(orcus::spreadsheet::import_styles& styles) +{ + const orcus::spreadsheet::cell_style_t* style = find_cell_style_by_name("Name22", &styles); + size_t xf = style->xf; + const orcus::spreadsheet::cell_format_t* cell_format = styles.get_cell_style_format(xf); + assert(cell_format); + + assert(cell_format->hor_align == orcus::spreadsheet::hor_alignment_t::right); + assert(cell_format->ver_align == orcus::spreadsheet::ver_alignment_t::middle); + } int main() { @@ -282,6 +294,7 @@ int main() test_odf_border(styles); test_odf_cell_protection(styles); test_odf_font(styles); + test_odf_text_alignment(styles); orcus::string_pool string_pool2; path = SRCDIR"/test/ods/styles/number-format.xml"; diff --git a/test/ods/styles/cell-styles.xml b/test/ods/styles/cell-styles.xml index 070f7ee67..5bdd45e72 100644 --- a/test/ods/styles/cell-styles.xml +++ b/test/ods/styles/cell-styles.xml @@ -27,4 +27,9 @@ + + + + + -- GitLab From 35c34559d5f0694794e68631ab21b91448ac54e5 Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Mon, 4 Jul 2016 13:07:26 +0530 Subject: [PATCH 6/6] Add initializations for various variables --- src/liborcus/odf_number_formatting_context.cpp | 12 +++++++++++- src/liborcus/odf_styles.cpp | 1 + src/liborcus/odf_styles.hpp | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/liborcus/odf_number_formatting_context.cpp b/src/liborcus/odf_number_formatting_context.cpp index 58ba9c58e..142bfc0bd 100644 --- a/src/liborcus/odf_number_formatting_context.cpp +++ b/src/liborcus/odf_number_formatting_context.cpp @@ -84,6 +84,8 @@ class number_attr_parser : std::unary_function public: number_attr_parser() : + m_decimal_places(0), + m_min_int_digits(0), m_grouping(false), m_has_decimal_places(false) {} @@ -129,7 +131,10 @@ class scientific_number_attr_parser : std::unary_function public: month_attr_parser(): + m_style_name(false), m_textual(false) {} @@ -233,6 +239,7 @@ class seconds_attr_parser : std::unary_function public: seconds_attr_parser(): + m_decimal_places(0), m_style_name(false), m_has_decimal_places(false) {} @@ -268,6 +275,9 @@ class fraction_attr_parser : std::unary_function public: fraction_attr_parser(): + m_min_int_digits(0), + m_min_deno_digits(0), + m_min_num_digits(0), m_predefined_deno(false) {} diff --git a/src/liborcus/odf_styles.cpp b/src/liborcus/odf_styles.cpp index cbbf3f8be..b07a467c4 100644 --- a/src/liborcus/odf_styles.cpp +++ b/src/liborcus/odf_styles.cpp @@ -79,6 +79,7 @@ number_formatting_style::number_formatting_style(const pstring& style_name, cons { name = style_name; is_volatile = volatile_style; + number_formatting = 0; } diff --git a/src/liborcus/odf_styles.hpp b/src/liborcus/odf_styles.hpp index c89f464aa..28bb0521c 100644 --- a/src/liborcus/odf_styles.hpp +++ b/src/liborcus/odf_styles.hpp @@ -107,6 +107,7 @@ struct number_formatting_style pstring character_stream; number_formatting_style(): + number_formatting(0), is_volatile(false) {} -- GitLab