#include "output.h"
#include "OutputParams.h"
#include "TexRow.h"
+#include "texstream.h"
#include "frontends/Application.h" // hexName
#include "support/bind.h"
#include "support/TempFile.h"
-#include <sstream>
+#include <atomic>
#include <fstream>
#include <iomanip>
+#include <memory>
+#include <mutex>
+#include <sstream>
#include <QTimer>
return ptr;
}
- // FIXME THREAD
- static bool first = true;
- if (first) {
- first = false;
- LYXERR0("PreviewLoader::startLoading()\n"
- << "No converter from \"" << from << "\" format has been defined.");
- }
+ // Show the error only once
+#ifdef LYX_USE_STD_CALL_ONCE
+ // This is thread-safe.
+ static once_flag flag;
+ call_once(flag, [&](){
+ LYXERR0("PreviewLoader::startLoading()\n"
+ << "No converter from \"" << from
+ << "\" format has been defined.");
+ });
+#else
+ // This is also thread-safe according to ยง6.7.4 of the C++11 standard.
+ static bool once = ([&]{
+ LYXERR0("PreviewLoader::startLoading()\n"
+ << "No converter from \"" << from
+ << "\" format has been defined.");
+ } (), true);
+#endif
return 0;
}
namespace lyx {
namespace graphics {
-class PreviewLoader::Impl : public boost::signals::trackable {
+class PreviewLoader::Impl : public boost::signals2::trackable {
public:
///
Impl(PreviewLoader & p, Buffer const & b);
void refreshPreviews();
/// Emit this signal when an image is ready for display.
- boost::signal<void(PreviewImage const &)> imageReady;
+ boost::signals2::signal<void(PreviewImage const &)> imageReady;
Buffer const & buffer() const { return buffer_; }
/** cache_ allows easy retrieval of already-generated images
* using the LaTeX snippet as the identifier.
*/
- typedef shared_ptr<PreviewImage> PreviewImagePtr;
+ typedef std::shared_ptr<PreviewImage> PreviewImagePtr;
///
typedef map<string, PreviewImagePtr> Cache;
///
}
-boost::signals::connection PreviewLoader::connect(slot_type const & slot) const
+boost::signals2::connection PreviewLoader::connect(slot_type const & slot) const
{
return pimpl_->imageReady.connect(slot);
}
: parent_(p), buffer_(b), finished_generating_(true)
{
font_scaling_factor_ = int(buffer_.fontScalingFactor());
- fg_color_ = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16);
- bg_color_ = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16);
+ if (theApp()) {
+ fg_color_ = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16);
+ bg_color_ = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16);
+ } else {
+ fg_color_ = 0x0;
+ bg_color_ = 0xffffff;
+ }
if (!pconverter_)
pconverter_ = setConverter("lyxpreview");
PreviewLoader::Impl::preview(string const & latex_snippet) const
{
int fs = int(buffer_.fontScalingFactor());
- int fg = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16);
- int bg = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16);
+ int fg = 0x0;
+ int bg = 0xffffff;
+ if (theApp()) {
+ fg = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16);
+ bg = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16);
+ }
if (font_scaling_factor_ != fs || fg_color_ != fg || bg_color_ != bg) {
// Schedule refresh of all previews on zoom or color changes.
// The previews are regenerated only after the zoom factor
return;
}
- TexRow texrow;
- otexstream os(of, texrow);
+ otexstream os(of);
OutputParams runparams(&enc);
LaTeXFeatures features(buffer_, buffer_.params(), runparams);
}
of << "\\batchmode\n";
+ // Set \jobname of previews to the document name (see bug 9627)
+ of << "\\def\\jobname{"
+ << from_utf8(changeExtension(buffer_.latexName(true), ""))
+ << "}\n";
+
LYXERR(Debug::LATEX, "Format = " << buffer_.params().getDefaultOutputFormat());
string latexparam = "";
bool docformat = !buffer_.params().default_output_format.empty()
if (wait) {
ForkedCall call(buffer_.filePath(), buffer_.layoutPos());
int ret = call.startScript(ForkedProcess::Wait, command);
- // FIXME THREAD
- static int fake = (2^20) + 1;
+ static atomic_int fake((2^20) + 1);
int pid = fake++;
inprogress.pid = pid;
inprogress.command = command;