From f6505e35fce3948284bbbd262f70765ced008489 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sun, 28 Jun 2020 09:49:20 +0200 Subject: [PATCH] fixed issue #41: "Build error when JKQtPlotter_BUILD_INCLUDE_XITS_FONTS set to OFF", code tried to use XITS-ressources, which were not there oif option is switched off. --> solved by adding optional private preprocessor definition --- lib/jkqtmathtext/CMakeLists.txt | 6 ++++++ lib/jkqtmathtext/jkqtmathtext.cpp | 10 ++++++++-- lib/jkqtmathtext/jkqtmathtext.h | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/jkqtmathtext/CMakeLists.txt b/lib/jkqtmathtext/CMakeLists.txt index a386fe70e5..1604240031 100644 --- a/lib/jkqtmathtext/CMakeLists.txt +++ b/lib/jkqtmathtext/CMakeLists.txt @@ -50,6 +50,9 @@ if(JKQtPlotter_BUILD_SHARED_LIBS) $ $ ) + if(JKQtPlotter_BUILD_INCLUDE_XITS_FONTS) + target_compile_definitions(${libsh_name} PRIVATE JKQTMATHTEXT_COMPILED_WITH_XITS) + endif(JKQtPlotter_BUILD_INCLUDE_XITS_FONTS) set_target_properties(${libsh_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS "ON") write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${libsh_name}Version.cmake VERSION ${PROJECT_VERSION} @@ -61,6 +64,9 @@ if(JKQtPlotter_BUILD_STATIC_LIBS) target_compile_features(${lib_name} PUBLIC cxx_std_11) set_property(TARGET ${lib_name} PROPERTY VERSION "${PROJECT_VERSION}") set_property(TARGET ${lib_name} PROPERTY OUTPUT_NAME "${lib_name_decorated}") + if(JKQtPlotter_BUILD_INCLUDE_XITS_FONTS) + target_compile_definitions(${lib_name} PRIVATE JKQTMATHTEXT_COMPILED_WITH_XITS) + endif(JKQtPlotter_BUILD_INCLUDE_XITS_FONTS) target_link_libraries(${lib_name} PUBLIC Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport JKQTCommonLib) target_include_directories(${lib_name} PUBLIC $ diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp index c8e461241d..9510496f40 100644 --- a/lib/jkqtmathtext/jkqtmathtext.cpp +++ b/lib/jkqtmathtext/jkqtmathtext.cpp @@ -3257,7 +3257,7 @@ JKQTMathText::JKQTMathText(QObject* parent): QObject(parent) { //std::chrono::high_resolution_clock::time_point t0=std::chrono::high_resolution_clock::now(); - Q_INIT_RESOURCE(xits); + initJKQTMathTextResources(); //qDebug()<<"init_resoucre: "<(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms"; t0=std::chrono::high_resolution_clock::now(); QFontDatabase fontdb; //qDebug()<<"init_fontDB: "<(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms"; t0=std::chrono::high_resolution_clock::now(); @@ -4983,7 +4983,13 @@ QString JKQTMathText::MTplainTextNode::textTransform(const QString &_text, JKQTM void initJKQTMathTextResources() { - Q_INIT_RESOURCE(xits); + static bool initialized=false; + if (!initialized) { +#ifdef JKQTMATHTEXT_COMPILED_WITH_XITS + Q_INIT_RESOURCE(xits); +#endif + initialized=true; + } } JKQTMathText::MTnodeSize::MTnodeSize(): diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h index 44d2119c40..163a07c828 100644 --- a/lib/jkqtmathtext/jkqtmathtext.h +++ b/lib/jkqtmathtext/jkqtmathtext.h @@ -421,6 +421,11 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject { * These are included by default in this library and also activated by default. * * \image html jkqtmathparser_xits.png + * + * \note The XITS fonts can be compiled into JKQTPlotter, when the CMake-option \c is set to ON (default: ON). + * Then the XITS fonts are added as Qt-Ressources to the library binary. + * If this is not the case, you have to provide the XITS fonts on the target system by other means, if you want + * to use them. */ bool useXITS(bool mathModeOnly=true);