Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to add new line. #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/duckx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/duckx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};

Expand Down