Skip to content

Commit 36c172e

Browse files
committed
make compile
1 parent ef93863 commit 36c172e

18 files changed

Lines changed: 814 additions & 263 deletions

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ set(ODR_SOURCE_FILES
141141

142142
"src/odr/internal/oldms/oldms_file.cpp"
143143

144-
# "src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp"
145-
# "src/odr/internal/ooxml/presentation/ooxml_presentation_parser.cpp"
146-
# "src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp"
147-
# "src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp"
148-
# "src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.cpp"
144+
"src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp"
145+
"src/odr/internal/ooxml/presentation/ooxml_presentation_element_registry.cpp"
146+
"src/odr/internal/ooxml/presentation/ooxml_presentation_parser.cpp"
147+
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp"
148+
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp"
149+
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element_registry.cpp"
150+
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.cpp"
149151
"src/odr/internal/ooxml/text/ooxml_text_document.cpp"
150152
"src/odr/internal/ooxml/text/ooxml_text_element_registry.cpp"
151153
"src/odr/internal/ooxml/text/ooxml_text_parser.cpp"

src/odr/internal/odf/odf_element_registry.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ void ElementRegistry::append_shape(const ExtendedElementIdentifier sheet_id,
163163
sheet_element(sheet_id).last_shape_id = shape_id.element_id();
164164
}
165165

166+
void ElementRegistry::append_sheet_cell(
167+
const ExtendedElementIdentifier sheet_id,
168+
const ExtendedElementIdentifier cell_id) {
169+
check_sheet_id(sheet_id);
170+
check_element_id(cell_id);
171+
172+
element(cell_id).parent_id = sheet_id;
173+
element(cell_id).first_child_id = null_element_id;
174+
element(cell_id).last_child_id = null_element_id;
175+
element(cell_id).previous_sibling_id = null_element_id;
176+
element(cell_id).next_sibling_id = null_element_id;
177+
}
178+
166179
void ElementRegistry::check_element_id(
167180
const ExtendedElementIdentifier id) const {
168181
if (id.is_null()) {

src/odr/internal/odf/odf_element_registry.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class ElementRegistry final {
9898
ExtendedElementIdentifier column_id);
9999
void append_shape(ExtendedElementIdentifier sheet_id,
100100
ExtendedElementIdentifier shape_id);
101+
void append_sheet_cell(ExtendedElementIdentifier sheet_id,
102+
ExtendedElementIdentifier cell_id);
101103

102104
private:
103105
std::vector<Element> m_elements;

src/odr/internal/odf/odf_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ parse_sheet(ElementRegistry &registry, const pugi::xml_node node) {
191191
ExtendedElementIdentifier::make_cell(
192192
element_id.element_id(), cursor.column() + column_repeat,
193193
cursor.row() + row_repeat);
194+
registry.append_sheet_cell(element_id, cell_id);
194195
parse_any_element_children(registry, cell_id, cell_node);
195196
}
196197
}

src/odr/internal/ooxml/ooxml_util.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ std::optional<std::string> read_border_node(pugi::xml_node);
4747
std::string read_text_property(pugi::xml_node);
4848

4949
using Relations = std::unordered_map<std::string, std::string>;
50+
using XmlDocumentsAndRelations =
51+
std::unordered_map<AbsPath, std::pair<pugi::xml_document, Relations>>;
52+
using SharedStrings = std::vector<pugi::xml_node>;
5053

5154
std::unordered_map<std::string, std::string>
5255
parse_relationships(const pugi::xml_document &relations);

src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Document::Document(std::shared_ptr<abstract::ReadableFilesystem> files)
2121
*m_files, AbsPath("/ppt").join(RelPath(relationships.second)));
2222
}
2323

24-
m_root_element = parse_tree(*this, m_document_xml.document_element());
24+
m_root_element =
25+
parse_tree(m_element_registry, m_document_xml.document_element());
2526
}
2627

2728
bool Document::is_editable() const noexcept { return false; }
@@ -38,11 +39,4 @@ void Document::save(const Path & /*path*/, const char * /*password*/) const {
3839
throw UnsupportedOperation();
3940
}
4041

41-
pugi::xml_node Document::get_slide_root(const std::string &ref) const {
42-
if (auto it = m_slides_xml.find(ref); it != std::end(m_slides_xml)) {
43-
return it->second.document_element();
44-
}
45-
return {};
46-
}
47-
4842
} // namespace odr::internal::ooxml::presentation

src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

