[LyX/master] Add "needcopiesfrom" converter flag

Juergen Spitzmueller spitz at lyx.org
Sun Aug 18 16:20:54 UTC 2024


commit 03c58420060fef520d74d835bb39e1b1c9fd7c1e
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sun Aug 18 17:53:51 2024 +0200

    Add "needcopiesfrom" converter flag
    
    This is needed to provide ePub and other DocBook-based exports with
    the right (renamed) images (fixes #12372)
---
 lib/configure.py             |  6 ++--
 lib/doc/Customization.lyx    | 69 ++++++++++++++++++++++++++++++++++++++++++++
 lib/doc/de/Customization.lyx | 45 +++++++++++++++++++++++++++++
 src/Buffer.cpp               |  3 +-
 src/Converter.cpp            | 22 +++++++++++++-
 src/Converter.h              |  9 +++++-
 6 files changed, 148 insertions(+), 6 deletions(-)

diff --git a/lib/configure.py b/lib/configure.py
index 15c2a0d589..7c944e72b3 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -986,7 +986,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':
@@ -995,9 +995,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      "%%"	""' ])
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index d27349cd2e..ce013f63e0 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -2617,6 +2617,65 @@ latex
  is used.
 \end_layout
 
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+
+\change_inserted -712698321 1723633863
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723632792
+needcopiesfrom=<format>
+\change_unchanged
+
+\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
+
+\change_inserted -712698321 1723633006
+<format>
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ (cf.
+ the DocBook to ePub converter,
+ which uses 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723633014
+needcopiesfrom=docbook5
+\change_unchanged
+
+\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
@@ -20272,6 +20331,8 @@ status collapsed
 
 \change_inserted -712698321 1723525171
 InsertCotext
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -20291,6 +20352,8 @@ status collapsed
 
 \change_inserted -712698321 1723525183
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -20309,11 +20372,15 @@ status collapsed
 
 \emph on
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
 
 ]
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -20326,6 +20393,8 @@ status collapsed
 
 \change_inserted -712698321 1723525171
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index b89a461d6c..a6bd63f3c5 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -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
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index ac2cca9a06..35b45202d1 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4629,7 +4629,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);
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 1a90f5b325..2393d09e8d 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -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"
@@ -144,6 +145,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_);
@@ -415,7 +418,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) ?
@@ -528,6 +532,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  "
diff --git a/src/Converter.h b/src/Converter.h
index 091dbcd394..720990013a 100644
--- a/src/Converter.h
+++ b/src/Converter.h
@@ -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);
 	///


More information about the lyx-cvs mailing list