Skip to content
Draft
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
13 changes: 9 additions & 4 deletions doc/project-doc/contributors/components/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ Important implication:

## 2. Interface contract you must implement

A backend must implement `IDocraftRenderingBackend`, which aggregates:
A backend must implement `IDocraftRenderingBackend`, which exposes capability
accessors for:

- text primitives,
- line/shape primitives,
- line primitives,
- shape primitives,
- image primitives,
- page management,
- save/output extension,
- metadata application,
- font registration and font selection hooks.

In practice you implement one concrete class inheriting `IDocraftRenderingBackend`.
In practice you implement one concrete class inheriting
`IDocraftRenderingBackend` and return the capability objects from the root via
`<capability>() const` and `edit_<capability>()`.

## 3. External integration (recommended path)

Expand Down Expand Up @@ -64,7 +68,8 @@ void render_with_external_backend(const std::string &craft_path) {
Typical steps for a backend added directly in this repository:

1. Add backend class, for example `docraft::backend::svg::DocraftSvgBackend`.
2. Implement all methods of `IDocraftRenderingBackend`.
2. Implement all root methods of `IDocraftRenderingBackend` and wire each
capability accessor to the appropriate capability object.
3. Add new source/header files to `docraft/CMakeLists.txt`.
4. Add tests in `docraft/test/backend/` and/or rendering smoke tests.
5. Choose selection strategy:
Expand Down
14 changes: 10 additions & 4 deletions doc/project-doc/contributors/components/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ The backend layer is the portability boundary for output targets.

## 1. Contract hierarchy

`IDocraftRenderingBackend` aggregates these contracts:
`IDocraftRenderingBackend` exposes these contracts via explicit accessors:

- `IDocraftTextRenderingBackend`
- `IDocraftLineRenderingBackend`
- `IDocraftShapeRenderingBackend`
- `IDocraftImageRenderingBackend`
- `IDocraftPageRenderingBackend`
Expand All @@ -18,17 +19,22 @@ Plus lifecycle methods:
- font registration/selection helpers
- metadata application

This design lets renderers/painters consume only the primitives they need.
Capability interfaces are standalone (no inheritance chain between them), and
the root backend provides `<capability>() const` plus `edit_<capability>()`
accessors so renderers/painters can consume only the primitives they need.

## 2. Concrete implementation: Haru backend

`DocraftHaruBackend` implements all contracts over libharu.
`DocraftHaruBackend` remains the single concrete backend entry point, but it
composes smaller libharu-backed capability objects internally.

Responsibilities include:

- managing document/page handles,
- text drawing and measurement,
- line/shape/image drawing,
- line drawing,
- shape drawing and graphics state,
- image drawing,
- page navigation and page format,
- metadata mapping to PDF info fields,
- save to `.pdf`.
Expand Down
10 changes: 7 additions & 3 deletions doc/source/api/backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ output.
IDocraftRenderingBackend
------------------------

Aggregated interface inheriting all sub-backend interfaces.
Root backend interface exposing lifecycle/font operations plus explicit
capability accessors such as ``line_rendering()`` / ``edit_line_rendering()``
and the corresponding text, shape, image, and page accessors.

.. doxygenclass:: docraft::backend::IDocraftRenderingBackend
:project: docraft
Expand All @@ -17,6 +19,8 @@ Aggregated interface inheriting all sub-backend interfaces.
Sub-backend Interfaces
----------------------

Capability interfaces are standalone and chain-free.

IDocraftTextRenderingBackend
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -58,9 +62,9 @@ Concrete Backends
DocraftHaruBackend
^^^^^^^^^^^^^^^^^^

PDF backend implementation using libharu.
PDF backend implementation using libharu, composed from capability-focused
internal objects behind the root backend.

.. doxygenclass:: docraft::backend::pdf::DocraftHaruBackend
:project: docraft
:members:

48 changes: 43 additions & 5 deletions docraft/include/docraft/backend/docraft_rendering_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "docraft/docraft_lib.h"
#include <string>

#include "docraft/backend/docraft_line_rendering_backend.h"
#include "docraft/backend/docraft_image_rendering_backend.h"
#include "docraft/backend/docraft_page_rendering_backend.h"
#include "docraft/backend/docraft_shape_rendering_backend.h"
Expand All @@ -32,15 +33,52 @@ namespace docraft::backend {
/**
* @brief Aggregated rendering backend interface.
*/
class DOCRAFT_LIB IDocraftRenderingBackend : public IDocraftTextRenderingBackend,
public IDocraftShapeRenderingBackend,
public IDocraftImageRenderingBackend,
public IDocraftPageRenderingBackend {
class DOCRAFT_LIB IDocraftRenderingBackend {
public:
/**
* @brief Virtual destructor.
*/
~IDocraftRenderingBackend() override = default;
virtual ~IDocraftRenderingBackend() = default;
/**
* @brief Returns the line rendering capability, if available.
*/
[[nodiscard]] virtual const IDocraftLineRenderingBackend *line_rendering() const = 0;
/**
* @brief Returns the editable line rendering capability, if available.
*/
[[nodiscard]] virtual IDocraftLineRenderingBackend *edit_line_rendering() = 0;
/**
* @brief Returns the text rendering capability, if available.
*/
[[nodiscard]] virtual const IDocraftTextRenderingBackend *text_rendering() const = 0;
/**
* @brief Returns the editable text rendering capability, if available.
*/
[[nodiscard]] virtual IDocraftTextRenderingBackend *edit_text_rendering() = 0;
/**
* @brief Returns the shape rendering capability, if available.
*/
[[nodiscard]] virtual const IDocraftShapeRenderingBackend *shape_rendering() const = 0;
/**
* @brief Returns the editable shape rendering capability, if available.
*/
[[nodiscard]] virtual IDocraftShapeRenderingBackend *edit_shape_rendering() = 0;
/**
* @brief Returns the image rendering capability, if available.
*/
[[nodiscard]] virtual const IDocraftImageRenderingBackend *image_rendering() const = 0;
/**
* @brief Returns the editable image rendering capability, if available.
*/
[[nodiscard]] virtual IDocraftImageRenderingBackend *edit_image_rendering() = 0;
/**
* @brief Returns the page rendering capability, if available.
*/
[[nodiscard]] virtual const IDocraftPageRenderingBackend *page_rendering() const = 0;
/**
* @brief Returns the editable page rendering capability, if available.
*/
[[nodiscard]] virtual IDocraftPageRenderingBackend *edit_page_rendering() = 0;
/**
* @brief Saves the document to a file path.
* @param path Output file path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@

#include <vector>

#include "docraft/backend/docraft_line_rendering_backend.h"
#include "docraft/model/docraft_position.h"

namespace docraft::backend {
/**
* @brief Interface for shape rendering backends used by Docraft.
*/
class DOCRAFT_LIB IDocraftShapeRenderingBackend : public virtual IDocraftLineRenderingBackend {
class DOCRAFT_LIB IDocraftShapeRenderingBackend {
public:
/**
* @brief Virtual destructor.
*/
~IDocraftShapeRenderingBackend() override = default;
virtual ~IDocraftShapeRenderingBackend() = default;
/**
* @brief Saves the current graphics state.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
#include "docraft/docraft_lib.h"
#include <string>

#include "docraft/backend/docraft_line_rendering_backend.h"

namespace docraft::backend {
/**
* @brief Interface for text rendering backends used by Docraft.
*/
class DOCRAFT_LIB IDocraftTextRenderingBackend : public virtual IDocraftLineRenderingBackend {
class DOCRAFT_LIB IDocraftTextRenderingBackend {
public:
/**
* @brief Virtual destructor.
*/
~IDocraftTextRenderingBackend() override = default;
virtual ~IDocraftTextRenderingBackend() = default;
/**
* @brief Initializes the text rendering context. Must be called before any text drawing operations.
*/
Expand Down
Loading