33
#include <odr/internal/common/document.hpp>
4+
#include <odr/internal/ooxml/presentation/ooxml_presentation_element_registry.hpp>
45

56
#include <unordered_map>
6-
#include <vector>
77

88
#include <pugixml.hpp>
99

@@ -22,6 +22,8 @@ class Document final : public internal::Document {
2222
private:
2323
pugi::xml_document m_document_xml;
2424
std::unordered_map<std::string, pugi::xml_document> m_slides_xml;
25+
26+
ElementRegistry m_element_registry;
2527
};
2628

2729
} // namespace odr::internal::ooxml::presentation
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#include <odr/internal/ooxml/presentation/ooxml_presentation_element_registry.hpp>
2+
3+
namespace odr::internal::ooxml::presentation {
4+
5+
void ElementRegistry::clear() noexcept {
6+
m_elements.clear();
7+
m_tables.clear();
8+
m_texts.clear();
9+
}
10+
11+
[[nodiscard]] std::size_t ElementRegistry::size() const noexcept {
12+
return m_elements.size();
13+
}
14+
15+
ExtendedElementIdentifier ElementRegistry::create_element() {
16+
m_elements.emplace_back();
17+
return ExtendedElementIdentifier(m_elements.size());
18+
}
19+
20+
ElementRegistry::Table &
21+
ElementRegistry::create_table_element(const ExtendedElementIdentifier id) {
22+
check_element_id(id);
23+
auto [it, success] = m_tables.emplace(id.element_id(), Table{});
24+
return it->second;
25+
}
26+
27+
ElementRegistry::Text &
28+
ElementRegistry::create_text_element(const ExtendedElementIdentifier id) {
29+
check_element_id(id);
30+
auto [it, success] = m_texts.emplace(id.element_id(), Text{});
31+
return it->second;
32+
}
33+
34+
[[nodiscard]] ElementRegistry::Element &
35+
ElementRegistry::element(const ExtendedElementIdentifier id) {
36+
check_element_id(id);
37+
return m_elements.at(id.element_id() - 1);
38+
}
39+
40+
[[nodiscard]] const ElementRegistry::Element &
41+
ElementRegistry::element(const ExtendedElementIdentifier id) const {
42+
check_element_id(id);
43+
return m_elements.at(id.element_id() - 1);
44+
}
45+
46+
[[nodiscard]] ElementRegistry::Table &
47+
ElementRegistry::table_element(const ExtendedElementIdentifier id) {
48+
check_table_id(id);
49+
return m_tables.at(id.element_id());
50+
}
51+
52+
[[nodiscard]] const ElementRegistry::Table &
53+
ElementRegistry::table_element(const ExtendedElementIdentifier id) const {
54+
check_table_id(id);
55+
return m_tables.at(id.element_id());
56+
}
57+
58+
[[nodiscard]] ElementRegistry::Text &
59+
ElementRegistry::text_element(const ExtendedElementIdentifier id) {
60+
check_text_id(id);
61+
return m_texts.at(id.element_id());
62+
}
63+
64+
[[nodiscard]] const ElementRegistry::Text &
65+
ElementRegistry::text_element(const ExtendedElementIdentifier id) const {
66+
check_text_id(id);
67+
return m_texts.at(id.element_id());
68+
}
69+
70+
void ElementRegistry::check_element_id(
71+
const ExtendedElementIdentifier id) const {
72+
if (id.is_null()) {
73+
throw std::out_of_range(
74+
"DocumentElementRegistry::check_id: null identifier");
75+
}
76+
if (id.element_id() - 1 >= m_elements.size()) {
77+
throw std::out_of_range(
78+
"DocumentElementRegistry::check_id: identifier out of range");
79+
}
80+
}
81+
82+
void ElementRegistry::check_table_id(const ExtendedElementIdentifier id) const {
83+
check_element_id(id);
84+
if (!m_tables.contains(id.element_id())) {
85+
throw std::out_of_range(
86+
"DocumentElementRegistry::check_id: identifier not found");
87+
}
88+
}
89+
90+
void ElementRegistry::check_text_id(const ExtendedElementIdentifier id) const {
91+
check_element_id(id);
92+
if (!m_texts.contains(id.element_id())) {
93+
throw std::out_of_range(
94+
"DocumentElementRegistry::check_id: identifier not found");
95+
}
96+
}
97+
98+
void ElementRegistry::append_child(const ExtendedElementIdentifier parent_id,
99+
const ExtendedElementIdentifier child_id) {
100+
check_element_id(parent_id);
101+
check_element_id(child_id);
102+
103+
const ExtendedElementIdentifier previous_sibling_id(
104+
element(parent_id).last_child_id);
105+
106+
element(child_id).parent_id = parent_id;
107+
element(child_id).first_child_id = null_element_id;
108+
element(child_id).last_child_id = null_element_id;
109+
element(child_id).previous_sibling_id = previous_sibling_id.element_id();
110+
element(child_id).next_sibling_id = null_element_id;
111+
112+
if (element(parent_id).first_child_id == null_element_id) {
113+
element(parent_id).first_child_id = child_id.element_id();
114+
} else {
115+
element(previous_sibling_id).next_sibling_id = child_id.element_id();
116+
}
117+
element(parent_id).last_child_id = child_id.element_id();
118+
}
119+
120+
void ElementRegistry::append_column(const ExtendedElementIdentifier table_id,
121+
const ExtendedElementIdentifier column_id) {
122+
check_table_id(table_id);
123+
check_element_id(column_id);
124+
125+
const ExtendedElementIdentifier previous_sibling_id(
126+
table_element(table_id).last_column_id);
127+
128+
element(column_id).parent_id = table_id;
129+
element(column_id).first_child_id = null_element_id;
130+
element(column_id).last_child_id = null_element_id;
131+
element(column_id).previous_sibling_id = previous_sibling_id.element_id();
132+
element(column_id).next_sibling_id = null_element_id;
133+
134+
if (table_element(table_id).first_column_id == null_element_id) {
135+
table_element(table_id).first_column_id = column_id.element_id();
136+
} else {
137+
element(previous_sibling_id).next_sibling_id = column_id.element_id();
138+
}
139+
table_element(table_id).last_column_id = column_id.element_id();
140+
}
141+
142+
} // namespace odr::internal::ooxml::presentation
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#include <odr/document_element.hpp>
4+
#include <odr/document_element_identifier.hpp>
5+
6+
#include <map>
7+
#include <unordered_map>
8+
#include <vector>
9+
10+
#include <pugixml.hpp>
11+
12+
namespace odr::internal::ooxml::presentation {
13+
14+
class ElementRegistry final {
15+
public:
16+
struct Element final {
17+
ExtendedElementIdentifier parent_id;
18+
ElementIdentifier first_child_id{null_element_id};
19+
ElementIdentifier last_child_id{null_element_id};
20+
ElementIdentifier previous_sibling_id{null_element_id};
21+
ElementIdentifier next_sibling_id{null_element_id};
22+
ElementType type{ElementType::none};
23+
pugi::xml_node node;
24+
bool is_editable{false};
25+
};
26+
27+
struct Table final {
28+
ElementIdentifier first_column_id{null_element_id};
29+
ElementIdentifier last_column_id{null_element_id};
30+
};
31+
32+
struct Text final {
33+
pugi::xml_node last;
34+
};
35+
36+
void clear() noexcept;
37+
38+
[[nodiscard]] std::size_t size() const noexcept;
39+
40+
ExtendedElementIdentifier create_element();
41+
Table &create_table_element(ExtendedElementIdentifier id);
42+
Text &create_text_element(ExtendedElementIdentifier id);
43+
44+
[[nodiscard]] Element &element(ExtendedElementIdentifier id);
45+
[[nodiscard]] const Element &element(ExtendedElementIdentifier id) const;
46+
47+
[[nodiscard]] Table &table_element(ExtendedElementIdentifier id);
48+
[[nodiscard]] const Table &table_element(ExtendedElementIdentifier id) const;
49+
50+
[[nodiscard]] Text &text_element(ExtendedElementIdentifier id);
51+
[[nodiscard]] const Text &text_element(ExtendedElementIdentifier id) const;
52+
53+
void append_child(ExtendedElementIdentifier parent_id,
54+
ExtendedElementIdentifier child_id);
55+
void append_column(ExtendedElementIdentifier table_id,
56+
ExtendedElementIdentifier column_id);
57+
58+
private:
59+
std::vector<Element> m_elements;
60+
std::unordered_map<ElementIdentifier, Table> m_tables;
61+
std::unordered_map<ElementIdentifier, Text> m_texts;
62+
63+
void check_element_id(ExtendedElementIdentifier id) const;
64+
void check_table_id(ExtendedElementIdentifier id) const;
65+
void check_text_id(ExtendedElementIdentifier id) const;
66+
};
67+
68+
} // namespace odr::internal::ooxml::presentation

0 commit comments

Comments
 (0)