Skip to content

Commit ef93863

Browse files
committed
ooxml text
1 parent 43f2880 commit ef93863

24 files changed

Lines changed: 435 additions & 827 deletions

CMakeLists.txt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,19 @@ 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_element.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_element.cpp"
149-
#"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp"
150-
#"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.cpp"
151-
#"src/odr/internal/ooxml/text/ooxml_text_document.cpp"
152-
#"src/odr/internal/ooxml/text/ooxml_text_element.cpp"
153-
#"src/odr/internal/ooxml/text/ooxml_text_parser.cpp"
154-
#"src/odr/internal/ooxml/text/ooxml_text_style.cpp"
155-
#"src/odr/internal/ooxml/ooxml_crypto.cpp"
156-
#"src/odr/internal/ooxml/ooxml_file.cpp"
157-
#"src/odr/internal/ooxml/ooxml_meta.cpp"
158-
#"src/odr/internal/ooxml/ooxml_util.cpp"
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"
149+
"src/odr/internal/ooxml/text/ooxml_text_document.cpp"
150+
"src/odr/internal/ooxml/text/ooxml_text_element_registry.cpp"
151+
"src/odr/internal/ooxml/text/ooxml_text_parser.cpp"
152+
"src/odr/internal/ooxml/text/ooxml_text_style.cpp"
153+
"src/odr/internal/ooxml/ooxml_crypto.cpp"
154+
"src/odr/internal/ooxml/ooxml_file.cpp"
155+
"src/odr/internal/ooxml/ooxml_meta.cpp"
156+
"src/odr/internal/ooxml/ooxml_util.cpp"
159157

160158
"src/odr/internal/pdf/pdf_cmap.cpp"
161159
"src/odr/internal/pdf/pdf_cmap_parser.cpp"

src/odr/internal/odf/odf_document.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <odr/file.hpp>
4-
53
#include <odr/internal/common/document.hpp>
64
#include <odr/internal/odf/odf_element_registry.hpp>
75
#include <odr/internal/odf/odf_style.hpp>
@@ -10,10 +8,6 @@
108

119
#include <memory>
1210

