Add "needcopiesfrom" converter flag

This is needed to provide ePub and other DocBook-based exports with
the right (renamed) images (fixes #12372)

(cherry picked from commit 03c5842006)
This commit is contained in:
Juergen Spitzmueller 2024-08-18 17:53:51 +02:00
parent f8b18714c4
commit b21f104b37
6 changed files with 124 additions and 6 deletions

View File

@ -1022,7 +1022,7 @@ def checkConverterEntries():
checkProg('DocBook converter -> PDF (docbook)',
['pandoc -f docbook -t latex --pdf-engine=lualatex --toc -o $$o $$i', # Since Pandoc 2.0
'pandoc -f docbook -t latex --latex-engine=lualatex --toc -o $$o $$i'], # Up to Pandoc 1.19
rc_entry = [ r'\converter docbook5 pdf9 "%%" ""' ])
rc_entry = [ r'\converter docbook5 pdf9 "%%" "needcopiesfrom=docbook5"' ])
#
xpath, xslt_sheet = checkProg('XSLT stylesheets for ePub', ['chunk.xsl'], '', ['/usr/share/xml/docbook/stylesheet/docbook-xsl-ns/epub3'])
if xslt_sheet == 'chunk.xsl':
@ -1031,9 +1031,9 @@ def checkConverterEntries():
xpath = 'none'
global java
if xsltproc != '':
addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py none none \"' + xsltproc + r'\" ' + xpath + ' $$i $$r $$o" ""')
addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py none none \"' + xsltproc + r'\" ' + xpath + ' $$i $$r $$o" "needcopiesfrom=docbook5"')
elif java != '':
addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py \"' + java + r'\" none none ' + xpath + ' $$i $$r $$o" ""')
addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py \"' + java + r'\" none none ' + xpath + ' $$i $$r $$o" "needcopiesfrom=docbook5"')
#
checkProg('a MS Word Office Open XML converter -> LaTeX', ['pandoc -s -f docx -o $$o -t latex $$i'],
rc_entry = [ r'\converter word2 latex "%%" ""' ])

View File

@ -2622,6 +2622,51 @@ latex
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
needcopiesfrom=<format>
\end_layout
\end_inset
Some formats (e.
\begin_inset space \thinspace{}
\end_inset
g.,
DocBook) generate external files with specific names (for instance if math is rendered as graphic),
but they are only generated in the working directory if the respective format is the target format.
If you have such a format in your conversion chain and need those files in conversion,
use this flag with the respective
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
<format>
\end_layout
\end_inset
(cf.
the DocBook to ePub converter,
which uses
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
needcopiesfrom=docbook5
\end_layout
\end_inset
).
The files will then be made available in the temporary directory as soon as the intermediate format has been generated.
\end_layout
\begin_layout Labeling
\labelwidthstring 00.00.0000
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
nice
\end_layout

View File

@ -2182,6 +2182,51 @@ latex
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
needcopiesfrom=<Format>
\end_layout
\end_inset
Manche Formate (bspw.
DocBook) erzeugen externe Dateien mit speziellen Namen (zum Beispiel,
wenn mathematische Formeln als Grafiken dargestellt werden),
allerdings geschieht dies nur,
wenn das Format den Endpunkt der Konversion darstellt,
die Dateien landen dann im Arbeitsverzeichnis.
Wenn Sie eines dieser Formate als Zwischenformat haben und diese Dateien im Konvertierungsprozess benötigen,
verwenden Sie diesen Flag mit dem entsprechenden
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
<Format>
\end_layout
\end_inset
(vgl.
den Konverter von DocBook nach ePub,
der
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
needcopiesfrom=docbook5
\end_layout
\end_inset
verwendet).
Die Dateien werden dann im temporären Verzeichnis zur Verfügung gestellt,
nachdem das Zwischenformat erzeugt wurde.
\end_layout
\begin_layout Labeling
\labelwidthstring 00.00.0000
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
nice
\end_layout

View File

@ -4615,7 +4615,8 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
Converters::RetVal const retval =
converters.convert(this, FileName(filename), tmp_result_file,
FileName(absFileName()), backend_format, format,
error_list, Converters::none, includeall);
error_list, Converters::none, includeall,
runparams.exportdata);
if (retval == Converters::KILLED)
return ExportCancel;
bool success = (retval == Converters::SUCCESS);

View File

@ -18,6 +18,7 @@
#include "TextClass.h"
#include "Encoding.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "InsetList.h"
#include "Language.h"
@ -143,6 +144,8 @@ void Converter::readFlags()
need_auth_ = true;
else if (flag_name == "hyperref-driver")
href_driver_ = flag_value;
else if (flag_name == "needcopiesfrom")
need_renamed_copies_from_ = flag_value;
}
if (!result_dir_.empty() && result_file_.empty())
result_file_ = "index." + theFormats().extension(to_);
@ -414,7 +417,8 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
FileName const & from_file, FileName const & to_file,
FileName const & orig_from,
string const & from_format, string const & to_format,
ErrorList & errorList, int conversionflags, bool includeall)
ErrorList & errorList, int conversionflags, bool includeall,
shared_ptr<ExportData> exportdata)
{
if (from_format == to_format)
return move(from_format, from_file, to_file, false) ?
@ -526,6 +530,22 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
FileName outfile = from_file;
for (auto const & edge : edgepath) {
Converter const & conv = converterlist_[edge];
// If the converter requires renamed file copies from an involved
// converter, handle this here. These copies stay in the tmp dir
if (exportdata && conv.need_renamed_copies_from() == conv.from()) {
vector<ExportedFile> const extfiles =
exportdata->externalFiles(conv.from());
CopyStatus status = FORCE;
for (ExportedFile const & exp : extfiles) {
string const fmt = theFormats().getFormatFromFile(exp.sourceName);
FileName expFileName = makeAbsPath(exp.exportName,
exp.sourceName.onlyPath().realPath());
status = copyFile(fmt, exp.sourceName,
expFileName,
exp.exportName, status == FORCE,
true);
}
}
bool dummy = conv.To()->dummy() && conv.to() != "program";
if (!dummy) {
LYXERR(Debug::FILES, "Converting from "

View File

@ -15,6 +15,7 @@
#include "Graph.h"
#include "support/trivstring.h"
#include <memory>
#include <vector>
#include <set>
#include <string>
@ -26,6 +27,7 @@ namespace support { class FileName; }
class Buffer;
class ErrorList;
class ExportData;
class Format;
class Formats;
class OutputParams;
@ -91,6 +93,8 @@ public:
std::string const parselog() const { return parselog_; }
///
std::string const hyperref_driver() const { return href_driver_; }
///
std::string const need_renamed_copies_from() const { return need_renamed_copies_from_; }
private:
///
@ -128,6 +132,8 @@ private:
trivstring parselog_;
/// The hyperref driver
trivstring href_driver_;
/// Needs renamed file copies from an intermediate format
trivstring need_renamed_copies_from_;
};
@ -195,7 +201,8 @@ public:
support::FileName const & from_file, support::FileName const & to_file,
support::FileName const & orig_from,
std::string const & from_format, std::string const & to_format,
ErrorList & errorList, int conversionflags = none, bool includeall = false);
ErrorList & errorList, int conversionflags = none, bool includeall = false,
std::shared_ptr<ExportData> exportdata = nullptr);
///
void update(Formats const & formats);
///