mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
DocBook: use a hash to determine the file names for generated images.
This way, the file names no more change without a reason.
This commit is contained in:
parent
33668e3a30
commit
21366155e4
@ -13,7 +13,7 @@
|
|||||||
<para>Here is a simple example:</para>
|
<para>Here is a simple example:</para>
|
||||||
<mediaobject>
|
<mediaobject>
|
||||||
<imageobject>
|
<imageobject>
|
||||||
<imagedata fileref='lyxpreviewAJskuj1.png' />
|
<imagedata fileref='lyx_waUJAzFwGUKDEN7MJCcs6gYNMbJuYBkgsRTDTpIvs.png' />
|
||||||
</imageobject>
|
</imageobject>
|
||||||
<textobject>
|
<textobject>
|
||||||
<programlisting language='latex' role='forest'>[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[D[a]][NP[letter]]] ] ]</programlisting>
|
<programlisting language='latex' role='forest'>[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[D[a]][NP[letter]]] ] ]</programlisting>
|
||||||
@ -26,7 +26,7 @@
|
|||||||
<para>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):</para>
|
<para>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):</para>
|
||||||
<para><mediaobject>
|
<para><mediaobject>
|
||||||
<imageobject>
|
<imageobject>
|
||||||
<imagedata fileref='lyxpreviewWZhpAx1.png' />
|
<imagedata fileref='lyx_Neo86S96tfZZQHjpBg7ADIb30ZP0DTrDTR1DEIL6dM.png' />
|
||||||
</imageobject>
|
</imageobject>
|
||||||
<textobject>
|
<textobject>
|
||||||
<programlisting language='latex' role='forest'>[VP [DP[Mary]] [V' [V[sent]] [DP[John]] [DP[D[a]][NP[response]]] ] ]</programlisting>
|
<programlisting language='latex' role='forest'>[VP [DP[Mary]] [V' [V[sent]] [DP[John]] [DP[D[a]][NP[response]]] ] ]</programlisting>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
<para>Roofs can be easily generated by means of the <code>roof</code> option (note that the comma has special meaning, as it marks options):</para>
|
<para>Roofs can be easily generated by means of the <code>roof</code> option (note that the comma has special meaning, as it marks options):</para>
|
||||||
<mediaobject>
|
<mediaobject>
|
||||||
<imageobject>
|
<imageobject>
|
||||||
<imagedata fileref='lyxpreviewQJTcYJ1.png' />
|
<imagedata fileref='lyx_Evmv0h17wY4EoBIBFZjUQJMv0cyWz6KodzrzPiY1tQ.png' />
|
||||||
</imageobject>
|
</imageobject>
|
||||||
<textobject>
|
<textobject>
|
||||||
<programlisting language='latex' role='forest'>[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[another letter, roof]] ] ]</programlisting>
|
<programlisting language='latex' role='forest'>[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[another letter, roof]] ] ]</programlisting>
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<para>In order to align nodes of the tree more elegantly, use the “tier” option. All nodes which have the same <code>tier</code> allocated get aligned. Here is an example:</para>
|
<para>In order to align nodes of the tree more elegantly, use the “tier” option. All nodes which have the same <code>tier</code> allocated get aligned. Here is an example:</para>
|
||||||
<mediaobject>
|
<mediaobject>
|
||||||
<imageobject>
|
<imageobject>
|
||||||
<imagedata fileref='lyxpreviewBkSuoA1.png' />
|
<imagedata fileref='lyx_EafAhhREpvwrFIFUHprlnoS9qCdR7kk23QfWTsObCjg.png' />
|
||||||
</imageobject>
|
</imageobject>
|
||||||
<textobject>
|
<textobject>
|
||||||
<programlisting language='latex' role='forest'>[VP [DP[John,tier=word]] [V' [V[sent,tier=word]] [DP[Mary,tier=word]] [DP[D[a,tier=word]][NP[letter,tier=word]]] ] ]</programlisting>
|
<programlisting language='latex' role='forest'>[VP [DP[John,tier=word]] [V' [V[sent,tier=word]] [DP[Mary,tier=word]] [DP[D[a,tier=word]][NP[letter,tier=word]]] ] ]</programlisting>
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
@ -72,6 +72,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace lyx::support;
|
using namespace lyx::support;
|
||||||
@ -669,8 +671,28 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH
|
|||||||
LASSERT(img != nullptr, return);
|
LASSERT(img != nullptr, return);
|
||||||
support::FileName const & filename = img->filename();
|
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.
|
// 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?
|
// TODO: deal with opts. What exactly is the WriterOuterTag here, for instance?
|
||||||
// Start writing the DocBook code for the image.
|
// 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.
|
// Output the rendered inset.
|
||||||
xs << xml::StartTag("imageobject")
|
xs << xml::StartTag("imageobject")
|
||||||
<< xml::CR()
|
<< xml::CR()
|
||||||
<< xml::CompTag("imagedata", std::string("fileref='") + filename.onlyFileName() + "'")
|
<< xml::CompTag("imagedata", std::string("fileref='") + newFileName + "'")
|
||||||
<< xml::CR()
|
<< xml::CR()
|
||||||
<< xml::EndTag("imageobject")
|
<< xml::EndTag("imageobject")
|
||||||
<< xml::CR();
|
<< xml::CR();
|
||||||
|
Loading…
Reference in New Issue
Block a user