2003-03-31 01:15:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file exporter.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-03-31 01:15:44 +00:00
|
|
|
|
* \author unknown
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-03-31 01:15:44 +00:00
|
|
|
|
*/
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "exporter.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2000-10-16 13:27:56 +00:00
|
|
|
|
#include "converter.h"
|
2003-02-28 09:49:49 +00:00
|
|
|
|
#include "format.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "output_plaintext.h"
|
|
|
|
|
#include "outputparams.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "support/filetools.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::AddName;
|
|
|
|
|
using lyx::support::bformat;
|
|
|
|
|
using lyx::support::ChangeExtension;
|
|
|
|
|
using lyx::support::contains;
|
|
|
|
|
using lyx::support::MakeDisplayPath;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
using std::find;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::vector;
|
|
|
|
|
|
2003-06-24 20:42:15 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
vector<string> const Backends(Buffer const & buffer)
|
2003-06-24 20:42:15 +00:00
|
|
|
|
{
|
|
|
|
|
vector<string> v;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (buffer.params().getLyXTextClass().isTeXClassAvailable())
|
2003-08-28 07:41:31 +00:00
|
|
|
|
v.push_back(BufferFormat(buffer));
|
2003-06-24 20:42:15 +00:00
|
|
|
|
v.push_back("text");
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace anon
|
|
|
|
|
|
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format,
|
2000-10-23 12:16:05 +00:00
|
|
|
|
bool put_in_tempdir, string & result_file)
|
2000-08-30 03:40:51 +00:00
|
|
|
|
{
|
2000-11-13 10:35:02 +00:00
|
|
|
|
string backend_format;
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams runparams;
|
|
|
|
|
runparams.flavor = OutputParams::LATEX;
|
2003-10-31 18:45:43 +00:00
|
|
|
|
runparams.linelen = lyxrc.ascii_linelen;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
vector<string> backends = Backends(*buffer);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
if (find(backends.begin(), backends.end(), format) == backends.end()) {
|
|
|
|
|
for (vector<string>::const_iterator it = backends.begin();
|
|
|
|
|
it != backends.end(); ++it) {
|
2003-02-28 09:49:49 +00:00
|
|
|
|
Graph::EdgePath p =
|
2001-07-30 11:56:00 +00:00
|
|
|
|
converters.getPath(*it, format);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
if (!p.empty()) {
|
2003-11-27 16:38:47 +00:00
|
|
|
|
runparams.flavor = converters.getFlavor(p);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
backend_format = *it;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (backend_format.empty()) {
|
2003-03-31 01:15:44 +00:00
|
|
|
|
Alert::error(_("Couldn't export file"),
|
2003-05-13 09:48:57 +00:00
|
|
|
|
bformat(_("No information for exporting the format %1$s."),
|
|
|
|
|
formats.prettyName(format)));
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
backend_format = format;
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
|
string filename = buffer->getLatexName(false);
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!buffer->temppath().empty())
|
|
|
|
|
filename = AddName(buffer->temppath(), filename);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
filename = ChangeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension(backend_format));
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2000-09-11 15:42:17 +00:00
|
|
|
|
// Ascii backend
|
2000-10-23 12:16:05 +00:00
|
|
|
|
if (backend_format == "text")
|
2003-11-05 12:06:20 +00:00
|
|
|
|
writeFileAscii(*buffer, filename, runparams);
|
2000-09-11 15:42:17 +00:00
|
|
|
|
// Linuxdoc backend
|
2003-10-31 18:45:43 +00:00
|
|
|
|
else if (buffer->isLinuxDoc()) {
|
|
|
|
|
runparams.nice = !put_in_tempdir;
|
|
|
|
|
buffer->makeLinuxDocFile(filename, runparams);
|
|
|
|
|
}
|
2000-09-11 15:42:17 +00:00
|
|
|
|
// Docbook backend
|
2003-10-31 18:45:43 +00:00
|
|
|
|
else if (buffer->isDocBook()) {
|
|
|
|
|
runparams.nice = !put_in_tempdir;
|
|
|
|
|
buffer->makeDocBookFile(filename, runparams);
|
|
|
|
|
}
|
2000-09-11 15:42:17 +00:00
|
|
|
|
// LaTeX backend
|
2003-05-22 21:10:22 +00:00
|
|
|
|
else if (backend_format == format) {
|
|
|
|
|
runparams.nice = true;
|
|
|
|
|
buffer->makeLaTeXFile(filename, string(), runparams);
|
|
|
|
|
} else if (contains(buffer->filePath(), ' ')) {
|
2003-03-31 01:15:44 +00:00
|
|
|
|
Alert::error(_("File name error"),
|
|
|
|
|
_("The directory path to the document cannot contain spaces."));
|
2001-04-14 08:10:52 +00:00
|
|
|
|
return false;
|
2003-05-22 21:10:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
runparams.nice = false;
|
|
|
|
|
buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
|
|
|
|
|
}
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
string outfile_base = (put_in_tempdir)
|
|
|
|
|
? filename : buffer->getLatexName(false);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
if (!converters.convert(buffer, filename, outfile_base,
|
2000-11-13 10:35:02 +00:00
|
|
|
|
backend_format, format, result_file))
|
2000-09-05 13:16:19 +00:00
|
|
|
|
return false;
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
|
if (!put_in_tempdir)
|
2003-07-07 08:37:02 +00:00
|
|
|
|
buffer->message(_("Document exported as ")
|
|
|
|
|
+ formats.prettyName(format)
|
|
|
|
|
+ _(" to file `")
|
|
|
|
|
+ MakeDisplayPath(result_file) +'\'');
|
2000-08-30 03:40:51 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-29 15:22:25 +00:00
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format,
|
|
|
|
|
bool put_in_tempdir)
|
|
|
|
|
{
|
|
|
|
|
string result_file;
|
|
|
|
|
return Export(buffer, format, put_in_tempdir, result_file);
|
|
|
|
|
}
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2002-10-29 15:22:25 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
bool Exporter::Preview(Buffer * buffer, string const & format)
|
2000-08-30 03:40:51 +00:00
|
|
|
|
{
|
2000-10-23 12:16:05 +00:00
|
|
|
|
string result_file;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
if (!Export(buffer, format, true, result_file))
|
2000-08-30 03:40:51 +00:00
|
|
|
|
return false;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
return formats.view(*buffer, result_file, format);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
bool Exporter::IsExportable(Buffer const & buffer, string const & format)
|
2000-10-02 16:44:47 +00:00
|
|
|
|
{
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<string> backends = Backends(buffer);
|
|
|
|
|
for (vector<string>::const_iterator it = backends.begin();
|
|
|
|
|
it != backends.end(); ++it)
|
2001-07-30 11:56:00 +00:00
|
|
|
|
if (converters.isReachable(*it, format))
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2000-10-02 16:44:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<Format const *> const
|
2003-08-28 07:41:31 +00:00
|
|
|
|
Exporter::GetExportableFormats(Buffer const & buffer, bool only_viewable)
|
2000-08-30 03:40:51 +00:00
|
|
|
|
{
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<string> backends = Backends(buffer);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
vector<Format const *> result =
|
2001-07-30 11:56:00 +00:00
|
|
|
|
converters.getReachable(backends[0], only_viewable, true);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
for (vector<string>::const_iterator it = backends.begin() + 1;
|
|
|
|
|
it != backends.end(); ++it) {
|
|
|
|
|
vector<Format const *> r =
|
2001-07-30 11:56:00 +00:00
|
|
|
|
converters.getReachable(*it, only_viewable, false);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
result.insert(result.end(), r.begin(), r.end());
|
|
|
|
|
}
|
2000-09-11 15:42:17 +00:00
|
|
|
|
return result;
|
2000-08-30 03:40:51 +00:00
|
|
|
|
}
|