Model — Core Nodes
Base node classes that form the document tree. Every visual element in a
Docraft document inherits from DocraftNode.
DocraftNode
Base class for all document nodes carrying position, size, weight, and visibility properties.
-
class DocraftNode : public docraft::model::DocraftTransform
Base class for all document nodes.
A node carries layout properties (position, size, weight, autofill flags) and exposes a draw hook used by renderers/painters.
Subclassed by docraft::model::DocraftBlankLine, docraft::model::DocraftChildrenContainerNode, docraft::model::DocraftCircle, docraft::model::DocraftImage, docraft::model::DocraftLine, docraft::model::DocraftNewPage, docraft::model::DocraftParagraph, docraft::model::DocraftPolygon, docraft::model::DocraftSettings, docraft::model::DocraftTable, docraft::model::DocraftTriangle
Public Functions
-
explicit DocraftNode()
Creates a node with a unique id.
-
DocraftNode(const DocraftNode &node)
Copy-constructs a node.
-
explicit DocraftNode(const DocraftNode *node)
Constructs a node from an existing pointer (copy).
-
virtual ~DocraftNode() = default
Draws the node using the provided context.
-
int id() const
Returns the node id.
- Returns:
Unique node id.
-
const std::string &node_name() const
Returns the node name.
- Returns:
Node name string.
-
bool auto_fill_height() const
Returns whether height is automatically filled.
- Returns:
true if height auto-fill is enabled.
-
bool auto_fill_width() const
Returns whether width is automatically filled.
- Returns:
true if width auto-fill is enabled.
-
float weight() const
Returns the layout weight.
- Returns:
Weight value, -1.0 if not set.
-
DocraftPositionType position_mode() const
Returns the positioning mode.
- Returns:
Position mode enum.
-
int page_owner() const
Returns the page owner for this node.
- Returns:
Page number (1-based) or -1 for all pages.
-
int z_index() const
Returns the z-index for rendering order.
- Returns:
Z index (higher renders on top).
-
bool visible() const
Returns whether the node is visible.
- Returns:
true if the node is visible, false if hidden.
-
void set_name(const std::string &name)
Sets the node name.
- Parameters:
name – New name.
-
void set_auto_fill_height(bool auto_fill_height)
Sets whether height is auto-filled.
- Parameters:
auto_fill_height – true to enable auto-fill.
-
void set_auto_fill_width(bool auto_fill_width)
Sets whether width is auto-filled.
- Parameters:
auto_fill_width – true to enable auto-fill.
-
virtual void set_x_for_children(float x)
Propagates x position to children.
- Parameters:
x – New x coordinate for children.
-
virtual void set_y_for_children(float y)
Propagates y position to children.
- Parameters:
y – New y coordinate for children.
-
void set_weight(float weight)
Sets the layout weight.
- Parameters:
weight – Weight value, -1 disables weighting.
-
void set_position_mode(DocraftPositionType position_mode)
Sets the positioning mode.
- Parameters:
position_mode – Positioning mode enum.
-
void set_page_owner(int page_owner)
Sets the page owner for this node.
- Parameters:
page_owner – Page number (1-based) or -1 for all pages.
-
void set_z_index(int z_index)
Sets the z-index for rendering order.
- Parameters:
z_index – Z index (higher renders on top).
Returns whether the node should render on the current page.
- Parameters:
context – Document context.
-
void set_visible(bool visible)
Sets the visibility of the node.
- Parameters:
visible – true to make the node visible, false to hide it.
-
explicit DocraftNode()
DocraftTransform
Position and size transform with cached anchor points.
-
class DocraftTransform
Position and size transform with cached anchors.
Subclassed by docraft::model::DocraftNode
Public Functions
-
DocraftTransform()
Creates a zero-sized transform at origin.
-
explicit DocraftTransform(const DocraftPoint &point, const float &width, const float &height)
Creates a transform with position, width, and height.
- Parameters:
point – Top-left position.
width – Width in points.
height – Height in points.
-
std::string to_string() const
Returns a string representation of the transform.
- Returns:
String in a human-readable format.
-
const DocraftAnchor &anchors() const
Get the anchors object.
- Returns:
const DocraftAnchor& Anchor positions for the rectangle.
-
const DocraftAnchor &content_anchors() const
Get the content anchors object.
- Returns:
const DocraftAnchor& Anchor positions for the content area.
-
float rotation() const
Returns the rotation in degrees.
- Returns:
Rotation in degrees.
-
const DocraftPoint &position() const
Returns the top-left position.
- Returns:
Position point.
-
const DocraftPoint ¢er() const
Returns the center position.
- Returns:
Center point.
-
float width() const
Returns the width.
- Returns:
Width in points.
-
float height() const
Returns the height.
- Returns:
Height in points.
-
float padding() const
Returns the padding.
- Returns:
Padding in points.
-
void set_position(const DocraftPoint &point)
Sets the top-left position and recomputes anchors.
- Parameters:
point – New position.
-
void set_width(const float &width)
Sets the width and recomputes anchors.
- Parameters:
width – New width in points.
-
void set_height(const float &height)
Sets the height and recomputes anchors.
- Parameters:
height – New height in points.
-
void set_padding(const float &padding)
Sets the padding and recomputes content anchors.
- Parameters:
padding – New padding in points.
-
DocraftTransform()
DocraftChildrenContainerNode
Node that owns and manages a list of child nodes. Used by composite nodes such as rectangles, layouts, lists, and text.
-
class DocraftChildrenContainerNode : public docraft::model::DocraftNode
Node that owns and manages a list of child nodes.
Used by composite nodes such as layout, rectangles, lists, and text.
Subclassed by docraft::model::DocraftForeach, docraft::model::DocraftLayout, docraft::model::DocraftList, docraft::model::DocraftRectangle, docraft::model::DocraftText
Public Functions
-
DocraftChildrenContainerNode(const DocraftChildrenContainerNode &node) = default
-
explicit DocraftChildrenContainerNode(DocraftChildrenContainerNode *node)
Constructs from an existing node pointer (copy).
Adds a child node.
- Parameters:
child – Child node to add.
Inserts a child node at the given index.
- Parameters:
index – Index to insert at (clamped to size).
child – Child node to insert.
Removes a child node.
- Parameters:
child – Child node to remove.
-
const std::vector<std::shared_ptr<DocraftNode>> &children() const
Returns all child nodes.
- Returns:
Vector of child nodes.
-
virtual void set_x_for_children(float x) override
Propagates x position to children.
- Parameters:
x – New x coordinate.
-
virtual void set_y_for_children(float y) override
Propagates y position to children.
- Parameters:
y – New y coordinate.
-
explicit DocraftNode()
Creates a node with a unique id.
-
DocraftNode(const DocraftNode &node)
Copy-constructs a node.
-
explicit DocraftNode(const DocraftNode *node)
Constructs a node from an existing pointer (copy).
-
DocraftChildrenContainerNode(const DocraftChildrenContainerNode &node) = default
DocraftSection
Rectangular document section with margin configuration. Base for header, body, and footer.
-
class DocraftSection : public docraft::model::DocraftRectangle
Rectangular document section with margin configuration.
Used as a base for header, body, and footer containers.
Subclassed by docraft::model::DocraftBody, docraft::model::DocraftFooter, docraft::model::DocraftHeader
Public Functions
-
DocraftSection()
-
DocraftSection(const DocraftSection &node) = default
-
explicit DocraftSection(DocraftSection *node)
Constructs from an existing node pointer (copy).
Draws the section using the provided context.
- Parameters:
context – Document context.
-
virtual std::shared_ptr<DocraftNode> clone() const override
Clones the section node and its children.
- Returns:
Shared pointer to the cloned node.
-
float margins() const
Returns the uniform margins value.
- Returns:
Margin value in points.
-
float margin_top() const
Returns the top margin.
- Returns:
Margin in points.
-
float margin_bottom() const
Returns the bottom margin.
- Returns:
Margin in points.
-
float margin_left() const
Returns the left margin.
- Returns:
Margin in points.
-
float margin_right() const
Returns the right margin.
- Returns:
Margin in points.
-
void set_margins(float margins)
Sets all margins to the same value.
- Parameters:
margins – Margin in points.
-
void set_margin_top(float margin_top)
Sets the top margin.
- Parameters:
margin_top – Margin in points.
-
void set_margin_bottom(float margin_bottom)
Sets the bottom margin.
- Parameters:
margin_bottom – Margin in points.
-
void set_margin_left(float margin_left)
Sets the left margin.
- Parameters:
margin_left – Margin in points.
-
void set_margin_right(float margin_right)
Sets the right margin.
- Parameters:
margin_right – Margin in points.
-
DocraftSection()
DocraftHeader
-
class DocraftHeader : public docraft::model::DocraftSection
Header section of the document.
Public Functions
-
DocraftHeader()
Creates a header section with default margins.
-
~DocraftHeader() override = default
-
virtual std::shared_ptr<DocraftNode> clone() const override
Clones the header node and its children.
- Returns:
Shared pointer to the cloned node.
-
DocraftHeader()
DocraftBody
-
class DocraftBody : public docraft::model::DocraftSection
Body section of the document.
Public Functions
-
~DocraftBody() override = default
-
virtual std::shared_ptr<DocraftNode> clone() const override
Clones the body node and its children.
- Returns:
Shared pointer to the cloned node.
-
DocraftSection()
-
DocraftSection(const DocraftSection &node) = default
-
explicit DocraftSection(DocraftSection *node)
Constructs from an existing node pointer (copy).
-
~DocraftBody() override = default
DocraftSettings
Document-level settings node (page format, fonts).
-
class DocraftSettings : public docraft::model::DocraftNode
Document-level settings node (fonts, etc.).
Settings are interpreted by the document context to register fonts and configure rendering behavior.
Public Functions
-
DocraftSettings() = default
-
~DocraftSettings() override = default
-
void add_font(const setting::DocraftFont &font)
Adds a font family to the settings.
- Parameters:
font – Font family definition.
-
void remove_font(const std::string &name)
Removes a font family by name.
- Parameters:
name – Font family name.
-
const std::vector<setting::DocraftFont> &fonts() const
Returns the configured font families.
- Returns:
Vector of font families.
-
void set_page_format(DocraftPageSize size, DocraftPageOrientation orientation)
Sets the page format.
- Parameters:
size – Page size.
orientation – Page orientation.
-
DocraftPageSize page_size() const
Returns the page size.
-
DocraftPageOrientation page_orientation() const
Returns the page orientation.
-
bool has_page_format() const
Returns whether a page format override is set.
-
void set_section_ratios(float header_ratio, float body_ratio, float footer_ratio)
Sets the header/body/footer ratios.
-
float header_ratio() const
Returns the header ratio.
-
float body_ratio() const
Returns the body ratio.
Returns the footer ratio.
-
bool has_section_ratios() const
Returns whether section ratios are set.
Draws settings (no-op in most backends).
- Parameters:
context – Document context.
-
DocraftSettings() = default
DocraftNewPage
Manual page break node.
-
class DocraftNewPage : public docraft::model::DocraftNode, public docraft::model::IDocraftClonable
Represents a manual page break in the document.
Public Functions
-
DocraftNewPage() = default
-
~DocraftNewPage() override = default
Draws the node using the provided context.
-
inline virtual std::shared_ptr<DocraftNode> clone() const override
Creates a deep copy of the node.
- Returns:
A shared pointer to the cloned node.
-
explicit DocraftNode()
Creates a node with a unique id.
-
DocraftNode(const DocraftNode &node)
Copy-constructs a node.
-
explicit DocraftNode(const DocraftNode *node)
Constructs a node from an existing pointer (copy).
-
DocraftNewPage() = default
DocraftBlankLine
Blank line node for vertical spacing.
-
class DocraftBlankLine : public docraft::model::DocraftNode, public docraft::model::IDocraftClonable
Blank line node used to add vertical spacing in flow layout.
Public Functions
Draws the blank line using the provided context.
-
virtual std::shared_ptr<DocraftNode> clone() const override
Clones the blank line node.
- Returns:
Shared pointer to the cloned node.
-
explicit DocraftNode()
Creates a node with a unique id.
-
DocraftNode(const DocraftNode &node)
Copy-constructs a node.
-
explicit DocraftNode(const DocraftNode *node)
Constructs a node from an existing pointer (copy).
DocraftParagraph
Paragraph placeholder node.
-
class DocraftParagraph : public docraft::model::DocraftNode, public docraft::model::IDocraftClonable
Paragraph node (placeholder for future behavior).
Currently inherits DocraftNode without additional data or rendering logic.
Public Functions
Draws the paragraph using the provided context.
-
virtual std::shared_ptr<DocraftNode> clone() const override
Clones the paragraph node.
- Returns:
Shared pointer to the cloned node.
IDocraftClonable
Interface for nodes that support deep cloning.
-
class IDocraftClonable
Interface for clonable Docraft nodes.
Nodes that implement this interface can be cloned, which is useful for templating and other operations that require copying nodes.
Subclassed by docraft::model::DocraftBlankLine, docraft::model::DocraftCircle, docraft::model::DocraftForeach, docraft::model::DocraftImage, docraft::model::DocraftLayout, docraft::model::DocraftLine, docraft::model::DocraftList, docraft::model::DocraftNewPage, docraft::model::DocraftParagraph, docraft::model::DocraftPolygon, docraft::model::DocraftRectangle, docraft::model::DocraftTable, docraft::model::DocraftText, docraft::model::DocraftTriangle
Public Functions
-
virtual ~IDocraftClonable() = default
-
virtual std::shared_ptr<DocraftNode> clone() const = 0
Creates a deep copy of the node.
- Returns:
A shared pointer to the cloned node.
-
virtual ~IDocraftClonable() = default