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
2 changes: 1 addition & 1 deletion doc/source/api/model_nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ stage: ``measured_size`` (Measure) → ``frame`` (Layout) → ``page_index``
(Pagination). Later stages read only what earlier stages wrote — skipping a
stage for a node type breaks whatever reads its field.

.. doxygenstruct:: docraft::loom::nodes::LayoutBox
.. doxygenclass:: docraft::loom::nodes::LayoutBox
:project: docraft
:members:

Expand Down
50 changes: 50 additions & 0 deletions docraft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ set(DOCRAFT_SOURCES
include/docraft/loom/nodes/docraft_loom_text.h
src/docraft/loom/nodes/docraft_loom_node.cc
include/docraft/loom/nodes/docraft_loom_node.h
include/docraft/loom/nodes/docraft_loom_layout_box_access.h
src/docraft/loom/pipeline/docraft_loom_measure_processor.cc
include/docraft/loom/pipeline/docraft_loom_measure_processor.h
src/docraft/loom/pipeline/docraft_loom_text_wrapper.cc
Expand Down Expand Up @@ -136,6 +137,8 @@ set(DOCRAFT_SOURCES
include/docraft/craft/docraft_craft_language_parser.h
src/docraft/craft/parser/docraft_parser_helpers.cc
include/docraft/craft/parser/docraft_parser_helpers.h
src/docraft/craft/parser/docraft_craft_enum_parsers.cc
include/docraft/craft/parser/docraft_craft_enum_parsers.h
src/docraft/craft/parser/docraft_shape_parser_utils.cc
include/docraft/craft/parser/docraft_shape_parser_utils.h
include/docraft/craft/parser/docraft_parser.h
Expand Down Expand Up @@ -171,6 +174,53 @@ set(DOCRAFT_SOURCES
# docraft/loom (translates DocraftParsedElement trees into loom nodes).
include/docraft/loom/craft/docraft_loom_tree_builder.h
src/docraft/loom/craft/docraft_loom_tree_builder.cc
include/docraft/loom/craft/docraft_loom_tree_builder_context.h
include/docraft/loom/craft/docraft_loom_tree_builder_utils.h
src/docraft/loom/craft/docraft_loom_tree_builder_utils.cc

# Loom tree-builder tag-handler registry: one IDocraftLoomTagHandler per Craft-
# language tag, mirroring docraft::craft's own IDocraftParser registry one stage
# earlier. Adding a new tag means adding one handler file + one registration line.
include/docraft/loom/craft/handlers/i_docraft_loom_tag_handler.h
include/docraft/loom/craft/docraft_loom_tag_handler_registry.h
src/docraft/loom/craft/docraft_loom_tag_handler_registry.cc
src/docraft/loom/craft/docraft_loom_builtin_tag_handlers.cc
include/docraft/loom/craft/handlers/docraft_loom_rectangle_handler.h
src/docraft/loom/craft/handlers/docraft_loom_rectangle_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_circle_handler.h
src/docraft/loom/craft/handlers/docraft_loom_circle_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_triangle_handler.h
src/docraft/loom/craft/handlers/docraft_loom_triangle_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_polygon_handler.h
src/docraft/loom/craft/handlers/docraft_loom_polygon_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_line_handler.h
src/docraft/loom/craft/handlers/docraft_loom_line_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_curve_line_handler.h
src/docraft/loom/craft/handlers/docraft_loom_curve_line_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_canvas_handler.h
src/docraft/loom/craft/handlers/docraft_loom_canvas_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_chart_handler.h
src/docraft/loom/craft/handlers/docraft_loom_chart_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_text_handler.h
src/docraft/loom/craft/handlers/docraft_loom_text_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_page_number_handler.h
src/docraft/loom/craft/handlers/docraft_loom_page_number_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_image_handler.h
src/docraft/loom/craft/handlers/docraft_loom_image_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_blank_line_handler.h
src/docraft/loom/craft/handlers/docraft_loom_blank_line_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_new_page_handler.h
src/docraft/loom/craft/handlers/docraft_loom_new_page_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_list_handler.h
src/docraft/loom/craft/handlers/docraft_loom_list_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_paragraph_handler.h
src/docraft/loom/craft/handlers/docraft_loom_paragraph_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_layout_handler.h
src/docraft/loom/craft/handlers/docraft_loom_layout_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_section_handler.h
src/docraft/loom/craft/handlers/docraft_loom_section_handler.cc
include/docraft/loom/craft/handlers/docraft_loom_table_handler.h
src/docraft/loom/craft/handlers/docraft_loom_table_handler.cc

# docraft/loom/charts (Chart/Series craft tags expand into a populated Canvas via
# a style registry -- Docraft's "chart plugin" mechanism; see DocraftChartBuilderRegistry).
Expand Down
38 changes: 38 additions & 0 deletions docraft/include/docraft/craft/parser/docraft_craft_enum_parsers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 <string>

#include "docraft/backend/docraft_page_format.h"
#include "docraft/docraft_lib.h"

namespace docraft::craft::parser::detail {
/**
* @brief Parses a `<Page size="...">` attribute value (case-insensitive
* A3/A4/A5/Letter/Legal).
* @throws docraft::exception::InvalidInputException if `size_str` isn't recognized.
*/
DOCRAFT_LIB docraft::backend::DocraftPageSize parse_page_size(const std::string& size_str);

/**
* @brief Parses a `<Page orientation="...">` attribute value (landscape/portrait).
* @throws docraft::exception::InvalidInputException if `orientation_str` isn't
* recognized.
*/
DOCRAFT_LIB docraft::backend::DocraftPageOrientation parse_page_orientation(const std::string& orientation_str);
} // namespace docraft::craft::parser::detail
7 changes: 7 additions & 0 deletions docraft/include/docraft/loom/charts/docraft_chart_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ namespace docraft::loom::charts {
kCenter
};

/**
* @brief Parses a `<Chart axis_position="...">` attribute value.
* @throws docraft::exception::InvalidInputException if `raw` isn't one of
* left/right/center/top-left/top-right/bottom-left/bottom-right.
*/
DOCRAFT_LIB DocraftChartAxisPosition parse_chart_axis_position(const std::string& raw);

/**
* @brief A single data series: a name (for the legend), a color, and its points in
* data space.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 <string>
#include <unordered_map>

#include "docraft/docraft_lib.h"
#include "docraft/loom/craft/handlers/i_docraft_loom_tag_handler.h"

namespace docraft::loom::craft {
/**
* @brief Maps a Craft-language tag name (e.g. "Rectangle", "Layout") to the
* `IDocraftLoomTagHandler` that builds it.
* @details Mirrors `docraft::craft::DocraftCraftLanguageParser`'s own tag ->
* `IDocraftParser` map one stage earlier, and `charts::DocraftChartBuilderRegistry`'s
* registry shape. Built-in tags register once via `register_builtin_tag_handlers()`,
* called from `DocraftLoomTreeBuilder`'s constructor.
*/
class DOCRAFT_LIB DocraftLoomTagHandlerRegistry
{
public:
static DocraftLoomTagHandlerRegistry& instance();

void register_handler(const std::string& tag, std::unique_ptr<IDocraftLoomTagHandler> handler);

/**
* @brief Returns the handler registered for `tag`, or nullptr if none is.
*/
IDocraftLoomTagHandler* find(const std::string& tag) const;

private:
DocraftLoomTagHandlerRegistry() = default;

std::unordered_map<std::string, std::unique_ptr<IDocraftLoomTagHandler>> handlers_;

Check warning on line 50 in docraft/include/docraft/loom/craft/docraft_loom_tag_handler_registry.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the transparent equality "std::equal_to<>" and a custom transparent heterogeneous hasher with this associative string container.

See more on https://sonarcloud.io/project/issues?id=Cadons_Docraft&issues=AaBTK8xUv2y9SQ4bqqr5&open=AaBTK8xUv2y9SQ4bqqr5&pullRequest=88
};

/**
* @brief Registers every Craft-language tag Docraft's loom pipeline ships out of the
* box into `DocraftLoomTagHandlerRegistry::instance()`.
* @details Safe to call more than once (re-registering a tag just overwrites its
* handler).
*/
DOCRAFT_LIB void register_builtin_tag_handlers();
} // namespace docraft::loom::craft
Loading
Loading