Skip to content

Commit 42e6ea6

Browse files
authored
fix text document path for tables (#451)
1 parent 6cc4718 commit 42e6ea6

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

cli/src/server.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ int main(const int argc, char **argv) {
2121
DecodePreference decode_preference;
2222
decode_preference.engine_priority = {
2323
DecoderEngine::poppler, DecoderEngine::wvware, DecoderEngine::odr};
24-
decode_preference.as_file_type = FileType::zip;
2524

2625
DecodedFile decoded_file{input, decode_preference, *logger};
2726

src/odr/document_path.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ Element DocumentPath::find(const Element root, const DocumentPath &path) {
116116
element = element.first_child();
117117
number = child->number;
118118
} else if (const auto column = std::get_if<Column>(&c)) {
119-
if (!element.as_table().first_column()) {
119+
if (!element.as_table_row()) {
120120
throw std::invalid_argument("column not found");
121121
}
122-
element = Element(element.as_table().first_column());
122+
element = element.as_table_row().first_child();
123123
number = column->number;
124124
} else if (const auto row = std::get_if<Row>(&c)) {
125125
if (!element.as_table().first_row()) {

test/src/document_test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ TEST(Document, odt_element_path) {
5757
EXPECT_EQ(t1_via_path, t1);
5858
}
5959

60+
TEST(Document, odt_element_path2) {
61+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
62+
63+
const DocumentFile document_file(
64+
TestData::test_file_path("odr-public/odt/style-various-1.odt"), *logger);
65+
66+
EXPECT_EQ(document_file.file_type(), FileType::opendocument_text);
67+
68+
const Document document = document_file.document();
69+
70+
EXPECT_EQ(document.document_type(), DocumentType::text);
71+
72+
const auto root = document.root_element();
73+
74+
const Element cell_via_path = DocumentPath::find(
75+
root, DocumentPath("/child:41/row:0/column:1/child:0/child:0"));
76+
EXPECT_EQ(cell_via_path.type(), ElementType::text);
77+
EXPECT_EQ(cell_via_path.as_text().content(), "B1");
78+
}
79+
6080
TEST(Document, odg) {
6181
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
6282

0 commit comments

Comments
 (0)