#include "support/convert.h"
#include "support/debug.h"
+#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/lstrings.h"
#include <algorithm>
#include <stack>
-#include <QCryptographicHash>
-
using namespace std;
using namespace lyx::support;
// TODO: no real support for Unicode. This code is very similar to RenderPreview::addPreview, the same gotcha applies.
graphics::PreviewLoader* loader = buffer().loader();
+ // This should be OK because we are exporting
+ LASSERT(loader != nullptr, return);
loader->add(snippet);
loader->startLoading(true); // Generate the image and wait until done.
graphics::PreviewImage const * img = loader->preview(snippet);
// same hash (by design of cryptographic hash functions). Computing a hash
// is typically slow, but extremely fast compared to compilation of the
// preview and image rendering.
- QString snippetQ = QString(snippet.c_str());
-#if QT_VERSION >= 0x050000
- QByteArray hash = QCryptographicHash::hash(snippetQ.toLocal8Bit(), QCryptographicHash::Sha256);
-#else
- QByteArray hash = QCryptographicHash::hash(snippetQ.toLocal8Bit(), QCryptographicHash::Sha1);
-#endif
- auto newFileBase = QString(hash.toBase64())
- .replace("/", "")
- .replace("+", "")
- .replace("=", "");
- std::string newFileName = "lyx_" + newFileBase.toStdString() + "." + filename.extension();
+ std::string newFileName = "lyx_" + sanitizeFileName(toHexHash(snippet)) + "." + filename.extension();
// Copy the image into the right folder.
rp.exportdata->addExternalFile("docbook5", filename, newFileName);