]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewLoader.cpp
Refactor OutputParams
[lyx.git] / src / graphics / PreviewLoader.cpp
index d73e353f4c72979c145bc69367c4c3fe1e655f98..7371ea68ffb057dc2d34d2f26d56efeac5bf57d7 100644 (file)
@@ -19,7 +19,6 @@
 #include "Converter.h"
 #include "Encoding.h"
 #include "Format.h"
-#include "InsetIterator.h"
 #include "LaTeXFeatures.h"
 #include "LyXRC.h"
 #include "output.h"
@@ -29,8 +28,6 @@
 
 #include "frontends/Application.h" // hexName
 
-#include "insets/Inset.h"
-
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/FileName.h"
@@ -193,7 +190,7 @@ private:
        /// Called by the ForkedCall process that generated the bitmap files.
        void finishedGenerating(pid_t, int);
        ///
-       void dumpPreamble(otexstream &, OutputParams::FLAVOR) const;
+       void dumpPreamble(otexstream &, FLAVOR) const;
        ///
        void dumpData(odocstream &, BitmapFile const &) const;
 
@@ -319,18 +316,26 @@ Buffer const & PreviewLoader::buffer() const
 
 namespace {
 
-std::function<SnippetPair (string const &)> IncrementedFileName
-       (string const & to_format, string const & filename_base)
-{
-       return [&to_format, &filename_base](string const & snippet)
+class IncrementedFileName {
+public:
+       IncrementedFileName(string const & to_format,
+                           string const & filename_base)
+               : to_format_(to_format), base_(filename_base), counter_(1)
+       {}
+
+       SnippetPair const operator()(string const & snippet)
        {
-               static int counter_ = 1;
                ostringstream os;
-               os << filename_base << counter_++ << '.' << to_format;
-               string const file = os.str();
-               return make_pair(snippet, FileName(file));
-       };
-}
+               os << base_ << counter_++ << '.' << to_format_;
+               string const file_name = os.str();
+               return make_pair(snippet, FileName(file_name));
+       }
+       
+private:
+       string const & to_format_;
+       string const & base_;
+       int counter_;
+};
 
 
 InProgress::InProgress(string const & filename_base,
@@ -375,8 +380,8 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
 {
        font_scaling_factor_ = int(buffer_.fontScalingFactor());
        if (theApp()) {
-               fg_color_ = strtol(theApp()->hexName(foregroundColor()).c_str(), nullptr, 16);
-               bg_color_ = strtol(theApp()->hexName(backgroundColor()).c_str(), nullptr, 16);
+               fg_color_ = convert(theApp()->hexName(foregroundColor()).c_str(), 16);
+               bg_color_ = convert(theApp()->hexName(backgroundColor()).c_str(), 16);
        } else {
                fg_color_ = 0x0;
                bg_color_ = 0xffffff;
@@ -439,8 +444,8 @@ PreviewLoader::Impl::preview(string const & latex_snippet) const
        int fg = 0x0;
        int bg = 0xffffff;
        if (theApp()) {
-               fg = strtol(theApp()->hexName(foregroundColor()).c_str(), nullptr, 16);
-               bg = strtol(theApp()->hexName(backgroundColor()).c_str(), nullptr, 16);
+               fg = convert(theApp()->hexName(foregroundColor()).c_str(), 16);
+               bg = convert(theApp()->hexName(backgroundColor()).c_str(), 16);
        }
        if (font_scaling_factor_ != fs || fg_color_ != fg || bg_color_ != bg) {
                // Schedule refresh of all previews on zoom or color changes.
@@ -532,7 +537,8 @@ void PreviewLoader::Impl::add(string const & latex_snippet)
 
 namespace {
 
-std::function<void (InProgressProcess &)> EraseSnippet(string const & s) {
+std::function<void (InProgressProcess &)> EraseSnippet(string const & s)
+{
        return [&s](InProgressProcess & process) {
                BitmapFile & snippets = process.second.snippets;
                BitmapFile::iterator it  = snippets.begin();
@@ -542,7 +548,7 @@ std::function<void (InProgressProcess &)> EraseSnippet(string const & s) {
                if (it != end)
                        snippets.erase(it, it+1);
        };
-};
+}
 
 } // namespace
 
@@ -622,7 +628,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
 
        // Set \jobname of previews to the document name (see bug 9627)
        of << "\\def\\jobname{"
-          << from_utf8(changeExtension(buffer_.latexName(true), ""))
+          << from_utf8(changeExtension(buffer_.latexName(), ""))
           << "}\n";
 
        LYXERR(Debug::LATEX, "Format = " << buffer_.params().getDefaultOutputFormat());
@@ -631,37 +637,37 @@ void PreviewLoader::Impl::startLoading(bool wait)
                        && buffer_.params().default_output_format != "default";
        // Use LATEX flavor if the document does not specify a specific
        // output format (see bug 9371).
-       OutputParams::FLAVOR flavor = docformat
+       FLAVOR flavor = docformat
                                        ? buffer_.params().getOutputFlavor()
-                                       : OutputParams::LATEX;
+                                       : FLAVOR::LATEX;
        if (buffer_.params().encoding().package() == Encoding::japanese) {
                latexparam = " --latex=platex";
-               flavor = OutputParams::LATEX;
+               flavor = FLAVOR::LATEX;
        }
        else if (buffer_.params().useNonTeXFonts) {
-               if (flavor == OutputParams::LUATEX)
+               if (flavor == FLAVOR::LUATEX)
                        latexparam = " --latex=lualatex";
                else {
-                       flavor = OutputParams::XETEX;
+                       flavor = FLAVOR::XETEX;
                        latexparam = " --latex=xelatex";
                }
        }
        else {
                switch (flavor) {
-                       case OutputParams::PDFLATEX:
+                       case FLAVOR::PDFLATEX:
                                latexparam = " --latex=pdflatex";
                                break;
-                       case OutputParams::XETEX:
+                       case FLAVOR::XETEX:
                                latexparam = " --latex=xelatex";
                                break;
-                       case OutputParams::LUATEX:
+                       case FLAVOR::LUATEX:
                                latexparam = " --latex=lualatex";
                                break;
-                       case OutputParams::DVILUATEX:
+                       case FLAVOR::DVILUATEX:
                                latexparam = " --latex=dvilualatex";
                                break;
                        default:
-                               flavor = OutputParams::LATEX;
+                               flavor = FLAVOR::LATEX;
                }
        }
        dumpPreamble(os, flavor);
@@ -805,10 +811,10 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval)
 }
 
 
-void PreviewLoader::Impl::dumpPreamble(otexstream & os, OutputParams::FLAVOR flavor) const
+void PreviewLoader::Impl::dumpPreamble(otexstream & os, FLAVOR flavor) const
 {
        // Dump the preamble only.
-       LYXERR(Debug::LATEX, "dumpPreamble, flavor == " << flavor);
+       LYXERR(Debug::LATEX, "dumpPreamble, flavor == " << static_cast<int>(flavor));
        OutputParams runparams(&buffer_.params().encoding());
        runparams.flavor = flavor;
        runparams.nice = true;