diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 080195e..2abf35b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 020ea66..12660a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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() diff --git a/doc/source/getting_started.rst b/doc/source/getting_started.rst index f0abf67..e93614d 100644 --- a/doc/source/getting_started.rst +++ b/doc/source/getting_started.rst @@ -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 + #include + #include int main() { // 1. Create a document @@ -92,7 +92,7 @@ Parse and render it from C++: .. code-block:: cpp - #include "docraft/craft/docraft_craft_language_parser.h" + #include int main() { docraft::craft::DocraftCraftLanguageParser parser; @@ -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 + #include int main() { docraft::craft::DocraftCraftLanguageParser parser; @@ -187,7 +187,7 @@ Register external TTF fonts at runtime: .. code-block:: cpp - #include "docraft/utils/docraft_font_registry.h" + #include auto& registry = docraft::utils::DocraftFontRegistry::instance(); registry.register_font("MyFont", "fonts/MyFont-Regular.ttf"); diff --git a/docraft/CMakeLists.txt b/docraft/CMakeLists.txt index 77027dd..3e74a93 100644 --- a/docraft/CMakeLists.txt +++ b/docraft/CMakeLists.txt @@ -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} @@ -167,8 +167,8 @@ target_compile_definitions(docraft PUBLIC $<$: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() @@ -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 diff --git a/docraft/include/docraft/docraft_lib.h b/docraft/include/docraft/docraft_lib.h index 0d20e78..a93b4e1 100644 --- a/docraft/include/docraft/docraft_lib.h +++ b/docraft/include/docraft/docraft_lib.h @@ -17,7 +17,7 @@ #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) @@ -25,7 +25,7 @@ #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 diff --git a/docraft/src/docraft/backend/pdf/docraft_haru_backend.cc b/docraft/src/docraft/backend/pdf/docraft_haru_backend.cc index f2fc47d..c845717 100644 --- a/docraft/src/docraft/backend/pdf/docraft_haru_backend.cc +++ b/docraft/src/docraft/backend/pdf/docraft_haru_backend.cc @@ -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(); diff --git a/docraft/src/docraft/layout/handler/docraft_basic_layout_handler.cc b/docraft/src/docraft/layout/handler/docraft_basic_layout_handler.cc index 02c86f1..f5ef66f 100644 --- a/docraft/src/docraft/layout/handler/docraft_basic_layout_handler.cc +++ b/docraft/src/docraft/layout/handler/docraft_basic_layout_handler.cc @@ -16,7 +16,6 @@ #include "docraft/layout/handler/docraft_basic_layout_handler.h" -#include #include "docraft/layout/docraft_layout_engine.h" #include "docraft/model/docraft_layout.h" diff --git a/docraft/src/docraft/layout/handler/docraft_layout_handler.cc b/docraft/src/docraft/layout/handler/docraft_layout_handler.cc index 96663c8..36c8078 100644 --- a/docraft/src/docraft/layout/handler/docraft_layout_handler.cc +++ b/docraft/src/docraft/layout/handler/docraft_layout_handler.cc @@ -15,7 +15,6 @@ */ #include "docraft/layout/handler/docraft_layout_handler.h" -#include #include "docraft/layout/docraft_layout_engine.h" #define PADDING 20.0F diff --git a/docraft/src/docraft/layout/handler/docraft_layout_table_handler.cc b/docraft/src/docraft/layout/handler/docraft_layout_table_handler.cc index 59b684d..deefde3 100644 --- a/docraft/src/docraft/layout/handler/docraft_layout_table_handler.cc +++ b/docraft/src/docraft/layout/handler/docraft_layout_table_handler.cc @@ -17,8 +17,8 @@ #include "docraft/layout/handler/docraft_layout_table_handler.h" #include +#include #include -#include #include #include "docraft/layout/docraft_layout_engine.h" @@ -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())); } } } diff --git a/docraft/src/docraft/layout/handler/docraft_layout_text_handler.cc b/docraft/src/docraft/layout/handler/docraft_layout_text_handler.cc index 475e986..81fdf64 100644 --- a/docraft/src/docraft/layout/handler/docraft_layout_text_handler.cc +++ b/docraft/src/docraft/layout/handler/docraft_layout_text_handler.cc @@ -18,7 +18,6 @@ #include #include -#include #include "docraft/generic/docraft_font_applier.h" #include "docraft/model/docraft_layout.h" diff --git a/docraft/src/docraft/model/docraft_position.cc b/docraft/src/docraft/model/docraft_position.cc index fe8ee88..d305db6 100644 --- a/docraft/src/docraft/model/docraft_position.cc +++ b/docraft/src/docraft/model/docraft_position.cc @@ -16,7 +16,7 @@ #include "docraft/model/docraft_position.h" -#include +#include #include #include "docraft/utils/docraft_logger.h" @@ -24,7 +24,7 @@ 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 diff --git a/docraft/src/docraft/renderer/painter/docraft_table_painter.cc b/docraft/src/docraft/renderer/painter/docraft_table_painter.cc index f988cdc..9d18acd 100644 --- a/docraft/src/docraft/renderer/painter/docraft_table_painter.cc +++ b/docraft/src/docraft/renderer/painter/docraft_table_painter.cc @@ -15,9 +15,10 @@ */ #include "docraft/renderer/painter/docraft_table_painter.h" -#include #include "docraft/backend/docraft_line_rendering_backend.h" +#include + #include "docraft/renderer/painter/docraft_image_painter.h" #include "docraft/utils/docraft_logger.h" @@ -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, diff --git a/docraft/src/docraft/renderer/painter/docraft_text_painter.cc b/docraft/src/docraft/renderer/painter/docraft_text_painter.cc index 6e82b58..6b760c9 100644 --- a/docraft/src/docraft/renderer/painter/docraft_text_painter.cc +++ b/docraft/src/docraft/renderer/painter/docraft_text_painter.cc @@ -17,7 +17,6 @@ #include "docraft/renderer/painter/docraft_text_painter.h" #include -#include #include #include "docraft/generic/docraft_font_applier.h" diff --git a/docraft/src/docraft/templating/docraft_template_engine.cc b/docraft/src/docraft/templating/docraft_template_engine.cc index 7b15d1c..ae8ad6b 100644 --- a/docraft/src/docraft/templating/docraft_template_engine.cc +++ b/docraft/src/docraft/templating/docraft_template_engine.cc @@ -21,7 +21,7 @@ #include "docraft/templating/docraft_template_engine.h" #include -#include +#include #include #include @@ -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}); } @@ -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; } @@ -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); } @@ -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}); @@ -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; } @@ -319,8 +319,7 @@ namespace docraft::templating { const auto expected_size = static_cast(width) * static_cast(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); } diff --git a/vcpkg.json b/vcpkg.json index 93d8fe2..86f61d7 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -6,6 +6,7 @@ "libharu", "nlohmann-json", "pugixml", - "gtest" + "gtest", + "fmt" ] } \ No newline at end of file