]> git.lyx.org Git - lyx.git/commitdiff
Add "needcopiesfrom" converter flag
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 18 Aug 2024 15:53:51 +0000 (17:53 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 18 Aug 2024 16:29:22 +0000 (18:29 +0200)
This is needed to provide ePub and other DocBook-based exports with
the right (renamed) images (fixes #12372)

(cherry picked from commit 03c58420060fef520d74d835bb39e1b1c9fd7c1e)

lib/configure.py
lib/doc/Customization.lyx
lib/doc/de/Customization.lyx
src/Buffer.cpp
src/Converter.cpp
src/Converter.h

index 2674cd58eee76948cc7fb46359e4b88f93dc631a..94501f08bfce48d547cf68d9d6854e73cb4fce27 100644 (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      "%%"   ""' ])
index 0500d0fce176db96d157e2f6ade01ce17e36a0c9..ab6369f6354fc8d08d49af5415496c0c2caefd36 100644 (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
index c19440e1808258b48619877f5a1e4b7f97112853..5a1ff49e5b349b997521958f3c85eb08330ab592 100644 (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
index 994d5476d5b8d0c68b79751e26d9f0e7903b9c6d..b6fd8a3bc3fc91a11a5bf316f33f86c48a4cc7cc 100644 (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);
index 881aac6bd394ef243ac92f0af098cccc17709387..41bd8ce1a05efcced51b6bf20442429f7de8d551 100644 (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  "
index 091dbcd394e4b8075f3d4d04af6ad279c96a3d7d..720990013aa8b8250f2e450c945a4a47dad43295 100644 (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);
        ///