]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewLoader.C
the AM_* flags patch
[lyx.git] / src / graphics / PreviewLoader.C
index f0ad7291bbfbb4b5557c80774b967ade2cfa3115..ddedc11b2c9b43a162fcfdf0d1a1b37b43f32c6e 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "PreviewLoader.h"
 #include "PreviewImage.h"
+#include "GraphicsCache.h"
 
 #include "buffer.h"
 #include "converter.h"
 #include "support/forkedcontr.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include <boost/bind.hpp>
 
-#include "support/std_sstream.h"
+#include <sstream>
 #include <fstream>
 #include <iomanip>
 
@@ -91,7 +92,8 @@ private:
 
 
 /// Store info on a currently executing, forked process.
-struct InProgress {
+class InProgress {
+public:
        ///
        InProgress() : pid(0) {}
        ///
@@ -121,7 +123,8 @@ typedef InProgressProcesses::value_type InProgressProcess;
 namespace lyx {
 namespace graphics {
 
-struct PreviewLoader::Impl : public boost::signals::trackable {
+class PreviewLoader::Impl : public boost::signals::trackable {
+public:
        ///
        Impl(PreviewLoader & p, Buffer const & b);
        /// Stop any InProgress items still executing.
@@ -138,7 +141,7 @@ struct PreviewLoader::Impl : public boost::signals::trackable {
        void startLoading();
 
        /// Emit this signal when an image is ready for display.
-       boost::signal1<void, PreviewImage const &> imageReady;
+       boost::signal<void(PreviewImage const &)> imageReady;
 
        Buffer const & buffer() const { return buffer_; }
 
@@ -252,7 +255,8 @@ Buffer const & PreviewLoader::buffer() const
 
 namespace {
 
-struct IncrementedFileName {
+class IncrementedFileName {
+public:
        IncrementedFileName(string const & to_format,
                            string const & filename_base)
                : to_format_(to_format), base_(filename_base), counter_(1)
@@ -316,7 +320,7 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
        : parent_(p), buffer_(b), font_scaling_factor_(0.0)
 {
        font_scaling_factor_ = 0.01 * lyxrc.dpi * lyxrc.zoom *
-               lyxrc.preview_scale_factor;
+               convert<double>(lyxrc.preview_scale_factor);
 
        lyxerr[Debug::GRAPHICS] << "The font scaling factor is "
                                << font_scaling_factor_ << endl;
@@ -406,7 +410,8 @@ void PreviewLoader::Impl::add(string const & latex_snippet)
 
 namespace {
 
-struct EraseSnippet {
+class EraseSnippet {
+public:
        EraseSnippet(string const & s) : snippet_(s) {}
        void operator()(InProgressProcess & process)
        {
@@ -492,10 +497,12 @@ void PreviewLoader::Impl::startLoading()
 
        // The conversion command.
        ostringstream cs;
-       cs << pconverter_->command << ' ' << latexfile << ' '
-          << int(font_scaling_factor_) << ' ' << pconverter_->to;
+       cs << pconverter_->command << ' ' << pconverter_->to << ' '
+          << latexfile << ' ' << int(font_scaling_factor_) << ' '
+          << lyx_gui::hexname(LColor::preview) << ' '
+          << lyx_gui::hexname(LColor::background);
 
-       string const command = "sh " + support::LibScriptSearch(cs.str());
+       string const command = support::LibScriptSearch(cs.str());
 
        // Initiate the conversion from LaTeX to bitmap images files.
        support::Forkedcall::SignalTypePtr
@@ -507,7 +514,7 @@ void PreviewLoader::Impl::startLoading()
 
        if (ret != 0) {
                lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()\n"
-                                       << "Unable to start process \n"
+                                       << "Unable to start process\n"
                                        << command << endl;
                return;
        }
@@ -605,7 +612,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
        InsetIterator const end = inset_iterator_end(inset);
 
        for (; it != end; ++it)
-               if (it->lyxCode() == InsetOld::MATHMACRO_CODE)
+               if (it->lyxCode() == InsetBase::MATHMACRO_CODE)
                        it->latex(buffer_, os, runparams);
 
        // All equation lables appear as "(#)" + preview.sty's rendering of
@@ -616,21 +623,8 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
        // Use the preview style file to ensure that each snippet appears on a
        // fresh page.
        os << "\n"
-          << "\\usepackage[active,delayed,dvips,tightpage,showlabels,lyx]{preview}\n"
+          << "\\usepackage[active,delayed,dvips,showlabels,lyx]{preview}\n"
           << "\n";
-
-       // This piece of PostScript magic ensures that the foreground and
-       // background colors are the same as the LyX screen.
-       string fg = lyx_gui::hexname(LColor::preview);
-       if (fg.empty()) fg = "000000";
-
-       string bg = lyx_gui::hexname(LColor::background);
-       if (bg.empty()) bg = "ffffff";
-
-       os << "\\AtBeginDocument{\\AtBeginDvi{%\n"
-          << "\\special{!userdict begin/bop-hook{//bop-hook exec\n"
-          << '<' << fg << bg << ">{255 div}forall setrgbcolor\n"
-          << "clippath fill setrgbcolor}bind def end}}}\n";
 }
 
 
@@ -658,7 +652,7 @@ namespace {
 string const unique_filename(string const bufferpath)
 {
        static int theCounter = 0;
-       string const filename = tostr(theCounter++) + "lyxpreview";
+       string const filename = convert<string>(theCounter++) + "lyxpreview";
        return support::AddName(bufferpath, filename);
 }
 
@@ -667,11 +661,14 @@ Converter const * setConverter()
 {
        string const from = "lyxpreview";
 
-       Formats::FormatList::const_iterator it  = formats.begin();
-       Formats::FormatList::const_iterator end = formats.end();
+       typedef vector<string> FmtList;
+       typedef lyx::graphics::Cache GCache;
+       FmtList const loadableFormats = GCache::get().loadableFormats();
+       FmtList::const_iterator it  = loadableFormats.begin();
+       FmtList::const_iterator const end = loadableFormats.end();
 
        for (; it != end; ++it) {
-               string const to = it->name();
+               string const to = *it;
                if (from == to)
                        continue;
 
@@ -712,56 +709,30 @@ void setAscentFractions(vector<double> & ascent_fractions,
 
        bool error = false;
 
-       // Tightpage dimensions affect all subsequent dimensions
-       int tp_ascent;
-       int tp_descent;
+       int snippet_counter = 1;
+       while (!in.eof() && it != end) {
+               string snippet;
+               int id;
+               double ascent_fraction;
 
-       int snippet_counter = 0;
-       while (!in.eof()) {
-               // Expecting lines of the form
-               // Preview: Tightpage tp_bl_x tp_bl_y tp_tr_x tp_tr_y
-               // Preview: Snippet id ascent descent width
-               string preview;
-               string type;
-               in >> preview >> type;
+               in >> snippet >> id >> ascent_fraction;
 
                if (!in.good())
                        // eof after all
                        break;
 
-               error = preview != "Preview:"
-                       || (type != "Tightpage" && type != "Snippet");
+               error = snippet != "Snippet";
                if (error)
                        break;
 
-               if (type == "Tightpage") {
-                       int dummy;
-                       in >> dummy >> tp_descent >> dummy >> tp_ascent;
-
-                       error = !in.good();
-                       if (error)
-                               break;
-
-               } else {
-                       int dummy;
-                       int snippet_id;
-                       int ascent;
-                       int descent;
-                       in >> snippet_id >> ascent >> descent >> dummy;
-
-                       error = !in.good() || ++snippet_counter != snippet_id;
-                       if (error)
-                               break;
-
-                       double const a = ascent + tp_ascent;
-                       double const d = descent - tp_descent;
+               error = id != snippet_counter;
+               if (error)
+                       break;
 
-                       if (!support::float_equal(a + d, 0, 0.1))
-                               *it = a / (a + d);
+               *it = ascent_fraction;
 
-                       if (++it == end)
-                               break;
-               }
+               ++snippet_counter;
+               ++it;
        }
 
        if (error) {