From 37e16983f866662af580fbccfffa71de010a0387 Mon Sep 17 00:00:00 2001 From: andiwand Date: Sun, 10 Dec 2023 17:24:31 +0100 Subject: [PATCH] redo sheet --- src/odr/document_element.cpp | 35 +-- src/odr/document_element.hpp | 14 +- src/odr/internal/abstract/sheet_element.hpp | 49 +--- src/odr/internal/html/document_element.cpp | 23 +- src/odr/internal/odf/odf_parser.hpp | 7 +- src/odr/internal/odf/odf_spreadsheet.cpp | 237 ++++++++++-------- src/odr/internal/odf/odf_spreadsheet.hpp | 36 ++- .../spreadsheet/ooxml_spreadsheet_element.cpp | 67 ++--- .../spreadsheet/ooxml_spreadsheet_element.hpp | 51 +--- .../spreadsheet/ooxml_spreadsheet_parser.cpp | 5 +- 10 files changed, 245 insertions(+), 279 deletions(-) diff --git a/src/odr/document_element.cpp b/src/odr/document_element.cpp index 2ee622bd..e6033d07 100644 --- a/src/odr/document_element.cpp +++ b/src/odr/document_element.cpp @@ -183,15 +183,11 @@ TableDimensions Sheet::content(std::optional range) const { } SheetColumn Sheet::column(std::uint32_t column) const { - return exists_() ? SheetColumn(m_document, m_element, column, - m_element->column(m_document, column)) - : SheetColumn(); + return exists_() ? SheetColumn(m_document, m_element, column) : SheetColumn(); } SheetRow Sheet::row(std::uint32_t row) const { - return exists_() ? SheetRow(m_document, m_element, row, - m_element->row(m_document, row)) - : SheetRow(); + return exists_() ? SheetRow(m_document, m_element, row) : SheetRow(); } SheetCell Sheet::cell(std::uint32_t column, std::uint32_t row) const { @@ -207,22 +203,20 @@ ElementRange Sheet::shapes() const { } SheetColumn::SheetColumn(const internal::abstract::Document *document, - internal::abstract::Sheet *sheet, std::uint32_t column, - internal::abstract::SheetColumn *element) - : TypedElement(document, element), m_sheet{sheet}, m_column{column} {} + internal::abstract::Sheet *sheet, std::uint32_t column) + : TypedElement(document, sheet), m_column{column} {} TableColumnStyle SheetColumn::style() const { - return exists_() ? m_element->style(m_document, m_sheet, m_column) + return exists_() ? m_element->column_style(m_document, m_column) : TableColumnStyle(); } SheetRow::SheetRow(const internal::abstract::Document *document, - internal::abstract::Sheet *sheet, std::uint32_t row, - internal::abstract::SheetRow *element) - : TypedElement(document, element), m_sheet{sheet}, m_row{row} {} + internal::abstract::Sheet *sheet, std::uint32_t row) + : TypedElement(document, sheet), m_row{row} {} TableRowStyle SheetRow::style() const { - return m_element->style(m_document, m_sheet, m_row); + return exists_() ? m_element->row_style(m_document, m_row) : TableRowStyle(); } SheetCell::SheetCell(const internal::abstract::Document *document, @@ -232,23 +226,20 @@ SheetCell::SheetCell(const internal::abstract::Document *document, m_row{row} {} bool SheetCell::is_covered() const { - return exists_() ? m_element->is_covered(m_document, m_sheet, m_column, m_row) - : false; + return exists_() ? m_element->is_covered(m_document) : false; } TableDimensions SheetCell::span() const { - return exists_() ? m_element->span(m_document, m_sheet, m_column, m_row) - : TableDimensions(); + return exists_() ? m_element->span(m_document) : TableDimensions(1, 1); } ValueType SheetCell::value_type() const { - return exists_() ? m_element->value_type(m_document, m_sheet, m_column, m_row) - : ValueType::unknown; + return exists_() ? m_element->value_type(m_document) : ValueType::unknown; } TableCellStyle SheetCell::style() const { - return exists_() ? m_element->style(m_document, m_sheet, m_column, m_row) - : TableCellStyle(); + return m_sheet != nullptr ? m_sheet->cell_style(m_document, m_column, m_row) + : TableCellStyle(); } std::string Page::name() const { diff --git a/src/odr/document_element.hpp b/src/odr/document_element.hpp index bd64a05c..a0147b85 100644 --- a/src/odr/document_element.hpp +++ b/src/odr/document_element.hpp @@ -278,31 +278,27 @@ class Sheet final : public TypedElement { [[nodiscard]] ElementRange shapes() const; }; -class SheetColumn final : public TypedElement { +class SheetColumn final : public TypedElement { public: SheetColumn() = default; SheetColumn(const internal::abstract::Document *document, - internal::abstract::Sheet *sheet, std::uint32_t column, - internal::abstract::SheetColumn *element); + internal::abstract::Sheet *sheet, std::uint32_t column); [[nodiscard]] TableColumnStyle style() const; private: - internal::abstract::Sheet *m_sheet{}; std::uint32_t m_column{}; }; -class SheetRow final : public TypedElement { +class SheetRow final : public TypedElement { public: SheetRow() = default; SheetRow(const internal::abstract::Document *document, - internal::abstract::Sheet *sheet, std::uint32_t row, - internal::abstract::SheetRow *element); + internal::abstract::Sheet *sheet, std::uint32_t row); [[nodiscard]] TableRowStyle style() const; private: - internal::abstract::Sheet *m_sheet{}; std::uint32_t m_row{}; }; @@ -320,7 +316,7 @@ class SheetCell final : public TypedElement { [[nodiscard]] TableCellStyle style() const; private: - internal::abstract::Sheet *m_sheet{}; + internal::abstract::Sheet *m_sheet; std::uint32_t m_column{}; std::uint32_t m_row{}; }; diff --git a/src/odr/internal/abstract/sheet_element.hpp b/src/odr/internal/abstract/sheet_element.hpp index d464700b..7760d769 100644 --- a/src/odr/internal/abstract/sheet_element.hpp +++ b/src/odr/internal/abstract/sheet_element.hpp @@ -4,8 +4,6 @@ #include namespace odr::internal::abstract { -class SheetColumn; -class SheetRow; class SheetCell; class Sheet : public virtual Element { @@ -20,36 +18,19 @@ class Sheet : public virtual Element { [[nodiscard]] virtual TableDimensions content(const Document *, std::optional range) const = 0; - [[nodiscard]] virtual SheetColumn *column(const Document *, - std::uint32_t column) const = 0; - [[nodiscard]] virtual SheetRow *row(const Document *, - std::uint32_t row) const = 0; [[nodiscard]] virtual SheetCell *cell(const Document *, std::uint32_t column, std::uint32_t row) const = 0; [[nodiscard]] virtual Element *first_shape(const Document *) const = 0; [[nodiscard]] virtual TableStyle style(const Document *) const = 0; -}; - -class SheetColumn : public virtual Element { -public: - [[nodiscard]] ElementType type(const Document *) const override { - return ElementType::table_column; - } - - [[nodiscard]] virtual TableColumnStyle style(const Document *, Sheet *, - std::uint32_t column) const = 0; -}; - -class SheetRow : public virtual Element { -public: - [[nodiscard]] ElementType type(const Document *) const override { - return ElementType::table_row; - } - - [[nodiscard]] virtual TableRowStyle style(const Document *, Sheet *, - std::uint32_t row) const = 0; + [[nodiscard]] virtual TableColumnStyle + column_style(const Document *, std::uint32_t column) const = 0; + [[nodiscard]] virtual TableRowStyle row_style(const Document *, + std::uint32_t row) const = 0; + [[nodiscard]] virtual TableCellStyle cell_style(const Document *, + std::uint32_t column, + std::uint32_t row) const = 0; }; class SheetCell : public virtual Element { @@ -58,19 +39,11 @@ class SheetCell : public virtual Element { return ElementType::table_cell; } - [[nodiscard]] virtual bool is_covered(const Document *, Sheet *, - std::uint32_t column, - std::uint32_t row) const = 0; - [[nodiscard]] virtual TableDimensions span(const Document *, Sheet *, - std::uint32_t column, - std::uint32_t row) const = 0; - [[nodiscard]] virtual ValueType value_type(const Document *, Sheet *, - std::uint32_t column, - std::uint32_t row) const = 0; + [[nodiscard]] virtual bool is_covered(const Document *) const = 0; + [[nodiscard]] virtual TableDimensions span(const Document *) const = 0; + [[nodiscard]] virtual ValueType value_type(const Document *) const = 0; - [[nodiscard]] virtual TableCellStyle style(const Document *, Sheet *, - std::uint32_t column, - std::uint32_t row) const = 0; + [[nodiscard]] virtual TableCellStyle style(const Document *) const = 0; }; } // namespace odr::internal::abstract diff --git a/src/odr/internal/html/document_element.cpp b/src/odr/internal/html/document_element.cpp index 791b2a2f..a5af7718 100644 --- a/src/odr/internal/html/document_element.cpp +++ b/src/odr/internal/html/document_element.cpp @@ -9,6 +9,7 @@ #include #include +#include "odr/internal/common/table_cursor.hpp" #include namespace odr::internal { @@ -99,6 +100,8 @@ void html::translate_sheet(Element element, std::ostream &out, end_column = std::min(end_column, config.spreadsheet_limit->columns); end_row = std::min(end_row, config.spreadsheet_limit->rows); } + end_column = std::max(1u, end_column); + end_row = std::max(1u, end_row); out << ""; @@ -127,7 +130,9 @@ void html::translate_sheet(Element element, std::ostream &out, out << ""; } - for (std::uint32_t row_index = 0; row_index < end_row; ++row_index) { + common::TableCursor cursor; + for (std::uint32_t row_index = cursor.row(); row_index < end_row; + row_index = cursor.row()) { auto table_row = sheet.row(row_index); auto table_row_style = table_row.style(); @@ -144,8 +149,8 @@ void html::translate_sheet(Element element, std::ostream &out, out << common::TablePosition::to_row_string(row_index); out << ""; - for (std::uint32_t column_index = 0; column_index < end_column; - ++column_index) { + for (std::uint32_t column_index = cursor.column(); + column_index < end_column; column_index = cursor.column()) { auto cell = sheet.cell(column_index, row_index); if (cell.is_covered()) { @@ -160,27 +165,31 @@ void html::translate_sheet(Element element, std::ostream &out, auto cell_elements = cell.children(); out << " 1) { - out << " rowspan=\"" << cell_span.rows << "\""; - } if (cell_span.columns > 1) { out << " colspan=\"" << cell_span.columns << "\""; } + if (cell_span.rows > 1) { + out << " rowspan=\"" << cell_span.rows << "\""; + } out << optional_style_attribute(translate_table_cell_style(cell_style)); if (cell_value_type == ValueType::float_number) { out << " class=\"odr-value-type-float\""; } out << ">"; - if ((row_index == 0) && (column_index == 0)) { + if ((column_index == 0) && (row_index == 0)) { for (auto shape : sheet.shapes()) { translate_element(shape, out, config); } } translate_children(cell_elements, out, config); out << ""; + + cursor.add_cell(cell_span.columns, cell_span.rows); } out << ""; + + cursor.add_row(); } out << ""; diff --git a/src/odr/internal/odf/odf_parser.hpp b/src/odr/internal/odf/odf_parser.hpp index 94ae6e8e..5540f4c6 100644 --- a/src/odr/internal/odf/odf_parser.hpp +++ b/src/odr/internal/odf/odf_parser.hpp @@ -20,14 +20,15 @@ class TableRow; Element *parse_tree(Document &document, pugi::xml_node node); -template +template std::tuple -parse_element_tree(Document &document, pugi::xml_node node) { +parse_element_tree(Document &document, pugi::xml_node node, args_t &&...args) { if (!node) { return std::make_tuple(nullptr, pugi::xml_node()); } - auto element_unique = std::make_unique(node); + auto element_unique = + std::make_unique(node, std::forward(args)...); auto element = element_unique.get(); document.register_element_(std::move(element_unique)); diff --git a/src/odr/internal/odf/odf_spreadsheet.cpp b/src/odr/internal/odf/odf_spreadsheet.cpp index a45a37c2..e734f2ce 100644 --- a/src/odr/internal/odf/odf_spreadsheet.cpp +++ b/src/odr/internal/odf/odf_spreadsheet.cpp @@ -8,50 +8,21 @@ namespace odr::internal::odf { -class SheetColumn final : public Element, public abstract::SheetColumn { -public: - using Element::Element; - - [[nodiscard]] TableColumnStyle style(const abstract::Document *document, - abstract::Sheet *, - std::uint32_t /*column*/) const final { - return partial_style(document).table_column_style; - } -}; - -class SheetRow final : public Element, public abstract::SheetRow { -public: - using Element::Element; - - [[nodiscard]] TableRowStyle style(const abstract::Document *document, - abstract::Sheet *, - std::uint32_t /*column*/) const final { - return partial_style(document).table_row_style; - } -}; - class SheetCell final : public Element, public abstract::SheetCell { public: - using Element::Element; + SheetCell(pugi::xml_node node, std::uint32_t column, std::uint32_t row) + : Element(node), m_column{column}, m_row{row} {} - [[nodiscard]] bool is_covered(const abstract::Document *, abstract::Sheet *, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const final { + [[nodiscard]] bool is_covered(const abstract::Document *) const final { return std::strcmp(m_node.name(), "table:covered-table-cell") == 0; } - [[nodiscard]] TableDimensions span(const abstract::Document *, - abstract::Sheet *, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const final { + [[nodiscard]] TableDimensions span(const abstract::Document *) const final { return {m_node.attribute("table:number-rows-spanned").as_uint(1), m_node.attribute("table:number-columns-spanned").as_uint(1)}; } - [[nodiscard]] ValueType value_type(const abstract::Document *, - abstract::Sheet *, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const final { + [[nodiscard]] ValueType value_type(const abstract::Document *) const final { auto value_type = m_node.attribute("office:value-type").value(); if (std::strcmp("float", value_type) == 0) { return ValueType::float_number; @@ -59,39 +30,25 @@ class SheetCell final : public Element, public abstract::SheetCell { return ValueType::string; } - [[nodiscard]] TableCellStyle style(const abstract::Document *document, - abstract::Sheet *sheet, - std::uint32_t column, - std::uint32_t row) const final { - auto style_name = style_name_(document); - if (style_name == nullptr) { - auto row_element = sheet->row(document, row); - // TODO should this ever be null? - if (row_element != nullptr) { - auto row_node = dynamic_cast(row_element)->m_node; - if (auto attr = row_node.attribute("table:default-cell-style-name")) { - style_name = attr.value(); - } - } - } - if (style_name == nullptr) { - auto column_element = sheet->column(document, column); - // TODO should this ever be null? - if (column_element != nullptr) { - auto column_node = dynamic_cast(column_element)->m_node; - if (auto attr = - column_node.attribute("table:default-cell-style-name")) { - style_name = attr.value(); - } - } - } - if (style_name != nullptr) { - if (auto style = style_(document)->style(style_name)) { - return style->resolved().table_cell_style; - } - } - return {}; + common::ResolvedStyle + partial_style(const abstract::Document *document) const final { + auto sheet = dynamic_cast(parent(document)); + return sheet->cell_style_(document, m_column, m_row); + } + + common::ResolvedStyle + intermediate_style(const abstract::Document *document) const final { + return partial_style(document); + } + + [[nodiscard]] TableCellStyle + style(const abstract::Document *document) const final { + return intermediate_style(document).table_cell_style; } + +private: + std::uint32_t m_column; + std::uint32_t m_row; }; std::string Sheet::name(const abstract::Document *) const { @@ -135,35 +92,66 @@ Sheet::content(const abstract::Document *, return result; } -abstract::SheetColumn *Sheet::column(const abstract::Document *, - std::uint32_t column) const { +pugi::xml_node Sheet::column_(std::uint32_t column) const { if (auto it = util::map::lookup_greater_than(m_columns, column); it != std::end(m_columns)) { - return dynamic_cast(it->second); + return it->second; } - return nullptr; + return {}; } -abstract::SheetRow *Sheet::row(const abstract::Document *, - std::uint32_t row) const { +pugi::xml_node Sheet::row_(std::uint32_t row) const { if (auto it = util::map::lookup_greater_than(m_rows, row); it != std::end(m_rows)) { - return it->second.element; + return it->second.row; } - return nullptr; + return {}; +} + +common::ResolvedStyle Sheet::cell_style_(const abstract::Document *document, + std::uint32_t column, + std::uint32_t row) const { + auto it = m_cells.find({column, row}); + if (it == std::end(m_cells)) { + return common::ResolvedStyle(); + } + + const char *style_name = nullptr; + + auto cell_node = it->second->m_node; + if (auto attr = cell_node.attribute("table:style-name")) { + style_name = attr.value(); + } + + if (style_name == nullptr) { + auto row_node = row_(row); + if (auto attr = row_node.attribute("table:default-cell-style-name")) { + style_name = attr.value(); + } + } + if (style_name == nullptr) { + auto column_node = column_(column); + if (auto attr = column_node.attribute("table:default-cell-style-name")) { + style_name = attr.value(); + } + } + + if (style_name == nullptr) { + return common::ResolvedStyle(); + } + auto style = style_(document)->style(style_name); + if (style == nullptr) { + return common::ResolvedStyle(); + } + return style->resolved(); } abstract::SheetCell *Sheet::cell(const abstract::Document *, std::uint32_t column, std::uint32_t row) const { - if (auto row_it = util::map::lookup_greater_than(m_rows, row); - row_it != std::end(m_rows)) { - auto &cells = row_it->second.cells; - if (auto column_it = util::map::lookup_greater_than(cells, column); - column_it != std::end(cells)) { - return column_it->second; - } - return nullptr; + if (auto cell_it = m_cells.find({column, row}); + cell_it != std::end(m_cells)) { + return cell_it->second; } return nullptr; } @@ -176,21 +164,60 @@ TableStyle Sheet::style(const abstract::Document *document) const { return partial_style(document).table_style; } +TableColumnStyle Sheet::column_style(const abstract::Document *document, + std::uint32_t column) const { + auto column_node = column_(column); + if (column_node) { + if (auto attr = column_node.attribute("table:style-name")) { + auto style = style_(document)->style(attr.value()); + if (style != nullptr) { + return style->resolved().table_column_style; + } + } + } + return TableColumnStyle(); +} + +TableRowStyle Sheet::row_style(const abstract::Document *document, + std::uint32_t row) const { + auto column_node = row_(row); + if (column_node) { + if (auto attr = column_node.attribute("table:style-name")) { + auto style = style_(document)->style(attr.value()); + if (style != nullptr) { + return style->resolved().table_row_style; + } + } + } + return TableRowStyle(); +} + +TableCellStyle Sheet::cell_style(const abstract::Document *document, + std::uint32_t column, + std::uint32_t row) const { + return cell_style_(document, column, row).table_cell_style; +} + void Sheet::init_column_(std::uint32_t column, std::uint32_t repeated, - SheetColumn *element) { - m_columns[column + repeated] = dynamic_cast(element); + pugi::xml_node element) { + m_columns[column + repeated] = element; } void Sheet::init_row_(std::uint32_t row, std::uint32_t repeated, - SheetRow *element) { - m_rows[row + repeated].element = dynamic_cast(element); + pugi::xml_node element) { + m_rows[row + repeated].row = element; } void Sheet::init_cell_(std::uint32_t column, std::uint32_t row, std::uint32_t columns_repeated, - std::uint32_t rows_repeated, SheetCell *element) { - m_rows[row + rows_repeated].cells[column + columns_repeated] = - dynamic_cast(element); + std::uint32_t rows_repeated, pugi::xml_node element) { + m_rows[row + rows_repeated].cells[column + columns_repeated] = element; +} + +void Sheet::init_cell_element_(std::uint32_t column, std::uint32_t row, + SheetCell *element) { + m_cells[{column, row}] = element; + element->m_parent = this; } void Sheet::init_dimensions_(TableDimensions dimensions) { @@ -219,9 +246,7 @@ odf::parse_element_tree(Document &document, pugi::xml_node node) { const auto columns_repeated = column_node.attribute("table:number-columns-repeated").as_uint(1); - auto [column, _] = parse_element_tree(document, column_node); - - sheet.init_column_(cursor.column(), columns_repeated, column); + sheet.init_column_(cursor.column(), columns_repeated, column_node); cursor.add_column(columns_repeated); } @@ -233,10 +258,9 @@ odf::parse_element_tree(Document &document, pugi::xml_node node) { const auto rows_repeated = row_node.attribute("table:number-rows-repeated").as_uint(1); - auto [row, _] = parse_element_tree(document, row_node); - - sheet.init_row_(cursor.row(), rows_repeated, row); + sheet.init_row_(cursor.row(), rows_repeated, row_node); + // TODO covered cells for (auto cell_node : row_node.children("table:table-cell")) { const auto columns_repeated = cell_node.attribute("table:number-columns-repeated").as_uint(1); @@ -245,10 +269,27 @@ odf::parse_element_tree(Document &document, pugi::xml_node node) { const auto rowspan = cell_node.attribute("table:number-rows-spanned").as_uint(1); - auto [cell, _] = parse_element_tree(document, cell_node); - sheet.init_cell_(cursor.column(), cursor.row(), columns_repeated, - rows_repeated, cell); + rows_repeated, cell_node); + + bool empty = false; + if (!cell_node.first_child()) { + empty = true; + } + + if (!empty) { + for (std::uint32_t row_repeat = 0; row_repeat < rows_repeated; + ++row_repeat) { + for (std::uint32_t column_repeat = 0; + column_repeat < columns_repeated; ++column_repeat) { + auto [cell, _] = parse_element_tree( + document, cell_node, cursor.column() + column_repeat, + cursor.row() + row_repeat); + sheet.init_cell_element_(cursor.column() + column_repeat, + cursor.row() + row_repeat, cell); + } + } + } cursor.add_cell(colspan, rowspan, columns_repeated); } diff --git a/src/odr/internal/odf/odf_spreadsheet.hpp b/src/odr/internal/odf/odf_spreadsheet.hpp index 92c1ec37..dd7e29df 100644 --- a/src/odr/internal/odf/odf_spreadsheet.hpp +++ b/src/odr/internal/odf/odf_spreadsheet.hpp @@ -18,8 +18,6 @@ class xml_node; namespace odr::internal::odf { class Document; -class SheetColumn; -class SheetRow; class SheetCell; class SpreadsheetRoot final : public Root { @@ -40,10 +38,6 @@ class Sheet final : public Element, public abstract::Sheet { content(const abstract::Document *, const std::optional range) const final; - abstract::SheetColumn *column(const abstract::Document *, - std::uint32_t column) const final; - abstract::SheetRow *row(const abstract::Document *, - std::uint32_t row) const final; abstract::SheetCell *cell(const abstract::Document *, std::uint32_t column, std::uint32_t row) const final; @@ -51,25 +45,43 @@ class Sheet final : public Element, public abstract::Sheet { first_shape(const abstract::Document *) const final; [[nodiscard]] TableStyle style(const abstract::Document *) const final; + [[nodiscard]] TableColumnStyle column_style(const abstract::Document *, + std::uint32_t column) const final; + [[nodiscard]] TableRowStyle row_style(const abstract::Document *, + std::uint32_t row) const final; + [[nodiscard]] TableCellStyle cell_style(const abstract::Document *, + std::uint32_t column, + std::uint32_t row) const final; void init_column_(std::uint32_t column, std::uint32_t repeated, - SheetColumn *element); - void init_row_(std::uint32_t row, std::uint32_t repeated, SheetRow *element); + pugi::xml_node element); + void init_row_(std::uint32_t row, std::uint32_t repeated, + pugi::xml_node element); void init_cell_(std::uint32_t column, std::uint32_t row, std::uint32_t columns_repeated, std::uint32_t rows_repeated, - SheetCell *element); + pugi::xml_node element); + void init_cell_element_(std::uint32_t column, std::uint32_t row, + SheetCell *element); void init_dimensions_(TableDimensions dimensions); + pugi::xml_node column_(std::uint32_t) const; + pugi::xml_node row_(std::uint32_t) const; + + common::ResolvedStyle cell_style_(const abstract::Document *, + std::uint32_t column, + std::uint32_t row) const; + private: struct Row { - abstract::SheetRow *element{nullptr}; - std::map cells; + pugi::xml_node row; + std::map cells; }; TableDimensions m_dimensions; - std::map m_columns; + std::map m_columns; std::map m_rows; + std::unordered_map m_cells; Element *m_first_shape{nullptr}; }; diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp index 6ceb474a..5c80b7b1 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp @@ -86,16 +86,6 @@ TableDimensions Sheet::content(const abstract::Document *document, return dimensions(document); // TODO } -abstract::SheetColumn *Sheet::column(const abstract::Document *, - std::uint32_t /*column*/) const { - return nullptr; // TODO -} - -abstract::SheetRow *Sheet::row(const abstract::Document *, - std::uint32_t /*row*/) const { - return nullptr; // TODO -} - abstract::SheetCell *Sheet::cell(const abstract::Document *, std::uint32_t /*column*/, std::uint32_t /*row*/) const { @@ -110,52 +100,35 @@ TableStyle Sheet::style(const abstract::Document *) const { return TableStyle(); // TODO } -pugi::xml_node Sheet::sheet_node_(const abstract::Document *document) const { - return sheet_(document, m_node.attribute("r:id").value()); -} - -pugi::xml_node Sheet::drawing_node_(const abstract::Document *document) const { - return drawing_(document, m_node.attribute("r:id").value()); +TableColumnStyle Sheet::column_style(const abstract::Document *, + std::uint32_t column) const { + return TableColumnStyle(); // TODO } -TableColumnStyle SheetColumn::style(const abstract::Document *, - abstract::Sheet *, - std::uint32_t /*column*/) const { - TableColumnStyle result; - if (auto width = m_node.attribute("width")) { - result.width = Measure(width.as_float(), DynamicUnit("ch")); - } - return result; +TableRowStyle Sheet::row_style(const abstract::Document *, + std::uint32_t row) const { + return TableRowStyle(); // TODO } -[[nodiscard]] std::uint32_t -SheetColumn::min_(const abstract::Document *) const { - return m_node.attribute("min").as_uint() - 1; +TableCellStyle Sheet::cell_style(const abstract::Document *, + std::uint32_t column, + std::uint32_t row) const { + return TableCellStyle(); // TODO } -[[nodiscard]] std::uint32_t -SheetColumn::max_(const abstract::Document *) const { - return m_node.attribute("max").as_uint() - 1; +pugi::xml_node Sheet::sheet_node_(const abstract::Document *document) const { + return sheet_(document, m_node.attribute("r:id").value()); } -TableRowStyle SheetRow::style(const abstract::Document *, abstract::Sheet *, - std::uint32_t /*row*/) const { - TableRowStyle result; - if (auto height = m_node.attribute("ht")) { - result.height = Measure(height.as_float(), DynamicUnit("pt")); - } - return result; +pugi::xml_node Sheet::drawing_node_(const abstract::Document *document) const { + return drawing_(document, m_node.attribute("r:id").value()); } -bool SheetCell::is_covered(const abstract::Document *, abstract::Sheet *, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const { +bool SheetCell::is_covered(const abstract::Document *) const { return false; // TODO } -ValueType SheetCell::value_type(const abstract::Document *, abstract::Sheet *, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const { +ValueType SheetCell::value_type(const abstract::Document *) const { return ValueType::string; } @@ -167,15 +140,11 @@ SheetCell::partial_style(const abstract::Document *document) const { return {}; } -TableDimensions SheetCell::span(const abstract::Document *, abstract::Sheet *, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const { +TableDimensions SheetCell::span(const abstract::Document *) const { return {1, 1}; } -TableCellStyle SheetCell::style(const abstract::Document *document, - abstract::Sheet *, std::uint32_t /*column*/, - std::uint32_t /*row*/) const { +TableCellStyle SheetCell::style(const abstract::Document *document) const { return partial_style(document).table_cell_style; } diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp index be747d31..d236e67d 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp @@ -66,10 +66,6 @@ class Sheet final : public Element, public abstract::Sheet { content(const abstract::Document *, std::optional) const final; - [[nodiscard]] abstract::SheetColumn *column(const abstract::Document *, - std::uint32_t column) const final; - [[nodiscard]] abstract::SheetRow *row(const abstract::Document *, - std::uint32_t row) const final; [[nodiscard]] abstract::SheetCell *cell(const abstract::Document *, std::uint32_t column, std::uint32_t row) const final; @@ -78,51 +74,28 @@ class Sheet final : public Element, public abstract::Sheet { first_shape(const abstract::Document *) const final; [[nodiscard]] TableStyle style(const abstract::Document *) const final; + [[nodiscard]] TableColumnStyle column_style(const abstract::Document *, + std::uint32_t column) const final; + [[nodiscard]] TableRowStyle row_style(const abstract::Document *, + std::uint32_t row) const final; + [[nodiscard]] TableCellStyle cell_style(const abstract::Document *, + std::uint32_t column, + std::uint32_t row) const final; private: pugi::xml_node sheet_node_(const abstract::Document *) const; pugi::xml_node drawing_node_(const abstract::Document *) const; }; -class SheetColumn final : public Element, public abstract::SheetColumn { -public: - using Element::Element; - - [[nodiscard]] TableColumnStyle style(const abstract::Document *, - abstract::Sheet *, - std::uint32_t column) const final; - -private: - [[nodiscard]] std::uint32_t min_(const abstract::Document *) const; - [[nodiscard]] std::uint32_t max_(const abstract::Document *) const; -}; - -class SheetRow final : public Element, public abstract::SheetRow { -public: - using Element::Element; - - [[nodiscard]] TableRowStyle style(const abstract::Document *, - abstract::Sheet *, - std::uint32_t row) const final; -}; - class SheetCell final : public Element, public abstract::SheetCell { public: using Element::Element; - [[nodiscard]] bool is_covered(const abstract::Document *, abstract::Sheet *, - std::uint32_t column, - std::uint32_t row) const final; - [[nodiscard]] TableDimensions span(const abstract::Document *, - abstract::Sheet *, std::uint32_t column, - std::uint32_t row) const final; - [[nodiscard]] ValueType value_type(const abstract::Document *, - abstract::Sheet *, std::uint32_t column, - std::uint32_t row) const final; - - [[nodiscard]] TableCellStyle style(const abstract::Document *, - abstract::Sheet *, std::uint32_t column, - std::uint32_t row) const final; + [[nodiscard]] bool is_covered(const abstract::Document *) const final; + [[nodiscard]] TableDimensions span(const abstract::Document *) const final; + [[nodiscard]] ValueType value_type(const abstract::Document *) const final; + + [[nodiscard]] TableCellStyle style(const abstract::Document *) const final; [[nodiscard]] common::ResolvedStyle partial_style(const abstract::Document *) const final; diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp index d7d3916f..91d5f817 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp @@ -88,8 +88,9 @@ parse_any_element_tree(Document &document, pugi::xml_node node) { static std::unordered_map parser_table{ {"workbook", parse_element_tree}, {"worksheet", parse_element_tree}, - {"col", parse_element_tree}, - {"row", parse_element_tree}, + // TODO + //{"col", parse_element_tree}, + //{"row", parse_element_tree}, {"r", parse_element_tree}, {"t", parse_element_tree}, {"v", parse_element_tree},