summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-08-31 19:51:00 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-08-31 19:51:00 -0400
commitec9ed72c183c2ffc60e1675610cb0d1f11bec0e3 (patch)
tree0d18ad6807fc0d8737b629114795712068b1d46f
parent6ad5cd2e434abc238571dfd28211a790f2c66b5b (diff)
downloadorcus-feature/160-ods-number-format-styles.tar.gz
Pick up the style:data-style-name and record the corresponding ... feature/160-ods-number-format-styles
... number format id.
-rw-r--r--src/liborcus/odf_style_context.cpp42
-rw-r--r--src/liborcus/odf_style_context.hpp2
-rw-r--r--src/liborcus/odf_styles.hpp11
-rw-r--r--src/liborcus/odf_styles_context.cpp2
4 files changed, 37 insertions, 20 deletions
diff --git a/src/liborcus/odf_style_context.cpp b/src/liborcus/odf_style_context.cpp
index e979d9d2..fbc8dac9 100644
--- a/src/liborcus/odf_style_context.cpp
+++ b/src/liborcus/odf_style_context.cpp
@@ -10,6 +10,8 @@
#include "odf_namespace_types.hpp"
#include "odf_token_constants.hpp"
#include "odf_helper.hpp"
+#include "session_context.hpp"
+#include "ods_session_data.hpp"
#include <mdds/sorted_string_map.hpp>
@@ -44,7 +46,7 @@ const map_type& get()
} // namespace style_family
-[[maybe_unused]] odf_style_family to_style_family(std::string_view val)
+odf_style_family to_style_family(std::string_view val)
{
return style_family::get().find(val.data(), val.size());
}
@@ -95,18 +97,6 @@ style_context::style_context(session_context& session_cxt, const tokens& tk, ss:
{
}
-xml_context_base* style_context::create_child_context(xmlns_id_t /*ns*/, xml_token_t /*name*/)
-{
- return nullptr;
-}
-
-void style_context::end_child_context(xmlns_id_t ns, xml_token_t name, xml_context_base* child)
-{
- (void)ns;
- (void)name;
- (void)child;
-}
-
void style_context::start_element(xmlns_id_t ns, xml_token_t name, const std::vector<xml_token_attr_t>& attrs)
{
xml_token_pair_t parent = push_stack(ns, name);
@@ -121,6 +111,7 @@ void style_context::start_element(xmlns_id_t ns, xml_token_t name, const std::ve
std::string_view style_name;
std::string_view parent_style_name;
+ std::optional<std::string_view> data_style_name;
odf_style_family family = style_family_unknown;
for (const xml_token_attr_t& attr : attrs)
@@ -138,11 +129,36 @@ void style_context::start_element(xmlns_id_t ns, xml_token_t name, const std::ve
case XML_parent_style_name:
parent_style_name = attr.value;
break;
+ case XML_data_style_name:
+ data_style_name = attr.value;
+ break;
}
}
}
m_current_style = std::make_unique<odf_style>(style_name, family, parent_style_name);
+
+ if (data_style_name && family == style_family_table_cell)
+ {
+ const auto& ods_data = get_session_context().get_data<ods_session_data>();
+ const auto& numfmt_name2id = ods_data.number_formats.name2id_map;
+
+ if (auto it = numfmt_name2id.find(*data_style_name); it != numfmt_name2id.end())
+ {
+ // record the number format id associated with the name.
+ auto& data = std::get<odf_style::cell>(m_current_style->data);
+ data.number_format = it->second;
+ }
+ else
+ {
+ if (get_config().debug)
+ {
+ std::ostringstream os;
+ os << "no number style found for the data style name of '" << *data_style_name << "'";
+ warn(os.str());
+ }
+ }
+ }
break;
}
case XML_table_column_properties:
diff --git a/src/liborcus/odf_style_context.hpp b/src/liborcus/odf_style_context.hpp
index d7e12c17..81e88ee5 100644
--- a/src/liborcus/odf_style_context.hpp
+++ b/src/liborcus/odf_style_context.hpp
@@ -29,8 +29,6 @@ class style_context : public xml_context_base
public:
style_context(session_context& session_cxt, const tokens& tk, spreadsheet::iface::import_styles* iface_styles);
- xml_context_base* create_child_context(xmlns_id_t ns, xml_token_t name) override;
- void end_child_context(xmlns_id_t ns, xml_token_t name, xml_context_base* child) override;
void start_element(xmlns_id_t ns, xml_token_t name, const std::vector<xml_token_attr_t>& attrs) override;
void characters(std::string_view str, bool transient) override;
bool end_element(xmlns_id_t ns, xml_token_t name) override;
diff --git a/src/liborcus/odf_styles.hpp b/src/liborcus/odf_styles.hpp
index 4f8a6bfb..9f24e6ff 100644
--- a/src/liborcus/odf_styles.hpp
+++ b/src/liborcus/odf_styles.hpp
@@ -48,13 +48,14 @@ struct odf_style
struct cell
{
- size_t font = 0;
- size_t fill = 0;
- size_t border = 0;
- size_t protection = 0;
+ std::size_t font = 0;
+ std::size_t fill = 0;
+ std::size_t border = 0;
+ std::size_t protection = 0;
+ std::size_t xf = 0;
+ std::size_t number_format = 0;
spreadsheet::hor_alignment_t hor_align = spreadsheet::hor_alignment_t::unknown;
spreadsheet::ver_alignment_t ver_align = spreadsheet::ver_alignment_t::unknown;
- size_t xf = 0;
};
struct table
diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp
index 136a1402..af413f3b 100644
--- a/src/liborcus/odf_styles_context.cpp
+++ b/src/liborcus/odf_styles_context.cpp
@@ -169,6 +169,7 @@ void styles_context::end_child_context(xmlns_id_t ns, xml_token_t name, xml_cont
xf->set_protection(cell.protection);
xf->set_horizontal_alignment(cell.hor_align);
xf->set_vertical_alignment(cell.ver_align);
+ xf->set_number_format(cell.number_format);
cell.xf = xf->commit();
}
else
@@ -183,6 +184,7 @@ void styles_context::end_child_context(xmlns_id_t ns, xml_token_t name, xml_cont
xf->set_protection(cell.protection);
xf->set_horizontal_alignment(cell.hor_align);
xf->set_vertical_alignment(cell.ver_align);
+ xf->set_number_format(cell.number_format);
size_t style_xf_id = xf->commit();
auto* cell_style = mp_styles->get_cell_style();