summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-06-06 17:31:20 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-06-06 17:32:24 -0400
commit36a2d91eae2b2e1583be79e837144de9d53b3e64 (patch)
tree2c73d6901d6c08f1fde3fc9ed863bc61cd9c5463
parent8b2e357176a538898bae7fba7b00bada9dcfb50d (diff)
downloadorcus-36a2d91eae2b2e1583be79e837144de9d53b3e64.tar.gz
Use import_number_format on ods styles import
I need to come back to this and fix the issue with number_formatting_context. It doesn't properly track the element stack within its context.
-rw-r--r--src/liborcus/odf_number_formatting_context.cpp21
-rw-r--r--src/liborcus/odf_styles_context.cpp6
-rw-r--r--src/liborcus/xml_context_base.hpp11
3 files changed, 30 insertions, 8 deletions
diff --git a/src/liborcus/odf_number_formatting_context.cpp b/src/liborcus/odf_number_formatting_context.cpp
index 31a9cd8c..7ebe89c4 100644
--- a/src/liborcus/odf_number_formatting_context.cpp
+++ b/src/liborcus/odf_number_formatting_context.cpp
@@ -9,6 +9,7 @@
#include "odf_namespace_types.hpp"
#include "odf_token_constants.hpp"
#include "odf_helper.hpp"
+#include "impl_utils.hpp"
#include <orcus/measurement.hpp>
#include <orcus/spreadsheet/import_interface.hpp>
@@ -408,6 +409,9 @@ void number_formatting_context::end_child_context(xmlns_id_t /*ns*/, xml_token_t
void number_formatting_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);
+ (void)parent;
+
m_current_style.character_stream = std::string_view{};
if (ns == NS_odf_number)
@@ -709,6 +713,12 @@ void number_formatting_context::start_element(xmlns_id_t ns, xml_token_t name, c
bool number_formatting_context::end_element(xmlns_id_t ns, xml_token_t name)
{
+ if (!mp_styles)
+ return pop_stack(ns, name);
+
+ auto* number_format = mp_styles->get_number_format();
+ ENSURE_INTERFACE(number_format, import_number_format);
+
std::string_view character_content = m_current_style.character_stream;
if (ns == NS_odf_number)
@@ -727,8 +737,8 @@ bool number_formatting_context::end_element(xmlns_id_t ns, xml_token_t name)
if (!m_current_style.number_formatting_code.empty())
{
- mp_styles->set_number_format_code(m_current_style.number_formatting_code);
- id_number_format = mp_styles->commit_number_format();
+ number_format->set_code(m_current_style.number_formatting_code);
+ id_number_format = number_format->commit();
}
mp_styles->set_xf_number_format(id_number_format);
@@ -736,7 +746,8 @@ bool number_formatting_context::end_element(xmlns_id_t ns, xml_token_t name)
mp_styles->set_cell_style_name(m_current_style.name);
mp_styles->set_cell_style_xf(mp_styles->commit_cell_style_xf());
mp_styles->commit_cell_style();
- return true;
+ return true; // TODO: fix this
+// return pop_stack(ns, name);
}
}
else if (name == XML_currency_symbol)
@@ -750,7 +761,9 @@ bool number_formatting_context::end_element(xmlns_id_t ns, xml_token_t name)
m_current_style.number_formatting_code += character_content;
}
}
- return false;
+
+ return false; // TODO: fix this
+// return pop_stack(ns, name);
}
diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp
index 81c68afc..8844cc13 100644
--- a/src/liborcus/odf_styles_context.cpp
+++ b/src/liborcus/odf_styles_context.cpp
@@ -766,13 +766,17 @@ void styles_context::commit_default_styles()
auto* cell_protection = mp_styles->get_cell_protection();
ENSURE_INTERFACE(cell_protection, import_cell_protection);
+ auto* number_format = mp_styles->get_number_format();
+ ENSURE_INTERFACE(number_format, import_number_format);
+
// Set default styles. Default styles must be associated with an index of 0.
// Set empty styles for all style types before importing real styles.
font_style->commit();
fill_style->commit();
border_style->commit();
cell_protection->commit();
- mp_styles->commit_number_format();
+ number_format->commit();
+
mp_styles->commit_cell_style_xf();
mp_styles->commit_cell_xf();
mp_styles->commit_cell_style();
diff --git a/src/liborcus/xml_context_base.hpp b/src/liborcus/xml_context_base.hpp
index 7f88cbba..f5796a52 100644
--- a/src/liborcus/xml_context_base.hpp
+++ b/src/liborcus/xml_context_base.hpp
@@ -69,7 +69,10 @@ public:
virtual void end_child_context(xmlns_id_t ns, xml_token_t name, xml_context_base* child) = 0;
/**
- * Called on the opening of each element.
+ * Called on the opening of each element. The implementor should call
+ * push_stack() at the beginning of this method to have the base class keep
+ * track of the element stack. Be sure to also call pop_stack() in
+ * end_element() to maintain correct element stack.
*
* @param ns namespace token
* @param name element name
@@ -83,8 +86,10 @@ public:
* @param ns namespace token
* @param name element name
*
- * @return true if the base element of the context is closing, false
- * otherwise.
+ * @return true if the element that's closing is the root element of the
+ * context, else return false. The implementor should simply call
+ * pop_stack() and use the returned value from it as this method's
+ * return value.
*/
virtual bool end_element(xmlns_id_t ns, xml_token_t name) = 0;