fixes #0001672: Raytracing export to POV-Ray - respect ASCII convention for I/O filenames

This commit is contained in:
wmayer
2018-09-22 10:48:45 +02:00
parent b5811a42b4
commit f6b4ffb149

View File

@@ -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();
}