Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Dec 3, 2023
1 parent e48bdf5 commit cfa29fb
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/odr/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Document::Document(std::shared_ptr<internal::abstract::Document> document)
}
}

bool Document::editable() const noexcept { return m_document->editable(); }
bool Document::editable() const noexcept { return m_document->is_editable(); }

bool Document::savable(const bool encrypted) const noexcept {
return m_document->savable(encrypted);
return m_document->is_savable(encrypted);
}

void Document::save(const std::string &path) const { m_document->save(path); }
Expand Down
6 changes: 3 additions & 3 deletions src/odr/internal/abstract/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class Document {
virtual ~Document() = default;

/// \return `true` if the document is editable in any way.
[[nodiscard]] virtual bool editable() const noexcept = 0;
[[nodiscard]] virtual bool is_editable() const noexcept = 0;

/// \param encrypted to ask for encrypted saves.
/// \return `true` if the document is savable.
[[nodiscard]] virtual bool savable(bool encrypted) const noexcept = 0;
/// \return `true` if the document is is_savable.
[[nodiscard]] virtual bool is_savable(bool encrypted) const noexcept = 0;

/// \param path the destination path.
virtual void save(const common::Path &path) const = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/odr/internal/abstract/document_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Element {
[[nodiscard]] virtual Element *last_child(const Document *) const = 0;
[[nodiscard]] virtual Element *previous_sibling(const Document *) const = 0;
[[nodiscard]] virtual Element *next_sibling(const Document *) const = 0;

[[nodiscard]] virtual bool
is_editable(const abstract::Document *document) const = 0;
};

class TextRoot : public virtual Element {
Expand Down
4 changes: 2 additions & 2 deletions src/odr/internal/odf/odf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Document::Document(const FileType file_type, const DocumentType document_type,
m_styles_xml.document_element());
}

bool Document::editable() const noexcept { return true; }
bool Document::is_editable() const noexcept { return true; }

bool Document::savable(const bool encrypted) const noexcept {
bool Document::is_savable(const bool encrypted) const noexcept {
return !encrypted;
}

Expand Down
4 changes: 2 additions & 2 deletions src/odr/internal/odf/odf_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Document : public common::TemplateDocument<Element> {
Document(FileType file_type, DocumentType document_type,
std::shared_ptr<abstract::ReadableFilesystem> files);

bool editable() const noexcept final;
bool savable(bool encrypted) const noexcept final;
bool is_editable() const noexcept final;
bool is_savable(bool encrypted) const noexcept final;

void save(const common::Path &path) const final;
void save(const common::Path &path, const char *password) const final;
Expand Down
85 changes: 23 additions & 62 deletions src/odr/internal/odf/odf_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ Element::intermediate_style(const abstract::Document *document) const {
return base;
}

bool Element::is_editable(const abstract::Document *document) const {
if (m_parent == nullptr) {
return document_(document)->is_editable();
}
return m_parent->is_editable(document);
}

const char *Element::style_name_(const abstract::Document *) const {
return default_style_name(m_node);
}
Expand All @@ -70,14 +77,10 @@ const StyleRegistry *Element::style_(const abstract::Document *document) {
return &static_cast<const Document *>(document)->m_style_registry;
}

Root::Root(pugi::xml_node node) : Element(node) {}

ElementType Root::type(const abstract::Document *) const {
return ElementType::root;
}

TextRoot::TextRoot(pugi::xml_node node) : Root(node) {}

ElementType TextRoot::type(const abstract::Document *) const {
return ElementType::root;
}
Expand All @@ -98,21 +101,13 @@ TextRoot::first_master_page(const abstract::Document *document) const {
return {};
}

PresentationRoot::PresentationRoot(pugi::xml_node node) : Root(node) {}

DrawingRoot::DrawingRoot(pugi::xml_node node) : Root(node) {}

MasterPage::MasterPage(pugi::xml_node node) : Element(node) {}

PageLayout MasterPage::page_layout(const abstract::Document *document) const {
if (auto attribute = m_node.attribute("style:page-layout-name")) {
return style_(document)->page_layout(attribute.value());
}
return {};
}

Slide::Slide(pugi::xml_node node) : Element(node) {}

PageLayout Slide::page_layout(const abstract::Document *document) const {
if (auto master_page =
dynamic_cast<MasterPage *>(this->master_page(document))) {
Expand All @@ -133,8 +128,6 @@ std::string Slide::name(const abstract::Document *) const {
return m_node.attribute("draw:name").value();
}

Page::Page(pugi::xml_node node) : Element(node) {}

PageLayout Page::page_layout(const abstract::Document *document) const {
if (auto master_page =
dynamic_cast<MasterPage *>(this->master_page(document))) {
Expand All @@ -154,14 +147,10 @@ std::string Page::name(const abstract::Document *) const {
return m_node.attribute("draw:name").value();
}

LineBreak::LineBreak(pugi::xml_node node) : Element(node) {}

TextStyle LineBreak::style(const abstract::Document *document) const {
return intermediate_style(document).text_style;
}

Paragraph::Paragraph(pugi::xml_node node) : Element(node) {}

ParagraphStyle Paragraph::style(const abstract::Document *document) const {
return intermediate_style(document).paragraph_style;
}
Expand All @@ -170,28 +159,10 @@ TextStyle Paragraph::text_style(const abstract::Document *document) const {
return intermediate_style(document).text_style;
}

Span::Span(pugi::xml_node node) : Element(node) {}

TextStyle Span::style(const abstract::Document *document) const {
return intermediate_style(document).text_style;
}

std::string Text::text(const pugi::xml_node node) {
if (node.type() == pugi::node_pcdata) {
return node.value();
}

std::string name = node.name();
if (name == "text:s") {
const auto count = node.attribute("text:c").as_uint(1);
return std::string(count, ' ');
}
if (name == "text:tab") {
return "\t";
}
return "";
}

Text::Text(pugi::xml_node node) : Text(node, node) {}

Text::Text(pugi::xml_node first, pugi::xml_node last)
Expand All @@ -206,7 +177,7 @@ std::string Text::content(const abstract::Document *) const {
std::string result;
for (auto node = m_node; node != m_last.next_sibling();
node = node.next_sibling()) {
result += text(node);
result += text_(node);
}
return result;
}
Expand Down Expand Up @@ -243,26 +214,34 @@ TextStyle Text::style(const abstract::Document *document) const {
return intermediate_style(document).text_style;
}

Link::Link(pugi::xml_node node) : Element(node) {}
std::string Text::text_(const pugi::xml_node node) {
if (node.type() == pugi::node_pcdata) {
return node.value();
}

std::string name = node.name();
if (name == "text:s") {
const auto count = node.attribute("text:c").as_uint(1);
return std::string(count, ' ');
}
if (name == "text:tab") {
return "\t";
}
return "";
}

std::string Link::href(const abstract::Document *) const {
return m_node.attribute("xlink:href").value();
}

Bookmark::Bookmark(pugi::xml_node node) : Element(node) {}

std::string Bookmark::name(const abstract::Document *) const {
return m_node.attribute("text:name").value();
}

ListItem::ListItem(pugi::xml_node node) : Element(node) {}

TextStyle ListItem::style(const abstract::Document *document) const {
return intermediate_style(document).text_style;
}

Table::Table(pugi::xml_node node) : Element(node) {}

TableStyle Table::style(const abstract::Document *document) const {
return partial_style(document).table_style;
}
Expand Down Expand Up @@ -291,20 +270,14 @@ TableDimensions Table::dimensions(const abstract::Document *) const {
return result;
}

TableColumn::TableColumn(pugi::xml_node node) : Element(node) {}

TableColumnStyle TableColumn::style(const abstract::Document *document) const {
return partial_style(document).table_column_style;
}

TableRow::TableRow(pugi::xml_node node) : Element(node) {}

TableRowStyle TableRow::style(const abstract::Document *document) const {
return partial_style(document).table_row_style;
}

TableCell::TableCell(pugi::xml_node node) : Element(node) {}

bool TableCell::covered(const abstract::Document *) const {
return std::strcmp(m_node.name(), "table:covered-table-cell") == 0;
}
Expand All @@ -326,8 +299,6 @@ TableCellStyle TableCell::style(const abstract::Document *document) const {
return partial_style(document).table_cell_style;
}

Frame::Frame(pugi::xml_node node) : Element(node) {}

AnchorType Frame::anchor_type(const abstract::Document *) const {
auto anchor_type = m_node.attribute("text:anchor-type").value();
if (std::strcmp("as-char", anchor_type) == 0) {
Expand Down Expand Up @@ -384,8 +355,6 @@ GraphicStyle Frame::style(const abstract::Document *document) const {
return intermediate_style(document).graphic_style;
}

Rect::Rect(pugi::xml_node node) : Element(node) {}

std::string Rect::x(const abstract::Document *) const {
return m_node.attribute("svg:x").value();
}
Expand All @@ -406,8 +375,6 @@ GraphicStyle Rect::style(const abstract::Document *document) const {
return intermediate_style(document).graphic_style;
}

Line::Line(pugi::xml_node node) : Element(node) {}

std::string Line::x1(const abstract::Document *) const {
return m_node.attribute("svg:x1").value();
}
Expand All @@ -428,8 +395,6 @@ GraphicStyle Line::style(const abstract::Document *document) const {
return intermediate_style(document).graphic_style;
}

Circle::Circle(pugi::xml_node node) : Element(node) {}

std::string Circle::x(const abstract::Document *) const {
return m_node.attribute("svg:x").value();
}
Expand All @@ -450,8 +415,6 @@ GraphicStyle Circle::style(const abstract::Document *document) const {
return intermediate_style(document).graphic_style;
}

CustomShape::CustomShape(pugi::xml_node node) : Element(node) {}

std::optional<std::string> CustomShape::x(const abstract::Document *) const {
return m_node.attribute("svg:x").value();
}
Expand All @@ -472,8 +435,6 @@ GraphicStyle CustomShape::style(const abstract::Document *document) const {
return intermediate_style(document).graphic_style;
}

Image::Image(pugi::xml_node node) : Element(node) {}

bool Image::internal(const abstract::Document *document) const {
auto doc = document_(document);
if (!doc || !doc->files()) {
Expand Down
Loading

0 comments on commit cfa29fb

Please sign in to comment.