Skip to content
Closed
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: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y cmake ninja-build g++-14 \
libhpdf-dev libpugixml-dev nlohmann-json3-dev libgtest-dev ccache
libhpdf-dev libpugixml-dev nlohmann-json3-dev libgtest-dev libfmt-dev ccache

- name: Setup ccache
uses: actions/cache@v3
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:

- name: Install dependencies
run: |
brew install cmake ninja libharu pugixml nlohmann-json googletest ccache
brew install cmake ninja libharu pugixml nlohmann-json googletest fmt ccache

- name: Display versions
run: |
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED_LIB "Build docraft as a shared library" OFF)
option(BUILD_SHARED_LIBS "Build docraft as a shared library" OFF)

include(.cmake/utils.cmake)
configure_build_folder(artifacts)
Expand All @@ -39,6 +39,7 @@ configure_build_folder(artifacts)
find_package(pugixml CONFIG REQUIRED)
find_package(unofficial-libharu QUIET)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
if(unofficial-libharu_FOUND)
set(LIBHARU_TARGET unofficial::libharu::hpdf)
else()
Expand Down
14 changes: 7 additions & 7 deletions doc/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Build a document entirely from C++ without any ``.craft`` file:

.. code-block:: cpp

#include "docraft/docraft_document.h"
#include "docraft/model/docraft_text.h"
#include "docraft/model/docraft_body.h"
#include <docraft/docraft_document.h>
#include <docraft/model/docraft_text.h>
#include <docraft/model/docraft_body.h>

