From f6b4ffb14904dbd9519152664c691a0d962c3cc6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 22 Sep 2018 10:48:45 +0200 Subject: [PATCH] fixes #0001672: Raytracing export to POV-Ray - respect ASCII convention for I/O filenames --- src/Mod/Raytracing/Gui/Command.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Mod/Raytracing/Gui/Command.cpp b/src/Mod/Raytracing/Gui/Command.cpp index 70a715218d..16b9e3df0c 100644 --- a/src/Mod/Raytracing/Gui/Command.cpp +++ b/src/Mod/Raytracing/Gui/Command.cpp @@ -645,7 +645,20 @@ void CmdRaytracingRender::activated(int) #ifdef FC_OS_WIN32 fn.replace(QLatin1String("\\"), QLatin1String("\\\\")); #endif - std::string fname = (const char*)fn.toUtf8(); + QByteArray utf8Name = fn.toUtf8(); + QByteArray localBit = fn.toLocal8Bit(); + QByteArray imageFile = utf8Name; + QString imageTemp; + + if (utf8Name != localBit) { + // Povray only supports ASCII file names. In case of a UTF-8 file name + // create the image file in the tmp. directory and copy it later to the + // destination file. + QString suffix = QFileInfo(fn).suffix(); + QFileInfo fi(QDir::temp(), QString::fromLatin1("Povray.%1").arg(suffix)); + imageTemp = fi.absoluteFilePath(); + imageFile = imageTemp.toLocal8Bit(); + } openCommand("Render project"); int width = hGrp->GetInt("OutputWidth", 800); std::stringstream w; @@ -663,12 +676,19 @@ void CmdRaytracingRender::activated(int) doCommand(Doc,"os.close(fd)"); #ifdef FC_OS_WIN32 // http://povray.org/documentation/view/3.6.1/603/ - doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" /EXIT /RENDER '+TempFile)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); + doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" /EXIT /RENDER '+TempFile)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),imageFile.data()); #else - doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" '+TempFile,shell=True)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); + doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" '+TempFile,shell=True)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),imageFile.data()); #endif + if (utf8Name != imageFile) { + imageFile = utf8Name; + if (QFile::exists(fn)) + QFile::remove(fn); + QFile::copy(imageTemp ,fn); + QFile::remove(imageTemp); + } doCommand(Gui,"import ImageGui"); - doCommand(Gui,"ImageGui.open('%s')",fname.c_str()); + doCommand(Gui,"ImageGui.open('%s')",imageFile.data()); doCommand(Doc,"del TempFile,PageFile"); commitCommand(); }