summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-10-16 22:40:27 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-10-16 22:40:27 -0400
commitc8bde749c6630b5a77bdf63c85982585f9c4b4f5 (patch)
tree803f48c08f182fad867ab6d1c447ec412858440b
parentf52ff30f94c65e4bb5c4f97b55f24e086d19e1ae (diff)
downloadorcus-feature/166-named-styles-to-columns.tar.gz
Add test on Sheet2, and fix the incorrect column style import feature/166-named-styles-to-columns
-rw-r--r--include/orcus/spreadsheet/sheet.hpp14
-rw-r--r--src/liborcus/ods_content_xml_context.cpp12
-rw-r--r--src/liborcus/ods_content_xml_context.hpp1
-rw-r--r--src/orcus_test_ods.cpp52
4 files changed, 73 insertions, 6 deletions
diff --git a/include/orcus/spreadsheet/sheet.hpp b/include/orcus/spreadsheet/sheet.hpp
index d6aa0c8c..ff6dcf11 100644
--- a/include/orcus/spreadsheet/sheet.hpp
+++ b/include/orcus/spreadsheet/sheet.hpp
@@ -64,6 +64,20 @@ public:
void set_grouped_formula(const range_t& range, ixion::formula_tokens_t tokens, ixion::formula_result result);
void set_col_width(col_t col, col_t col_span, col_width_t width);
+
+ /**
+ * Get column width in twips.
+ *
+ * @param col column index
+ * @param col_start pointer to a variable to store the index of the starting
+ * column of the range with the same width. Pass nullptr if
+ * the caller doesn't need this information.
+ * @param col_end pointer to a variable to store the index of the ending
+ * column plus one, of the range with the same width. Pass
+ * nullptr if the caller doesn't need this information.
+ *
+ * @return width of the specified column index (in twips).
+ */
col_width_t get_col_width(col_t col, col_t* col_start, col_t* col_end) const;
void set_col_hidden(col_t col, col_t col_span, bool hidden);
diff --git a/src/liborcus/ods_content_xml_context.cpp b/src/liborcus/ods_content_xml_context.cpp
index ffea3f52..44b45aaa 100644
--- a/src/liborcus/ods_content_xml_context.cpp
+++ b/src/liborcus/ods_content_xml_context.cpp
@@ -114,7 +114,7 @@ ods_content_xml_context::cell_attr::cell_attr() :
ods_content_xml_context::ods_content_xml_context(session_context& session_cxt, const tokens& tokens, spreadsheet::iface::import_factory* factory) :
xml_context_base(session_cxt, tokens),
mp_factory(factory),
- m_row(0), m_col(0),
+ m_row(0), m_col(0), m_col_repeated(0),
m_para_index(0),
m_has_content(false),
m_styles(),
@@ -430,7 +430,7 @@ void ods_content_xml_context::start_column(const xml_attrs_t& attrs)
std::string_view style_name;
std::string_view default_cell_style_name;
- ss::col_t columns_repeated = 1;
+ m_col_repeated = 1;
for (const xml_token_attr_t& attr : attrs)
{
@@ -445,7 +445,7 @@ void ods_content_xml_context::start_column(const xml_attrs_t& attrs)
default_cell_style_name = intern(attr);
break;
case XML_number_columns_repeated:
- columns_repeated = to_long(attr.value);
+ m_col_repeated = to_long(attr.value);
break;
}
}
@@ -456,17 +456,17 @@ void ods_content_xml_context::start_column(const xml_attrs_t& attrs)
const odf_style& style = *it->second;
sheet_props->set_column_width(
- m_col, columns_repeated,
+ m_col, m_col_repeated,
std::get<odf_style::column>(style.data).width.value,
std::get<odf_style::column>(style.data).width.unit);
}
- push_default_column_cell_style(default_cell_style_name, columns_repeated);
+ push_default_column_cell_style(default_cell_style_name, m_col_repeated);
}
void ods_content_xml_context::end_column()
{
- ++m_col;
+ m_col += m_col_repeated;
}
void ods_content_xml_context::start_row(const xml_attrs_t& attrs)
diff --git a/src/liborcus/ods_content_xml_context.hpp b/src/liborcus/ods_content_xml_context.hpp
index ede6fbdb..499833b7 100644
--- a/src/liborcus/ods_content_xml_context.hpp
+++ b/src/liborcus/ods_content_xml_context.hpp
@@ -120,6 +120,7 @@ private:
int m_row;
int m_col;
+ int m_col_repeated;
size_t m_para_index;
bool m_has_content;
diff --git a/src/orcus_test_ods.cpp b/src/orcus_test_ods.cpp
index 7b28f17d..65e4a932 100644
--- a/src/orcus_test_ods.cpp
+++ b/src/orcus_test_ods.cpp
@@ -599,6 +599,58 @@ void test_ods_import_styles_column_styles()
assert(fill->first.fg_color == ss::color_t(0xFF, 0x00, 0xA9, 0x33));
assert(fill->second.fg_color);
}
+
+ // Move on to the next sheet...
+ sh = doc->get_sheet(1);
+ assert(sh);
+
+ // Column A uses "Default"
+ xfid = sh->get_cell_format(0, 0);
+ xf = styles.get_cell_format(xfid);
+ assert(xf);
+ xstyle = styles.get_cell_style_by_xf(xf->style_xf);
+ assert(xstyle);
+ assert(xstyle->name == "Default");
+
+ // Columns B:D use "Gray With Lime" with direct background color
+ for (ss::col_t col : {1, 2, 3})
+ {
+ std::cout << "column " << col << std::endl;
+ xfid = sh->get_cell_format(0, col);
+ xf = styles.get_cell_format(xfid);
+ assert(xf);
+
+ xstyle = styles.get_cell_style_by_xf(xf->style_xf);
+ assert(xstyle);
+ assert(xstyle->name == "Gray With Lime" || xstyle->display_name == "Gray With Lime");
+
+ fill = styles.get_fill_state(xf->fill);
+ assert(fill);
+ assert(fill->first.pattern_type == ss::fill_pattern_t::solid);
+ assert(fill->second.pattern_type);
+ assert(fill->first.fg_color == ss::color_t(0xFF, 0xFF, 0xDE, 0x59));
+ assert(fill->second.fg_color);
+ }
+
+ // Column E and the rest all use "Default"
+ xfid = sh->get_cell_format(0, 4);
+ xf = styles.get_cell_format(xfid);
+ assert(xf);
+ xstyle = styles.get_cell_style_by_xf(xf->style_xf);
+ assert(xstyle);
+ assert(xstyle->name == "Default");
+
+ // Columns F:I have narrower width of 0.5 inch.
+ {
+ ss::col_t col_start = -1, col_end = -1;
+ // column widths are stored in twips
+ ss::col_width_t cw = sh->get_col_width(5, &col_start, &col_end);
+ assert(col_start == 5);
+ assert(col_end == 9); // column I has an id = 8, plus 1 for the end position
+ length_t v{length_unit_t::inch, 0.5};
+ ss::col_width_t cw_expected = convert(0.5, length_unit_t::inch, length_unit_t::twip);
+ assert(cw == cw_expected);
+ }
}
} // anonymous namespace