Layout Engine
The layout engine computes position and size for every node in the document tree. It uses a chain-of-responsibility pattern: specialized handlers claim specific node types, while a fallback handler covers generic nodes.
DocraftLayoutEngine
Main engine that walks the DOM and delegates box computation to handlers.
-
class DocraftLayoutEngine
Computes layout boxes for document nodes using a chain of handlers.
The engine walks node trees and delegates box computation to specialized handlers (text, table, list, etc.), maintaining a cursor for flow layout.
Public Functions
Creates a layout engine for the given document context.
- Parameters:
context – Document context used for measurements and page info.
reset_cursor – Whether to reset the cursor before layout.
-
DocraftLayoutEngine(const DocraftLayoutEngine&) = delete
-
DocraftLayoutEngine &operator=(const DocraftLayoutEngine&) = delete
-
~DocraftLayoutEngine() = default
Destructor.
Computes the layout for a single node tree.
- Parameters:
node – A shared pointer to a DocraftNode object.
- Returns:
A DocraftTransform representing the computed layout box.
Computes the layout for a single node tree with a custom cursor.
- Parameters:
node – A shared pointer to a DocraftNode object.
cursor – Cursor used for layout traversal.
- Returns:
A DocraftTransform representing the computed layout box.
Computes the layout for a full document represented by a vector of nodes.
- Parameters:
nodes – A vector of shared pointers to DocraftNode objects.
AbstractDocraftLayoutHandler
Base template for all layout handlers.
-
template<typename T>
class AbstractDocraftLayoutHandler : public docraft::generic::DocraftChainOfResponsibilityHandler<model::DocraftNode, model::DocraftTransform> Public Functions
-
~AbstractDocraftLayoutHandler() override = default
Creates a handler bound to a document context.
- Throws:
std::invalid_argument – if context is null.
Computes the layout box for a concrete node type.
- Parameters:
node – Node to layout.
box – Output transform.
cursor – Layout cursor.
-
inline std::shared_ptr<DocraftDocumentContext> context() const
Returns the bound document context.
- Returns:
Document context.
-
~AbstractDocraftLayoutHandler() override = default
DocraftBasicLayoutHandler
Fallback handler for generic nodes.
-
class DocraftBasicLayoutHandler : public docraft::layout::handler::AbstractDocraftLayoutHandler<model::DocraftNode>
Fallback layout handler for generic nodes.
Used when no specialized handler claims the node.
Public Functions
Computes the layout box for a basic node.
- Parameters:
node – Node to layout.
box – Output transform.
cursor – Layout cursor.
Handles a node if no specialized handler applies.
- Parameters:
request – Node to handle.
result – Output transform.
cursor – Layout cursor.
- Returns:
true if handled.
Creates a handler bound to a document context.
- Throws:
std::invalid_argument – if context is null.
DocraftLayoutTextHandler
Handles text measurement, alignment, and line-breaking.
-
class DocraftLayoutTextHandler : public docraft::layout::handler::AbstractDocraftLayoutHandler<model::DocraftText>
Layout handler for text nodes.
Measures text width, handles alignment, and manages line breaks.
Public Functions
Computes the layout box for a text node.
- Parameters:
node – Text node.
box – Output transform.
cursor – Layout cursor.
Handles a node if it is a DocraftText.
- Parameters:
request – Node to handle.
result – Output transform.
cursor – Layout cursor.
- Returns:
true if handled.
Creates a handler bound to a document context.
- Throws:
std::invalid_argument – if context is null.
DocraftLayoutTableHandler
Calculates cell boxes and header/content areas.
-
class DocraftLayoutTableHandler : public docraft::layout::handler::AbstractDocraftLayoutHandler<model::DocraftTable>
Layout handler for table nodes.
Calculates cell boxes and header/content areas based on weights.
Public Functions
Computes the layout box for a table node.
- Parameters:
node – Table node.
box – Output transform.
cursor – Layout cursor.
Handles a node if it is a DocraftTable.
- Parameters:
request – Node to handle.
result – Output transform.
cursor – Layout cursor.
- Returns:
true if handled.
DocraftLayoutListHandler
Computes marker positions and list item content.
-
class DocraftLayoutListHandler : public docraft::layout::handler::AbstractDocraftLayoutHandler<model::DocraftList>
Layout handler for list nodes.
Computes marker positions and lays out list item content.
Public Functions
Computes the layout box for a list node.
- Parameters:
node – List node.
box – Output transform.
cursor – Layout cursor.
Computes layout for list children using a provided layout function.
- Parameters:
node – List node.
cursor – Layout cursor.
child_boxes – Output transforms for children.
layout_child – Layout function for a child node.
max_width – Available width in points.
Handles a node if it is a DocraftList.
- Parameters:
request – Node to handle.
result – Output transform.
cursor – Layout cursor.
- Returns:
true if handled.
DocraftLayoutHandler
Handler for DocraftLayout nodes (horizontal/vertical children).
-
class DocraftLayoutHandler : public docraft::layout::handler::AbstractDocraftLayoutHandler<model::DocraftLayout>
Layout handler for DocraftLayout nodes.
Computes child boxes based on orientation and weights.
Public Functions
Computes the layout for a layout node.
- Parameters:
node – Layout node.
box – Output transform.
cursor – Layout cursor.
Handles a node if it is a DocraftLayout.
- Parameters:
request – Node to handle.
result – Output transform.
cursor – Layout cursor.
- Returns:
true if handled.
DocraftLayoutBlankLine
Advances the cursor for blank-line spacing.
-
class DocraftLayoutBlankLine : public docraft::layout::handler::AbstractDocraftLayoutHandler<model::DocraftBlankLine>
Layout handler for blank line nodes.
Advances the cursor to create vertical spacing.
Public Functions
Computes the layout box for a blank line.
- Parameters:
node – Blank line node.
box – Output transform.
cursor – Layout cursor.
Handles a node if it is a DocraftBlankLine.
- Parameters:
request – Node to handle.
result – Output transform.
cursor – Layout cursor.
- Returns:
true if handled.