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.
22 #include "buffer_funcs.h"
23 #include "bufferparams.h"
24 #include "converter.h"
27 #include "latexrunparams.h"
30 #include "frontends/Alert.h"
32 #include "support/filetools.h"
34 using lyx::support::AddName;
35 using lyx::support::bformat;
36 using lyx::support::ChangeExtension;
37 using lyx::support::contains;
38 using lyx::support::MakeDisplayPath;
47 vector<string> const Backends(Buffer const & buffer)
50 if (buffer.params().getLyXTextClass().isTeXClassAvailable())
51 v.push_back(BufferFormat(buffer));
59 bool Exporter::Export(Buffer * buffer, string const & format,
60 bool put_in_tempdir, string & result_file)
62 string backend_format;
63 LatexRunParams runparams;
64 runparams.flavor = LatexRunParams::LATEX;
65 vector<string> backends = Backends(*buffer);
66 if (find(backends.begin(), backends.end(), format) == backends.end()) {
67 for (vector<string>::const_iterator it = backends.begin();
68 it != backends.end(); ++it) {
70 converters.getPath(*it, format);
72 if (converters.usePdflatex(p))
73 runparams.flavor = LatexRunParams::PDFLATEX;
78 if (backend_format.empty()) {
79 Alert::error(_("Couldn't export file"),
80 bformat(_("No information for exporting the format %1$s."),
81 formats.prettyName(format)));
85 backend_format = format;
87 string filename = buffer->getLatexName(false);
88 if (!buffer->temppath().empty())
89 filename = AddName(buffer->temppath(), filename);
90 filename = ChangeExtension(filename,
91 formats.extension(backend_format));
94 if (backend_format == "text")
95 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
97 else if (buffer->isLinuxDoc())
98 buffer->makeLinuxDocFile(filename, !put_in_tempdir);
100 else if (buffer->isDocBook())
101 buffer->makeDocBookFile(filename, !put_in_tempdir);
103 else if (backend_format == format) {
104 runparams.nice = true;
105 buffer->makeLaTeXFile(filename, string(), runparams);
106 } else if (contains(buffer->filePath(), ' ')) {
107 Alert::error(_("File name error"),
108 _("The directory path to the document cannot contain spaces."));
111 runparams.nice = false;
112 buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
115 string outfile_base = (put_in_tempdir)
116 ? filename : buffer->getLatexName(false);
118 if (!converters.convert(buffer, filename, outfile_base,
119 backend_format, format, result_file))
123 buffer->message(_("Document exported as ")
124 + formats.prettyName(format)
126 + MakeDisplayPath(result_file) +'\'');
131 bool Exporter::Export(Buffer * buffer, string const & format,
135 return Export(buffer, format, put_in_tempdir, result_file);
139 bool Exporter::Preview(Buffer * buffer, string const & format)
142 if (!Export(buffer, format, true, result_file))
144 return formats.view(*buffer, result_file, format);
148 bool Exporter::IsExportable(Buffer const & buffer, string const & format)
150 vector<string> backends = Backends(buffer);
151 for (vector<string>::const_iterator it = backends.begin();
152 it != backends.end(); ++it)
153 if (converters.isReachable(*it, format))
159 vector<Format const *> const
160 Exporter::GetExportableFormats(Buffer const & buffer, bool only_viewable)
162 vector<string> backends = Backends(buffer);
163 vector<Format const *> result =
164 converters.getReachable(backends[0], only_viewable, true);
165 for (vector<string>::const_iterator it = backends.begin() + 1;
166 it != backends.end(); ++it) {
167 vector<Format const *> r =
168 converters.getReachable(*it, only_viewable, false);
169 result.insert(result.end(), r.begin(), r.end());