diff --git a/autotests/export/docbook/Linguistics_forest.xml b/autotests/export/docbook/Linguistics_forest.xml index 65c0f0bc98..65144e7f21 100644 --- a/autotests/export/docbook/Linguistics_forest.xml +++ b/autotests/export/docbook/Linguistics_forest.xml @@ -13,7 +13,7 @@ Here is a simple example: - + [VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[D[a]][NP[letter]]] ] ] @@ -26,7 +26,7 @@ expands to a real structure tree. To view the result within the work area, you can simply embed the Structure Tree inset into a Preview inset. If instant preview is correctly installed and activated, you should see the tree immediately (just click on the image in order to edit): - + [VP [DP[Mary]] [V' [V[sent]] [DP[John]] [DP[D[a]][NP[response]]] ] ] @@ -35,7 +35,7 @@ Roofs can be easily generated by means of the roof option (note that the comma has special meaning, as it marks options): - + [VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[another letter, roof]] ] ] @@ -44,7 +44,7 @@ In order to align nodes of the tree more elegantly, use the “tier” option. All nodes which have the same tier allocated get aligned. Here is an example: - + [VP [DP[John,tier=word]] [V' [V[sent,tier=word]] [DP[Mary,tier=word]] [DP[D[a,tier=word]][NP[letter,tier=word]]] ] ] diff --git a/autotests/export/docbook/lyx_EafAhhREpvwrFIFUHprlnoS9qCdR7kk23QfWTsObCjg.png b/autotests/export/docbook/lyx_EafAhhREpvwrFIFUHprlnoS9qCdR7kk23QfWTsObCjg.png new file mode 100644 index 0000000000..d2c57a4031 Binary files /dev/null and b/autotests/export/docbook/lyx_EafAhhREpvwrFIFUHprlnoS9qCdR7kk23QfWTsObCjg.png differ diff --git a/autotests/export/docbook/lyx_Evmv0h17wY4EoBIBFZjUQJMv0cyWz6KodzrzPiY1tQ.png b/autotests/export/docbook/lyx_Evmv0h17wY4EoBIBFZjUQJMv0cyWz6KodzrzPiY1tQ.png new file mode 100644 index 0000000000..0fa6b403b9 Binary files /dev/null and b/autotests/export/docbook/lyx_Evmv0h17wY4EoBIBFZjUQJMv0cyWz6KodzrzPiY1tQ.png differ diff --git a/autotests/export/docbook/lyx_Neo86S96tfZZQHjpBg7ADIb30ZP0DTrDTR1DEIL6dM.png b/autotests/export/docbook/lyx_Neo86S96tfZZQHjpBg7ADIb30ZP0DTrDTR1DEIL6dM.png new file mode 100644 index 0000000000..4245f72f8c Binary files /dev/null and b/autotests/export/docbook/lyx_Neo86S96tfZZQHjpBg7ADIb30ZP0DTrDTR1DEIL6dM.png differ diff --git a/autotests/export/docbook/lyxpreviewAJskuj1.png b/autotests/export/docbook/lyx_waUJAzFwGUKDEN7MJCcs6gYNMbJuYBkgsRTDTpIvs.png similarity index 100% rename from autotests/export/docbook/lyxpreviewAJskuj1.png rename to autotests/export/docbook/lyx_waUJAzFwGUKDEN7MJCcs6gYNMbJuYBkgsRTDTpIvs.png diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 2fc63cef7f..7bb0c0c8df 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -72,6 +72,8 @@ #include #include +#include + using namespace std; using namespace lyx::support; @@ -669,8 +671,28 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH LASSERT(img != nullptr, return); support::FileName const & filename = img->filename(); + // Use a file name that is only determined by the LaTeX code: the name of + // the snippet is more or less random (i.e., if the user generates the file + // several times, they will have a clutter of preview files). + // Hence: use a cryptographic hash of the snippet. If the snippet changes, + // the file name will change a lot; two snippets are unlikely to have the + // 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(); + // Copy the image into the right folder. - rp.exportdata->addExternalFile("docbook5", filename, filename.onlyFileName()); + rp.exportdata->addExternalFile("docbook5", filename, newFileName); // TODO: deal with opts. What exactly is the WriterOuterTag here, for instance? // Start writing the DocBook code for the image. @@ -680,7 +702,7 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH // Output the rendered inset. xs << xml::StartTag("imageobject") << xml::CR() - << xml::CompTag("imagedata", std::string("fileref='") + filename.onlyFileName() + "'") + << xml::CompTag("imagedata", std::string("fileref='") + newFileName + "'") << xml::CR() << xml::EndTag("imageobject") << xml::CR();