diff --git a/src/odr/document_element.cpp b/src/odr/document_element.cpp index c4c333ea..cf7ae623 100644 --- a/src/odr/document_element.cpp +++ b/src/odr/document_element.cpp @@ -24,27 +24,32 @@ bool Element::operator!=(const Element &rhs) const { Element::operator bool() const { return m_element; } ElementType Element::type() const { - return m_element ? m_element->type(m_document) : ElementType::none; + return m_element ? m_element->type(m_document, m_elementId) + : ElementType::none; } Element Element::parent() const { - return m_element ? Element(m_document, m_element->parent(m_document)) - : Element(); + return m_element + ? Element(m_document, m_element->parent(m_document, m_elementId)) + : Element(); } Element Element::first_child() const { - return m_element ? Element(m_document, m_element->first_child(m_document)) + return m_element ? Element(m_document, + m_element->first_child(m_document, m_elementId)) : Element(); } Element Element::previous_sibling() const { return m_element - ? Element(m_document, m_element->previous_sibling(m_document)) + ? Element(m_document, + m_element->previous_sibling(m_document, m_elementId)) : Element(); } Element Element::next_sibling() const { - return m_element ? Element(m_document, m_element->next_sibling(m_document)) + return m_element ? Element(m_document, + m_element->next_sibling(m_document, m_elementId)) : Element(); } @@ -94,7 +99,8 @@ Image Element::image() const { return {m_document, m_element}; } ElementIterator Element::begin() const { return m_element - ? ElementIterator(m_document, m_element->first_child(m_document)) + ? ElementIterator(m_document, + m_element->first_child(m_document, m_elementId)) : ElementIterator(); } @@ -107,11 +113,11 @@ ElementIterator::ElementIterator(const internal::abstract::Document *document, : m_document{document}, m_element{element} {} bool ElementIterator::operator==(const ElementIterator &rhs) const { - return m_element == rhs.m_element; + return m_elementId == rhs.m_elementId; } bool ElementIterator::operator!=(const ElementIterator &rhs) const { - return m_element != rhs.m_element; + return m_elementId != rhs.m_elementId; } ElementIterator::reference ElementIterator::operator*() const { @@ -120,7 +126,7 @@ ElementIterator::reference ElementIterator::operator*() const { ElementIterator &ElementIterator::operator++() { if (m_element != nullptr) { - m_element = m_element->next_sibling(m_document); + m_element = m_element->next_sibling(m_document, m_elementId); } return *this; } @@ -129,7 +135,7 @@ ElementIterator ElementIterator::operator++(int) { if (m_element == nullptr) { return {}; } - return {m_document, m_element->next_sibling(m_document)}; + return {m_document, m_element->next_sibling(m_document, m_elementId)}; } ElementRange::ElementRange() = default; @@ -144,292 +150,318 @@ ElementIterator ElementRange::begin() const { return m_begin; } ElementIterator ElementRange::end() const { return m_end; } PageLayout TextRoot::page_layout() const { - return m_element ? m_element->page_layout(m_document) : PageLayout(); + return m_element ? m_element->page_layout(m_document, m_elementId) + : PageLayout(); } MasterPage TextRoot::first_master_page() const { return m_element - ? MasterPage(m_document, m_element->first_master_page(m_document)) + ? MasterPage(m_document, + m_element->first_master_page(m_document, m_elementId)) : MasterPage(); } std::string Slide::name() const { - return m_element ? m_element->name(m_document) : ""; + return m_element ? m_element->name(m_document, m_elementId) : ""; } PageLayout Slide::page_layout() const { - return m_element ? m_element->page_layout(m_document) : PageLayout(); + return m_element ? m_element->page_layout(m_document, m_elementId) + : PageLayout(); } MasterPage Slide::master_page() const { - return m_element ? MasterPage(m_document, m_element->master_page(m_document)) + return m_element ? MasterPage(m_document, + m_element->master_page(m_document, m_elementId)) : MasterPage(); } std::string Sheet::name() const { - return m_element ? m_element->name(m_document) : ""; + return m_element ? m_element->name(m_document, m_elementId) : ""; } TableDimensions Sheet::dimensions() const { - return m_element ? m_element->dimensions(m_document) : TableDimensions(); + return m_element ? m_element->dimensions(m_document, m_elementId) + : TableDimensions(); } TableDimensions Sheet::content(std::optional range) const { - return m_element ? m_element->content(m_document, range) : TableDimensions(); + return m_element ? m_element->content(m_document, m_elementId, range) + : TableDimensions(); } TableColumn Sheet::column(std::uint32_t column) const { return m_element - ? TableColumn(m_document, m_element->column(m_document, column)) + ? TableColumn(m_document, + m_element->column(m_document, m_elementId, column)) : TableColumn(); } TableRow Sheet::row(std::uint32_t row) const { - return m_element ? TableRow(m_document, m_element->row(m_document, row)) + return m_element ? TableRow(m_document, + m_element->row(m_document, m_elementId, row)) : TableRow(); } TableCell Sheet::cell(std::uint32_t column, std::uint32_t row) const { return m_element - ? TableCell(m_document, m_element->cell(m_document, column, row)) + ? TableCell(m_document, + m_element->cell(m_document, m_elementId, column, row)) : TableCell(); } ElementRange Sheet::shapes() const { - return m_element ? ElementRange(ElementIterator( - m_document, m_element->first_shape(m_document))) - : ElementRange(); + return m_element + ? ElementRange(ElementIterator( + m_document, m_element->first_shape(m_document, m_elementId))) + : ElementRange(); } TableStyle Sheet::style() const { - return m_element ? m_element->style(m_document) : TableStyle(); + return m_element ? m_element->style(m_document, m_elementId) : TableStyle(); } std::string Page::name() const { - return m_element ? m_element->name(m_document) : ""; + return m_element ? m_element->name(m_document, m_elementId) : ""; } PageLayout Page::page_layout() const { - return m_element ? m_element->page_layout(m_document) : PageLayout(); + return m_element ? m_element->page_layout(m_document, m_elementId) + : PageLayout(); } MasterPage Page::master_page() const { - return m_element ? MasterPage(m_document, m_element->master_page(m_document)) + return m_element ? MasterPage(m_document, + m_element->master_page(m_document, m_elementId)) : MasterPage(); } PageLayout MasterPage::page_layout() const { - return m_element ? m_element->page_layout(m_document) : PageLayout(); + return m_element ? m_element->page_layout(m_document, m_elementId) + : PageLayout(); } TextStyle LineBreak::style() const { - return m_element ? m_element->style(m_document) : TextStyle(); + return m_element ? m_element->style(m_document, m_elementId) : TextStyle(); } ParagraphStyle Paragraph::style() const { - return m_element ? m_element->style(m_document) : ParagraphStyle(); + return m_element ? m_element->style(m_document, m_elementId) + : ParagraphStyle(); } TextStyle Paragraph::text_style() const { - return m_element ? m_element->text_style(m_document) : TextStyle(); + return m_element ? m_element->text_style(m_document, m_elementId) + : TextStyle(); } TextStyle Span::style() const { - return m_element ? m_element->style(m_document) : TextStyle(); + return m_element ? m_element->style(m_document, m_elementId) : TextStyle(); } std::string Text::content() const { - return m_element ? m_element->content(m_document) : ""; + return m_element ? m_element->content(m_document, m_elementId) : ""; } void Text::set_content(const std::string &text) const { if (m_element) { - m_element->set_content(m_document, text); + m_element->set_content(m_document, m_elementId, text); } } TextStyle Text::style() const { - return m_element ? m_element->style(m_document) : TextStyle(); + return m_element ? m_element->style(m_document, m_elementId) : TextStyle(); } std::string Link::href() const { - return m_element ? m_element->href(m_document) : ""; + return m_element ? m_element->href(m_document, m_elementId) : ""; } std::string Bookmark::name() const { - return m_element ? m_element->name(m_document) : ""; + return m_element ? m_element->name(m_document, m_elementId) : ""; } TextStyle ListItem::style() const { - return m_element ? m_element->style(m_document) : TextStyle(); + return m_element ? m_element->style(m_document, m_elementId) : TextStyle(); } ElementRange Table::columns() const { return m_element ? ElementRange(ElementIterator( - m_document, m_element->first_column(m_document))) + m_document, + m_element->first_column(m_document, m_elementId))) : ElementRange(); } ElementRange Table::rows() const { - return m_element ? ElementRange(ElementIterator( - m_document, m_element->first_row(m_document))) - : ElementRange(); + return m_element + ? ElementRange(ElementIterator( + m_document, m_element->first_row(m_document, m_elementId))) + : ElementRange(); } TableDimensions Table::dimensions() const { - return m_element ? m_element->dimensions(m_document) : TableDimensions(); + return m_element ? m_element->dimensions(m_document, m_elementId) + : TableDimensions(); } TableStyle Table::style() const { - return m_element ? m_element->style(m_document) : TableStyle(); + return m_element ? m_element->style(m_document, m_elementId) : TableStyle(); } TableColumnStyle TableColumn::style() const { - return m_element ? m_element->style(m_document) : TableColumnStyle(); + return m_element ? m_element->style(m_document, m_elementId) + : TableColumnStyle(); } TableRowStyle TableRow::style() const { - return m_element ? m_element->style(m_document) : TableRowStyle(); + return m_element ? m_element->style(m_document, m_elementId) + : TableRowStyle(); } bool TableCell::covered() const { - return m_element && m_element->covered(m_document); + return m_element && m_element->covered(m_document, m_elementId); } TableDimensions TableCell::span() const { - return m_element ? m_element->span(m_document) : TableDimensions(); + return m_element ? m_element->span(m_document, m_elementId) + : TableDimensions(); } ValueType TableCell::value_type() const { - return m_element ? m_element->value_type(m_document) : ValueType::string; + return m_element ? m_element->value_type(m_document, m_elementId) + : ValueType::string; } TableCellStyle TableCell::style() const { - return m_element ? m_element->style(m_document) : TableCellStyle(); + return m_element ? m_element->style(m_document, m_elementId) + : TableCellStyle(); } AnchorType Frame::anchor_type() const { - return m_element ? m_element->anchor_type(m_document) + return m_element ? m_element->anchor_type(m_document, m_elementId) : AnchorType::as_char; // TODO default? } std::optional Frame::x() const { - return m_element ? m_element->x(m_document) : std::optional(); + return m_element ? m_element->x(m_document, m_elementId) + : std::optional(); } std::optional Frame::y() const { - return m_element ? m_element->y(m_document) : std::optional(); + return m_element ? m_element->y(m_document, m_elementId) + : std::optional(); } std::optional Frame::width() const { - return m_element ? m_element->width(m_document) + return m_element ? m_element->width(m_document, m_elementId) : std::optional(); } std::optional Frame::height() const { - return m_element ? m_element->height(m_document) + return m_element ? m_element->height(m_document, m_elementId) : std::optional(); } std::optional Frame::z_index() const { - return m_element ? m_element->z_index(m_document) + return m_element ? m_element->z_index(m_document, m_elementId) : std::optional(); } GraphicStyle Frame::style() const { - return m_element ? m_element->style(m_document) : GraphicStyle(); + return m_element ? m_element->style(m_document, m_elementId) : GraphicStyle(); } std::string Rect::x() const { - return m_element ? m_element->x(m_document) : ""; + return m_element ? m_element->x(m_document, m_elementId) : ""; } std::string Rect::y() const { - return m_element ? m_element->y(m_document) : ""; + return m_element ? m_element->y(m_document, m_elementId) : ""; } std::string Rect::width() const { - return m_element ? m_element->width(m_document) : ""; + return m_element ? m_element->width(m_document, m_elementId) : ""; } std::string Rect::height() const { - return m_element ? m_element->height(m_document) : ""; + return m_element ? m_element->height(m_document, m_elementId) : ""; } GraphicStyle Rect::style() const { - return m_element ? m_element->style(m_document) : GraphicStyle(); + return m_element ? m_element->style(m_document, m_elementId) : GraphicStyle(); } std::string Line::x1() const { - return m_element ? m_element->x1(m_document) : ""; + return m_element ? m_element->x1(m_document, m_elementId) : ""; } std::string Line::y1() const { - return m_element ? m_element->y1(m_document) : ""; + return m_element ? m_element->y1(m_document, m_elementId) : ""; } std::string Line::x2() const { - return m_element ? m_element->x2(m_document) : ""; + return m_element ? m_element->x2(m_document, m_elementId) : ""; } std::string Line::y2() const { - return m_element ? m_element->y2(m_document) : ""; + return m_element ? m_element->y2(m_document, m_elementId) : ""; } GraphicStyle Line::style() const { - return m_element ? m_element->style(m_document) : GraphicStyle(); + return m_element ? m_element->style(m_document, m_elementId) : GraphicStyle(); } std::string Circle::x() const { - return m_element ? m_element->x(m_document) : ""; + return m_element ? m_element->x(m_document, m_elementId) : ""; } std::string Circle::y() const { - return m_element ? m_element->y(m_document) : ""; + return m_element ? m_element->y(m_document, m_elementId) : ""; } std::string Circle::width() const { - return m_element ? m_element->width(m_document) : ""; + return m_element ? m_element->width(m_document, m_elementId) : ""; } std::string Circle::height() const { - return m_element ? m_element->height(m_document) : ""; + return m_element ? m_element->height(m_document, m_elementId) : ""; } GraphicStyle Circle::style() const { - return m_element ? m_element->style(m_document) : GraphicStyle(); + return m_element ? m_element->style(m_document, m_elementId) : GraphicStyle(); } std::optional CustomShape::x() const { - return m_element ? m_element->x(m_document) : ""; + return m_element ? m_element->x(m_document, m_elementId) : ""; } std::optional CustomShape::y() const { - return m_element ? m_element->y(m_document) : ""; + return m_element ? m_element->y(m_document, m_elementId) : ""; } std::string CustomShape::width() const { - return m_element ? m_element->width(m_document) : ""; + return m_element ? m_element->width(m_document, m_elementId) : ""; } std::string CustomShape::height() const { - return m_element ? m_element->height(m_document) : ""; + return m_element ? m_element->height(m_document, m_elementId) : ""; } GraphicStyle CustomShape::style() const { - return m_element ? m_element->style(m_document) : GraphicStyle(); + return m_element ? m_element->style(m_document, m_elementId) : GraphicStyle(); } bool Image::internal() const { - return m_element && m_element->internal(m_document); + return m_element && m_element->internal(m_document, m_elementId); } std::optional Image::file() const { - return m_element ? m_element->file(m_document) : std::optional(); + return m_element ? m_element->file(m_document, m_elementId) + : std::optional(); } std::string Image::href() const { - return m_element ? m_element->href(m_document) : ""; + return m_element ? m_element->href(m_document, m_elementId) : ""; } } // namespace odr diff --git a/src/odr/document_element.hpp b/src/odr/document_element.hpp index 422966ee..95d1dc35 100644 --- a/src/odr/document_element.hpp +++ b/src/odr/document_element.hpp @@ -72,6 +72,10 @@ class Circle; class CustomShape; class Image; +using ElementIdentifier = std::uint64_t; +using ColumnIndex = std::uint32_t; +using RowIndex = std::uint32_t; + enum class ElementType { none, @@ -168,6 +172,7 @@ class Element { protected: const internal::abstract::Document *m_document{nullptr}; internal::abstract::Element *m_element{nullptr}; + ElementIdentifier m_elementId{0}; }; class ElementIterator { @@ -193,6 +198,7 @@ class ElementIterator { private: const internal::abstract::Document *m_document{nullptr}; internal::abstract::Element *m_element{nullptr}; + ElementIdentifier m_elementId{0}; }; template class TypedElement : public Element { @@ -252,9 +258,9 @@ class Sheet final : public TypedElement { [[nodiscard]] TableDimensions content(std::optional range) const; - [[nodiscard]] TableColumn column(std::uint32_t column) const; - [[nodiscard]] TableRow row(std::uint32_t row) const; - [[nodiscard]] TableCell cell(std::uint32_t column, std::uint32_t row) const; + [[nodiscard]] TableColumn column(ColumnIndex column) const; + [[nodiscard]] TableRow row(RowIndex row) const; + [[nodiscard]] TableCell cell(ColumnIndex column, RowIndex row) const; [[nodiscard]] ElementRange shapes() const; diff --git a/src/odr/internal/abstract/document.hpp b/src/odr/internal/abstract/document.hpp index e0923070..52924aab 100644 --- a/src/odr/internal/abstract/document.hpp +++ b/src/odr/internal/abstract/document.hpp @@ -1,8 +1,6 @@ #ifndef ODR_INTERNAL_ABSTRACT_DOCUMENT_H #define ODR_INTERNAL_ABSTRACT_DOCUMENT_H -#include - #include namespace odr { diff --git a/src/odr/internal/abstract/document_element.hpp b/src/odr/internal/abstract/document_element.hpp index 0fefc9f1..8e0c6269 100644 --- a/src/odr/internal/abstract/document_element.hpp +++ b/src/odr/internal/abstract/document_element.hpp @@ -24,312 +24,418 @@ struct TableDimensions; namespace odr::internal::abstract { class Document; +class MasterPage; class Element { public: virtual ~Element() = default; - [[nodiscard]] virtual ElementType type(const Document *) const = 0; - - [[nodiscard]] virtual Element *parent(const Document *) const = 0; - [[nodiscard]] virtual Element *first_child(const Document *) const = 0; - [[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 ElementType type(const Document *, + ElementIdentifier) const = 0; + + [[nodiscard]] virtual Element *parent(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual Element *first_child(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual Element *last_child(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual Element *previous_sibling(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual Element *next_sibling(const Document *, + ElementIdentifier) const = 0; }; class TextRoot : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::root; } - [[nodiscard]] virtual PageLayout - page_layout(const Document *document) const = 0; + [[nodiscard]] virtual PageLayout page_layout(const Document *, + ElementIdentifier) const = 0; [[nodiscard]] virtual MasterPage * - first_master_page(const Document *document) const = 0; + first_master_page(const Document *, ElementIdentifier) const = 0; }; class Slide : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::slide; } - [[nodiscard]] virtual PageLayout - page_layout(const Document *document) const = 0; + [[nodiscard]] virtual PageLayout page_layout(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual MasterPage * - master_page(const Document *document) const = 0; + [[nodiscard]] virtual MasterPage *master_page(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual std::string name(const Document *document) const = 0; + [[nodiscard]] virtual std::string name(const Document *, + ElementIdentifier) const = 0; }; class Sheet : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::sheet; } - [[nodiscard]] virtual std::string name(const Document *document) const = 0; + [[nodiscard]] virtual std::string name(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual TableDimensions dimensions(const Document *, + ElementIdentifier) const = 0; [[nodiscard]] virtual TableDimensions - dimensions(const Document *document) const = 0; - [[nodiscard]] virtual TableDimensions - content(const Document *document, + content(const Document *, ElementIdentifier, std::optional range) const = 0; - [[nodiscard]] virtual Element *column(const Document *document, - std::uint32_t column) const = 0; - [[nodiscard]] virtual Element *row(const Document *document, - std::uint32_t row) const = 0; - [[nodiscard]] virtual Element *cell(const Document *document, - std::uint32_t column, - std::uint32_t row) const = 0; + [[nodiscard]] virtual Element *column(const Document *, ElementIdentifier, + ColumnIndex column) const = 0; + [[nodiscard]] virtual Element *row(const Document *, ElementIdentifier, + RowIndex row) const = 0; + [[nodiscard]] virtual Element *cell(const Document *, ElementIdentifier, + ColumnIndex column, + RowIndex row) const = 0; - [[nodiscard]] virtual Element * - first_shape(const Document *document) const = 0; + [[nodiscard]] virtual Element *first_shape(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual TableStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TableStyle style(const Document *, + ElementIdentifier) const = 0; }; class Page : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::page; } - [[nodiscard]] virtual PageLayout - page_layout(const Document *document) const = 0; + [[nodiscard]] virtual PageLayout page_layout(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual MasterPage * - master_page(const Document *document) const = 0; + [[nodiscard]] virtual MasterPage *master_page(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual std::string name(const Document *document) const = 0; + [[nodiscard]] virtual std::string name(const Document *, + ElementIdentifier) const = 0; }; class MasterPage : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::master_page; } - [[nodiscard]] virtual PageLayout - page_layout(const Document *document) const = 0; + [[nodiscard]] virtual PageLayout page_layout(const Document *, + ElementIdentifier) const = 0; }; class LineBreak : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::line_break; } - [[nodiscard]] virtual TextStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TextStyle style(const Document *, + ElementIdentifier) const = 0; }; class Paragraph : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::paragraph; } - [[nodiscard]] virtual ParagraphStyle - style(const Document *document) const = 0; - [[nodiscard]] virtual TextStyle - text_style(const Document *document) const = 0; + [[nodiscard]] virtual ParagraphStyle style(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual TextStyle text_style(const Document *, + ElementIdentifier) const = 0; }; class Span : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::span; } - [[nodiscard]] virtual TextStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TextStyle style(const Document *document, + ElementIdentifier) const = 0; }; class Text : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::text; } - [[nodiscard]] virtual std::string content(const Document *document) const = 0; - virtual void set_content(const Document *document, + [[nodiscard]] virtual std::string content(const Document *, + ElementIdentifier) const = 0; + virtual void set_content(const Document *, ElementIdentifier, const std::string &text) = 0; - [[nodiscard]] virtual TextStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TextStyle style(const Document *, + ElementIdentifier) const = 0; }; class Link : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::link; } - [[nodiscard]] virtual std::string href(const Document *document) const = 0; + [[nodiscard]] virtual std::string href(const Document *, + ElementIdentifier) const = 0; }; class Bookmark : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::bookmark; } - [[nodiscard]] virtual std::string name(const Document *document) const = 0; + [[nodiscard]] virtual std::string name(const Document *, + ElementIdentifier) const = 0; }; class ListItem : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::list_item; } - [[nodiscard]] virtual TextStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TextStyle style(const Document *, + ElementIdentifier) const = 0; }; class Table : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::table; } - [[nodiscard]] virtual TableDimensions - dimensions(const Document *document) const = 0; + [[nodiscard]] virtual TableDimensions dimensions(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual Element * - first_column(const Document *document) const = 0; - [[nodiscard]] virtual Element *first_row(const Document *document) const = 0; + [[nodiscard]] virtual Element *first_column(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual Element *first_row(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual TableStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TableStyle style(const Document *, + ElementIdentifier) const = 0; }; class TableColumn : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::table_column; } - [[nodiscard]] virtual TableColumnStyle - style(const Document *document) const = 0; + [[nodiscard]] virtual TableColumnStyle style(const Document *, + ElementIdentifier) const = 0; }; class TableRow : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::table_row; } - [[nodiscard]] virtual TableRowStyle style(const Document *document) const = 0; + [[nodiscard]] virtual TableRowStyle style(const Document *, + ElementIdentifier) const = 0; }; class TableCell : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::table_cell; } - [[nodiscard]] virtual bool covered(const Document *document) const = 0; - [[nodiscard]] virtual TableDimensions - span(const Document *document) const = 0; - [[nodiscard]] virtual ValueType - value_type(const Document *document) const = 0; + [[nodiscard]] virtual bool covered(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual TableDimensions span(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual ValueType value_type(const Document *, + ElementIdentifier) const = 0; - [[nodiscard]] virtual TableCellStyle - style(const Document *document) const = 0; + [[nodiscard]] virtual TableCellStyle style(const Document *, + ElementIdentifier) const = 0; }; class Frame : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::frame; } - [[nodiscard]] virtual AnchorType - anchor_type(const Document *document) const = 0; + [[nodiscard]] virtual AnchorType anchor_type(const Document *, + ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - x(const Document *document) const = 0; + x(const Document *, ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - y(const Document *document) const = 0; + y(const Document *, ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - width(const Document *document) const = 0; + width(const Document *, ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - height(const Document *document) const = 0; + height(const Document *, ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - z_index(const Document *document) const = 0; + z_index(const Document *, ElementIdentifier) const = 0; - [[nodiscard]] virtual GraphicStyle style(const Document *document) const = 0; + [[nodiscard]] virtual GraphicStyle style(const Document *, + ElementIdentifier) const = 0; }; class Rect : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::rect; } - [[nodiscard]] virtual std::string x(const Document *document) const = 0; - [[nodiscard]] virtual std::string y(const Document *document) const = 0; - [[nodiscard]] virtual std::string width(const Document *document) const = 0; - [[nodiscard]] virtual std::string height(const Document *document) const = 0; - - [[nodiscard]] virtual GraphicStyle style(const Document *document) const = 0; + [[nodiscard]] virtual std::string x(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string y(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string width(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string height(const Document *, + ElementIdentifier) const = 0; + + [[nodiscard]] virtual GraphicStyle style(const Document *, + ElementIdentifier) const = 0; }; class Line : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::line; } - [[nodiscard]] virtual std::string x1(const Document *document) const = 0; - [[nodiscard]] virtual std::string y1(const Document *document) const = 0; - [[nodiscard]] virtual std::string x2(const Document *document) const = 0; - [[nodiscard]] virtual std::string y2(const Document *document) const = 0; - - [[nodiscard]] virtual GraphicStyle style(const Document *document) const = 0; + [[nodiscard]] virtual std::string x1(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string y1(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string x2(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string y2(const Document *, + ElementIdentifier) const = 0; + + [[nodiscard]] virtual GraphicStyle style(const Document *, + ElementIdentifier) const = 0; }; class Circle : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::circle; } - [[nodiscard]] virtual std::string x(const Document *document) const = 0; - [[nodiscard]] virtual std::string y(const Document *document) const = 0; - [[nodiscard]] virtual std::string width(const Document *document) const = 0; - [[nodiscard]] virtual std::string height(const Document *document) const = 0; - - [[nodiscard]] virtual GraphicStyle style(const Document *document) const = 0; + [[nodiscard]] virtual std::string x(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string y(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string width(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string height(const Document *, + ElementIdentifier) const = 0; + + [[nodiscard]] virtual GraphicStyle style(const Document *, + ElementIdentifier) const = 0; }; class CustomShape : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::custom_shape; } [[nodiscard]] virtual std::optional - x(const Document *document) const = 0; + x(const Document *, ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - y(const Document *document) const = 0; - [[nodiscard]] virtual std::string width(const Document *document) const = 0; - [[nodiscard]] virtual std::string height(const Document *document) const = 0; - - [[nodiscard]] virtual GraphicStyle style(const Document *document) const = 0; + y(const Document *, ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string width(const Document *, + ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string height(const Document *, + ElementIdentifier) const = 0; + + [[nodiscard]] virtual GraphicStyle style(const Document *, + ElementIdentifier) const = 0; }; class Image : public virtual Element { public: - [[nodiscard]] ElementType type(const Document *) const override { + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { return ElementType::image; } - [[nodiscard]] virtual bool internal(const Document *document) const = 0; + [[nodiscard]] virtual bool internal(const Document *, + ElementIdentifier) const = 0; [[nodiscard]] virtual std::optional - file(const Document *document) const = 0; - [[nodiscard]] virtual std::string href(const Document *document) const = 0; + file(const Document *, ElementIdentifier) const = 0; + [[nodiscard]] virtual std::string href(const Document *, + ElementIdentifier) const = 0; +}; + +class SheetColumn : public virtual Element { +public: + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { + return ElementType::table_column; + } + + [[nodiscard]] virtual TableColumnStyle + style(const Document *, ElementIdentifier, ColumnIndex) const = 0; +}; + +class SheetRow : public virtual Element { +public: + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { + return ElementType::table_row; + } + + [[nodiscard]] virtual TableRowStyle style(const Document *, ElementIdentifier, + RowIndex) const = 0; +}; + +class SheetCell : public virtual Element { +public: + [[nodiscard]] ElementType type(const Document *, + ElementIdentifier) const override { + return ElementType::table_cell; + } + + [[nodiscard]] virtual bool covered(const Document *, ElementIdentifier, + ColumnIndex, RowIndex) const = 0; + [[nodiscard]] virtual TableDimensions + span(const Document *, ElementIdentifier, ColumnIndex, RowIndex) const = 0; + [[nodiscard]] virtual ValueType value_type(const Document *, + ElementIdentifier, ColumnIndex, + RowIndex) const = 0; + + [[nodiscard]] virtual TableCellStyle + style(const Document *, ElementIdentifier, ColumnIndex, RowIndex) const = 0; }; } // namespace odr::internal::abstract diff --git a/src/odr/internal/common/document_element.cpp b/src/odr/internal/common/document_element.cpp index 1c7090bb..7103fb83 100644 --- a/src/odr/internal/common/document_element.cpp +++ b/src/odr/internal/common/document_element.cpp @@ -10,21 +10,27 @@ Element::Element(pugi::xml_node node) : m_node{node} { } } -Element *Element::parent(const abstract::Document *) const { return m_parent; } +Element *Element::parent(const abstract::Document *, ElementIdentifier) const { + return m_parent; +} -Element *Element::first_child(const abstract::Document *) const { +Element *Element::first_child(const abstract::Document *, + ElementIdentifier) const { return m_first_child; } -Element *Element::last_child(const abstract::Document *) const { +Element *Element::last_child(const abstract::Document *, + ElementIdentifier) const { return m_last_child; } -Element *Element::previous_sibling(const abstract::Document *) const { +Element *Element::previous_sibling(const abstract::Document *, + ElementIdentifier) const { return m_previous_sibling; } -Element *Element::next_sibling(const abstract::Document *) const { +Element *Element::next_sibling(const abstract::Document *, + ElementIdentifier) const { return m_next_sibling; } @@ -41,15 +47,22 @@ void Element::init_append_child(Element *element) { Table::Table(pugi::xml_node node) : Element(node) {} -Element *Table::first_child(const abstract::Document *) const { return {}; } +Element *Table::first_child(const abstract::Document *, + ElementIdentifier) const { + return {}; +} -Element *Table::last_child(const abstract::Document *) const { return {}; } +Element *Table::last_child(const abstract::Document *, + ElementIdentifier) const { + return {}; +} -Element *Table::first_column(const abstract::Document * /*document*/) const { +Element *Table::first_column(const abstract::Document *, + ElementIdentifier) const { return m_first_column; } -Element *Table::first_row(const abstract::Document * /*document*/) const { +Element *Table::first_row(const abstract::Document *, ElementIdentifier) const { return m_first_child; } diff --git a/src/odr/internal/common/document_element.hpp b/src/odr/internal/common/document_element.hpp index b928975e..9497864a 100644 --- a/src/odr/internal/common/document_element.hpp +++ b/src/odr/internal/common/document_element.hpp @@ -15,13 +15,16 @@ class Element : public virtual abstract::Element { public: explicit Element(const pugi::xml_node node); - [[nodiscard]] Element *parent(const abstract::Document *) const override; - [[nodiscard]] Element *first_child(const abstract::Document *) const override; - [[nodiscard]] Element *last_child(const abstract::Document *) const override; - [[nodiscard]] Element * - previous_sibling(const abstract::Document *) const override; - [[nodiscard]] Element * - next_sibling(const abstract::Document *) const override; + [[nodiscard]] Element *parent(const abstract::Document *, + ElementIdentifier) const override; + [[nodiscard]] Element *first_child(const abstract::Document *, + ElementIdentifier) const override; + [[nodiscard]] Element *last_child(const abstract::Document *, + ElementIdentifier) const override; + [[nodiscard]] Element *previous_sibling(const abstract::Document *, + ElementIdentifier) const override; + [[nodiscard]] Element *next_sibling(const abstract::Document *, + ElementIdentifier) const override; void init_append_child(Element *element); @@ -40,11 +43,14 @@ class Table : public virtual Element, public abstract::Table { public: explicit Table(const pugi::xml_node node); - [[nodiscard]] Element *first_child(const abstract::Document *) const final; - [[nodiscard]] Element *last_child(const abstract::Document *) const final; + [[nodiscard]] Element *first_child(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] Element *last_child(const abstract::Document *, + ElementIdentifier) const final; - Element *first_column(const abstract::Document *document) const final; - Element *first_row(const abstract::Document *document) const final; + Element *first_column(const abstract::Document *, + ElementIdentifier) const final; + Element *first_row(const abstract::Document *, ElementIdentifier) const final; void init_append_column(Element *element); void init_append_row(Element *element); diff --git a/src/odr/internal/odf/odf_element.cpp b/src/odr/internal/odf/odf_element.cpp index 7f6c0e9f..ed7e7b0e 100644 --- a/src/odr/internal/odf/odf_element.cpp +++ b/src/odr/internal/odf/odf_element.cpp @@ -65,25 +65,28 @@ const StyleRegistry *Element::style_(const abstract::Document *document) { Root::Root(pugi::xml_node node) : common::Element(node), Element(node) {} -ElementType Root::type(const abstract::Document *) const { +ElementType Root::type(const abstract::Document *, ElementIdentifier) const { return ElementType::root; } TextRoot::TextRoot(pugi::xml_node node) : common::Element(node), Root(node) {} -ElementType TextRoot::type(const abstract::Document *) const { +ElementType TextRoot::type(const abstract::Document *, + ElementIdentifier) const { return ElementType::root; } -PageLayout TextRoot::page_layout(const abstract::Document *document) const { - if (auto master_page = this->first_master_page(document)) { - return master_page->page_layout(document); +PageLayout TextRoot::page_layout(const abstract::Document *document, + ElementIdentifier elementId) const { + if (auto master_page = this->first_master_page(document, elementId)) { + return master_page->page_layout(document, elementId); } return {}; } abstract::MasterPage * -TextRoot::first_master_page(const abstract::Document *document) const { +TextRoot::first_master_page(const abstract::Document *document, + ElementIdentifier) const { if (auto first_master_page = style_(document)->first_master_page()) { return first_master_page; } @@ -99,7 +102,8 @@ DrawingRoot::DrawingRoot(pugi::xml_node node) MasterPage::MasterPage(pugi::xml_node node) : common::Element(node), Element(node) {} -PageLayout MasterPage::page_layout(const abstract::Document *document) const { +PageLayout MasterPage::page_layout(const abstract::Document *document, + ElementIdentifier) const { if (auto attribute = m_node.attribute("style:page-layout-name")) { return style_(document)->page_layout(attribute.value()); } @@ -108,67 +112,73 @@ PageLayout MasterPage::page_layout(const abstract::Document *document) const { Slide::Slide(pugi::xml_node node) : common::Element(node), Element(node) {} -PageLayout Slide::page_layout(const abstract::Document *document) const { - if (auto master_page = this->master_page(document)) { - return master_page->page_layout(document); +PageLayout Slide::page_layout(const abstract::Document *document, + ElementIdentifier elementId) const { + if (auto master_page = this->master_page(document, elementId)) { + return master_page->page_layout(document, elementId); } return {}; } -abstract::MasterPage * -Slide::master_page(const abstract::Document *document) const { +abstract::MasterPage *Slide::master_page(const abstract::Document *document, + ElementIdentifier) const { if (auto master_page_name_attr = m_node.attribute("draw:master-page-name")) { return style_(document)->master_page(master_page_name_attr.value()); } return {}; } -std::string Slide::name(const abstract::Document *) const { +std::string Slide::name(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("draw:name").value(); } Page::Page(pugi::xml_node node) : common::Element(node), Element(node) {} -PageLayout Page::page_layout(const abstract::Document *document) const { - if (auto master_page = this->master_page(document)) { - return master_page->page_layout(document); +PageLayout Page::page_layout(const abstract::Document *document, + ElementIdentifier elementId) const { + if (auto master_page = this->master_page(document, elementId)) { + return master_page->page_layout(document, elementId); } return {}; } -abstract::MasterPage * -Page::master_page(const abstract::Document *document) const { +abstract::MasterPage *Page::master_page(const abstract::Document *document, + ElementIdentifier) const { if (auto master_page_name_attr = m_node.attribute("draw:master-page-name")) { return style_(document)->master_page(master_page_name_attr.value()); } return {}; } -std::string Page::name(const abstract::Document *) const { +std::string Page::name(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("draw:name").value(); } LineBreak::LineBreak(pugi::xml_node node) : common::Element(node), Element(node) {} -TextStyle LineBreak::style(const abstract::Document *document) const { +TextStyle LineBreak::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).text_style; } Paragraph::Paragraph(pugi::xml_node node) : common::Element(node), Element(node) {} -ParagraphStyle Paragraph::style(const abstract::Document *document) const { +ParagraphStyle Paragraph::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).paragraph_style; } -TextStyle Paragraph::text_style(const abstract::Document *document) const { +TextStyle Paragraph::text_style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).text_style; } Span::Span(pugi::xml_node node) : common::Element(node), Element(node) {} -TextStyle Span::style(const abstract::Document *document) const { +TextStyle Span::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).text_style; } @@ -198,7 +208,7 @@ Text::Text(pugi::xml_node first, pugi::xml_node last) } } -std::string Text::content(const abstract::Document *) const { +std::string Text::content(const abstract::Document *, ElementIdentifier) const { std::string result; for (auto node = m_node; node != m_last.next_sibling(); node = node.next_sibling()) { @@ -207,7 +217,8 @@ std::string Text::content(const abstract::Document *) const { return result; } -void Text::set_content(const abstract::Document *, const std::string &text) { +void Text::set_content(const abstract::Document *, ElementIdentifier, + const std::string &text) { auto parent = m_node.parent(); auto old_start = m_node; @@ -235,39 +246,43 @@ void Text::set_content(const abstract::Document *, const std::string &text) { // TODO set first and last } -TextStyle Text::style(const abstract::Document *document) const { +TextStyle Text::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).text_style; } Link::Link(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Link::href(const abstract::Document *) const { +std::string Link::href(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("xlink:href").value(); } Bookmark::Bookmark(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Bookmark::name(const abstract::Document *) const { +std::string Bookmark::name(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("text:name").value(); } ListItem::ListItem(pugi::xml_node node) : common::Element(node), Element(node) {} -TextStyle ListItem::style(const abstract::Document *document) const { +TextStyle ListItem::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).text_style; } Table::Table(pugi::xml_node node) : common::Element(node), Element(node), common::Table(node) {} -TableStyle Table::style(const abstract::Document *document) const { +TableStyle Table::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_style; } -TableDimensions -Table::dimensions(const abstract::Document * /*document*/) const { +TableDimensions Table::dimensions(const abstract::Document *, + ElementIdentifier) const { TableDimensions result; common::TableCursor cursor; @@ -294,30 +309,34 @@ Table::dimensions(const abstract::Document * /*document*/) const { TableColumn::TableColumn(pugi::xml_node node) : common::Element(node), Element(node) {} -TableColumnStyle TableColumn::style(const abstract::Document *document) const { +TableColumnStyle TableColumn::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_column_style; } TableRow::TableRow(pugi::xml_node node) : common::Element(node), Element(node) {} -TableRowStyle TableRow::style(const abstract::Document *document) const { +TableRowStyle TableRow::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_row_style; } TableCell::TableCell(pugi::xml_node node) : common::Element(node), Element(node) {} -bool TableCell::covered(const abstract::Document *) const { +bool TableCell::covered(const abstract::Document *, ElementIdentifier) const { return std::strcmp(m_node.name(), "table:covered-table-cell") == 0; } -TableDimensions TableCell::span(const abstract::Document *) const { +TableDimensions TableCell::span(const abstract::Document *, + ElementIdentifier) const { return {m_node.attribute("table:number-rows-spanned").as_uint(1), m_node.attribute("table:number-columns-spanned").as_uint(1)}; } -ValueType TableCell::value_type(const abstract::Document *) const { +ValueType TableCell::value_type(const abstract::Document *, + ElementIdentifier) const { auto value_type = m_node.attribute("office:value-type").value(); if (std::strcmp("float", value_type) == 0) { return ValueType::float_number; @@ -325,13 +344,15 @@ ValueType TableCell::value_type(const abstract::Document *) const { return ValueType::string; } -TableCellStyle TableCell::style(const abstract::Document *document) const { +TableCellStyle TableCell::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_cell_style; } Frame::Frame(pugi::xml_node node) : common::Element(node), Element(node) {} -AnchorType Frame::anchor_type(const abstract::Document *) const { +AnchorType Frame::anchor_type(const abstract::Document *, + ElementIdentifier) const { auto anchor_type = m_node.attribute("text:anchor-type").value(); if (std::strcmp("as-char", anchor_type) == 0) { return AnchorType::as_char; @@ -348,157 +369,174 @@ AnchorType Frame::anchor_type(const abstract::Document *) const { return AnchorType::at_page; } -std::optional Frame::x(const abstract::Document *) const { +std::optional Frame::x(const abstract::Document *, + ElementIdentifier) const { if (auto attribute = m_node.attribute("svg:x")) { return attribute.value(); } return {}; } -std::optional Frame::y(const abstract::Document *) const { +std::optional Frame::y(const abstract::Document *, + ElementIdentifier) const { if (auto attribute = m_node.attribute("svg:y")) { return attribute.value(); } return {}; } -std::optional Frame::width(const abstract::Document *) const { +std::optional Frame::width(const abstract::Document *, + ElementIdentifier) const { if (auto attribute = m_node.attribute("svg:width")) { return attribute.value(); } return {}; } -std::optional Frame::height(const abstract::Document *) const { +std::optional Frame::height(const abstract::Document *, + ElementIdentifier) const { if (auto attribute = m_node.attribute("svg:height")) { return attribute.value(); } return {}; } -std::optional Frame::z_index(const abstract::Document *) const { +std::optional Frame::z_index(const abstract::Document *, + ElementIdentifier) const { if (auto attribute = m_node.attribute("draw:z-index")) { return attribute.value(); } return {}; } -GraphicStyle Frame::style(const abstract::Document *document) const { +GraphicStyle Frame::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).graphic_style; } Rect::Rect(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Rect::x(const abstract::Document *) const { +std::string Rect::x(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:x").value(); } -std::string Rect::y(const abstract::Document *) const { +std::string Rect::y(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:y").value(); } -std::string Rect::width(const abstract::Document *) const { +std::string Rect::width(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:width").value(); } -std::string Rect::height(const abstract::Document *) const { +std::string Rect::height(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:height").value(); } -GraphicStyle Rect::style(const abstract::Document *document) const { +GraphicStyle Rect::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).graphic_style; } Line::Line(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Line::x1(const abstract::Document *) const { +std::string Line::x1(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:x1").value(); } -std::string Line::y1(const abstract::Document *) const { +std::string Line::y1(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:y1").value(); } -std::string Line::x2(const abstract::Document *) const { +std::string Line::x2(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:x2").value(); } -std::string Line::y2(const abstract::Document *) const { +std::string Line::y2(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:y2").value(); } -GraphicStyle Line::style(const abstract::Document *document) const { +GraphicStyle Line::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).graphic_style; } Circle::Circle(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Circle::x(const abstract::Document *) const { +std::string Circle::x(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:x").value(); } -std::string Circle::y(const abstract::Document *) const { +std::string Circle::y(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:y").value(); } -std::string Circle::width(const abstract::Document *) const { +std::string Circle::width(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("svg:width").value(); } -std::string Circle::height(const abstract::Document *) const { +std::string Circle::height(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("svg:height").value(); } -GraphicStyle Circle::style(const abstract::Document *document) const { +GraphicStyle Circle::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).graphic_style; } CustomShape::CustomShape(pugi::xml_node node) : common::Element(node), Element(node) {} -std::optional CustomShape::x(const abstract::Document *) const { +std::optional CustomShape::x(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("svg:x").value(); } -std::optional CustomShape::y(const abstract::Document *) const { +std::optional CustomShape::y(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("svg:y").value(); } -std::string CustomShape::width(const abstract::Document *) const { +std::string CustomShape::width(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("svg:width").value(); } -std::string CustomShape::height(const abstract::Document *) const { +std::string CustomShape::height(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("svg:height").value(); } -GraphicStyle CustomShape::style(const abstract::Document *document) const { +GraphicStyle CustomShape::style(const abstract::Document *document, + ElementIdentifier) const { return intermediate_style(document).graphic_style; } Image::Image(pugi::xml_node node) : common::Element(node), Element(node) {} -bool Image::internal(const abstract::Document *document) const { +bool Image::internal(const abstract::Document *document, + ElementIdentifier elementId) const { auto doc = document_(document); if (!doc || !doc->files()) { return false; } try { - return doc->files()->is_file(href(document)); + return doc->files()->is_file(href(document, elementId)); } catch (...) { } return false; } -std::optional Image::file(const abstract::Document *document) const { +std::optional Image::file(const abstract::Document *document, + ElementIdentifier elementId) const { auto doc = document_(document); - if (!doc || !internal(document)) { + if (!doc || !internal(document, elementId)) { return {}; } - return File(doc->files()->open(href(document))); + return File(doc->files()->open(href(document, elementId))); } -std::string Image::href(const abstract::Document *) const { +std::string Image::href(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("xlink:href").value(); } diff --git a/src/odr/internal/odf/odf_element.hpp b/src/odr/internal/odf/odf_element.hpp index d90dde40..4680571a 100644 --- a/src/odr/internal/odf/odf_element.hpp +++ b/src/odr/internal/odf/odf_element.hpp @@ -17,18 +17,17 @@ class StyleRegistry; class Element : public virtual common::Element { public: - explicit Element(pugi::xml_node node); + explicit Element(pugi::xml_node); + virtual common::ResolvedStyle partial_style(const abstract::Document *) const; virtual common::ResolvedStyle - partial_style(const abstract::Document *document) const; - virtual common::ResolvedStyle - intermediate_style(const abstract::Document *document) const; + intermediate_style(const abstract::Document *) const; protected: - virtual const char *style_name_(const abstract::Document *document) const; + virtual const char *style_name_(const abstract::Document *) const; - static const Document *document_(const abstract::Document *document); - static const StyleRegistry *style_(const abstract::Document *document); + static const Document *document_(const abstract::Document *); + static const StyleRegistry *style_(const abstract::Document *); }; template class DefaultElement : public Element { @@ -36,116 +35,122 @@ template class DefaultElement : public Element { explicit DefaultElement(pugi::xml_node node) : common::Element(node), Element(node) {} - [[nodiscard]] ElementType type(const abstract::Document *) const final { + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const final { return element_type; } }; class Root : public Element { public: - explicit Root(pugi::xml_node node); + explicit Root(pugi::xml_node); - [[nodiscard]] ElementType - type(const abstract::Document *document) const override; + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const override; }; class TextRoot final : public Root, public abstract::TextRoot { public: - explicit TextRoot(pugi::xml_node node); + explicit TextRoot(pugi::xml_node); - [[nodiscard]] ElementType - type(const abstract::Document *document) const final; + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] PageLayout - page_layout(const abstract::Document *document) const final; + [[nodiscard]] PageLayout page_layout(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] abstract::MasterPage * - first_master_page(const abstract::Document *document) const final; + first_master_page(const abstract::Document *, ElementIdentifier) const final; }; class PresentationRoot final : public Root { public: - explicit PresentationRoot(pugi::xml_node node); + explicit PresentationRoot(pugi::xml_node); }; class DrawingRoot final : public Root { public: - explicit DrawingRoot(pugi::xml_node node); + explicit DrawingRoot(pugi::xml_node); }; class MasterPage final : public Element, public abstract::MasterPage { public: - explicit MasterPage(pugi::xml_node node); + explicit MasterPage(pugi::xml_node); - [[nodiscard]] PageLayout - page_layout(const abstract::Document *document) const final; + [[nodiscard]] PageLayout page_layout(const abstract::Document *, + ElementIdentifier) const final; }; class Slide final : public Element, public abstract::Slide { public: - explicit Slide(pugi::xml_node node); + explicit Slide(pugi::xml_node); - [[nodiscard]] PageLayout - page_layout(const abstract::Document *document) const final; + [[nodiscard]] PageLayout page_layout(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] abstract::MasterPage * - master_page(const abstract::Document *document) const final; + master_page(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] std::string - name(const abstract::Document *document) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; }; class Page final : public Element, public abstract::Page { public: - explicit Page(pugi::xml_node node); + explicit Page(pugi::xml_node); - [[nodiscard]] PageLayout - page_layout(const abstract::Document *document) const final; + [[nodiscard]] PageLayout page_layout(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] abstract::MasterPage * - master_page(const abstract::Document *document) const final; + master_page(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] std::string - name(const abstract::Document *document) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; }; class LineBreak final : public Element, public abstract::LineBreak { public: - explicit LineBreak(pugi::xml_node node); + explicit LineBreak(pugi::xml_node); - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Paragraph final : public Element, public abstract::Paragraph { public: - explicit Paragraph(pugi::xml_node node); + explicit Paragraph(pugi::xml_node); - [[nodiscard]] ParagraphStyle - style(const abstract::Document *document) const final; + [[nodiscard]] ParagraphStyle style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TextStyle - text_style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle text_style(const abstract::Document *, + ElementIdentifier) const final; }; class Span final : public Element, public abstract::Span { public: - explicit Span(pugi::xml_node node); + explicit Span(pugi::xml_node); - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Text final : public Element, public abstract::Text { public: - static std::string text(const pugi::xml_node node); + static std::string text(const pugi::xml_node); - explicit Text(pugi::xml_node node); + explicit Text(pugi::xml_node); Text(pugi::xml_node first, pugi::xml_node last); - [[nodiscard]] std::string content(const abstract::Document *) const final; + [[nodiscard]] std::string content(const abstract::Document *, + ElementIdentifier) const final; - void set_content(const abstract::Document *, const std::string &text) final; + void set_content(const abstract::Document *, ElementIdentifier, + const std::string &text) final; - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; private: pugi::xml_node m_last; @@ -153,164 +158,175 @@ class Text final : public Element, public abstract::Text { class Link final : public Element, public abstract::Link { public: - explicit Link(pugi::xml_node node); + explicit Link(pugi::xml_node); - [[nodiscard]] std::string - href(const abstract::Document *document) const final; + [[nodiscard]] std::string href(const abstract::Document *, + ElementIdentifier) const final; }; class Bookmark final : public Element, public abstract::Bookmark { public: - explicit Bookmark(pugi::xml_node node); + explicit Bookmark(pugi::xml_node); - [[nodiscard]] std::string - name(const abstract::Document *document) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; }; class ListItem final : public Element, public abstract::ListItem { public: - explicit ListItem(pugi::xml_node node); + explicit ListItem(pugi::xml_node); - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Table : public Element, public common::Table { public: - explicit Table(pugi::xml_node node); + explicit Table(pugi::xml_node); - [[nodiscard]] TableStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableStyle style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions - dimensions(const abstract::Document *document) const final; + [[nodiscard]] TableDimensions dimensions(const abstract::Document *, + ElementIdentifier) const final; }; class TableColumn final : public Element, public abstract::TableColumn { public: - explicit TableColumn(pugi::xml_node node); + explicit TableColumn(pugi::xml_node); - [[nodiscard]] TableColumnStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableColumnStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableRow final : public Element, public abstract::TableRow { public: - explicit TableRow(pugi::xml_node node); + explicit TableRow(pugi::xml_node); - [[nodiscard]] TableRowStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableRowStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableCell final : public Element, public abstract::TableCell { public: - explicit TableCell(pugi::xml_node node); + explicit TableCell(pugi::xml_node); - [[nodiscard]] bool covered(const abstract::Document *document) const final; + [[nodiscard]] bool covered(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions - span(const abstract::Document *document) const final; + [[nodiscard]] TableDimensions span(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] ValueType - value_type(const abstract::Document *document) const final; + [[nodiscard]] ValueType value_type(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableCellStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableCellStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Frame final : public Element, public abstract::Frame { public: - explicit Frame(pugi::xml_node node); + explicit Frame(pugi::xml_node); - [[nodiscard]] AnchorType - anchor_type(const abstract::Document *document) const final; + [[nodiscard]] AnchorType anchor_type(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional width(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] std::optional - x(const abstract::Document *document) const final; - [[nodiscard]] std::optional - y(const abstract::Document *document) const final; - [[nodiscard]] std::optional - width(const abstract::Document *document) const final; - [[nodiscard]] std::optional - height(const abstract::Document *document) const final; + height(const abstract::Document *, ElementIdentifier) const final; [[nodiscard]] std::optional - z_index(const abstract::Document *document) const final; + z_index(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] GraphicStyle - style(const abstract::Document *document) const final; + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Rect final : public Element, public abstract::Rect { public: - explicit Rect(pugi::xml_node node); - - [[nodiscard]] std::string x(const abstract::Document *document) const final; - [[nodiscard]] std::string y(const abstract::Document *document) const final; - [[nodiscard]] std::string - width(const abstract::Document *document) const final; - [[nodiscard]] std::string - height(const abstract::Document *document) const final; - - [[nodiscard]] GraphicStyle - style(const abstract::Document *document) const final; + explicit Rect(pugi::xml_node); + + [[nodiscard]] std::string x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string width(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string height(const abstract::Document *, + ElementIdentifier) const final; + + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Line final : public Element, public abstract::Line { public: - explicit Line(pugi::xml_node node); - - [[nodiscard]] std::string x1(const abstract::Document *document) const final; - [[nodiscard]] std::string y1(const abstract::Document *document) const final; - [[nodiscard]] std::string x2(const abstract::Document *document) const final; - [[nodiscard]] std::string y2(const abstract::Document *document) const final; - - [[nodiscard]] GraphicStyle - style(const abstract::Document *document) const final; + explicit Line(pugi::xml_node); + + [[nodiscard]] std::string x1(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string y1(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string x2(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string y2(const abstract::Document *, + ElementIdentifier) const final; + + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Circle final : public Element, public abstract::Circle { public: - explicit Circle(pugi::xml_node node); - - [[nodiscard]] std::string x(const abstract::Document *document) const final; - [[nodiscard]] std::string y(const abstract::Document *document) const final; - [[nodiscard]] std::string - width(const abstract::Document *document) const final; - [[nodiscard]] std::string - height(const abstract::Document *document) const final; - - [[nodiscard]] GraphicStyle - style(const abstract::Document *document) const final; + explicit Circle(pugi::xml_node); + + [[nodiscard]] std::string x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string width(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string height(const abstract::Document *, + ElementIdentifier) const final; + + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class CustomShape final : public Element, public abstract::CustomShape { public: - explicit CustomShape(pugi::xml_node node); - - [[nodiscard]] std::optional - x(const abstract::Document *document) const final; - [[nodiscard]] std::optional - y(const abstract::Document *document) const final; - [[nodiscard]] std::string - width(const abstract::Document *document) const final; - [[nodiscard]] std::string - height(const abstract::Document *document) const final; - - [[nodiscard]] GraphicStyle - style(const abstract::Document *document) const final; + explicit CustomShape(pugi::xml_node); + + [[nodiscard]] std::optional x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string width(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::string height(const abstract::Document *, + ElementIdentifier) const final; + + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Image final : public Element, public abstract::Image { public: - explicit Image(pugi::xml_node node); + explicit Image(pugi::xml_node); - [[nodiscard]] bool internal(const abstract::Document *document) const final; + [[nodiscard]] bool internal(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::optional - file(const abstract::Document *document) const final; + [[nodiscard]] std::optional file(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::string - href(const abstract::Document *document) const final; + [[nodiscard]] std::string href(const abstract::Document *, + ElementIdentifier) const final; }; } // namespace odr::internal::odf diff --git a/src/odr/internal/odf/odf_spreadsheet.cpp b/src/odr/internal/odf/odf_spreadsheet.cpp index 86756e4b..0e402bf4 100644 --- a/src/odr/internal/odf/odf_spreadsheet.cpp +++ b/src/odr/internal/odf/odf_spreadsheet.cpp @@ -15,8 +15,8 @@ class SheetColumn final : public Element, public abstract::TableColumn { explicit SheetColumn(pugi::xml_node node) : common::Element(node), Element(node) {} - [[nodiscard]] TableColumnStyle - style(const abstract::Document *document) const final { + [[nodiscard]] TableColumnStyle style(const abstract::Document *document, + ElementIdentifier) const final { return partial_style(document).table_column_style; } }; @@ -26,8 +26,8 @@ class SheetRow final : public Element, public abstract::TableRow { explicit SheetRow(pugi::xml_node node) : common::Element(node), Element(node) {} - [[nodiscard]] TableRowStyle - style(const abstract::Document *document) const final { + [[nodiscard]] TableRowStyle style(const abstract::Document *document, + ElementIdentifier) const final { return partial_style(document).table_row_style; } }; @@ -37,19 +37,19 @@ class SheetCell final : public Element, public abstract::TableCell { explicit SheetCell(pugi::xml_node node) : common::Element(node), Element(node) {} - [[nodiscard]] bool - covered(const abstract::Document * /*document*/) const final { + [[nodiscard]] bool covered(const abstract::Document *, + ElementIdentifier) const final { return std::strcmp(m_node.name(), "table:covered-table-cell") == 0; } - [[nodiscard]] TableDimensions - span(const abstract::Document * /*document*/) const final { + [[nodiscard]] TableDimensions span(const abstract::Document *, + ElementIdentifier) const final { return {m_node.attribute("table:number-rows-spanned").as_uint(1), m_node.attribute("table:number-columns-spanned").as_uint(1)}; } - [[nodiscard]] ValueType - value_type(const abstract::Document * /*document*/) const final { + [[nodiscard]] ValueType value_type(const abstract::Document *, + ElementIdentifier) const final { auto value_type = m_node.attribute("office:value-type").value(); if (std::strcmp("float", value_type) == 0) { return ValueType::float_number; @@ -57,8 +57,8 @@ class SheetCell final : public Element, public abstract::TableCell { return ValueType::string; } - [[nodiscard]] TableCellStyle - style(const abstract::Document *document) const final { + [[nodiscard]] TableCellStyle style(const abstract::Document *document, + ElementIdentifier) const final { return partial_style(document).table_cell_style; } }; @@ -71,17 +71,17 @@ SpreadsheetRoot::SpreadsheetRoot(pugi::xml_node node) Sheet::Sheet(pugi::xml_node node) : common::Element(node), Element(node), common::Sheet(node) {} -std::string Sheet::name(const abstract::Document * /*document*/) const { +std::string Sheet::name(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("table:name").value(); } -TableDimensions -Sheet::dimensions(const abstract::Document * /*document*/) const { +TableDimensions Sheet::dimensions(const abstract::Document *, + ElementIdentifier) const { return m_dimensions; } TableDimensions -Sheet::content(const abstract::Document * /*document*/, +Sheet::content(const abstract::Document *, ElementIdentifier, const std::optional range) const { TableDimensions result; @@ -113,8 +113,8 @@ Sheet::content(const abstract::Document * /*document*/, return result; } -abstract::Element *Sheet::column(const abstract::Document * /*document*/, - std::uint32_t column) const { +abstract::Element *Sheet::column(const abstract::Document *, ElementIdentifier, + ColumnIndex column) const { if (auto it = util::map::lookup_greater_than(m_columns, column); it != std::end(m_columns)) { return it->second; @@ -122,8 +122,8 @@ abstract::Element *Sheet::column(const abstract::Document * /*document*/, return nullptr; } -abstract::Element *Sheet::row(const abstract::Document * /*document*/, - std::uint32_t row) const { +abstract::Element *Sheet::row(const abstract::Document *, ElementIdentifier, + RowIndex row) const { if (auto it = util::map::lookup_greater_than(m_rows, row); it != std::end(m_rows)) { return it->second.element; @@ -131,8 +131,8 @@ abstract::Element *Sheet::row(const abstract::Document * /*document*/, return nullptr; } -abstract::Element *Sheet::cell(const abstract::Document * /*document*/, - std::uint32_t column, std::uint32_t row) const { +abstract::Element *Sheet::cell(const abstract::Document *, ElementIdentifier, + ColumnIndex column, RowIndex row) const { if (auto row_it = util::map::lookup_greater_than(m_rows, row); row_it != std::end(m_rows)) { auto &cells = row_it->second.cells; @@ -145,30 +145,30 @@ abstract::Element *Sheet::cell(const abstract::Document * /*document*/, return nullptr; } -abstract::Element * -Sheet::first_shape(const abstract::Document * /*document*/) const { +abstract::Element *Sheet::first_shape(const abstract::Document *, + ElementIdentifier) const { return m_first_shape; } -TableStyle Sheet::style(const abstract::Document *document) const { +TableStyle Sheet::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_style; } -void Sheet::init_column(std::uint32_t column, std::uint32_t repeated, +void Sheet::init_column(ColumnIndex column, std::uint32_t repeated, Element *element) { init_child(element); m_columns[column + repeated] = element; } -void Sheet::init_row(std::uint32_t row, std::uint32_t repeated, - Element *element) { +void Sheet::init_row(RowIndex row, std::uint32_t repeated, Element *element) { init_child(element); m_rows[row + repeated].element = element; } -void Sheet::init_cell(std::uint32_t column, std::uint32_t row, +void Sheet::init_cell(ColumnIndex column, RowIndex row, std::uint32_t columns_repeated, std::uint32_t rows_repeated, Element *element) { init_child(element); diff --git a/src/odr/internal/odf/odf_spreadsheet.hpp b/src/odr/internal/odf/odf_spreadsheet.hpp index 1ac50bd2..c7df998e 100644 --- a/src/odr/internal/odf/odf_spreadsheet.hpp +++ b/src/odr/internal/odf/odf_spreadsheet.hpp @@ -27,29 +27,30 @@ class Sheet final : public Element, public common::Sheet { public: explicit Sheet(pugi::xml_node node); - [[nodiscard]] std::string - name(const abstract::Document *document) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions - dimensions(const abstract::Document *document) const final; + [[nodiscard]] TableDimensions dimensions(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] TableDimensions - content(const abstract::Document *document, + content(const abstract::Document *, ElementIdentifier, const std::optional range) const final; - [[nodiscard]] abstract::Element *column(const abstract::Document *document, - std::uint32_t column) const final; - [[nodiscard]] abstract::Element *row(const abstract::Document *document, - std::uint32_t row) const final; - [[nodiscard]] abstract::Element *cell(const abstract::Document *document, - std::uint32_t column, - std::uint32_t row) const final; - + [[nodiscard]] abstract::Element *column(const abstract::Document *, + ElementIdentifier, + ColumnIndex column) const final; [[nodiscard]] abstract::Element * - first_shape(const abstract::Document *document) const final; + row(const abstract::Document *, ElementIdentifier, RowIndex row) const final; + [[nodiscard]] abstract::Element *cell(const abstract::Document *, + ElementIdentifier, ColumnIndex column, + RowIndex row) const final; + + [[nodiscard]] abstract::Element *first_shape(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableStyle style(const abstract::Document *, + ElementIdentifier) const final; void init_column(std::uint32_t column, std::uint32_t repeated, Element *element); diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp index 3b015f9a..ba5ab2e8 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp @@ -36,15 +36,17 @@ pugi::xml_node Element::slide_(const abstract::Document *document, return document_(document)->m_slides_xml.at(id).document_element(); } -PageLayout Slide::page_layout(const abstract::Document *) const { +PageLayout Slide::page_layout(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -abstract::MasterPage *Slide::master_page(const abstract::Document *) const { +abstract::MasterPage *Slide::master_page(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -std::string Slide::name(const abstract::Document *) const { +std::string Slide::name(const abstract::Document *, ElementIdentifier) const { return {}; // TODO } @@ -52,15 +54,18 @@ pugi::xml_node Slide::slide_node_(const abstract::Document *document) const { return slide_(document, m_node.attribute("r:id").value()); } -ParagraphStyle Paragraph::style(const abstract::Document *document) const { +ParagraphStyle Paragraph::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).paragraph_style; } -TextStyle Paragraph::text_style(const abstract::Document *document) const { +TextStyle Paragraph::text_style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).text_style; } -TextStyle Span::style(const abstract::Document *document) const { +TextStyle Span::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).text_style; } @@ -69,7 +74,7 @@ Text::Text(pugi::xml_node node) : Text(node, node) {} Text::Text(pugi::xml_node first, pugi::xml_node last) : Element(first), m_last{last} {} -std::string Text::content(const abstract::Document *) const { +std::string Text::content(const abstract::Document *, ElementIdentifier) const { std::string result; for (auto node = m_node; node != m_last.next_sibling(); node = node.next_sibling()) { @@ -78,11 +83,13 @@ std::string Text::content(const abstract::Document *) const { return result; } -void Text::set_content(const abstract::Document *, const std::string &) { +void Text::set_content(const abstract::Document *, ElementIdentifier, + const std::string &) { // TODO } -TextStyle Text::style(const abstract::Document *document) const { +TextStyle Text::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).text_style; } @@ -99,50 +106,62 @@ std::string Text::text_(const pugi::xml_node node) { return ""; } -TableDimensions TableElement::dimensions(const abstract::Document *) const { +TableDimensions TableElement::dimensions(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -abstract::Element * -TableElement::first_column(const abstract::Document *) const { +abstract::Element *TableElement::first_column(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -abstract::Element *TableElement::first_row(const abstract::Document *) const { +abstract::Element *TableElement::first_row(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -TableStyle TableElement::style(const abstract::Document *document) const { +TableStyle TableElement::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_style; } -TableColumnStyle TableColumn::style(const abstract::Document *document) const { +TableColumnStyle TableColumn::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_column_style; } -TableRowStyle TableRow::style(const abstract::Document *document) const { +TableRowStyle TableRow::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_row_style; } -bool TableCell::covered(const abstract::Document *) const { return false; } +bool TableCell::covered(const abstract::Document *, ElementIdentifier) const { + return false; +} -TableDimensions TableCell::span(const abstract::Document *) const { +TableDimensions TableCell::span(const abstract::Document *, + ElementIdentifier) const { return {1, 1}; // TODO } -ValueType TableCell::value_type(const abstract::Document *) const { +ValueType TableCell::value_type(const abstract::Document *, + ElementIdentifier) const { return ValueType::string; } -TableCellStyle TableCell::style(const abstract::Document *document) const { +TableCellStyle TableCell::style(const abstract::Document *document, + ElementIdentifier) const { return partial_style(document).table_cell_style; } -AnchorType Frame::anchor_type(const abstract::Document *) const { +AnchorType Frame::anchor_type(const abstract::Document *, + ElementIdentifier) const { return AnchorType::at_page; } -std::optional Frame::x(const abstract::Document *) const { +std::optional Frame::x(const abstract::Document *, + ElementIdentifier) const { if (auto x = read_emus_attribute( m_node.child("p:spPr").child("a:xfrm").child("a:off").attribute( "x"))) { @@ -151,7 +170,8 @@ std::optional Frame::x(const abstract::Document *) const { return {}; } -std::optional Frame::y(const abstract::Document *) const { +std::optional Frame::y(const abstract::Document *, + ElementIdentifier) const { if (auto y = read_emus_attribute( m_node.child("p:spPr").child("a:xfrm").child("a:off").attribute( "y"))) { @@ -160,7 +180,8 @@ std::optional Frame::y(const abstract::Document *) const { return {}; } -std::optional Frame::width(const abstract::Document *) const { +std::optional Frame::width(const abstract::Document *, + ElementIdentifier) const { if (auto cx = read_emus_attribute( m_node.child("p:spPr").child("a:xfrm").child("a:ext").attribute( "cx"))) { @@ -169,7 +190,8 @@ std::optional Frame::width(const abstract::Document *) const { return {}; } -std::optional Frame::height(const abstract::Document *) const { +std::optional Frame::height(const abstract::Document *, + ElementIdentifier) const { if (auto cy = read_emus_attribute( m_node.child("p:spPr").child("a:xfrm").child("a:ext").attribute( "cy"))) { @@ -178,21 +200,27 @@ std::optional Frame::height(const abstract::Document *) const { return {}; } -std::optional Frame::z_index(const abstract::Document *) const { +std::optional Frame::z_index(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -GraphicStyle Frame::style(const abstract::Document *) const { +GraphicStyle Frame::style(const abstract::Document *, ElementIdentifier) const { return {}; // TODO } -bool ImageElement::internal(const abstract::Document *) const { return false; } +bool ImageElement::internal(const abstract::Document *, + ElementIdentifier) const { + return false; +} -std::optional ImageElement::file(const abstract::Document *) const { +std::optional ImageElement::file(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -std::string ImageElement::href(const abstract::Document *) const { +std::string ImageElement::href(const abstract::Document *, + ElementIdentifier) const { return ""; // TODO } diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp index 32ebc45c..d5615d14 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp @@ -28,7 +28,8 @@ template class DefaultElement : public Element { public: using Element::Element; - [[nodiscard]] ElementType type(const abstract::Document *) const override { + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const override { return element_type; } }; @@ -42,14 +43,14 @@ class Slide final : public Element, public abstract::Slide { public: using Element::Element; - [[nodiscard]] PageLayout - page_layout(const abstract::Document *document) const final; + [[nodiscard]] PageLayout page_layout(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] abstract::MasterPage * - master_page(const abstract::Document *document) const final; + master_page(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] std::string - name(const abstract::Document *document) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; private: pugi::xml_node slide_node_(const abstract::Document *document) const; @@ -59,18 +60,19 @@ class Paragraph final : public Element, public abstract::Paragraph { public: using Element::Element; - [[nodiscard]] ParagraphStyle - style(const abstract::Document *document) const final; + [[nodiscard]] ParagraphStyle style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TextStyle - text_style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle text_style(const abstract::Document *, + ElementIdentifier) const final; }; class Span final : public Element, public abstract::Span { public: using Element::Element; - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Text final : public Element, public abstract::Text { @@ -78,13 +80,14 @@ class Text final : public Element, public abstract::Text { explicit Text(pugi::xml_node node); Text(pugi::xml_node first, pugi::xml_node last); - [[nodiscard]] std::string - content(const abstract::Document *document) const final; + [[nodiscard]] std::string content(const abstract::Document *, + ElementIdentifier) const final; - void set_content(const abstract::Document *document, + void set_content(const abstract::Document *, ElementIdentifier, const std::string &content); - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; private: static std::string text_(const pugi::xml_node node); @@ -96,85 +99,87 @@ class TableElement : public Element, public abstract::Table { public: using Element::Element; - [[nodiscard]] TableDimensions - dimensions(const abstract::Document *document) const final; + [[nodiscard]] TableDimensions dimensions(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] abstract::Element * - first_column(const abstract::Document *document) const final; + [[nodiscard]] abstract::Element *first_column(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] abstract::Element * - first_row(const abstract::Document *document) const final; + [[nodiscard]] abstract::Element *first_row(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableColumn final : public Element, public abstract::TableColumn { public: using Element::Element; - [[nodiscard]] TableColumnStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableColumnStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableRow final : public Element, public abstract::TableRow { public: using Element::Element; - [[nodiscard]] TableRowStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableRowStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableCell final : public Element, public abstract::TableCell { public: using Element::Element; - [[nodiscard]] bool covered(const abstract::Document *document) const final; + [[nodiscard]] bool covered(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions - span(const abstract::Document *document) const final; + [[nodiscard]] TableDimensions span(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] ValueType - value_type(const abstract::Document *document) const final; + [[nodiscard]] ValueType value_type(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableCellStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableCellStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Frame final : public Element, public abstract::Frame { public: using Element::Element; - [[nodiscard]] AnchorType - anchor_type(const abstract::Document *document) const final; + [[nodiscard]] AnchorType anchor_type(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional width(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] std::optional - x(const abstract::Document *document) const final; - [[nodiscard]] std::optional - y(const abstract::Document *document) const final; - [[nodiscard]] std::optional - width(const abstract::Document *document) const final; - [[nodiscard]] std::optional - height(const abstract::Document *document) const final; + height(const abstract::Document *, ElementIdentifier) const final; [[nodiscard]] std::optional - z_index(const abstract::Document *document) const final; + z_index(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] GraphicStyle - style(const abstract::Document *document) const final; + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class ImageElement final : public Element, public abstract::Image { public: using Element::Element; - [[nodiscard]] bool internal(const abstract::Document *document) const final; + [[nodiscard]] bool internal(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::optional - file(const abstract::Document *document) const final; + [[nodiscard]] std::optional file(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::string - href(const abstract::Document *document) const final; + [[nodiscard]] std::string href(const abstract::Document *, + ElementIdentifier) const final; }; } // namespace odr::internal::ooxml::presentation diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp index b1ffd5a8..4840c98d 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp @@ -21,17 +21,20 @@ namespace odr::internal::ooxml::spreadsheet { Element::Element(pugi::xml_node node) : common::Element(node) {} -common::ResolvedStyle Element::partial_style(const abstract::Document *) const { +common::ResolvedStyle Element::partial_style(const abstract::Document *, + ElementIdentifier) const { return {}; } common::ResolvedStyle -Element::intermediate_style(const abstract::Document *document) const { +Element::intermediate_style(const abstract::Document *document, + ElementIdentifier elementId) const { if (m_parent == nullptr) { - return partial_style(document); + return partial_style(document, elementId); } - auto base = dynamic_cast(m_parent)->intermediate_style(document); - base.override(partial_style(document)); + auto base = dynamic_cast(m_parent)->intermediate_style(document, + elementId); + base.override(partial_style(document, elementId)); return base; } @@ -59,15 +62,16 @@ Element::shared_strings_(const abstract::Document *document) { return document_(document)->m_shared_strings; } -ElementType Sheet::type(const abstract::Document *) const { +ElementType Sheet::type(const abstract::Document *, ElementIdentifier) const { return ElementType::sheet; } -std::string Sheet::name(const abstract::Document *) const { +std::string Sheet::name(const abstract::Document *, ElementIdentifier) const { return m_node.attribute("name").value(); } -TableDimensions Sheet::dimensions(const abstract::Document *document) const { +TableDimensions Sheet::dimensions(const abstract::Document *document, + ElementIdentifier) const { if (auto dimension = sheet_node_(document).child("dimension").attribute("ref")) { try { @@ -80,33 +84,34 @@ TableDimensions Sheet::dimensions(const abstract::Document *document) const { } TableDimensions Sheet::content(const abstract::Document *document, + ElementIdentifier elementId, std::optional) const { - return dimensions(document); // TODO + return dimensions(document, elementId); // TODO } -abstract::Element *Sheet::column(const abstract::Document * /*document*/, - std::uint32_t /*column*/) const { +abstract::Element *Sheet::column(const abstract::Document *, ElementIdentifier, + ColumnIndex) const { return nullptr; // TODO } -abstract::Element *Sheet::row(const abstract::Document * /*document*/, - std::uint32_t /*row*/) const { +abstract::Element *Sheet::row(const abstract::Document *, ElementIdentifier, + RowIndex) const { return nullptr; // TODO } -abstract::Element *Sheet::cell(const abstract::Document * /*document*/, - std::uint32_t /*column*/, - std::uint32_t /*row*/) const { +abstract::Element *Sheet::cell(const abstract::Document *, ElementIdentifier, + ColumnIndex /*column*/, RowIndex /*row*/) const { return nullptr; // TODO } -abstract::Element * -Sheet::first_shape(const abstract::Document * /*document*/) const { +abstract::Element *Sheet::first_shape(const abstract::Document *, + ElementIdentifier) const { return nullptr; // TODO } -TableStyle Sheet::style(const abstract::Document *document) const { - return partial_style(document).table_style; +TableStyle Sheet::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return partial_style(document, elementId).table_style; } pugi::xml_node Sheet::sheet_node_(const abstract::Document *document) const { return sheet_(document, m_node.attribute("r:id").value()); @@ -116,7 +121,8 @@ pugi::xml_node Sheet::drawing_node_(const abstract::Document *document) const { return drawing_(document, m_node.attribute("r:id").value()); } -TableColumnStyle TableColumn::style(const abstract::Document *) const { +TableColumnStyle TableColumn::style(const abstract::Document *, + ElementIdentifier) const { TableColumnStyle result; if (auto width = m_node.attribute("width")) { result.width = Measure(width.as_float(), DynamicUnit("ch")); @@ -132,7 +138,8 @@ TableColumnStyle TableColumn::style(const abstract::Document *) const { return m_node.attribute("min").as_uint() - 1; } -TableRowStyle TableRow::style(const abstract::Document * /*document*/) const { +TableRowStyle TableRow::style(const abstract::Document *, + ElementIdentifier) const { TableRowStyle result; if (auto height = m_node.attribute("ht")) { result.height = Measure(height.as_float(), DynamicUnit("pt")); @@ -140,32 +147,37 @@ TableRowStyle TableRow::style(const abstract::Document * /*document*/) const { return result; } -bool TableCell::covered(const abstract::Document * /*document*/) const { +bool TableCell::covered(const abstract::Document *, ElementIdentifier) const { return false; // TODO } -ValueType TableCell::value_type(const abstract::Document * /*document*/) const { +ValueType TableCell::value_type(const abstract::Document *, + ElementIdentifier) const { return ValueType::string; } common::ResolvedStyle -TableCell::partial_style(const abstract::Document *document) const { +TableCell::partial_style(const abstract::Document *document, + ElementIdentifier) const { if (auto id = m_node.attribute("s")) { return style_registry_(document)->cell_style(id.as_uint()); } return {}; } -TableDimensions TableCell::span(const abstract::Document * /*document*/) const { +TableDimensions TableCell::span(const abstract::Document *, + ElementIdentifier) const { return {1, 1}; } -TableCellStyle TableCell::style(const abstract::Document *document) const { - return partial_style(document).table_cell_style; +TableCellStyle TableCell::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return partial_style(document, elementId).table_cell_style; } -TextStyle Span::style(const abstract::Document *document) const { - return intermediate_style(document).text_style; +TextStyle Span::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).text_style; } Text::Text(pugi::xml_node node) : Text(node, node) {} @@ -173,7 +185,7 @@ Text::Text(pugi::xml_node node) : Text(node, node) {} Text::Text(pugi::xml_node first, pugi::xml_node last) : Element(first), m_last{last} {} -std::string Text::content(const abstract::Document * /*document*/) const { +std::string Text::content(const abstract::Document *, ElementIdentifier) const { std::string result; for (auto node = m_node; node != m_last.next_sibling(); node = node.next_sibling()) { @@ -182,13 +194,14 @@ std::string Text::content(const abstract::Document * /*document*/) const { return result; } -void Text::set_content(const abstract::Document * /*document*/, - const std::string & /*text*/) { +void Text::set_content(const abstract::Document *, ElementIdentifier, + const std::string &) { // TODO } -TextStyle Text::style(const abstract::Document *document) const { - return intermediate_style(document).text_style; +TextStyle Text::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).text_style; } std::string Text::text_(const pugi::xml_node node) { @@ -201,12 +214,13 @@ std::string Text::text_(const pugi::xml_node node) { return ""; } -AnchorType Frame::anchor_type(const abstract::Document * /*document*/) const { +AnchorType Frame::anchor_type(const abstract::Document *, + ElementIdentifier) const { return AnchorType::at_page; } -std::optional -Frame::x(const abstract::Document * /*document*/) const { +std::optional Frame::x(const abstract::Document *, + ElementIdentifier) const { if (auto x = read_emus_attribute(m_node.child("xdr:pic") .child("xdr:spPr") .child("a:xfrm") @@ -217,8 +231,8 @@ Frame::x(const abstract::Document * /*document*/) const { return {}; } -std::optional -Frame::y(const abstract::Document * /*document*/) const { +std::optional Frame::y(const abstract::Document *, + ElementIdentifier) const { if (auto y = read_emus_attribute(m_node.child("xdr:pic") .child("xdr:spPr") .child("a:xfrm") @@ -229,8 +243,8 @@ Frame::y(const abstract::Document * /*document*/) const { return {}; } -std::optional -Frame::width(const abstract::Document * /*document*/) const { +std::optional Frame::width(const abstract::Document *, + ElementIdentifier) const { if (auto width = read_emus_attribute(m_node.child("xdr:pic") .child("xdr:spPr") .child("a:xfrm") @@ -241,8 +255,8 @@ Frame::width(const abstract::Document * /*document*/) const { return {}; } -std::optional -Frame::height(const abstract::Document * /*document*/) const { +std::optional Frame::height(const abstract::Document *, + ElementIdentifier) const { if (auto height = read_emus_attribute(m_node.child("xdr:pic") .child("xdr:spPr") .child("a:xfrm") @@ -253,37 +267,39 @@ Frame::height(const abstract::Document * /*document*/) const { return {}; } -std::optional -Frame::z_index(const abstract::Document * /*document*/) const { +std::optional Frame::z_index(const abstract::Document *, + ElementIdentifier) const { return {}; } -GraphicStyle Frame::style(const abstract::Document * /*document*/) const { +GraphicStyle Frame::style(const abstract::Document *, ElementIdentifier) const { return {}; } -bool ImageElement::internal(const abstract::Document *document) const { +bool ImageElement::internal(const abstract::Document *document, + ElementIdentifier elementId) const { auto doc = document_(document); if (!doc || !doc->files()) { return false; } try { - return doc->files()->is_file(href(document)); + return doc->files()->is_file(href(document, elementId)); } catch (...) { } return false; } -std::optional -ImageElement::file(const abstract::Document *document) const { +std::optional ImageElement::file(const abstract::Document *document, + ElementIdentifier elementId) const { auto doc = document_(document); - if (!doc || !internal(document)) { + if (!doc || !internal(document, elementId)) { return {}; } - return File(doc->files()->open(href(document))); + return File(doc->files()->open(href(document, elementId))); } -std::string ImageElement::href(const abstract::Document * /*document*/) const { +std::string ImageElement::href(const abstract::Document *, + ElementIdentifier) const { if (auto ref = m_node.attribute("r:embed")) { /* TODO auto relations = document_relations_(document); diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp index 79fbcaff..6c885477 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp @@ -18,28 +18,28 @@ class Element : public common::Element { public: explicit Element(pugi::xml_node node); - virtual common::ResolvedStyle - partial_style(const abstract::Document *document) const; - common::ResolvedStyle - intermediate_style(const abstract::Document *document) const; + virtual common::ResolvedStyle partial_style(const abstract::Document *, + ElementIdentifier) const; + common::ResolvedStyle intermediate_style(const abstract::Document *, + ElementIdentifier) const; protected: - static const Document *document_(const abstract::Document *document); - static const StyleRegistry * - style_registry_(const abstract::Document *document); - static pugi::xml_node sheet_(const abstract::Document *document, + static const Document *document_(const abstract::Document *); + static const StyleRegistry *style_registry_(const abstract::Document *); + static pugi::xml_node sheet_(const abstract::Document *, const std::string &id); - static pugi::xml_node drawing_(const abstract::Document *document, + static pugi::xml_node drawing_(const abstract::Document *, const std::string &id); static const std::vector & - shared_strings_(const abstract::Document *document); + shared_strings_(const abstract::Document *); }; template class DefaultElement : public Element { public: using Element::Element; - [[nodiscard]] ElementType type(const abstract::Document *) const override { + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const override { return element_type; } }; @@ -53,44 +53,45 @@ class Sheet final : public Element, public abstract::Sheet { public: using Element::Element; - [[nodiscard]] ElementType - type(const abstract::Document *document) const final; + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::string - name(const abstract::Document *document) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions - dimensions(const abstract::Document *document) const final; + [[nodiscard]] TableDimensions dimensions(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] TableDimensions - content(const abstract::Document *document, + content(const abstract::Document *, ElementIdentifier, std::optional) const final; - [[nodiscard]] abstract::Element *column(const abstract::Document *document, - std::uint32_t column) const final; - [[nodiscard]] abstract::Element *row(const abstract::Document *document, - std::uint32_t row) const final; - [[nodiscard]] abstract::Element *cell(const abstract::Document *document, - std::uint32_t column, - std::uint32_t row) const final; - + [[nodiscard]] abstract::Element *column(const abstract::Document *, + ElementIdentifier, + ColumnIndex column) const final; [[nodiscard]] abstract::Element * - first_shape(const abstract::Document *document) const final; + row(const abstract::Document *, ElementIdentifier, RowIndex row) const final; + [[nodiscard]] abstract::Element *cell(const abstract::Document *, + ElementIdentifier, ColumnIndex column, + RowIndex row) const final; + + [[nodiscard]] abstract::Element *first_shape(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableStyle style(const abstract::Document *, + ElementIdentifier) const final; private: - pugi::xml_node sheet_node_(const abstract::Document *document) const; - pugi::xml_node drawing_node_(const abstract::Document *document) const; + pugi::xml_node sheet_node_(const abstract::Document *) const; + pugi::xml_node drawing_node_(const abstract::Document *) const; }; class TableColumn final : public Element, public abstract::TableColumn { public: using Element::Element; - [[nodiscard]] TableColumnStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableColumnStyle style(const abstract::Document *, + ElementIdentifier) const final; private: [[nodiscard]] std::uint32_t min_() const; @@ -101,32 +102,36 @@ class TableRow final : public Element, public abstract::TableRow { public: using Element::Element; - [[nodiscard]] TableRowStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableRowStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableCell final : public Element, public abstract::TableCell { public: using Element::Element; - [[nodiscard]] bool covered(const abstract::Document *) const final; + [[nodiscard]] bool covered(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions span(const abstract::Document *) const final; + [[nodiscard]] TableDimensions span(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] ValueType value_type(const abstract::Document *) const final; + [[nodiscard]] ValueType value_type(const abstract::Document *, + ElementIdentifier) const final; - common::ResolvedStyle - partial_style(const abstract::Document *document) const final; + common::ResolvedStyle partial_style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableCellStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableCellStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Span final : public Element, public abstract::Span { public: using Element::Element; - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Text final : public Element, public abstract::Text { @@ -134,11 +139,14 @@ class Text final : public Element, public abstract::Text { explicit Text(pugi::xml_node node); Text(pugi::xml_node first, pugi::xml_node last); - [[nodiscard]] std::string content(const abstract::Document *) const final; + [[nodiscard]] std::string content(const abstract::Document *, + ElementIdentifier) const final; - void set_content(const abstract::Document *, const std::string &) final; + void set_content(const abstract::Document *, ElementIdentifier, + const std::string &) final; - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; private: static std::string text_(const pugi::xml_node node); @@ -150,33 +158,37 @@ class Frame final : public Element, public abstract::Frame { public: using Element::Element; - [[nodiscard]] AnchorType anchor_type(const abstract::Document *) const final; + [[nodiscard]] AnchorType anchor_type(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional width(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] std::optional - x(const abstract::Document *) const final; - [[nodiscard]] std::optional - y(const abstract::Document *) const final; - [[nodiscard]] std::optional - width(const abstract::Document *) const final; - [[nodiscard]] std::optional - height(const abstract::Document *) const final; + height(const abstract::Document *, ElementIdentifier) const final; [[nodiscard]] std::optional - z_index(const abstract::Document *) const final; + z_index(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] GraphicStyle style(const abstract::Document *) const final; + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class ImageElement final : public Element, public abstract::Image { public: using Element::Element; - [[nodiscard]] bool internal(const abstract::Document *document) const final; + [[nodiscard]] bool internal(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::optional - file(const abstract::Document *document) const final; + [[nodiscard]] std::optional file(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::string href(const abstract::Document *) const final; + [[nodiscard]] std::string href(const abstract::Document *, + ElementIdentifier) const final; }; } // namespace odr::internal::ooxml::spreadsheet diff --git a/src/odr/internal/ooxml/text/ooxml_text_element.cpp b/src/odr/internal/ooxml/text/ooxml_text_element.cpp index be6fc129..1c6fa4e6 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_element.cpp +++ b/src/odr/internal/ooxml/text/ooxml_text_element.cpp @@ -23,19 +23,22 @@ namespace odr::internal::ooxml::text { Element::Element(pugi::xml_node node) : common::Element(node) {} -common::ResolvedStyle Element::partial_style(const abstract::Document *) const { +common::ResolvedStyle Element::partial_style(const abstract::Document *, + ElementIdentifier) const { return {}; } common::ResolvedStyle -Element::intermediate_style(const abstract::Document *document) const { +Element::intermediate_style(const abstract::Document *document, + ElementIdentifier elementId) const { common::ResolvedStyle base; if (m_parent == nullptr) { base = style_(document)->default_style()->resolved(); } else { - base = dynamic_cast(m_parent)->intermediate_style(document); + base = dynamic_cast(m_parent)->intermediate_style(document, + elementId); } - base.override(partial_style(document)); + base.override(partial_style(document, elementId)); return base; } @@ -54,12 +57,13 @@ Element::document_relations_(const abstract::Document *document) { Root::Root(pugi::xml_node node) : common::Element(node), Element(node) {} -PageLayout Root::page_layout(const abstract::Document * /*document*/) const { +PageLayout Root::page_layout(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -abstract::MasterPage * -Root::first_master_page(const abstract::Document * /*document*/) const { +abstract::MasterPage *Root::first_master_page(const abstract::Document *, + ElementIdentifier) const { return nullptr; // TODO } @@ -67,27 +71,31 @@ Paragraph::Paragraph(pugi::xml_node node) : common::Element(node), Element(node) {} common::ResolvedStyle -Paragraph::partial_style(const abstract::Document *document) const { +Paragraph::partial_style(const abstract::Document *document, + ElementIdentifier) const { return style_(document)->partial_paragraph_style(m_node); } -ParagraphStyle Paragraph::style(const abstract::Document *document) const { - return intermediate_style(document).paragraph_style; +ParagraphStyle Paragraph::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).paragraph_style; } -TextStyle Paragraph::text_style(const abstract::Document *document) const { - return intermediate_style(document).text_style; +TextStyle Paragraph::text_style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).text_style; } Span::Span(pugi::xml_node node) : common::Element(node), Element(node) {} -common::ResolvedStyle -Span::partial_style(const abstract::Document *document) const { +common::ResolvedStyle Span::partial_style(const abstract::Document *document, + ElementIdentifier) const { return style_(document)->partial_text_style(m_node); } -TextStyle Span::style(const abstract::Document *document) const { - return intermediate_style(document).text_style; +TextStyle Span::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).text_style; } std::string Text::text(const pugi::xml_node node) { @@ -113,7 +121,7 @@ Text::Text(pugi::xml_node first, pugi::xml_node last) } } -std::string Text::content(const abstract::Document *) const { +std::string Text::content(const abstract::Document *, ElementIdentifier) const { std::string result; for (auto node = m_node; node != m_last.next_sibling(); node = node.next_sibling()) { @@ -122,7 +130,8 @@ std::string Text::content(const abstract::Document *) const { return result; } -void Text::set_content(const abstract::Document *, const std::string &text) { +void Text::set_content(const abstract::Document *, ElementIdentifier, + const std::string &text) { // TODO http://officeopenxml.com/WPtextSpacing.php // // use `xml:space` @@ -158,13 +167,15 @@ void Text::set_content(const abstract::Document *, const std::string &text) { // TODO remove other } -TextStyle Text::style(const abstract::Document *document) const { - return intermediate_style(document).text_style; +TextStyle Text::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).text_style; } Link::Link(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Link::href(const abstract::Document *document) const { +std::string Link::href(const abstract::Document *document, + ElementIdentifier) const { if (auto anchor = m_node.attribute("w:anchor")) { return std::string("#") + anchor.value(); } @@ -180,38 +191,43 @@ std::string Link::href(const abstract::Document *document) const { Bookmark::Bookmark(pugi::xml_node node) : common::Element(node), Element(node) {} -std::string Bookmark::name(const abstract::Document *) const { +std::string Bookmark::name(const abstract::Document *, + ElementIdentifier) const { return m_node.attribute("w:name").value(); } List::List(pugi::xml_node node) : common::Element(node), Element(node) {} -ElementType List::type(const abstract::Document *) const { +ElementType List::type(const abstract::Document *, ElementIdentifier) const { return ElementType::list; } ListItem::ListItem(pugi::xml_node node) : common::Element(node), Element(node) {} -TextStyle ListItem::style(const abstract::Document *document) const { - return intermediate_style(document).text_style; +TextStyle ListItem::style(const abstract::Document *document, + ElementIdentifier elementId) const { + return intermediate_style(document, elementId).text_style; } Table::Table(pugi::xml_node node) : common::Element(node), Element(node), common::Table(node) {} -TableDimensions Table::dimensions(const abstract::Document *) const { +TableDimensions Table::dimensions(const abstract::Document *, + ElementIdentifier) const { return {}; // TODO } -TableStyle Table::style(const abstract::Document *document) const { +TableStyle Table::style(const abstract::Document *document, + ElementIdentifier) const { return style_(document)->partial_table_style(m_node).table_style; } TableColumn::TableColumn(pugi::xml_node node) : common::Element(node), Element(node) {} -TableColumnStyle TableColumn::style(const abstract::Document *) const { +TableColumnStyle TableColumn::style(const abstract::Document *, + ElementIdentifier) const { TableColumnStyle result; if (auto width = read_twips_attribute(m_node.attribute("w:w"))) { result.width = width; @@ -222,45 +238,55 @@ TableColumnStyle TableColumn::style(const abstract::Document *) const { TableRow::TableRow(pugi::xml_node node) : common::Element(node), Element(node) {} -TableRowStyle TableRow::style(const abstract::Document *document) const { +TableRowStyle TableRow::style(const abstract::Document *document, + ElementIdentifier) const { return style_(document)->partial_table_row_style(m_node).table_row_style; } TableCell::TableCell(pugi::xml_node node) : common::Element(node), Element(node) {} -bool TableCell::covered(const abstract::Document *) const { return false; } +bool TableCell::covered(const abstract::Document *, ElementIdentifier) const { + return false; +} -TableDimensions TableCell::span(const abstract::Document *) const { +TableDimensions TableCell::span(const abstract::Document *, + ElementIdentifier) const { return {1, 1}; } -ValueType TableCell::value_type(const abstract::Document *) const { +ValueType TableCell::value_type(const abstract::Document *, + ElementIdentifier) const { return ValueType::string; } -TableCellStyle TableCell::style(const abstract::Document *document) const { +TableCellStyle TableCell::style(const abstract::Document *document, + ElementIdentifier) const { return style_(document)->partial_table_cell_style(m_node).table_cell_style; } Frame::Frame(pugi::xml_node node) : common::Element(node), Element(node) {} -AnchorType Frame::anchor_type(const abstract::Document *) const { +AnchorType Frame::anchor_type(const abstract::Document *, + ElementIdentifier) const { if (m_node.child("wp:inline")) { return AnchorType::as_char; } return AnchorType::as_char; // TODO default? } -std::optional Frame::x(const abstract::Document *) const { +std::optional Frame::x(const abstract::Document *, + ElementIdentifier) const { return {}; } -std::optional Frame::y(const abstract::Document *) const { +std::optional Frame::y(const abstract::Document *, + ElementIdentifier) const { return {}; } -std::optional Frame::width(const abstract::Document *) const { +std::optional Frame::width(const abstract::Document *, + ElementIdentifier) const { if (auto width = read_emus_attribute( inner_node_().child("wp:extent").attribute("cx"))) { return width->to_string(); @@ -268,7 +294,8 @@ std::optional Frame::width(const abstract::Document *) const { return {}; } -std::optional Frame::height(const abstract::Document *) const { +std::optional Frame::height(const abstract::Document *, + ElementIdentifier) const { if (auto height = read_emus_attribute( inner_node_().child("wp:extent").attribute("cy"))) { return height->to_string(); @@ -276,11 +303,14 @@ std::optional Frame::height(const abstract::Document *) const { return {}; } -std::optional Frame::z_index(const abstract::Document *) const { +std::optional Frame::z_index(const abstract::Document *, + ElementIdentifier) const { return {}; } -GraphicStyle Frame::style(const abstract::Document *) const { return {}; } +GraphicStyle Frame::style(const abstract::Document *, ElementIdentifier) const { + return {}; +} pugi::xml_node Frame::inner_node_() const { if (auto anchor = m_node.child("wp:anchor")) { @@ -293,27 +323,30 @@ pugi::xml_node Frame::inner_node_() const { Image::Image(pugi::xml_node node) : common::Element(node), Element(node) {} -bool Image::internal(const abstract::Document *document) const { +bool Image::internal(const abstract::Document *document, + ElementIdentifier elementId) const { auto doc = document_(document); if (!doc || !doc->files()) { return false; } try { - return doc->files()->is_file(href(document)); + return doc->files()->is_file(href(document, elementId)); } catch (...) { } return false; } -std::optional Image::file(const abstract::Document *document) const { +std::optional Image::file(const abstract::Document *document, + ElementIdentifier elementId) const { auto doc = document_(document); - if (!doc || !internal(document)) { + if (!doc || !internal(document, elementId)) { return {}; } - return File(doc->files()->open(href(document))); + return File(doc->files()->open(href(document, elementId))); } -std::string Image::href(const abstract::Document *document) const { +std::string Image::href(const abstract::Document *document, + ElementIdentifier) const { if (auto ref = m_node.child("pic:pic") .child("pic:blipFill") .child("a:blip") diff --git a/src/odr/internal/ooxml/text/ooxml_text_element.hpp b/src/odr/internal/ooxml/text/ooxml_text_element.hpp index 0520d5cf..fd744eb9 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_element.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_element.hpp @@ -17,18 +17,18 @@ class Style; class Element : public virtual common::Element { public: - explicit Element(pugi::xml_node node); + explicit Element(pugi::xml_node); - virtual common::ResolvedStyle - partial_style(const abstract::Document *document) const; - virtual common::ResolvedStyle - intermediate_style(const abstract::Document *document) const; + virtual common::ResolvedStyle partial_style(const abstract::Document *, + ElementIdentifier) const; + virtual common::ResolvedStyle intermediate_style(const abstract::Document *, + ElementIdentifier) const; protected: - static const Document *document_(const abstract::Document *document); - static const StyleRegistry *style_(const abstract::Document *document); + static const Document *document_(const abstract::Document *); + static const StyleRegistry *style_(const abstract::Document *); static const std::unordered_map & - document_relations_(const abstract::Document *document); + document_relations_(const abstract::Document *); friend class Style; }; @@ -38,58 +38,63 @@ template class DefaultElement : public Element { explicit DefaultElement(pugi::xml_node node) : common::Element(node), Element(node) {} - [[nodiscard]] ElementType type(const abstract::Document *) const override { + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const override { return _element_type; } }; class Root final : public Element, public abstract::TextRoot { public: - explicit Root(pugi::xml_node node); + explicit Root(pugi::xml_node); - [[nodiscard]] PageLayout - page_layout(const abstract::Document *document) const final; + [[nodiscard]] PageLayout page_layout(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] abstract::MasterPage * - first_master_page(const abstract::Document *document) const final; + first_master_page(const abstract::Document *, ElementIdentifier) const final; }; class Paragraph : public Element, public abstract::Paragraph { public: - explicit Paragraph(pugi::xml_node node); + explicit Paragraph(pugi::xml_node); - common::ResolvedStyle - partial_style(const abstract::Document *document) const final; + common::ResolvedStyle partial_style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] ParagraphStyle - style(const abstract::Document *document) const final; + [[nodiscard]] ParagraphStyle style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TextStyle - text_style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle text_style(const abstract::Document *, + ElementIdentifier) const final; }; class Span final : public Element, public abstract::Span { public: explicit Span(pugi::xml_node node); - common::ResolvedStyle - partial_style(const abstract::Document *document) const final; + common::ResolvedStyle partial_style(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Text final : public Element, public abstract::Text { public: static std::string text(const pugi::xml_node node); - explicit Text(pugi::xml_node node); + explicit Text(pugi::xml_node); Text(pugi::xml_node first, pugi::xml_node last); - [[nodiscard]] std::string content(const abstract::Document *) const final; + [[nodiscard]] std::string content(const abstract::Document *, + ElementIdentifier) const final; - void set_content(const abstract::Document *, const std::string &text) final; + void set_content(const abstract::Document *, ElementIdentifier, + const std::string &text) final; - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; private: pugi::xml_node m_last; @@ -97,92 +102,101 @@ class Text final : public Element, public abstract::Text { class Link final : public Element, public abstract::Link { public: - explicit Link(pugi::xml_node node); + explicit Link(pugi::xml_node); - [[nodiscard]] std::string - href(const abstract::Document *document) const final; + [[nodiscard]] std::string href(const abstract::Document *, + ElementIdentifier) const final; }; class Bookmark final : public Element, public abstract::Bookmark { public: - explicit Bookmark(pugi::xml_node node); + explicit Bookmark(pugi::xml_node); - [[nodiscard]] std::string name(const abstract::Document *) const final; + [[nodiscard]] std::string name(const abstract::Document *, + ElementIdentifier) const final; }; class List final : public Element { public: - explicit List(pugi::xml_node node); + explicit List(pugi::xml_node); - [[nodiscard]] ElementType type(const abstract::Document *) const final; + [[nodiscard]] ElementType type(const abstract::Document *, + ElementIdentifier) const final; }; class ListItem final : public Element, public abstract::ListItem { public: - explicit ListItem(pugi::xml_node node); + explicit ListItem(pugi::xml_node); - [[nodiscard]] TextStyle style(const abstract::Document *document) const final; + [[nodiscard]] TextStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Table final : public Element, public common::Table { public: - explicit Table(pugi::xml_node node); + explicit Table(pugi::xml_node); - [[nodiscard]] TableDimensions - dimensions(const abstract::Document *) const final; + [[nodiscard]] TableDimensions dimensions(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableColumn final : public Element, public abstract::TableColumn { public: - explicit TableColumn(pugi::xml_node node); + explicit TableColumn(pugi::xml_node); - [[nodiscard]] TableColumnStyle style(const abstract::Document *) const final; + [[nodiscard]] TableColumnStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableRow final : public Element, public abstract::TableRow { public: - explicit TableRow(pugi::xml_node node); + explicit TableRow(pugi::xml_node); - [[nodiscard]] TableRowStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableRowStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class TableCell final : public Element, public abstract::TableCell { public: - explicit TableCell(pugi::xml_node node); + explicit TableCell(pugi::xml_node); - [[nodiscard]] bool covered(const abstract::Document *) const final; + [[nodiscard]] bool covered(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableDimensions span(const abstract::Document *) const final; + [[nodiscard]] TableDimensions span(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] ValueType value_type(const abstract::Document *) const final; + [[nodiscard]] ValueType value_type(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] TableCellStyle - style(const abstract::Document *document) const final; + [[nodiscard]] TableCellStyle style(const abstract::Document *, + ElementIdentifier) const final; }; class Frame final : public Element, public abstract::Frame { public: - explicit Frame(pugi::xml_node node); + explicit Frame(pugi::xml_node); - [[nodiscard]] AnchorType anchor_type(const abstract::Document *) const final; + [[nodiscard]] AnchorType anchor_type(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional x(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional y(const abstract::Document *, + ElementIdentifier) const final; + [[nodiscard]] std::optional width(const abstract::Document *, + ElementIdentifier) const final; [[nodiscard]] std::optional - x(const abstract::Document *) const final; - [[nodiscard]] std::optional - y(const abstract::Document *) const final; - [[nodiscard]] std::optional - width(const abstract::Document *) const final; - [[nodiscard]] std::optional - height(const abstract::Document *) const final; + height(const abstract::Document *, ElementIdentifier) const final; [[nodiscard]] std::optional - z_index(const abstract::Document *) const final; + z_index(const abstract::Document *, ElementIdentifier) const final; - [[nodiscard]] GraphicStyle style(const abstract::Document *) const final; + [[nodiscard]] GraphicStyle style(const abstract::Document *, + ElementIdentifier) const final; private: [[nodiscard]] pugi::xml_node inner_node_() const; @@ -190,15 +204,16 @@ class Frame final : public Element, public abstract::Frame { class Image final : public Element, public abstract::Image { public: - explicit Image(pugi::xml_node node); + explicit Image(pugi::xml_node); - [[nodiscard]] bool internal(const abstract::Document *document) const final; + [[nodiscard]] bool internal(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::optional - file(const abstract::Document *document) const final; + [[nodiscard]] std::optional file(const abstract::Document *, + ElementIdentifier) const final; - [[nodiscard]] std::string - href(const abstract::Document *document) const final; + [[nodiscard]] std::string href(const abstract::Document *, + ElementIdentifier) const final; }; } // namespace odr::internal::ooxml::text