From 3db6d8c29be7843f4cdc9efb88c5667b66c9400d Mon Sep 17 00:00:00 2001 From: NXiss7 Date: Sun, 8 Mar 2020 22:18:32 +0300 Subject: [PATCH 1/3] Added function to add new line. --- src/duckx.cpp | 6 ++++++ src/duckx.hpp | 1 + 2 files changed, 7 insertions(+) diff --git a/src/duckx.cpp b/src/duckx.cpp index 88480e1..452d025 100755 --- a/src/duckx.cpp +++ b/src/duckx.cpp @@ -243,6 +243,12 @@ duckx::Run &duckx::Paragraph::add_run(const char *text, duckx::formatting_flag f return *new Run(this->current, new_run); } +void duckx::Paragraph::add_newline() { + // Add new run + pugi::xml_node new_run = this->current.append_child("w:r"); + this->current.append_child("w:br"); +} + 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..feac998 100755 --- a/src/duckx.hpp +++ b/src/duckx.hpp @@ -66,6 +66,7 @@ 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); + void add_newline(); Paragraph &insert_paragraph_after(const std::string&, duckx::formatting_flag = duckx::none); }; From af884a2e46a266de7eeda2008aa9195a7c567b20 Mon Sep 17 00:00:00 2001 From: NXiss7 Date: Fri, 27 Mar 2020 17:59:59 +0300 Subject: [PATCH 2/3] Add break constants and implement line, page, column breaks. --- src/constants.hpp | 8 ++++++++ src/duckx.cpp | 12 +++++++++--- src/duckx.hpp | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) 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 452d025..2fe26b4 100755 --- a/src/duckx.cpp +++ b/src/duckx.cpp @@ -243,10 +243,16 @@ duckx::Run &duckx::Paragraph::add_run(const char *text, duckx::formatting_flag f return *new Run(this->current, new_run); } -void duckx::Paragraph::add_newline() { - // Add new run +duckx::Run &duckx::Paragraph::add_run(Break break_type) { pugi::xml_node new_run = this->current.append_child("w:r"); - this->current.append_child("w:br"); + 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) { diff --git a/src/duckx.hpp b/src/duckx.hpp index feac998..17e283f 100755 --- a/src/duckx.hpp +++ b/src/duckx.hpp @@ -66,7 +66,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); - void add_newline(); + Run &add_run(Break break_type); + Paragraph &insert_paragraph_after(const std::string&, duckx::formatting_flag = duckx::none); }; From 657d89a4a5a9d550fb993caed2387a3f49491144 Mon Sep 17 00:00:00 2001 From: NXiss7 Date: Fri, 27 Mar 2020 22:50:22 +0300 Subject: [PATCH 3/3] Added "tab character" support. --- src/duckx.cpp | 5 +++++ src/duckx.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/src/duckx.cpp b/src/duckx.cpp index 2fe26b4..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; diff --git a/src/duckx.hpp b/src/duckx.hpp index 17e283f..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;