diff --git a/src/constants.hpp b/src/constants.hpp index 3f79589..a7229be 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -2,6 +2,14 @@ #define CONSTANTS_HPP namespace duckx { + // Break constants. + // https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.wdbreaktype + enum class Break { + Line = 6, + Page = 7, + Column = 8, + }; + typedef unsigned const int formatting_flag; // text-formatting flags diff --git a/src/duckx.cpp b/src/duckx.cpp index 88480e1..ca731cf 100755 --- a/src/duckx.cpp +++ b/src/duckx.cpp @@ -43,6 +43,11 @@ bool duckx::Run::set_text(const char *text) const { return this->current.child("w:t").text().set(text); } +duckx::Run& duckx::Run::add_tab() { + this->current.append_child("w:tab"); + return *this; +} + duckx::Run& duckx::Run::next() { this->current = this->current.next_sibling(); return *this; @@ -243,6 +248,18 @@ duckx::Run &duckx::Paragraph::add_run(const char *text, duckx::formatting_flag f return *new Run(this->current, new_run); } +duckx::Run &duckx::Paragraph::add_run(Break break_type) { + pugi::xml_node new_run = this->current.append_child("w:r"); + pugi::xml_node break_node = this->current.append_child("w:br"); + + if (break_type == Break::Page) + break_node.append_attribute("w:type").set_value("page"); + else if (break_type == Break::Column) + break_node.append_attribute("w:type").set_value("column"); + + return *new Run(this->current, new_run); +} + duckx::Paragraph &duckx::Paragraph::insert_paragraph_after(const std::string& text, duckx::formatting_flag f) { pugi::xml_node new_para = this->parent.insert_child_after("w:p", this->current); diff --git a/src/duckx.hpp b/src/duckx.hpp index ae6f2c6..451aa1c 100755 --- a/src/duckx.hpp +++ b/src/duckx.hpp @@ -37,6 +37,7 @@ namespace duckx { std::string get_text() const; bool set_text(const std::string&) const; bool set_text(const char *) const; + Run& add_tab(); Run &next(); bool has_next() const; @@ -66,6 +67,8 @@ namespace duckx { Run &runs(); Run &add_run(const std::string&, duckx::formatting_flag = duckx::none); Run &add_run(const char*, duckx::formatting_flag = duckx::none); + Run &add_run(Break break_type); + Paragraph &insert_paragraph_after(const std::string&, duckx::formatting_flag = duckx::none); };