Skip to content
Merged
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
4 changes: 4 additions & 0 deletions docraft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ set(DOCRAFT_SOURCES
include/docraft/renderer/painter/docraft_rectangle_painter.h
src/docraft/renderer/painter/docraft_circle_painter.cc
include/docraft/renderer/painter/docraft_circle_painter.h
src/docraft/renderer/painter/docraft_polygonal_shape_painter_base.cc
include/docraft/renderer/painter/docraft_polygonal_shape_painter_base.h
src/docraft/renderer/painter/docraft_triangle_painter.cc
include/docraft/renderer/painter/docraft_triangle_painter.h
src/docraft/renderer/painter/docraft_line_painter.cc
Expand All @@ -118,6 +120,8 @@ set(DOCRAFT_SOURCES
include/docraft/model/docraft_blank_line.h
src/docraft/layout/handler/docraft_layout_blank_line.cc
include/docraft/layout/handler/docraft_layout_blank_line.h
src/docraft/layout/handler/docraft_layout_line_handler.cc
include/docraft/layout/handler/docraft_layout_line_handler.h
src/docraft/renderer/painter/docraft_blank_line_painter.cc
include/docraft/renderer/painter/docraft_blank_line_painter.h
src/docraft/craft/docraft_craft_language_parser.cc
Expand Down
3 changes: 2 additions & 1 deletion docraft/include/docraft/craft/parser/docraft_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ namespace docraft::craft::parser {
*/
class DOCRAFT_LIB DocraftForeachParser : public IDocraftParser {
public:
DocraftForeachParser(DocraftCraftLanguageParser* craft_language_parser);
explicit DocraftForeachParser(DocraftCraftLanguageParser *craft_language_parser);

/**
* @brief Parses a foreach XML node.
* @param craft_language_source XML node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "docraft/docraft_lib.h"
#include "docraft/layout/docraft_layout_engine.h"
#include "docraft/layout/handler/docraft_layout_table_handler.h"
#include "docraft/layout/handler/docraft_layout_table_pipeline_overrides.h"

namespace docraft::layout::handler {
/**
Expand All @@ -49,14 +50,7 @@ namespace docraft::layout::handler {
DocraftCursor &cursor) override;

protected:
void setup_pipeline_state(const std::shared_ptr<model::DocraftTable> &node,
DocraftCursor &cursor) override;

void prepare_table_layout(const std::shared_ptr<model::DocraftTable> &node) override;

[[nodiscard]] float layout_table_content(const std::shared_ptr<model::DocraftTable> &node) override;

[[nodiscard]] float resolve_table_width() const override;
DOCRAFT_TABLE_PIPELINE_OVERRIDES;

private:
struct TableContent {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026 Matteo Cadoni (https://github.com/cadons)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cstddef>
#include <vector>

#include "docraft/docraft_lib.h"
#include "abstract_docraft_layout_handler.h"
#include "docraft/model/docraft_line.h"

namespace docraft::layout::handler {
/**
* @brief Layout handler for Line nodes.
*
* Lines are drawn at absolute positions within the current layout context.
* Coordinates (x1, y1, x2, y2) are interpreted as global positions within the section,
* not as local offsets relative to the layout cursor.
*/
class DOCRAFT_LIB DocraftLayoutLineHandler : public AbstractDocraftLayoutHandler<model::DocraftLine> {
public:
struct HorizontalChildPlacement {
std::shared_ptr<model::DocraftNode> node;
std::size_t box_index;
};

using AbstractDocraftLayoutHandler::AbstractDocraftLayoutHandler;

static void align_horizontal_row_lines_to_baseline(
const std::vector<HorizontalChildPlacement> &placements,
std::vector<model::DocraftTransform> &row_boxes);

void compute(const std::shared_ptr<model::DocraftLine> &node,
model::DocraftTransform *box,
DocraftCursor &cursor) override;

bool handle(const std::shared_ptr<model::DocraftNode> &request,
model::DocraftTransform *result,
DocraftCursor &cursor) override;
};
} // namespace docraft::layout::handler


Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2026 Matteo Cadoni (https://github.com/cadons)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

// Shared override declarations used by horizontal/vertical table handlers.
#define DOCRAFT_TABLE_PIPELINE_OVERRIDES \
void setup_pipeline_state(const std::shared_ptr<model::DocraftTable> &node, \
DocraftCursor &cursor) override; \
void prepare_table_layout(const std::shared_ptr<model::DocraftTable> &node) override; \
[[nodiscard]] float layout_table_content(const std::shared_ptr<model::DocraftTable> &node) override; \
[[nodiscard]] float resolve_table_width() const override

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "docraft/docraft_lib.h"
#include "docraft/layout/docraft_layout_engine.h"
#include "docraft/layout/handler/docraft_layout_table_handler.h"
#include "docraft/layout/handler/docraft_layout_table_pipeline_overrides.h"

namespace docraft::layout::handler {
/**
Expand All @@ -49,14 +50,7 @@ namespace docraft::layout::handler {
DocraftCursor &cursor) override;

protected:
void setup_pipeline_state(const std::shared_ptr<model::DocraftTable> &node,
DocraftCursor &cursor) override;

void prepare_table_layout(const std::shared_ptr<model::DocraftTable> &node) override;

[[nodiscard]] float layout_table_content(const std::shared_ptr<model::DocraftTable> &node) override;

[[nodiscard]] float resolve_table_width() const override;
DOCRAFT_TABLE_PIPELINE_OVERRIDES;

private:
struct TableData {
Expand Down
6 changes: 3 additions & 3 deletions docraft/include/docraft/model/docraft_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ namespace docraft::model {
*/
float border_width() const;
private:
DocraftPoint start_{};
DocraftPoint end_{};
DocraftColor border_color_ = DocraftColor(0, 0, 0, 0);
DocraftPoint start_{.x = 0.0F, .y = 0.0F};
DocraftPoint end_{.x = 100.0F, .y = 0.0F};
DocraftColor border_color_ = DocraftColor(0, 0, 0, 1);
float border_width_ = 1.0F;
};
} // docraft::model
23 changes: 16 additions & 7 deletions docraft/include/docraft/renderer/painter/docraft_polygon_painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,33 @@

#include "docraft/docraft_lib.h"
#include "docraft/model/docraft_polygon.h"
#include "docraft/renderer/painter/i_painter.h"
#include "docraft/renderer/painter/docraft_polygonal_shape_painter_base.h"

namespace docraft::renderer::painter {
/**
* @brief Painter that draws DocraftPolygon nodes.
*/
class DOCRAFT_LIB DocraftPolygonPainter : public IPainter {
class DOCRAFT_LIB DocraftPolygonPainter : public DocraftPolygonalShapePainterBase {
public:
/**
* @brief Creates a polygon painter bound to the polygon node.
* @param polygon_node Polygon node.
*/
explicit DocraftPolygonPainter(const model::DocraftPolygon &polygon_node);
/**
* @brief Draws the polygon using the provided context.
* @param context Document context.
*/
void draw(const std::shared_ptr<DocraftDocumentContext> &context) override;

// draw(...) is inherited from DocraftPolygonalShapePainterBase.

protected:
[[nodiscard]] const std::vector<model::DocraftPoint> &shape_points() const override;

[[nodiscard]] const model::DocraftPoint &shape_origin() const override;

[[nodiscard]] const DocraftColor &shape_background_color() const override;

[[nodiscard]] const DocraftColor &shape_border_color() const override;

[[nodiscard]] float shape_border_width() const override;

private:
model::DocraftPolygon polygon_node_;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2026 Matteo Cadoni (https://github.com/cadons)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <memory>
#include <vector>

#include "docraft/docraft_color.h"
#include "docraft/model/docraft_position.h"
#include "docraft/renderer/painter/i_painter.h"

namespace docraft::renderer::painter {
/**
* @brief Shared painter base for polygonal shapes (triangle, polygon, ...).
*/
class DOCRAFT_LIB DocraftPolygonalShapePainterBase : public IPainter {
public:
void draw(const std::shared_ptr<DocraftDocumentContext> &context) override;

protected:
[[nodiscard]] virtual const std::vector<model::DocraftPoint> &shape_points() const = 0;

[[nodiscard]] virtual const model::DocraftPoint &shape_origin() const = 0;

[[nodiscard]] virtual const DocraftColor &shape_background_color() const = 0;

[[nodiscard]] virtual const DocraftColor &shape_border_color() const = 0;

[[nodiscard]] virtual float shape_border_width() const = 0;
};
} // namespace docraft::renderer::painter

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace docraft::renderer::painter {
* @brief Creates a rectangle painter bound to the rectangle node.
* @param rectangle_node Rectangle node.
*/
DocraftRectanglePainter(const model::DocraftRectangle &rectangle_node);
explicit DocraftRectanglePainter(const model::DocraftRectangle &rectangle_node);

/**
* @brief Draws the rectangle using the provided context.
* @param context Document context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace docraft::renderer::painter {
* @brief Creates a table painter bound to the table node.
* @param table_node Table node.
*/
DocraftTablePainter(const model::DocraftTable &table_node);
explicit DocraftTablePainter(const model::DocraftTable &table_node);

/**
* @brief Draws the table using the provided context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,33 @@

#include "docraft/docraft_lib.h"
#include "docraft/model/docraft_triangle.h"
#include "docraft/renderer/painter/i_painter.h"
#include "docraft/renderer/painter/docraft_polygonal_shape_painter_base.h"

namespace docraft::renderer::painter {
/**
* @brief Painter that draws DocraftTriangle nodes.
*/
class DOCRAFT_LIB DocraftTrianglePainter : public IPainter {
class DOCRAFT_LIB DocraftTrianglePainter : public DocraftPolygonalShapePainterBase {
public:
/**
* @brief Creates a triangle painter bound to the triangle node.
* @param triangle_node Triangle node.
*/
explicit DocraftTrianglePainter(const model::DocraftTriangle &triangle_node);
/**
* @brief Draws the triangle using the provided context.
* @param context Document context.
*/
void draw(const std::shared_ptr<DocraftDocumentContext> &context) override;

// draw(...) is inherited from DocraftPolygonalShapePainterBase.

protected:
[[nodiscard]] const std::vector<model::DocraftPoint> &shape_points() const override;

[[nodiscard]] const model::DocraftPoint &shape_origin() const override;

[[nodiscard]] const DocraftColor &shape_background_color() const override;

[[nodiscard]] const DocraftColor &shape_border_color() const override;

[[nodiscard]] float shape_border_width() const override;

private:
model::DocraftTriangle triangle_node_;
};
Expand Down
Loading
Loading