3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Alfredo Braunstein
8 * \author Lars Gullik Bjønnes
9 * \author Jean Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
14 * Full author contact details are available in file CREDITS.
21 #include "buffer_funcs.h"
22 #include "support/filetools.h"
24 #include "converter.h"
26 #include "frontends/Alert.h"
31 using namespace lyx::support;
39 vector<string> const Backends(Buffer const & buffer)
42 if (buffer.params.getLyXTextClass().isTeXClassAvailable())
43 v.push_back(BufferFormat(buffer));
51 bool Exporter::Export(Buffer * buffer, string const & format,
52 bool put_in_tempdir, string & result_file)
54 string backend_format;
55 LatexRunParams runparams;
56 runparams.flavor = LatexRunParams::LATEX;
57 vector<string> backends = Backends(*buffer);
58 if (find(backends.begin(), backends.end(), format) == backends.end()) {
59 for (vector<string>::const_iterator it = backends.begin();
60 it != backends.end(); ++it) {
62 converters.getPath(*it, format);
64 if (converters.usePdflatex(p))
65 runparams.flavor = LatexRunParams::PDFLATEX;
70 if (backend_format.empty()) {
71 Alert::error(_("Couldn't export file"),
72 bformat(_("No information for exporting the format %1$s."),
73 formats.prettyName(format)));
77 backend_format = format;
79 string filename = buffer->getLatexName(false);
80 if (!buffer->tmppath.empty())
81 filename = AddName(buffer->tmppath, filename);
82 filename = ChangeExtension(filename,
83 formats.extension(backend_format));
86 if (backend_format == "text")
87 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
89 else if (buffer->isLinuxDoc())
90 buffer->makeLinuxDocFile(filename, !put_in_tempdir);
92 else if (buffer->isDocBook())
93 buffer->makeDocBookFile(filename, !put_in_tempdir);
95 else if (backend_format == format) {
96 runparams.nice = true;
97 buffer->makeLaTeXFile(filename, string(), runparams);
98 } else if (contains(buffer->filePath(), ' ')) {
99 Alert::error(_("File name error"),
100 _("The directory path to the document cannot contain spaces."));
103 runparams.nice = false;
104 buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
107 string outfile_base = (put_in_tempdir)
108 ? filename : buffer->getLatexName(false);
110 if (!converters.convert(buffer, filename, outfile_base,
111 backend_format, format, result_file))
115 buffer->message(_("Document exported as ")
116 + formats.prettyName(format)
118 + MakeDisplayPath(result_file) +'\'');
123 bool Exporter::Export(Buffer * buffer, string const & format,
127 return Export(buffer, format, put_in_tempdir, result_file);
131 bool Exporter::Preview(Buffer * buffer, string const & format)
134 if (!Export(buffer, format, true, result_file))
136 return formats.view(*buffer, result_file, format);
140 bool Exporter::IsExportable(Buffer const & buffer, string const & format)
142 vector<string> backends = Backends(buffer);
143 for (vector<string>::const_iterator it = backends.begin();
144 it != backends.end(); ++it)
145 if (converters.isReachable(*it, format))
151 vector<Format const *> const
152 Exporter::GetExportableFormats(Buffer const & buffer, bool only_viewable)
154 vector<string> backends = Backends(buffer);
155 vector<Format const *> result =
156 converters.getReachable(backends[0], only_viewable, true);
157 for (vector<string>::const_iterator it = backends.begin() + 1;
158 it != backends.end(); ++it) {
159 vector<Format const *> r =
160 converters.getReachable(*it, only_viewable, false);
161 result.insert(result.end(), r.begin(), r.end());