13-
namespace odr::internal::abstract {
14-
class ReadableFilesystem;
15-
} // namespace odr::internal::abstract
16-
1711
namespace odr::internal::odf {
1812

1913
class Document final : public internal::Document {

src/odr/internal/odf/odf_element_registry.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
namespace odr::internal::odf {
66

7-
void ElementRegistry::clear() noexcept { m_elements.clear(); }
7+
void ElementRegistry::clear() noexcept {
8+
m_elements.clear();
9+
m_tables.clear();
10+
m_texts.clear();
11+
m_sheets.clear();
12+
}
813

914
[[nodiscard]] std::size_t ElementRegistry::size() const noexcept {
1015
return m_elements.size();
@@ -16,21 +21,21 @@ ExtendedElementIdentifier ElementRegistry::create_element() {
1621
}
1722

1823
ElementRegistry::Table &
19-
ElementRegistry::create_table_element(ExtendedElementIdentifier id) {
24+
ElementRegistry::create_table_element(const ExtendedElementIdentifier id) {
2025
check_element_id(id);
2126
auto [it, success] = m_tables.emplace(id.element_id(), Table{});
2227
return it->second;
2328
}
2429

2530
ElementRegistry::Text &
26-
ElementRegistry::create_text_element(ExtendedElementIdentifier id) {
31+
ElementRegistry::create_text_element(const ExtendedElementIdentifier id) {
2732
check_element_id(id);
2833
auto [it, success] = m_texts.emplace(id.element_id(), Text{});
2934
return it->second;
3035
}
3136

3237
ElementRegistry::Sheet &
33-
ElementRegistry::create_sheet_element(ExtendedElementIdentifier id) {
38+
ElementRegistry::create_sheet_element(const ExtendedElementIdentifier id) {
3439
check_element_id(id);
3540
auto [it, success] = m_sheets.emplace(id.element_id(), Sheet{});
3641
return it->second;

src/odr/internal/odf/odf_parser.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

3-
#include <odr/document_element_identifier.hpp>
4-
53
namespace pugi {
64
class xml_node;
75
} // namespace pugi
86

7+
namespace odr {
8+
class ExtendedElementIdentifier;
9+
}
10+
911
namespace odr::internal::odf {
1012
class ElementRegistry;
1113

src/odr/internal/ooxml/ooxml_file.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
namespace odr::internal::ooxml {
1717

1818
OfficeOpenXmlFile::OfficeOpenXmlFile(
19-
std::shared_ptr<abstract::ReadableFilesystem> filesystem)
20-
: m_filesystem(std::move(filesystem)) {
21-
m_file_meta = parse_file_meta(*m_filesystem);
19+
std::shared_ptr<abstract::ReadableFilesystem> files)
20+
: m_files(std::move(files)) {
21+
m_file_meta = parse_file_meta(*m_files);
2222

2323
if (m_file_meta.password_encrypted) {
2424
m_encryption_state = EncryptionState::encrypted;
@@ -61,8 +61,8 @@ OfficeOpenXmlFile::decrypt(const std::string &password) const {
6161
throw NotEncryptedError();
6262
}
6363

64-
const std::string encryption_info = util::stream::read(
65-
*m_filesystem->open(AbsPath("/EncryptionInfo"))->stream());
64+
const std::string encryption_info =
65+
util::stream::read(*m_files->open(AbsPath("/EncryptionInfo"))->stream());
6666
// TODO cache Crypto::Util
6767
const crypto::Util util(encryption_info);
6868
const std::string key = util.derive_key(password);
@@ -71,15 +71,14 @@ OfficeOpenXmlFile::decrypt(const std::string &password) const {
7171
}
7272

7373
const std::string encrypted_package = util::stream::read(
74-
*m_filesystem->open(AbsPath("/EncryptedPackage"))->stream());
74+
*m_files->open(AbsPath("/EncryptedPackage"))->stream());
7575
std::string decrypted_package = util.decrypt(encrypted_package, key);
7676

7777
const auto memory_file =
7878
std::make_shared<MemoryFile>(std::move(decrypted_package));
7979
auto decrypted = std::make_shared<OfficeOpenXmlFile>(*this);
80-
decrypted->m_filesystem =
81-
zip::ZipFile(memory_file).archive()->as_filesystem();
82-
decrypted->m_file_meta = parse_file_meta(*decrypted->m_filesystem);
80+
decrypted->m_files = zip::ZipFile(memory_file).archive()->as_filesystem();
81+
decrypted->m_file_meta = parse_file_meta(*decrypted->m_files);
8382
decrypted->m_encryption_state = EncryptionState::decrypted;
8483
return decrypted;
8584
}
@@ -88,11 +87,11 @@ std::shared_ptr<abstract::Document> OfficeOpenXmlFile::document() const {
8887
// TODO throw if encrypted
8988
switch (file_type()) {
9089
case FileType::office_open_xml_document:
91-
return std::make_shared<text::Document>(m_filesystem);
90+
return std::make_shared<text::Document>(m_files);
9291
case FileType::office_open_xml_presentation:
93-
return std::make_shared<presentation::Document>(m_filesystem);
92+
return std::make_shared<presentation::Document>(m_files);
9493
case FileType::office_open_xml_workbook:
95-
return std::make_shared<spreadsheet::Document>(m_filesystem);
94+
return std::make_shared<spreadsheet::Document>(m_files);
9695
default:
9796
throw UnsupportedOperation();
9897
}

src/odr/internal/ooxml/ooxml_file.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace odr::internal::ooxml {
2020
class OfficeOpenXmlFile final : public abstract::DocumentFile {
2121
public:
2222
explicit OfficeOpenXmlFile(
23-
std::shared_ptr<abstract::ReadableFilesystem> storage);
23+
std::shared_ptr<abstract::ReadableFilesystem> files);
2424

2525
[[nodiscard]] std::shared_ptr<abstract::File> file() const noexcept override;
2626

@@ -39,7 +39,7 @@ class OfficeOpenXmlFile final : public abstract::DocumentFile {
3939
[[nodiscard]] std::shared_ptr<abstract::Document> document() const override;
4040

4141
private:
42-
std::shared_ptr<abstract::ReadableFilesystem> m_filesystem;
42+
std::shared_ptr<abstract::ReadableFilesystem> m_files;
4343
FileMeta m_file_meta;
4444
EncryptionState m_encryption_state{EncryptionState::not_encrypted};
4545
};

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010

1111
namespace odr::internal::ooxml::presentation {
1212

13-
Document::Document(std::shared_ptr<abstract::ReadableFilesystem> filesystem)
14-
: TemplateDocument<Element>(FileType::office_open_xml_presentation,
15-
DocumentType::presentation,
16-
std::move(filesystem)) {
17-
m_document_xml =
18-
util::xml::parse(*m_filesystem, AbsPath("/ppt/presentation.xml"));
13+
Document::Document(std::shared_ptr<abstract::ReadableFilesystem> files)
14+
: internal::Document(FileType::office_open_xml_presentation,
15+
DocumentType::presentation, std::move(files)) {
16+
m_document_xml = util::xml::parse(*m_files, AbsPath("/ppt/presentation.xml"));
1917

2018
for (const auto &relationships :
21-
parse_relationships(*m_filesystem, AbsPath("/ppt/presentation.xml"))) {
19+
parse_relationships(*m_files, AbsPath("/ppt/presentation.xml"))) {
2220
m_slides_xml[relationships.first] = util::xml::parse(
23-
*m_filesystem, AbsPath("/ppt").join(RelPath(relationships.second)));
21+
*m_files, AbsPath("/ppt").join(RelPath(relationships.second)));
2422
}
2523

2624
m_root_element = parse_tree(*this, m_document_xml.document_element());
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <odr/internal/common/document.hpp>
4-
#include <odr/internal/ooxml/presentation/ooxml_presentation_element.hpp>
54

65
#include <unordered_map>
76
#include <vector>
@@ -10,23 +9,19 @@
109

1110
namespace odr::internal::ooxml::presentation {
1211

13-
class Document final : public TemplateDocument<Element> {
12+
class Document final : public internal::Document {
1413
public:
15-
explicit Document(std::shared_ptr<abstract::ReadableFilesystem> filesystem);
14+
explicit Document(std::shared_ptr<abstract::ReadableFilesystem> files);
1615

17-
[[nodiscard]] bool is_editable() const noexcept final;
18-
[[nodiscard]] bool is_savable(bool encrypted) const noexcept final;
16+
[[nodiscard]] bool is_editable() const noexcept override;
17+
[[nodiscard]] bool is_savable(bool encrypted) const noexcept override;
1918

20-
void save(const Path &path) const final;
21-
void save(const Path &path, const char *password) const final;
22-
23-
pugi::xml_node get_slide_root(const std::string &ref) const;
19+
void save(const Path &path) const override;
20+
void save(const Path &path, const char *password) const override;
2421

2522
private:
2623
pugi::xml_document m_document_xml;
2724
std::unordered_map<std::string, pugi::xml_document> m_slides_xml;
28-
29-
friend class Element;
3025
};
3126

3227
} // namespace odr::internal::ooxml::presentation

0 commit comments

Comments
 (0)