int main() {
// 1. Create a document
Expand Down Expand Up @@ -92,7 +92,7 @@ Parse and render it from C++:

.. code-block:: cpp

#include "docraft/craft/docraft_craft_language_parser.h"
#include <docraft/craft/docraft_craft_language_parser.h>

int main() {
docraft::craft::DocraftCraftLanguageParser parser;
Expand All @@ -118,8 +118,8 @@ Inject runtime data into a ``.craft`` template:

.. code-block:: cpp

#include "docraft/craft/docraft_craft_language_parser.h"
#include "docraft/templating/docraft_template_engine.h"
#include <docraft/craft/docraft_craft_language_parser.h>
#include <docraft/templating/docraft_template_engine.h>

int main() {
docraft::craft::DocraftCraftLanguageParser parser;
Expand Down Expand Up @@ -187,7 +187,7 @@ Register external TTF fonts at runtime:

.. code-block:: cpp

#include "docraft/utils/docraft_font_registry.h"
#include <docraft/utils/docraft_font_registry.h>

auto& registry = docraft::utils::DocraftFontRegistry::instance();
registry.register_font("MyFont", "fonts/MyFont-Regular.ttf");
Expand Down
8 changes: 4 additions & 4 deletions docraft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ set(DOCRAFT_SOURCES
src/docraft/craft/parser/docraft_foreach_parser.cc
)
set(DOCRAFT_LIBRARY_TYPE STATIC)
if(BUILD_SHARED_LIB)
if(BUILD_SHARED_LIBS)
set(DOCRAFT_LIBRARY_TYPE SHARED)
endif()
add_library(docraft ${DOCRAFT_LIBRARY_TYPE}
Expand All @@ -167,8 +167,8 @@ target_compile_definitions(docraft PUBLIC
$<$<CONFIG:Debug>:docraft_debugf>
)

if(BUILD_SHARED_LIB)
target_compile_definitions(docraft PRIVATE DOCRAFT_BUILD_SHARED_LIB)#define the macro to build the shared lib
if(BUILD_SHARED_LIBS)
target_compile_definitions(docraft PRIVATE DOCRAFT_BUILD_SHARED_LIBS)#define the macro to build the shared lib
target_compile_definitions(docraft INTERFACE DOCRAFT_USE_SHARED_LIB)#define the macro to use the shared lib
endif()

Expand All @@ -185,7 +185,7 @@ else()
message(FATAL_ERROR "No pugixml CMake target found")
endif()

target_link_libraries(docraft PUBLIC ${PUGIXML_TARGET} nlohmann_json::nlohmann_json ${LIBHARU_TARGET})
target_link_libraries(docraft PUBLIC ${PUGIXML_TARGET} nlohmann_json::nlohmann_json ${LIBHARU_TARGET} fmt::fmt)
target_link_libraries(docraft_tool PRIVATE docraft)

target_include_directories(docraft
Expand Down
4 changes: 2 additions & 2 deletions docraft/include/docraft/docraft_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#pragma once

#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(DOCRAFT_BUILD_SHARED_LIB)
#if defined(DOCRAFT_BUILD_SHARED_LIBS)
#define DOCRAFT_LIB __declspec(dllexport)
#elif defined(DOCRAFT_USE_SHARED_LIB)
#define DOCRAFT_LIB __declspec(dllimport)
#else
#define DOCRAFT_LIB
#endif
#elif defined(__GNUC__) && __GNUC__ >= 4
#if defined(DOCRAFT_BUILD_SHARED_LIB)
#if defined(DOCRAFT_BUILD_SHARED_LIBS)
#define DOCRAFT_LIB __attribute__((visibility("default")))
#else
#define DOCRAFT_LIB
Expand Down
2 changes: 1 addition & 1 deletion docraft/src/docraft/backend/pdf/docraft_haru_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace {
}
};

void error_handler(HPDF_STATUS error_no, HPDF_STATUS, void *) {
void HPDF_STDCALL error_handler(HPDF_STATUS error_no, HPDF_STATUS, void *) {
std::ostringstream ss;
ss << std::hex << error_no;
std::string error_no_hex = ss.str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "docraft/layout/handler/docraft_basic_layout_handler.h"

#include <print>

#include "docraft/layout/docraft_layout_engine.h"
#include "docraft/model/docraft_layout.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include "docraft/layout/handler/docraft_layout_handler.h"
#include <print>

#include "docraft/layout/docraft_layout_engine.h"
#define PADDING 20.0F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "docraft/layout/handler/docraft_layout_table_handler.h"

#include <algorithm>
#include <fmt/format.h>
#include <numeric>
#include <print>
#include <vector>

#include "docraft/layout/docraft_layout_engine.h"
Expand Down Expand Up @@ -544,7 +544,7 @@ namespace docraft::layout::handler {
for (const auto &row: node->content_nodes()) {
for (const auto &cell: row) {
if (cell) {
LOG_DEBUG(std::format("Cell at ({}, {}) with size ({}, {})", cell->position().x, cell->position().y, cell->width(), cell->height()));
LOG_DEBUG(fmt::format("Cell at ({}, {}) with size ({}, {})", cell->position().x, cell->position().y, cell->width(), cell->height()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <algorithm>
#include <sstream>
#include <print>

#include "docraft/generic/docraft_font_applier.h"
#include "docraft/model/docraft_layout.h"
Expand Down
4 changes: 2 additions & 2 deletions docraft/src/docraft/model/docraft_position.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

#include "docraft/model/docraft_position.h"

#include <format>
#include <fmt/format.h>
#include <sstream>

#include "docraft/utils/docraft_logger.h"

namespace docraft::model {
#pragma region DocraftPoint
std::string DocraftPoint::to_string() const {
return std::format("{{{};{}}}", x, y);
return fmt::format("{{{};{}}}", x, y);
}
#pragma endregion
#pragma region DocraftTransform
Expand Down
5 changes: 3 additions & 2 deletions docraft/src/docraft/renderer/painter/docraft_table_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/

#include "docraft/renderer/painter/docraft_table_painter.h"
#include <print>
#include "docraft/backend/docraft_line_rendering_backend.h"

#include <fmt/format.h>

#include "docraft/renderer/painter/docraft_image_painter.h"
#include "docraft/utils/docraft_logger.h"

Expand Down Expand Up @@ -253,7 +254,7 @@ namespace docraft::renderer::painter {

// draw horizontal line at bottom of this row
float line_y_here = bottom_y;
LOG_DEBUG(std::format("Drawing horizontal line at y={}", line_y_here));
LOG_DEBUG(fmt::format("Drawing horizontal line at y={}", line_y_here));
line_backend->draw_line(
start_x,
line_y_here,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "docraft/renderer/painter/docraft_text_painter.h"

#include <algorithm>
#include <print>
#include <sstream>

#include "docraft/generic/docraft_font_applier.h"
Expand Down
17 changes: 8 additions & 9 deletions docraft/src/docraft/templating/docraft_template_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "docraft/templating/docraft_template_engine.h"

#include <algorithm>
#include <format>
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>

Expand All @@ -48,7 +48,7 @@ namespace docraft::templating {
void DocraftTemplateEngine::add_template_variable(const std::string &name, const std::string &value) {
auto normalized_name = normalize_name(name);
if (has_template_variable(normalized_name)) {
throw std::runtime_error(std::format("Template variable '{}' already exists.", name));
throw std::runtime_error(fmt::format("Template variable '{}' already exists.", name));
}
template_variables_.insert({normalized_name, value});
}
Expand All @@ -57,7 +57,7 @@ namespace docraft::templating {
auto normalized_name = normalize_name(name);
auto it = template_variables_.find(normalized_name);
if (it == template_variables_.end()) {
throw std::runtime_error(std::format("Template variable '{}' not found.", name));
throw std::runtime_error(fmt::format("Template variable '{}' not found.", name));
}
return it->second;
}
Expand All @@ -70,7 +70,7 @@ namespace docraft::templating {
auto normalized_name = normalize_name(name);
auto it = template_variables_.find(normalized_name);
if (it == template_variables_.end()) {
throw std::runtime_error(std::format("Template variable '{}' not found.", name));
throw std::runtime_error(fmt::format("Template variable '{}' not found.", name));
}
template_variables_.erase(it);
}
Expand Down Expand Up @@ -291,10 +291,10 @@ namespace docraft::templating {
int height) {
auto name = normalize_name(image_id);
if (image_data_.contains(name)) {
throw std::runtime_error(std::format("Image data for '{}' already exists.", image_id));
throw std::runtime_error(fmt::format("Image data for '{}' already exists.", image_id));
}
if (width <= 0 || height <= 0) {
throw std::runtime_error(std::format("Image data for '{}' has invalid dimensions.", image_id));
throw std::runtime_error(fmt::format("Image data for '{}' has invalid dimensions.", image_id));
}
//emplace the key also in the standard unordered_map with the same normalized name to ensure consistency
template_variables_.insert({name, name});
Expand All @@ -306,7 +306,7 @@ namespace docraft::templating {
auto name = normalize_name(image_id);
auto it = image_data_.find(name);
if (it == image_data_.end()) {
throw std::runtime_error(std::format("Image data for '{}' not found.", image_id));
throw std::runtime_error(fmt::format("Image data for '{}' not found.", image_id));
}
return it->second;
}
Expand All @@ -319,8 +319,7 @@ namespace docraft::templating {
const auto expected_size =
static_cast<size_t>(width) * static_cast<size_t>(height) * 3U; //3 bytes per pixel for RGB
if (decoded.size() != expected_size) {
throw std::runtime_error(std::format(
"Base64 image '{}' size does not match dimensions (RGB expected).", image_id));
throw std::runtime_error(fmt::format("Base64 image '{}' size does not match dimensions (RGB expected).", image_id));
}
add_image_data(image_id, decoded, width, height);
}
Expand Down
3 changes: 2 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"libharu",
"nlohmann-json",
"pugixml",
"gtest"
"gtest",
"fmt"
]
}
Loading