2002-09-05 11:31:30 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file PreviewLoader.cpp
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-07-05 21:24:15 +00:00
|
|
|
*
|
2002-11-04 02:12:42 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 11:31:30 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-07-05 21:24:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "PreviewLoader.h"
|
|
|
|
#include "PreviewImage.h"
|
2004-04-16 14:34:41 +00:00
|
|
|
#include "GraphicsCache.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2007-05-28 07:43:15 +00:00
|
|
|
#include "BufferParams.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Converter.h"
|
2007-05-28 07:43:15 +00:00
|
|
|
#include "Encoding.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Format.h"
|
|
|
|
#include "InsetIterator.h"
|
2007-05-28 07:43:15 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2007-05-28 07:43:15 +00:00
|
|
|
#include "output.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2007-05-28 07:43:15 +00:00
|
|
|
#include "TexRow.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2006-10-12 14:10:13 +00:00
|
|
|
#include "frontends/Application.h" // hexName
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
#include "insets/Inset.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
2007-11-29 19:19:39 +00:00
|
|
|
#include "support/convert.h"
|
|
|
|
#include "support/debug.h"
|
2007-12-17 16:04:46 +00:00
|
|
|
#include "support/FileName.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
#include "support/filetools.h"
|
2007-11-29 19:19:39 +00:00
|
|
|
#include "support/ForkedCalls.h"
|
2003-05-23 13:54:09 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
#include "support/bind.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2002-07-05 21:24:15 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
namespace {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
typedef pair<string, FileName> SnippetPair;
|
2002-07-06 11:36:11 +00:00
|
|
|
|
2007-02-25 22:18:13 +00:00
|
|
|
// A list of all snippets to be converted to previews
|
2002-07-16 18:10:51 +00:00
|
|
|
typedef list<string> PendingSnippets;
|
2002-07-09 09:30:54 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
// Each item in the vector is a pair<snippet, image file name>.
|
2006-11-26 21:30:39 +00:00
|
|
|
typedef vector<SnippetPair> BitmapFile;
|
2002-07-09 09:30:54 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
string const unique_filename(string const & bufferpath)
|
|
|
|
{
|
|
|
|
static int theCounter = 0;
|
|
|
|
string const filename = lyx::convert<string>(theCounter++) + "lyxpreview";
|
2007-12-12 19:57:42 +00:00
|
|
|
return addName(bufferpath, filename);
|
2006-10-21 00:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-18 17:26:09 +00:00
|
|
|
lyx::Converter const * setConverter(string const from)
|
2006-10-21 00:16:43 +00:00
|
|
|
{
|
|
|
|
typedef vector<string> FmtList;
|
|
|
|
typedef lyx::graphics::Cache GCache;
|
2008-06-06 11:34:49 +00:00
|
|
|
FmtList const & loadableFormats = GCache::get().loadableFormats();
|
2006-10-21 00:16:43 +00:00
|
|
|
FmtList::const_iterator it = loadableFormats.begin();
|
|
|
|
FmtList::const_iterator const end = loadableFormats.end();
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
string const to = *it;
|
|
|
|
if (from == to)
|
|
|
|
continue;
|
|
|
|
|
2007-01-17 13:18:16 +00:00
|
|
|
lyx::Converter const * ptr = lyx::theConverters().getConverter(from, to);
|
2006-10-21 00:16:43 +00:00
|
|
|
if (ptr)
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool first = true;
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR0("PreviewLoader::startLoading()\n"
|
2010-04-06 00:48:58 +00:00
|
|
|
<< "No converter from \"" << from << "\" format has been defined.");
|
2006-10-21 00:16:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-09 09:30:54 +00:00
|
|
|
|
|
|
|
void setAscentFractions(vector<double> & ascent_fractions,
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const & metrics_file)
|
2006-10-21 00:16:43 +00:00
|
|
|
{
|
|
|
|
// If all else fails, then the images will have equal ascents and
|
|
|
|
// descents.
|
|
|
|
vector<double>::iterator it = ascent_fractions.begin();
|
|
|
|
vector<double>::iterator end = ascent_fractions.end();
|
|
|
|
fill(it, end, 0.5);
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
ifstream in(metrics_file.toFilesystemEncoding().c_str());
|
2006-10-21 00:16:43 +00:00
|
|
|
if (!in.good()) {
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR(lyx::Debug::GRAPHICS, "setAscentFractions(" << metrics_file << ")\n"
|
|
|
|
<< "Unable to open file!");
|
2006-10-21 00:16:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
int snippet_counter = 1;
|
|
|
|
while (!in.eof() && it != end) {
|
|
|
|
string snippet;
|
|
|
|
int id;
|
|
|
|
double ascent_fraction;
|
|
|
|
|
|
|
|
in >> snippet >> id >> ascent_fraction;
|
|
|
|
|
|
|
|
if (!in.good())
|
|
|
|
// eof after all
|
|
|
|
break;
|
|
|
|
|
|
|
|
error = snippet != "Snippet";
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
|
|
|
|
error = id != snippet_counter;
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
|
|
|
|
*it = ascent_fraction;
|
|
|
|
|
|
|
|
++snippet_counter;
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR(lyx::Debug::GRAPHICS, "setAscentFractions(" << metrics_file << ")\n"
|
|
|
|
<< "Error reading file!\n");
|
2006-10-21 00:16:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-06 11:36:11 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
class FindFirst
|
|
|
|
{
|
2004-01-31 15:30:24 +00:00
|
|
|
public:
|
2002-07-06 11:36:11 +00:00
|
|
|
FindFirst(string const & comp) : comp_(comp) {}
|
2007-11-28 22:12:03 +00:00
|
|
|
bool operator()(SnippetPair const & sp) const { return sp.first == comp_; }
|
2002-07-06 11:36:11 +00:00
|
|
|
private:
|
|
|
|
string const comp_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
/// Store info on a currently executing, forked process.
|
2005-01-19 15:03:31 +00:00
|
|
|
class InProgress {
|
|
|
|
public:
|
2002-07-08 13:01:09 +00:00
|
|
|
///
|
|
|
|
InProgress() : pid(0) {}
|
|
|
|
///
|
2002-07-09 09:30:54 +00:00
|
|
|
InProgress(string const & filename_base,
|
2002-07-16 18:10:51 +00:00
|
|
|
PendingSnippets const & pending,
|
2002-07-09 09:30:54 +00:00
|
|
|
string const & to_format);
|
2002-07-17 16:56:42 +00:00
|
|
|
/// Remove any files left lying around and kill the forked process.
|
2002-07-08 13:01:09 +00:00
|
|
|
void stop() const;
|
|
|
|
|
|
|
|
///
|
|
|
|
pid_t pid;
|
|
|
|
///
|
2002-10-31 12:42:26 +00:00
|
|
|
string command;
|
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName metrics_file;
|
2002-07-16 18:10:51 +00:00
|
|
|
///
|
|
|
|
BitmapFile snippets;
|
2002-07-08 13:01:09 +00:00
|
|
|
};
|
|
|
|
|
2002-10-31 12:42:26 +00:00
|
|
|
typedef map<pid_t, InProgress> InProgressProcesses;
|
2002-07-16 18:10:51 +00:00
|
|
|
|
|
|
|
typedef InProgressProcesses::value_type InProgressProcess;
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class PreviewLoader::Impl : public boost::signals::trackable {
|
|
|
|
public:
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
|
|
|
Impl(PreviewLoader & p, Buffer const & b);
|
2002-07-08 13:01:09 +00:00
|
|
|
/// Stop any InProgress items still executing.
|
2002-07-06 12:38:44 +00:00
|
|
|
~Impl();
|
|
|
|
///
|
2002-07-05 21:24:15 +00:00
|
|
|
PreviewImage const * preview(string const & latex_snippet) const;
|
|
|
|
///
|
|
|
|
PreviewLoader::Status status(string const & latex_snippet) const;
|
|
|
|
///
|
|
|
|
void add(string const & latex_snippet);
|
|
|
|
///
|
|
|
|
void remove(string const & latex_snippet);
|
2010-07-21 14:28:38 +00:00
|
|
|
/// \p wait whether to wait for the process to complete or, instead,
|
|
|
|
/// to do it in the background.
|
2010-07-21 13:19:52 +00:00
|
|
|
void startLoading(bool wait = false);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
/// Emit this signal when an image is ready for display.
|
2004-09-26 14:19:47 +00:00
|
|
|
boost::signal<void(PreviewImage const &)> imageReady;
|
2002-07-17 16:56:42 +00:00
|
|
|
|
2002-08-02 16:30:58 +00:00
|
|
|
Buffer const & buffer() const { return buffer_; }
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
private:
|
2007-11-29 19:19:39 +00:00
|
|
|
/// Called by the ForkedCall process that generated the bitmap files.
|
2002-10-31 12:42:26 +00:00
|
|
|
void finishedGenerating(pid_t, int);
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
2006-10-19 16:51:30 +00:00
|
|
|
void dumpPreamble(odocstream &) const;
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
2006-10-19 16:51:30 +00:00
|
|
|
void dumpData(odocstream &, BitmapFile const &) const;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-06 11:36:11 +00:00
|
|
|
/** cache_ allows easy retrieval of already-generated images
|
2002-07-05 21:24:15 +00:00
|
|
|
* using the LaTeX snippet as the identifier.
|
|
|
|
*/
|
2010-04-22 11:37:32 +00:00
|
|
|
typedef shared_ptr<PreviewImage> PreviewImagePtr;
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
2002-07-06 11:36:11 +00:00
|
|
|
typedef map<string, PreviewImagePtr> Cache;
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
|
|
|
Cache cache_;
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
/** pending_ stores the LaTeX snippets in anticipation of them being
|
|
|
|
* sent to the converter.
|
2002-07-05 21:24:15 +00:00
|
|
|
*/
|
2002-07-16 18:10:51 +00:00
|
|
|
PendingSnippets pending_;
|
2002-07-06 12:38:44 +00:00
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
/** in_progress_ stores all forked processes so that we can proceed
|
|
|
|
* thereafter.
|
|
|
|
The map uses the conversion commands as its identifiers.
|
|
|
|
*/
|
2002-07-16 18:10:51 +00:00
|
|
|
InProgressProcesses in_progress_;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
PreviewLoader & parent_;
|
|
|
|
///
|
|
|
|
Buffer const & buffer_;
|
2002-07-09 09:30:54 +00:00
|
|
|
|
|
|
|
/// We don't own this
|
2007-03-20 21:53:01 +00:00
|
|
|
static lyx::Converter const * pconverter_;
|
2002-07-05 21:24:15 +00:00
|
|
|
};
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2007-03-20 21:53:01 +00:00
|
|
|
lyx::Converter const * PreviewLoader::Impl::pconverter_;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
//
|
2002-07-08 13:01:09 +00:00
|
|
|
// The public interface, defined in PreviewLoader.h
|
2006-10-21 00:16:43 +00:00
|
|
|
//
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
PreviewLoader::PreviewLoader(Buffer const & b)
|
|
|
|
: pimpl_(new Impl(*this, b))
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
PreviewLoader::~PreviewLoader()
|
2007-11-21 23:47:47 +00:00
|
|
|
{
|
|
|
|
delete pimpl_;
|
|
|
|
}
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PreviewImage const * PreviewLoader::preview(string const & latex_snippet) const
|
|
|
|
{
|
|
|
|
return pimpl_->preview(latex_snippet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PreviewLoader::Status PreviewLoader::status(string const & latex_snippet) const
|
|
|
|
{
|
|
|
|
return pimpl_->status(latex_snippet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
void PreviewLoader::add(string const & latex_snippet) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
|
|
|
pimpl_->add(latex_snippet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
void PreviewLoader::remove(string const & latex_snippet) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
|
|
|
pimpl_->remove(latex_snippet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-21 13:19:52 +00:00
|
|
|
void PreviewLoader::startLoading(bool wait) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2010-07-21 13:19:52 +00:00
|
|
|
pimpl_->startLoading(wait);
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
|
|
boost::signals::connection PreviewLoader::connect(slot_type const & slot) const
|
|
|
|
{
|
|
|
|
return pimpl_->imageReady.connect(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewLoader::emitSignal(PreviewImage const & pimage) const
|
|
|
|
{
|
|
|
|
pimpl_->imageReady(pimage);
|
|
|
|
}
|
|
|
|
|
2002-08-02 16:30:58 +00:00
|
|
|
|
|
|
|
Buffer const & PreviewLoader::buffer() const
|
|
|
|
{
|
|
|
|
return pimpl_->buffer();
|
|
|
|
}
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
2002-07-08 13:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
// The details of the Impl
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class IncrementedFileName {
|
|
|
|
public:
|
2002-07-16 18:10:51 +00:00
|
|
|
IncrementedFileName(string const & to_format,
|
2002-09-04 10:15:56 +00:00
|
|
|
string const & filename_base)
|
|
|
|
: to_format_(to_format), base_(filename_base), counter_(1)
|
2002-07-16 18:10:51 +00:00
|
|
|
{}
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
SnippetPair const operator()(string const & snippet)
|
2002-07-16 18:10:51 +00:00
|
|
|
{
|
|
|
|
ostringstream os;
|
2002-11-27 10:30:28 +00:00
|
|
|
os << base_ << counter_++ << '.' << to_format_;
|
2003-09-15 11:00:00 +00:00
|
|
|
string const file = os.str();
|
2002-07-16 18:10:51 +00:00
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
return make_pair(snippet, FileName(file));
|
2002-07-16 18:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
string const & to_format_;
|
|
|
|
string const & base_;
|
|
|
|
int counter_;
|
|
|
|
};
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
2002-07-09 09:30:54 +00:00
|
|
|
InProgress::InProgress(string const & filename_base,
|
2002-07-16 18:10:51 +00:00
|
|
|
PendingSnippets const & pending,
|
2002-07-09 09:30:54 +00:00
|
|
|
string const & to_format)
|
|
|
|
: pid(0),
|
2008-07-30 06:51:50 +00:00
|
|
|
metrics_file(filename_base + ".metrics"),
|
2002-07-09 09:30:54 +00:00
|
|
|
snippets(pending.size())
|
|
|
|
{
|
2002-07-16 18:10:51 +00:00
|
|
|
PendingSnippets::const_iterator pit = pending.begin();
|
|
|
|
PendingSnippets::const_iterator pend = pending.end();
|
|
|
|
BitmapFile::iterator sit = snippets.begin();
|
2002-07-09 09:30:54 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
transform(pit, pend, sit,
|
2002-09-04 10:15:56 +00:00
|
|
|
IncrementedFileName(to_format, filename_base));
|
2002-07-09 09:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
void InProgress::stop() const
|
|
|
|
{
|
|
|
|
if (pid)
|
2007-12-12 19:57:42 +00:00
|
|
|
ForkedCallsController::kill(pid, 0);
|
2002-07-08 13:01:09 +00:00
|
|
|
|
|
|
|
if (!metrics_file.empty())
|
2007-11-28 09:01:49 +00:00
|
|
|
metrics_file.removeFile();
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
BitmapFile::const_iterator vit = snippets.begin();
|
|
|
|
BitmapFile::const_iterator vend = snippets.end();
|
2002-07-08 13:01:09 +00:00
|
|
|
for (; vit != vend; ++vit) {
|
|
|
|
if (!vit->second.empty())
|
2007-11-28 09:01:49 +00:00
|
|
|
vit->second.removeFile();
|
2002-07-08 13:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-17 16:56:42 +00:00
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-09 09:30:54 +00:00
|
|
|
PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
|
2009-12-17 15:25:55 +00:00
|
|
|
: parent_(p), buffer_(b)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2010-09-21 16:34:30 +00:00
|
|
|
if (b.bufferFormat() == "lilypond-book")
|
|
|
|
pconverter_ = setConverter("lyxpreview-lytex");
|
|
|
|
else if (b.params().encoding().package() == Encoding::japanese)
|
|
|
|
pconverter_ = setConverter("lyxpreview-platex");
|
|
|
|
else
|
|
|
|
pconverter_ = setConverter("lyxpreview");
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-06 12:38:44 +00:00
|
|
|
PreviewLoader::Impl::~Impl()
|
|
|
|
{
|
2002-07-16 18:10:51 +00:00
|
|
|
InProgressProcesses::iterator ipit = in_progress_.begin();
|
|
|
|
InProgressProcesses::iterator ipend = in_progress_.end();
|
2002-07-06 12:38:44 +00:00
|
|
|
|
2007-11-29 19:56:25 +00:00
|
|
|
for (; ipit != ipend; ++ipit)
|
2002-07-08 13:01:09 +00:00
|
|
|
ipit->second.stop();
|
|
|
|
}
|
2002-07-06 12:38:44 +00:00
|
|
|
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
PreviewImage const *
|
|
|
|
PreviewLoader::Impl::preview(string const & latex_snippet) const
|
|
|
|
{
|
|
|
|
Cache::const_iterator it = cache_.find(latex_snippet);
|
|
|
|
return (it == cache_.end()) ? 0 : it->second.get();
|
2002-07-06 12:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-11-29 19:56:25 +00:00
|
|
|
class FindSnippet {
|
2004-01-31 15:30:24 +00:00
|
|
|
public:
|
2002-07-16 18:10:51 +00:00
|
|
|
FindSnippet(string const & s) : snippet_(s) {}
|
2004-01-31 15:30:24 +00:00
|
|
|
bool operator()(InProgressProcess const & process) const
|
2002-07-16 18:10:51 +00:00
|
|
|
{
|
|
|
|
BitmapFile const & snippets = process.second.snippets;
|
2004-01-31 15:30:24 +00:00
|
|
|
BitmapFile::const_iterator beg = snippets.begin();
|
2002-07-16 18:10:51 +00:00
|
|
|
BitmapFile::const_iterator end = snippets.end();
|
2004-01-31 15:30:24 +00:00
|
|
|
return find_if(beg, end, FindFirst(snippet_)) != end;
|
2002-07-16 18:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2004-01-31 15:30:24 +00:00
|
|
|
string const snippet_;
|
2002-07-16 18:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
PreviewLoader::Status
|
|
|
|
PreviewLoader::Impl::status(string const & latex_snippet) const
|
|
|
|
{
|
|
|
|
Cache::const_iterator cit = cache_.find(latex_snippet);
|
|
|
|
if (cit != cache_.end())
|
2002-07-08 13:01:09 +00:00
|
|
|
return Ready;
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
PendingSnippets::const_iterator pit = pending_.begin();
|
|
|
|
PendingSnippets::const_iterator pend = pending_.end();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
pit = find(pit, pend, latex_snippet);
|
2002-07-09 09:30:54 +00:00
|
|
|
if (pit != pend)
|
2002-07-08 13:01:09 +00:00
|
|
|
return InQueue;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
InProgressProcesses::const_iterator ipit = in_progress_.begin();
|
|
|
|
InProgressProcesses::const_iterator ipend = in_progress_.end();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
ipit = find_if(ipit, ipend, FindSnippet(latex_snippet));
|
|
|
|
if (ipit != ipend)
|
|
|
|
return Processing;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
return NotFound;
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewLoader::Impl::add(string const & latex_snippet)
|
|
|
|
{
|
2002-07-09 09:30:54 +00:00
|
|
|
if (!pconverter_ || status(latex_snippet) != NotFound)
|
2002-07-05 21:24:15 +00:00
|
|
|
return;
|
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
string const snippet = trim(latex_snippet);
|
2002-08-02 16:30:58 +00:00
|
|
|
if (snippet.empty())
|
|
|
|
return;
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "adding snippet:\n" << snippet);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2002-08-02 16:30:58 +00:00
|
|
|
pending_.push_back(snippet);
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
namespace {
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class EraseSnippet {
|
|
|
|
public:
|
2002-07-16 18:10:51 +00:00
|
|
|
EraseSnippet(string const & s) : snippet_(s) {}
|
|
|
|
void operator()(InProgressProcess & process)
|
|
|
|
{
|
|
|
|
BitmapFile & snippets = process.second.snippets;
|
|
|
|
BitmapFile::iterator it = snippets.begin();
|
|
|
|
BitmapFile::iterator end = snippets.end();
|
|
|
|
|
|
|
|
it = find_if(it, end, FindFirst(snippet_));
|
|
|
|
if (it != end)
|
|
|
|
snippets.erase(it, it+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
string const & snippet_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
void PreviewLoader::Impl::remove(string const & latex_snippet)
|
|
|
|
{
|
|
|
|
Cache::iterator cit = cache_.find(latex_snippet);
|
|
|
|
if (cit != cache_.end())
|
|
|
|
cache_.erase(cit);
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
PendingSnippets::iterator pit = pending_.begin();
|
|
|
|
PendingSnippets::iterator pend = pending_.end();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
pending_.erase(std::remove(pit, pend, latex_snippet), pend);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
InProgressProcesses::iterator ipit = in_progress_.begin();
|
|
|
|
InProgressProcesses::iterator ipend = in_progress_.end();
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
for_each(ipit, ipend, EraseSnippet(latex_snippet));
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2003-09-14 19:59:52 +00:00
|
|
|
while (ipit != ipend) {
|
2002-07-16 18:10:51 +00:00
|
|
|
InProgressProcesses::iterator curr = ipit++;
|
|
|
|
if (curr->second.snippets.empty())
|
2002-07-05 21:24:15 +00:00
|
|
|
in_progress_.erase(curr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-21 13:19:52 +00:00
|
|
|
void PreviewLoader::Impl::startLoading(bool wait)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2002-07-09 09:30:54 +00:00
|
|
|
if (pending_.empty() || !pconverter_)
|
2002-07-08 13:01:09 +00:00
|
|
|
return;
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2003-10-22 13:15:18 +00:00
|
|
|
// Only start the process off after the buffer is loaded from file.
|
2007-10-20 10:03:45 +00:00
|
|
|
if (!buffer_.isFullyLoaded())
|
2003-10-22 13:15:18 +00:00
|
|
|
return;
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()");
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
// As used by the LaTeX file and by the resulting image files
|
2004-02-25 12:00:53 +00:00
|
|
|
string const directory = buffer_.temppath();
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
string const filename_base = unique_filename(directory);
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2002-07-06 11:36:11 +00:00
|
|
|
// Create an InProgress instance to place in the map of all
|
|
|
|
// such processes if it starts correctly.
|
2002-07-09 09:30:54 +00:00
|
|
|
InProgress inprogress(filename_base, pending_, pconverter_->to);
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2002-09-04 10:15:56 +00:00
|
|
|
// clear pending_, so we're ready to start afresh.
|
|
|
|
pending_.clear();
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
// Output the LaTeX file.
|
2006-12-04 15:46:57 +00:00
|
|
|
FileName const latexfile(filename_base + ".tex");
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-05-28 07:43:15 +00:00
|
|
|
// we use the encoding of the buffer
|
|
|
|
Encoding const & enc = buffer_.params().encoding();
|
2008-11-16 12:21:29 +00:00
|
|
|
ofdocstream of;
|
2007-12-29 18:04:43 +00:00
|
|
|
try { of.reset(enc.iconvName()); }
|
|
|
|
catch (iconv_codecvt_facet_exception & e) {
|
|
|
|
LYXERR0("Caught iconv exception: " << e.what()
|
|
|
|
<< "\nUnable to create LaTeX file: " << latexfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-28 07:43:15 +00:00
|
|
|
TexRow texrow;
|
|
|
|
OutputParams runparams(&enc);
|
|
|
|
LaTeXFeatures features(buffer_, buffer_.params(), runparams);
|
|
|
|
|
|
|
|
if (!openFileWrite(of, latexfile))
|
|
|
|
return;
|
|
|
|
|
2004-02-25 12:00:53 +00:00
|
|
|
if (!of) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
|
|
|
|
<< "Unable to create LaTeX file\n" << latexfile);
|
2004-02-25 12:00:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-07-10 09:09:37 +00:00
|
|
|
of << "\\batchmode\n";
|
2002-07-05 21:24:15 +00:00
|
|
|
dumpPreamble(of);
|
2007-05-28 07:43:15 +00:00
|
|
|
// handle inputenc etc.
|
2007-05-28 12:25:53 +00:00
|
|
|
buffer_.params().writeEncodingPreamble(of, features, texrow);
|
2002-07-05 21:24:15 +00:00
|
|
|
of << "\n\\begin{document}\n";
|
2002-07-06 11:36:11 +00:00
|
|
|
dumpData(of, inprogress.snippets);
|
2002-07-05 21:24:15 +00:00
|
|
|
of << "\n\\end{document}\n";
|
|
|
|
of.close();
|
2007-05-28 07:43:15 +00:00
|
|
|
if (of.fail()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
|
|
|
|
<< "File was not closed properly.");
|
2007-05-28 07:43:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2010-07-29 16:38:58 +00:00
|
|
|
double const font_scaling_factor =
|
|
|
|
buffer_.isExporting() ? 75.0 * buffer_.params().html_math_img_scale
|
|
|
|
: 0.01 * lyxrc.dpi * lyxrc.zoom * lyxrc.preview_scale_factor;
|
2009-12-17 15:25:55 +00:00
|
|
|
|
2010-07-29 16:38:58 +00:00
|
|
|
// FIXME XHTML
|
|
|
|
// The colors should be customizable.
|
|
|
|
ColorCode const bg = buffer_.isExporting()
|
2010-07-21 13:19:52 +00:00
|
|
|
? Color_white : PreviewLoader::backgroundColor();
|
2010-07-29 16:38:58 +00:00
|
|
|
ColorCode const fg = buffer_.isExporting()
|
|
|
|
? Color_black : PreviewLoader::foregroundColor();
|
2002-07-05 21:24:15 +00:00
|
|
|
// The conversion command.
|
|
|
|
ostringstream cs;
|
2004-04-16 14:34:41 +00:00
|
|
|
cs << pconverter_->command << ' ' << pconverter_->to << ' '
|
2007-12-12 19:57:42 +00:00
|
|
|
<< quoteName(latexfile.toFilesystemEncoding()) << ' '
|
2009-12-17 15:25:55 +00:00
|
|
|
<< int(font_scaling_factor) << ' '
|
2010-07-29 16:38:58 +00:00
|
|
|
<< theApp()->hexName(fg) << ' '
|
2010-07-21 13:19:52 +00:00
|
|
|
<< theApp()->hexName(bg);
|
2010-11-23 16:09:05 +00:00
|
|
|
// FIXME what about LuaTeX?
|
2010-11-23 13:18:28 +00:00
|
|
|
if (buffer_.bufferFormat() == "xetex")
|
2010-02-24 10:47:35 +00:00
|
|
|
cs << " xelatex";
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
string const command = libScriptSearch(cs.str());
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2010-07-21 13:19:52 +00:00
|
|
|
if (wait) {
|
|
|
|
ForkedCall call;
|
|
|
|
int ret = call.startScript(ForkedProcess::Wait, command);
|
|
|
|
static int fake = (2^20) + 1;
|
|
|
|
int pid = fake++;
|
|
|
|
inprogress.pid = pid;
|
|
|
|
inprogress.command = command;
|
|
|
|
in_progress_[pid] = inprogress;
|
|
|
|
finishedGenerating(pid, ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
// Initiate the conversion from LaTeX to bitmap images files.
|
2007-12-12 19:57:42 +00:00
|
|
|
ForkedCall::SignalTypePtr
|
|
|
|
convert_ptr(new ForkedCall::SignalType);
|
2004-01-31 15:30:24 +00:00
|
|
|
convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2));
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
ForkedCall call;
|
2007-11-29 19:19:39 +00:00
|
|
|
int ret = call.startScript(command, convert_ptr);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
if (ret != 0) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()\n"
|
|
|
|
<< "Unable to start process\n" << command);
|
2002-07-06 11:36:11 +00:00
|
|
|
return;
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2002-07-06 12:50:09 +00:00
|
|
|
// Store the generation process in a list of all such processes
|
2002-07-06 12:38:44 +00:00
|
|
|
inprogress.pid = call.pid();
|
2002-10-31 12:42:26 +00:00
|
|
|
inprogress.command = command;
|
|
|
|
in_progress_[inprogress.pid] = inprogress;
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-31 12:42:26 +00:00
|
|
|
void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2002-10-31 12:42:26 +00:00
|
|
|
// Paranoia check!
|
|
|
|
InProgressProcesses::iterator git = in_progress_.find(pid);
|
|
|
|
if (git == in_progress_.end()) {
|
|
|
|
lyxerr << "PreviewLoader::finishedGenerating(): unable to find "
|
|
|
|
"data for PID " << pid << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const command = git->second.command;
|
2002-07-05 21:24:15 +00:00
|
|
|
string const status = retval > 0 ? "failed" : "succeeded";
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "PreviewLoader::finishedInProgress("
|
2002-07-05 21:24:15 +00:00
|
|
|
<< retval << "): processing " << status
|
2007-11-15 20:04:51 +00:00
|
|
|
<< " for " << command);
|
2002-07-05 21:24:15 +00:00
|
|
|
if (retval > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Read the metrics file, if it exists
|
2002-07-09 09:30:54 +00:00
|
|
|
vector<double> ascent_fractions(git->second.snippets.size());
|
|
|
|
setAscentFractions(ascent_fractions, git->second.metrics_file);
|
2002-07-08 13:01:09 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
// Add these newly generated bitmap files to the cache and
|
|
|
|
// start loading them into LyX.
|
2002-07-16 18:10:51 +00:00
|
|
|
BitmapFile::const_iterator it = git->second.snippets.begin();
|
|
|
|
BitmapFile::const_iterator end = git->second.snippets.end();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
list<PreviewImagePtr> newimages;
|
2002-07-15 11:08:46 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
int metrics_counter = 0;
|
2002-07-09 09:30:54 +00:00
|
|
|
for (; it != end; ++it, ++metrics_counter) {
|
2002-07-05 21:24:15 +00:00
|
|
|
string const & snip = it->first;
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const & file = it->second;
|
2002-07-09 09:30:54 +00:00
|
|
|
double af = ascent_fractions[metrics_counter];
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-09 09:30:54 +00:00
|
|
|
PreviewImagePtr ptr(new PreviewImage(parent_, snip, file, af));
|
2002-07-05 21:24:15 +00:00
|
|
|
cache_[snip] = ptr;
|
|
|
|
|
2002-07-15 11:08:46 +00:00
|
|
|
newimages.push_back(ptr);
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
2002-07-08 13:01:09 +00:00
|
|
|
// Remove the item from the list of still-executing processes.
|
2002-07-05 21:24:15 +00:00
|
|
|
in_progress_.erase(git);
|
2002-07-15 11:08:46 +00:00
|
|
|
|
|
|
|
// Tell the outside world
|
2007-12-12 19:28:07 +00:00
|
|
|
list<PreviewImagePtr>::const_reverse_iterator
|
2003-02-25 11:20:59 +00:00
|
|
|
nit = newimages.rbegin();
|
2007-12-12 19:28:07 +00:00
|
|
|
list<PreviewImagePtr>::const_reverse_iterator
|
2003-02-25 11:20:59 +00:00
|
|
|
nend = newimages.rend();
|
2002-07-15 11:08:46 +00:00
|
|
|
for (; nit != nend; ++nit) {
|
2002-07-17 16:56:42 +00:00
|
|
|
imageReady(*nit->get());
|
2002-07-15 11:08:46 +00:00
|
|
|
}
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
void PreviewLoader::Impl::dumpPreamble(odocstream & os) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
|
|
|
// Dump the preamble only.
|
2010-06-15 18:26:38 +00:00
|
|
|
OutputParams runparams(&buffer_.params().encoding());
|
2003-11-05 12:06:20 +00:00
|
|
|
runparams.flavor = OutputParams::LATEX;
|
2003-05-22 21:10:22 +00:00
|
|
|
runparams.nice = true;
|
2003-05-23 09:23:03 +00:00
|
|
|
runparams.moving_arg = true;
|
2003-05-23 08:59:47 +00:00
|
|
|
runparams.free_spacing = true;
|
2008-10-29 13:42:09 +00:00
|
|
|
buffer_.writeLaTeXSource(os, buffer_.filePath(), runparams, true, false);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2003-01-21 17:54:03 +00:00
|
|
|
// FIXME! This is a HACK! The proper fix is to control the 'true'
|
|
|
|
// passed to WriteStream below:
|
2007-02-25 22:18:13 +00:00
|
|
|
// int InsetMathNest::latex(Buffer const &, odocstream & os,
|
|
|
|
// OutputParams const & runparams) const
|
2003-01-21 17:54:03 +00:00
|
|
|
// {
|
2003-05-23 09:23:03 +00:00
|
|
|
// WriteStream wi(os, runparams.moving_arg, true);
|
2003-01-21 17:54:03 +00:00
|
|
|
// par_->write(wi);
|
|
|
|
// return wi.line();
|
|
|
|
// }
|
|
|
|
os << "\n"
|
|
|
|
<< "\\def\\lyxlock{}\n"
|
|
|
|
<< "\n";
|
|
|
|
|
2007-02-25 22:18:13 +00:00
|
|
|
// All equation labels appear as "(#)" + preview.sty's rendering of
|
2002-07-10 09:09:37 +00:00
|
|
|
// the label name
|
|
|
|
if (lyxrc.preview_hashed_labels)
|
|
|
|
os << "\\renewcommand{\\theequation}{\\#}\n";
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
// Use the preview style file to ensure that each snippet appears on a
|
|
|
|
// fresh page.
|
2008-07-02 14:42:04 +00:00
|
|
|
// Also support PDF output (automatically generated e.g. when
|
2010-02-24 10:47:35 +00:00
|
|
|
// \usepackage[pdftex]{hyperref} is used and XeTeX.
|
2002-07-05 21:24:15 +00:00
|
|
|
os << "\n"
|
2010-02-24 10:47:35 +00:00
|
|
|
<< "\\newif\\ifxetex\n"
|
|
|
|
<< "\\expandafter\\ifx\\csname XeTeXrevision\\endcsname\\relax\n"
|
|
|
|
<< " \\xetexfalse\n"
|
|
|
|
<< "\\else\n"
|
|
|
|
<< " \\xetextrue\n"
|
|
|
|
<< "\\fi\n"
|
2008-07-02 14:42:04 +00:00
|
|
|
<< "\\newif\\ifpdf\n"
|
|
|
|
<< "\\ifx\\pdfoutput\\undefined\n"
|
|
|
|
<< "\\else\\ifx\\pdfoutput\\relax\n"
|
|
|
|
<< "\\else\\ifnum0=\\pdfoutput\n"
|
|
|
|
<< "\\else\\pdftrue\\fi\\fi\\fi\n"
|
2010-02-24 10:47:35 +00:00
|
|
|
<< "\\ifxetex\n"
|
|
|
|
<< " \\usepackage[active,delayed,tightpage,showlabels,lyx,xetex]{preview}\n"
|
|
|
|
<< "\\else\n"
|
2008-07-02 14:42:04 +00:00
|
|
|
<< "\\ifpdf\n"
|
|
|
|
<< " \\usepackage[active,delayed,tightpage,showlabels,lyx,pdftex]{preview}\n"
|
|
|
|
<< "\\else\n"
|
|
|
|
<< " \\usepackage[active,delayed,showlabels,lyx,dvips]{preview}\n"
|
|
|
|
<< "\\fi\n"
|
2010-02-24 10:47:35 +00:00
|
|
|
<< "\\fi\n"
|
2002-07-05 21:24:15 +00:00
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
void PreviewLoader::Impl::dumpData(odocstream & os,
|
2002-07-16 18:10:51 +00:00
|
|
|
BitmapFile const & vec) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2002-07-06 11:36:11 +00:00
|
|
|
if (vec.empty())
|
2002-07-05 21:24:15 +00:00
|
|
|
return;
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
BitmapFile::const_iterator it = vec.begin();
|
|
|
|
BitmapFile::const_iterator end = vec.end();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
2006-10-19 16:51:30 +00:00
|
|
|
// FIXME UNICODE
|
2002-07-05 21:24:15 +00:00
|
|
|
os << "\\begin{preview}\n"
|
2006-10-21 00:16:43 +00:00
|
|
|
<< from_utf8(it->first)
|
2002-07-05 21:24:15 +00:00
|
|
|
<< "\n\\end{preview}\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|