]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewLoader.C
If the graphics loader has a copy c-tor it should have copy assignment that does...
[lyx.git] / src / graphics / PreviewLoader.C
index b8533eba811ca0b311da3617ddc6bb88e1e6efbc..cf4ae4faaf2f9bfce80d02a749a9af4b61cd4b72 100644 (file)
@@ -3,25 +3,23 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming 
+ * \author Angus Leeming
  *
  * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "PreviewLoader.h"
 #include "PreviewImage.h"
 
 #include "buffer.h"
 #include "converter.h"
+#include "format.h"
 #include "debug.h"
 #include "lyxrc.h"
 #include "LColor.h"
+#include "Lsstream.h"
 
 #include "insets/inset.h"
 
@@ -30,6 +28,7 @@
 #include "support/filetools.h"
 #include "support/forkedcall.h"
 #include "support/forkedcontr.h"
+#include "support/tostr.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 
@@ -81,7 +80,7 @@ struct FindFirst {
        FindFirst(string const & comp) : comp_(comp) {}
        bool operator()(StrPair const & sp)
        {
-               return sp.first < comp_;
+               return sp.first == comp_;
        }
 private:
        string const comp_;
@@ -257,8 +256,8 @@ struct IncrementedFileName {
        StrPair const operator()(string const & snippet)
        {
                ostringstream os;
-               os << base_ << counter_++ << "." << to_format_;
-               string const file = os.str().c_str();
+               os << base_ << counter_++ << '.' << to_format_;
+               string const file = STRCONV(os.str());
 
                return make_pair(snippet, file);
        }
@@ -281,7 +280,7 @@ InProgress::InProgress(string const & filename_base,
        PendingSnippets::const_iterator pend = pending.end();
        BitmapFile::iterator sit = snippets.begin();
 
-       std::transform(pit, pend, sit, 
+       std::transform(pit, pend, sit,
                       IncrementedFileName(to_format, filename_base));
 }
 
@@ -453,7 +452,11 @@ void PreviewLoader::Impl::startLoading()
        lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl;
 
        // As used by the LaTeX file and by the resulting image files
-       string const filename_base(unique_filename(buffer_.tmppath));
+       string directory = buffer_.tmppath;
+       if (directory.empty())
+               directory = buffer_.filePath();
+       
+       string const filename_base(unique_filename(directory));
 
        // Create an InProgress instance to place in the map of all
        // such processes if it starts correctly.
@@ -475,10 +478,10 @@ void PreviewLoader::Impl::startLoading()
 
        // The conversion command.
        ostringstream cs;
-       cs << pconverter_->command << " " << latexfile << " "
-          << int(font_scaling_factor_) << " " << pconverter_->to;
+       cs << pconverter_->command << ' ' << latexfile << ' '
+          << int(font_scaling_factor_) << ' ' << pconverter_->to;
 
-       string const command = "sh " + LibScriptSearch(cs.str().c_str());
+       string const command = "sh " + LibScriptSearch(STRCONV(cs.str()));
 
        // Initiate the conversion from LaTeX to bitmap images files.
        Forkedcall::SignalTypePtr convert_ptr(new Forkedcall::SignalType);
@@ -547,8 +550,10 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval)
        in_progress_.erase(git);
 
        // Tell the outside world
-       std::list<PreviewImagePtr>::const_iterator nit  = newimages.begin();
-       std::list<PreviewImagePtr>::const_iterator nend = newimages.end();
+       std::list<PreviewImagePtr>::const_reverse_iterator
+               nit  = newimages.rbegin();
+       std::list<PreviewImagePtr>::const_reverse_iterator
+               nend = newimages.rend();
        for (; nit != nend; ++nit) {
                imageReady(*nit->get());
        }
@@ -560,7 +565,25 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
        // Why on earth is Buffer::makeLaTeXFile a non-const method?
        Buffer & tmp = const_cast<Buffer &>(buffer_);
        // Dump the preamble only.
-       tmp.makeLaTeXFile(os, buffer_.filePath(), true, false, true);
+       LatexRunParams runparams;
+       runparams.flavor = LatexRunParams::LATEX;
+       runparams.nice = true;
+       runparams.moving_arg = true;
+       runparams.free_spacing = true;
+       tmp.makeLaTeXFile(os, buffer_.filePath(), runparams, false, true);
+
+       // FIXME! This is a HACK! The proper fix is to control the 'true'
+       // passed to WriteStream below:
+       // int InsetFormula::latex(Buffer const *, ostream & os,
+       //                         LatexRunParams const & runparams) const
+       // {
+       //      WriteStream wi(os, runparams.moving_arg, true);
+       //      par_->write(wi);
+       //      return wi.line();
+       // }
+       os << "\n"
+          << "\\def\\lyxlock{}\n"
+          << "\n";
 
        // Loop over the insets in the buffer and dump all the math-macros.
        Buffer::inset_iterator it  = buffer_.inset_const_iterator_begin();
@@ -568,7 +591,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
 
        for (; it != end; ++it)
                if (it->lyxCode() == Inset::MATHMACRO_CODE)
-                       it->latex(&buffer_, os, true, true);
+                       it->latex(&buffer_, os, runparams);
 
        // All equation lables appear as "(#)" + preview.sty's rendering of
        // the label name
@@ -591,7 +614,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
 
        os << "\\AtBeginDocument{\\AtBeginDvi{%\n"
           << "\\special{!userdict begin/bop-hook{//bop-hook exec\n"
-          << "<" << fg << bg << ">{255 div}forall setrgbcolor\n"
+          << '<' << fg << bg << ">{255 div}forall setrgbcolor\n"
           << "clippath fill setrgbcolor}bind def end}}}\n";
 }