Model — Types & Enums

Value types, enumerations, and small structs used throughout the model layer.

DocraftColor

Color helper supporting named colors, RGB components, hex codes, and template expressions.

class DocraftColor

Color helper that supports named, RGB, and hex representations.

Public Functions

explicit DocraftColor(ColorName name = ColorName::kBlack)

Creates a color from a known name.

Parameters:

name – Named color.

explicit DocraftColor(float r, float g, float b, float a = 1.0F)

Creates a color from RGBA components.

Parameters:
  • r – Red in [0,1].

  • g – Green in [0,1].

  • b – Blue in [0,1].

  • a – Alpha in [0,1].

explicit DocraftColor(const std::string &hex_code)

Creates a color from a hex code (#RRGGBB or #RRGGBBAA).

Parameters:

hex_code – Hex string.

~DocraftColor() = default

Destructor.

RGB toRGB() const

Returns the RGBA representation.

Returns:

RGBA components.

ColorName toColorName() const

Returns the named color (if available).

Returns:

ColorName enum value.

bool is_template_expression() const

Checks if this color is a template expression.

Returns:

true if the color is a template expression like ${data(“field”)} or ${variable}

const std::string &template_expression() const

Gets the template expression string if this is a template color.

Returns:

Template expression string (e.g., “${data(“field”)}”)

Public Static Functions

static DocraftColor fromColorName(ColorName name)

Creates a DocraftColor from a named color.

Parameters:

name – Named color.

Returns:

DocraftColor instance.

static DocraftColor fromRGB(float r, float g, float b, float a = 1.0F)

Creates a DocraftColor from RGBA components.

Parameters:
  • r – Red in [0,1].

  • g – Green in [0,1].

  • b – Blue in [0,1].

  • a – Alpha in [0,1].

Returns:

DocraftColor instance.

RGB

struct RGB

RGBA color with components in the [0,1] range.

Public Functions

inline std::string to_hex() const

Converts the RGBA color to a hex string #RRGGBBAA.

Returns:

Hex string in #RRGGBBAA format.

Public Members

float r = 0.0F
float g = 0.0F
float b = 0.0F
float a = 1.0F

DocraftCursor

Tracks the current 2D position for flow layout with a direction stack.

class DocraftCursor

Tracks the current position for flow layout.

The cursor stores a 2D point plus a stack of layout directions, enabling nested horizontal/vertical layout operations.

Public Functions

DocraftCursor()

Creates a cursor at origin with horizontal direction.

~DocraftCursor()

Destructor.

float x() const

Returns the current x position.

Returns:

X coordinate.

float y() const

Returns the current y position.

Returns:

Y coordinate.

DocraftCursorDirection direction() const

Returns the current direction.

Returns:

Current cursor direction.

void reset_x()

Resets the x-coordinate of the cursor to 0.

void reset_y()

Resets the y-coordinate of the cursor to 0.

void set_x(float x)

Sets the x position.

Parameters:

x – New x coordinate.

void set_y(float y)

Sets the y position.

Parameters:

y – New y coordinate.

void push_direction(DocraftCursorDirection direction)

Pushes a new movement direction onto the stack.

Parameters:

direction – Direction to push.

void pop_direction()

Pops the current direction, restoring the previous one.

void reset_direction()

Clears all direction hints, restoring default vertical flow.

void move_to(float x, float y)

Moves the cursor to the specified coordinates.

Parameters:
  • x – New x coordinate.

  • y – New y coordinate.

DocraftDocumentMetadata

Metadata container for PDF document information (author, title, dates, etc.). Includes the nested DateTime struct for creation/modification dates.

class DocraftDocumentMetadata

Metadata container for PDF document information.

Supports all document info fields exposed by libharu (string attributes plus creation and modification dates).

Public Functions

inline void set_author(const std::string &author)
inline void set_creator(const std::string &creator)
inline void set_producer(const std::string &producer)
inline void set_title(const std::string &title)
inline void set_subject(const std::string &subject)
inline void set_keywords(const std::string &keywords)
inline void set_trapped(const std::string &trapped)
inline void set_gts_pdfx(const std::string &gts_pdfx)
inline void set_creation_date(const DateTime &creation_date)
inline void set_modification_date(const DateTime &modification_date)
inline void clear_author()
inline void clear_creator()
inline void clear_producer()
inline void clear_title()
inline void clear_subject()
inline void clear_keywords()
inline void clear_trapped()
inline void clear_gts_pdfx()
inline void clear_creation_date()
inline void clear_modification_date()
inline const std::optional<std::string> &author() const
inline const std::optional<std::string> &creator() const
inline const std::optional<std::string> &producer() const
inline const std::optional<std::string> &title() const
inline const std::optional<std::string> &subject() const
inline const std::optional<std::string> &keywords() const
inline const std::optional<std::string> &trapped() const
inline const std::optional<std::string> &gts_pdfx() const
inline const std::optional<DateTime> &creation_date() const
inline const std::optional<DateTime> &modification_date() const
struct DateTime

Date/time structure compatible with libharu info dates.

Public Members

int year = 0
int month = 0
int day = 0
int hour = 0
int minutes = 0
int seconds = 0
char ind = '+'
int off_hour = 0
int off_minutes = 0

DocraftPoint

struct DocraftPoint

2D point in document space.

Public Functions

std::string to_string() const

Returns a string representation of the point.

Returns:

String in a human-readable format.

Public Members

float x = 0.0F
float y = 0.0F

DocraftAnchor

struct DocraftAnchor

Anchor points around a rectangle and its edges.

Public Members

DocraftPoint top_left
DocraftPoint top_center
DocraftPoint top_right
DocraftPoint bottom_left
DocraftPoint bottom_center
DocraftPoint bottom_right
DocraftPoint left_center
DocraftPoint right_center

Enumerations

enum class docraft::ColorName

Named colors supported by the library.

Values:

enumerator kBlack
enumerator kWhite
enumerator kRed
enumerator kGreen
enumerator kBlue
enumerator kYellow
enumerator kMagenta
enumerator kCyan
enumerator kPurple
enum class docraft::DocraftCursorDirection

Cursor movement direction hints for layout handlers.

Values:

enumerator kHorizontal
enumerator kVertical
enum class docraft::model::ImageFormat

Supported image formats for DocraftImage.

Values:

enumerator kPng
enumerator kJpeg
enumerator kRaw
enum class docraft::model::LayoutOrientation

Layout orientation for child nodes.

Values:

enumerator kHorizontal
enumerator kVertical
enum class docraft::model::ListKind

List kinds supported by Docraft.

Values:

enumerator kOrdered
enumerator kUnordered
enum class docraft::model::OrderedListStyle

Ordered list style variants.

Values:

enumerator kNumber
enumerator kRoman
enum class docraft::model::UnorderedListDot

Unordered list marker shapes.

Values:

enumerator kDash
enumerator kStar
enumerator kCircle
enumerator kBox
enum class docraft::model::DocraftPageSize

Supported page sizes.

Values:

enumerator kA4
enumerator kA3
enumerator kA5
enumerator kLetter
enumerator kLegal
enum class docraft::model::DocraftPageOrientation

Page orientation.

Values:

enumerator kPortrait
enumerator kLandscape
enum class docraft::model::DocraftPositionType

Positioning modes for layout.

Values:

enumerator kBlock
enumerator kAbsolute
enum class docraft::model::TextStyle

Text styles supported by Docraft.

Values:

enumerator kNormal
enumerator kBold
enumerator kItalic
enumerator kBoldItalic
enum class docraft::model::TextAlignment

Text alignment options.

Values:

enumerator kLeft
enumerator kCenter
enumerator kRight
enumerator kJustified