Skip to content

Commit 202b90b

Browse files
committed
fix ods empty spanned cells
1 parent 5d92ca0 commit 202b90b

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

src/odr/document_path.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <odr/document_element.hpp>
44

55
#include <algorithm>
6+
#include <iostream>
67
#include <stdexcept>
78

89
namespace odr {
@@ -131,12 +132,12 @@ DocumentPath DocumentPath::extract(const Element element) {
131132
DocumentPath DocumentPath::extract(const Element element, const Element root) {
132133
std::vector<Component> reverse;
133134

134-
for (auto current = element; current != root;) {
135+
for (Element current = element; current != root;) {
135136
if (!current.parent()) {
136137
break;
137138
}
138139

139-
if (const SheetCell sheet_cell = element.as_sheet_cell(); sheet_cell) {
140+
if (const SheetCell sheet_cell = current.as_sheet_cell(); sheet_cell) {
140141
const auto [parent, cell] = Cell::extract(sheet_cell);
141142
reverse.emplace_back(cell);
142143
current = static_cast<Element>(parent);

src/odr/internal/odf/odf_document.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,16 @@ class ElementAdapter final : public abstract::ElementAdapter,
573573
}
574574
[[nodiscard]] ElementIdentifier
575575
sheet_first_shape(const ElementIdentifier element_id) const override {
576-
(void)element_id;
577-
return {}; // TODO
576+
if (const ElementRegistry::Sheet *sheet_registry =
577+
m_registry->sheet_element(element_id);
578+
sheet_registry != nullptr) {
579+
return sheet_registry->first_shape_id;
580+
}
581+
return null_element_id;
578582
}
579583
[[nodiscard]] TableStyle
580584
sheet_style(const ElementIdentifier element_id) const override {
581-
(void)element_id;
582-
return {}; // TODO
585+
return get_partial_style(element_id).table_style;
583586
}
584587
[[nodiscard]] TableColumnStyle
585588
sheet_column_style(const ElementIdentifier element_id,
@@ -633,8 +636,12 @@ class ElementAdapter final : public abstract::ElementAdapter,
633636

634637
[[nodiscard]] TablePosition
635638
sheet_cell_position(const ElementIdentifier element_id) const override {
636-
(void)element_id;
637-
return {0, 0};
639+
if (const ElementRegistry::SheetCell *sheet_cell =
640+
m_registry->sheet_cell_element(element_id);
641+
sheet_cell != nullptr) {
642+
return sheet_cell->position;
643+
}
644+
return {};
638645
}
639646
[[nodiscard]] bool
640647
sheet_cell_is_covered(const ElementIdentifier element_id) const override {
@@ -924,7 +931,7 @@ class ElementAdapter final : public abstract::ElementAdapter,
924931
[[nodiscard]] std::optional<std::string>
925932
frame_z_index(const ElementIdentifier element_id) const override {
926933
const pugi::xml_node node = get_node(element_id);
927-
if (const pugi::xml_attribute attribute = node.attribute("svg:z-index")) {
934+
if (const pugi::xml_attribute attribute = node.attribute("draw:z-index")) {
928935
return attribute.value();
929936
}
930937
return std::nullopt;

src/odr/internal/odf/odf_parser.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,17 @@ parse_sheet(ElementRegistry &registry, const pugi::xml_node node) {
164164
bool row_empty = true;
165165
for (const pugi::xml_node cell_node :
166166
row_node.children("table:table-cell")) {
167-
bool cell_empty = false;
168-
if (!cell_node.first_child()) {
169-
cell_empty = true;
167+
const std::uint32_t colspan =
168+
cell_node.attribute("table:number-columns-spanned").as_uint(1);
169+
const std::uint32_t rowspan =
170+
cell_node.attribute("table:number-rows-spanned").as_uint(1);
171+
172+
bool cell_empty = true;
173+
if (cell_node.first_child()) {
174+
cell_empty = false;
175+
}
176+
if (colspan > 1 || rowspan > 1) {
177+
cell_empty = false;
170178
}
171179

172180
if (!cell_empty) {
@@ -213,9 +221,12 @@ parse_sheet(ElementRegistry &registry, const pugi::xml_node node) {
213221
cell_node.attribute("table:number-rows-spanned").as_uint(1);
214222
const bool is_repeated = columns_repeated > 1 || rows_repeated > 1;
215223

216-
bool cell_empty = false;
217-
if (!cell_node.first_child()) {
218-
cell_empty = true;
224+
bool cell_empty = true;
225+
if (cell_node.first_child()) {
226+
cell_empty = false;
227+
}
228+
if (colspan > 1 || rowspan > 1) {
229+
cell_empty = false;
219230
}
220231

221232
if (cell_empty) {

test/scripts/compare_output_server.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ docker run -ti \
1717
-v $(pwd):/repo \
1818
-p 8000:8000 \
1919
--platform linux/amd64 \
20-
ghcr.io/opendocument-app/odr_core_test:1.0.15 \
21-
compare-html-server /repo/$REF /repo/$OBS --compare --driver $DRIVER --port 8000
20+
ghcr.io/opendocument-app/odr_core_test:1.0.18 \
21+
compare-html-server /repo/$REF /repo/$OBS --compare --driver $DRIVER --port 8000 -vv

0 commit comments

Comments
 (0)