TEX -> DVI -> PS -> PNG
| 253 | |
| 254 | // TEX -> DVI -> PS -> PNG |
| 255 | QByteArray TeXRenderer::imageFromDVI(const QTemporaryFile& file, const int dpi, Result* res) { |
| 256 | QFileInfo fi(file.fileName()); |
| 257 | const QString& baseName = fi.completeBaseName(); |
| 258 | |
| 259 | if (!executeLatexProcess(QLatin1String("latex"), baseName, file, QStringLiteral("dvi"), res)) |
| 260 | return {}; |
| 261 | |
| 262 | // dvips: DVI -> PS |
| 263 | const QString dvipsFullPath = safeExecutableName(QStringLiteral("dvips")); |
| 264 | if (dvipsFullPath.isEmpty()) { |
| 265 | res->successful = false; |
| 266 | res->errorMessage = i18n("dvips not found"); |
| 267 | WARN("dvips not found"); |
| 268 | return {}; |
| 269 | } |
| 270 | QProcess dvipsProcess; |
| 271 | startHostProcess(dvipsProcess, dvipsFullPath, QStringList() << QStringLiteral("-E") << baseName); |
| 272 | if (!dvipsProcess.waitForFinished() || dvipsProcess.exitCode() != 0) { |
| 273 | QString err = i18n("dvips process failed, exit code =") + QStringLiteral(" ") + QString::number(dvipsProcess.exitCode()); |
| 274 | WARN(err.toStdString()); |
| 275 | res->successful = false; |
| 276 | res->errorMessage = std::move(err); |
| 277 | QFile::remove(baseName + QStringLiteral(".aux")); |
| 278 | QFile::remove(baseName + QStringLiteral(".log")); |
| 279 | QFile::remove(baseName + QStringLiteral(".dvi")); |
| 280 | return {}; |
| 281 | } |
| 282 | |
| 283 | // convert: PS -> PNG |
| 284 | QProcess convertProcess; |
| 285 | #if defined(HAVE_WINDOWS) |
| 286 | // need to set path to magick coder modules (which are in the labplot directory) |
| 287 | auto env = QProcessEnvironment::systemEnvironment(); |
| 288 | env.insert(QStringLiteral("MAGICK_CODER_MODULE_PATH"), QString::fromLocal8Bit(qgetenv("PROGRAMFILES")) + QStringLiteral("\\labplot")); |
| 289 | convertProcess.setProcessEnvironment(env); |
| 290 | #endif |
| 291 | const QString convertFullPath = safeExecutableName(QStringLiteral("convert")); |
| 292 | if (convertFullPath.isEmpty()) { |
| 293 | WARN("convert not found"); |
| 294 | res->successful = false; |
| 295 | res->errorMessage = i18n("convert not found"); |
| 296 | return {}; |
| 297 | } |
| 298 | |
| 299 | const QStringList params{QStringLiteral("-density"), QString::number(dpi), baseName + QStringLiteral(".ps"), baseName + QStringLiteral(".pdf")}; |
| 300 | startHostProcess(convertProcess, convertFullPath, params); |
| 301 | |
| 302 | if (!convertProcess.waitForFinished() || convertProcess.exitCode() != 0) { |
| 303 | QString err = i18n("convert process failed, exit code =") + QStringLiteral(" ") + QString::number(convertProcess.exitCode()); |
| 304 | WARN(err.toStdString()); |
| 305 | res->successful = false; |
| 306 | res->errorMessage = std::move(err); |
| 307 | QFile::remove(baseName + QStringLiteral(".aux")); |
| 308 | QFile::remove(baseName + QStringLiteral(".log")); |
| 309 | QFile::remove(baseName + QStringLiteral(".dvi")); |
| 310 | QFile::remove(baseName + QStringLiteral(".ps")); |
| 311 | return {}; |
| 312 | } |
nothing calls this directly
no test coverage detected