From bdec44d614e9a1bcc7e829653e2df7b27a8311cc Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sun, 14 Jun 2015 18:05:39 +0200 Subject: [PATCH] Revert bc47054b and the related commit ad0d0f6d As discussed on the devel list. See the subthread starting at http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg187916.html Soon to be replaced with the same strategy adopted in the stable branch. --- src/graphics/PreviewLoader.cpp | 31 ------------------------------ src/graphics/PreviewLoader.h | 6 ------ src/insets/InsetPreview.cpp | 35 +++------------------------------- src/insets/RenderPreview.cpp | 18 ----------------- src/insets/RenderPreview.h | 5 ----- src/mathed/InsetMathHull.cpp | 19 +++++------------- 6 files changed, 8 insertions(+), 106 deletions(-) diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index 3c82c00660..ea8e3ce11b 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -207,10 +207,6 @@ public: void add(string const & latex_snippet); /// void remove(string const & latex_snippet); - /// Record math macro definitions added to the loader - void addMacroDef(docstring const & latex_snippet); - /// Has a math macro definition already been added to the loader? - bool hasMacroDef(docstring const & latex_snippet) const; /// \p wait whether to wait for the process to complete or, instead, /// to do it in the background. void startLoading(bool wait = false); @@ -250,9 +246,6 @@ private: */ InProgressProcesses in_progress_; - /// - set macrodefs_; - /// PreviewLoader & parent_; /// @@ -309,18 +302,6 @@ void PreviewLoader::remove(string const & latex_snippet) const } -void PreviewLoader::addMacroDef(docstring const & latex_snippet) const -{ - pimpl_->addMacroDef(latex_snippet); -} - - -bool PreviewLoader::hasMacroDef(docstring const & latex_snippet) const -{ - return pimpl_->hasMacroDef(latex_snippet); -} - - void PreviewLoader::startLoading(bool wait) const { pimpl_->startLoading(wait); @@ -581,18 +562,6 @@ void PreviewLoader::Impl::remove(string const & latex_snippet) } -void PreviewLoader::Impl::addMacroDef(docstring const & latex_snippet) -{ - macrodefs_.insert(latex_snippet); -} - - -bool PreviewLoader::Impl::hasMacroDef(docstring const & latex_snippet) const -{ - return macrodefs_.find(latex_snippet) != macrodefs_.end(); -} - - void PreviewLoader::Impl::startLoading(bool wait) { if (pending_.empty() || !pconverter_) diff --git a/src/graphics/PreviewLoader.h b/src/graphics/PreviewLoader.h index 70807e613c..3f617628fc 100644 --- a/src/graphics/PreviewLoader.h +++ b/src/graphics/PreviewLoader.h @@ -20,7 +20,6 @@ #include #include -#include "support/docstring.h" #include "ColorCode.h" @@ -68,11 +67,6 @@ public: /// Remove this snippet of LaTeX from the PreviewLoader. void remove(std::string const & latex_snippet) const; - /// Record math macro definitions added to the loader - void addMacroDef(docstring const & latex_snippet) const; - /// Has a math macro definition already been added to the loader? - bool hasMacroDef(docstring const & latex_snippet) const; - /** We have accumulated several latex snippets with status "InQueue". * Initiate their transformation into bitmap images. */ diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp index 2e240da3be..1b3456eac9 100644 --- a/src/insets/InsetPreview.cpp +++ b/src/insets/InsetPreview.cpp @@ -24,18 +24,12 @@ #include "graphics/PreviewImage.h" -#include "mathed/MacroTable.h" - -#include "support/lstrings.h" - #include using namespace std; namespace lyx { -using support::prefixIs; - InsetPreview::InsetPreview(Buffer * buf) : InsetText(buf), @@ -76,33 +70,10 @@ void InsetPreview::preparePreview(DocIterator const & pos) const TexRow texrow; odocstringstream str; otexstream os(str, texrow); - Buffer const * buffer = pos.buffer(); - OutputParams runparams(&buffer->params().encoding()); + OutputParams runparams(&pos.buffer()->params().encoding()); latex(os, runparams); - // collect macros at this position in case they are used in a math inset - MacroNameSet macros; - buffer->listMacroNames(macros); - MacroNameSet::iterator it = macros.begin(); - MacroNameSet::iterator end = macros.end(); - docstring macro_preamble; - for (; it != end; ++it) { - MacroData const * data = buffer->getMacro(*it, pos, true); - if (data) { - odocstringstream macro_def; - data->write(macro_def, true); - docstring const md = macro_def.str(); - macro_def << endl; - bool is_newcomm = prefixIs(md, from_ascii("\\newcomm")); - // assure that \newcommand defs are only added once - if (!is_newcomm || !preview_->hasMacroDef(md, *buffer)) { - if (is_newcomm) - preview_->addMacroDef(md, *buffer); - macro_preamble.append(macro_def.str()); - } - } - } - docstring const snippet = macro_preamble + str.str(); - preview_->addPreview(snippet, *buffer); + docstring const snippet = str.str(); + preview_->addPreview(snippet, *pos.buffer()); } diff --git a/src/insets/RenderPreview.cpp b/src/insets/RenderPreview.cpp index 60346f92c8..9d7304f2e7 100644 --- a/src/insets/RenderPreview.cpp +++ b/src/insets/RenderPreview.cpp @@ -257,24 +257,6 @@ void RenderPreview::removePreview(Buffer const & buffer) } -void RenderPreview::addMacroDef(docstring const & latex_snippet, - Buffer const & buffer) -{ - graphics::PreviewLoader * loader = buffer.loader(); - LASSERT(loader, return); - loader->addMacroDef(latex_snippet); -} - - -bool RenderPreview::hasMacroDef(docstring const & latex_snippet, - Buffer const & buffer) -{ - graphics::PreviewLoader * loader = buffer.loader(); - LASSERT(loader, return false); - return loader->hasMacroDef(latex_snippet); -} - - void RenderPreview::imageReady(graphics::PreviewImage const & pimage) { // Check the current snippet is the same as that previewed. diff --git a/src/insets/RenderPreview.h b/src/insets/RenderPreview.h index e9e3cb10c2..cc7a4b6928 100644 --- a/src/insets/RenderPreview.h +++ b/src/insets/RenderPreview.h @@ -74,11 +74,6 @@ public: graphics::PreviewLoader & ploader, bool ignore_lyxrc = false); - /// Record math macro definitions added to the preview loader - void addMacroDef(docstring const & latex_snippet, Buffer const & buffer); - /// Has a math macro definition already been added to the preview loader? - bool hasMacroDef(docstring const & latex_snippet, Buffer const & buffer); - /// Begin the loading process. /// \param forexport : whether this is intended for export. if so, /// then we ignore LyXRC and wait for the image to be generated. diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index ab1b5860f0..f8e68ba132 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -638,22 +638,12 @@ void InsetMathHull::preparePreview(DocIterator const & pos, buffer->listMacroNames(macros); MacroNameSet::iterator it = macros.begin(); MacroNameSet::iterator end = macros.end(); - docstring macro_preamble; + odocstringstream macro_preamble; for (; it != end; ++it) { MacroData const * data = buffer->getMacro(*it, pos, true); if (data) { - odocstringstream mac_preamble; - data->write(mac_preamble, true); - docstring const mps = mac_preamble.str(); - bool const is_new_def = prefixIs(mps, from_ascii("\\newcomm")); - // assure that \newcommand definitions of macros are only added once - if (!is_new_def || !preview_->hasMacroDef(mps, *buffer)) { - if (is_new_def) - preview_->addMacroDef(mps, *buffer); - if (!macro_preamble.empty()) - macro_preamble += '\n'; - macro_preamble += mps; - } + data->write(macro_preamble, true); + macro_preamble << endl; } } @@ -678,7 +668,8 @@ void InsetMathHull::preparePreview(DocIterator const & pos, '{' + convert(num) + '}'; } } - docstring const snippet = macro_preamble + setcnt + latexString(*this); + docstring const snippet = macro_preamble.str() + + setcnt + latexString(*this); LYXERR(Debug::MACROS, "Preview snippet: " << snippet); preview_->addPreview(snippet, *buffer, forexport); }