Document Context

Shared rendering and layout state used across the entire document pipeline. Holds the active backend, cached sub-backends (text, shape, image, page), page metrics, section nodes, and the layout cursor.

class DocraftDocumentContext

Shared rendering and layout state for a document.

The context holds the active rendering backend, cached backend interfaces, page metrics, section nodes, and the layout cursor used by the engine.

Public Functions

DocraftDocumentContext()

Constructs a context with a default backend.

explicit DocraftDocumentContext(const std::shared_ptr<backend::IDocraftRenderingBackend> &backend)

Constructs a context with the provided rendering backend.

Parameters:

backend – Rendering backend to use.

~DocraftDocumentContext()

Releases context resources.

const std::shared_ptr<backend::IDocraftRenderingBackend> &rendering_backend() const

Returns the active rendering backend.

Returns:

Shared pointer to the rendering backend.

DocraftCursor &cursor()

Returns the mutable layout cursor.

Returns:

Reference to the cursor.

float available_space() const

Returns remaining vertical space on the current page section.

Returns:

Available vertical space in points.

void set_renderer(const std::shared_ptr<renderer::DocraftAbstractRenderer> &renderer)

Sets the renderer responsible for translating nodes to backend calls.

Parameters:

renderer – Renderer instance.

std::shared_ptr<renderer::DocraftAbstractRenderer> renderer()

Returns the current renderer.

Returns:

Shared pointer to the renderer (may be nullptr).

void set_current_rect_width(float x)

Sets the width of the current layout rectangle.

Parameters:

x – Width in points.

float page_width() const

Returns the page width in points.

Returns:

Page width in points.

float page_height() const

Returns the page height in points.

Returns:

Page height in points.

void set_header(const std::shared_ptr<model::DocraftHeader> &header)

Sets the document header node.

Parameters:

header – Header node.

const std::shared_ptr<model::DocraftHeader> &header() const

Returns the header node.

Returns:

Header node (may be nullptr).

void set_body(const std::shared_ptr<model::DocraftBody> &body)

Sets the document body node.

Parameters:

body – Body node.

const std::shared_ptr<model::DocraftBody> &body() const

Returns the body node.

Returns:

Body node (may be nullptr).

void set_footer(const std::shared_ptr<model::DocraftFooter> &footer)

Sets the document footer node.

Parameters:

footer – Footer node.

const std::shared_ptr<model::DocraftFooter> &footer() const

Returns the footer node.

Returns:

Footer node (may be nullptr).

void set_font_applier(const std::shared_ptr<docraft::generic::DocraftFontApplier> &font_applier)

Sets the font applier used for text nodes.

Parameters:

font_applier – Font applier instance.

const std::shared_ptr<docraft::generic::DocraftFontApplier> &font_applier() const

Returns the font applier instance.

Returns:

Font applier (may be nullptr).

const std::shared_ptr<backend::IDocraftLineRenderingBackend> &line_backend() const

Returns the line backend (cached).

Returns:

Line rendering backend.

const std::shared_ptr<backend::IDocraftShapeRenderingBackend> &shape_backend() const

Returns the shape backend (cached).

Returns:

Shape rendering backend.

const std::shared_ptr<backend::IDocraftTextRenderingBackend> &text_backend() const

Returns the text backend (cached).

Returns:

Text rendering backend.

const std::shared_ptr<backend::IDocraftImageRenderingBackend> &image_backend() const

Returns the image backend (cached).

Returns:

Image rendering backend.

const std::shared_ptr<backend::IDocraftPageRenderingBackend> &page_backend() const

Returns the page backend (cached).

Returns:

Page rendering backend.

void set_backend(const std::shared_ptr<backend::IDocraftRenderingBackend> &backend)

Replaces the underlying rendering backend.

Parameters:

backend – New rendering backend. Pass nullptr to restore the default backend.

void set_page_format(model::DocraftPageSize size, model::DocraftPageOrientation orientation)

Sets the page format for the backend and updates cached size.

void go_to_first_page() const

Moves to the first page (index 0).

void go_to_previous_page() const

Moves to the previous page.

void go_to_last_page() const

Moves to the last page.

void set_section_ratios(float header_ratio, float body_ratio, float footer_ratio)

Sets header/body/footer ratios.

float header_ratio() const

Returns the header ratio.

float body_ratio() const

Returns the body ratio.

float footer_ratio() const

Returns the footer ratio.