From d32c7f52414d6a2bcb8b2a62bb780333348000be Mon Sep 17 00:00:00 2001 From: albert-github Date: Sat, 15 Feb 2020 14:43:31 +0100 Subject: Creation of svg images for formulas with inkscape Based on the implementation as mentioned in #7578 to add the possibilities to generated svg images for formulas - When running with inkscape 92.3 / 92.4 on Cygwin /Windows there were no images generated as the `-o` flag didn't exist, the output file had to be specified as part of the `-l` (or `--export-plain-svg`) option - For more flexibility the system is checked on existence of the `pdf2svg` and `inkscape` executables, so no compilations flags are necessary --- src/config.xml | 3 ++- src/formula.cpp | 51 ++++++++++++++++++++++++--------------------------- src/portable.cpp | 14 +++++++++++++- src/portable.h | 1 + 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/config.xml b/src/config.xml index de5efdc..a9b954c 100644 --- a/src/config.xml +++ b/src/config.xml @@ -2361,7 +2361,8 @@ The \c DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. diff --git a/src/formula.cpp b/src/formula.cpp index 92647ed..de004ed 100644 --- a/src/formula.cpp +++ b/src/formula.cpp @@ -38,15 +38,6 @@ #define RM_TMP_FILES (true) //#define RM_TMP_FILES (false) -// for SVG output choose which tool to use -#define USE_PDF2SVG 1 -#define USE_INKSCAPE 0 - -#if (USE_PDF2SVG+USE_INKSCAPE!=1) -#error "Invalid configuration: either USE_PDF2SVG or USE_INKSCAPE should be 1" -#endif - - struct FormulaManager::Private { void storeDisplaySize(int id,int w,int h) @@ -303,31 +294,37 @@ void FormulaManager::generateImages(const char *path,Format format,HighDPI hd) c } Portable::sysTimerStop(); -#if USE_PDF2SVG - sprintf(args,"%s_tmp.pdf form_%d.svg",formBase.data(),pageNum); - Portable::sysTimerStart(); - if (Portable::system("pdf2svg",args)!=0) + if (Portable::checkForExecutable("pdf2svg")) { - err("Problems running pdf2svg. Check your installation!\n"); + sprintf(args,"%s_tmp.pdf form_%d.svg",formBase.data(),pageNum); + Portable::sysTimerStart(); + if (Portable::system("pdf2svg",args)!=0) + { + err("Problems running pdf2svg. Check your installation!\n"); + Portable::sysTimerStop(); + QDir::setCurrent(oldDir); + return; + } Portable::sysTimerStop(); - QDir::setCurrent(oldDir); - return; } - Portable::sysTimerStop(); -#endif - -#if USE_INKSCAPE // alternative using inkscape (does seem to work very well on my system) - sprintf(args,"-l -z %s_tmp.pdf -o form_%d.svg 2>%s",formBase.data(),pageNum,Portable::devNull()); - Portable::sysTimerStart(); - if (Portable::system("inkscape",args)!=0) + else if (Portable::checkForExecutable("inkscape")) { - err("Problems running inkscape. Check your installation!\n"); + sprintf(args,"-l form_%d.svg -z %s_tmp.pdf 2>%s",pageNum,formBase.data(),Portable::devNull()); + Portable::sysTimerStart(); + if (Portable::system("inkscape",args)!=0) + { + err("Problems running inkscape. Check your installation!\n"); + Portable::sysTimerStop(); + QDir::setCurrent(oldDir); + return; + } Portable::sysTimerStop(); - QDir::setCurrent(oldDir); + } + else + { + err("Neither 'pdf2svg' nor 'inkscape' present for conversion of formula to 'svg'\n"); return; } - Portable::sysTimerStop(); -#endif if (RM_TMP_FILES) { diff --git a/src/portable.cpp b/src/portable.cpp index 8ceb7d6..8c941b6 100644 --- a/src/portable.cpp +++ b/src/portable.cpp @@ -348,7 +348,6 @@ char Portable::pathListSeparator(void) #endif } -#if defined(_WIN32) && !defined(__CYGWIN__) static const bool ExistsOnPath(const char *fileName) { QFileInfo fi1(fileName); @@ -380,7 +379,20 @@ static const bool ExistsOnPath(const char *fileName) } return false; } + +const bool Portable::checkForExecutable(const char *fileName) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + char *extensions[] = {".bat",".com",".exe"}; + for (int i = 0; i < sizeof(extensions) / sizeof(*extensions); i++) + { + if (ExistsOnPath(QCString(fileName) + extensions[i])) return true; + } + return false; +#else + return ExistsOnPath(fileName); #endif +} const char *Portable::ghostScriptCommand(void) { diff --git a/src/portable.h b/src/portable.h index 956ae41..6c215a8 100644 --- a/src/portable.h +++ b/src/portable.h @@ -44,6 +44,7 @@ namespace Portable void setShortDir(void); const char * strnstr(const char *haystack, const char *needle, size_t haystack_len); const char * devNull(); + const bool checkForExecutable(const char *fileName); } -- cgit v0.12