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.
This commit is contained in:
Enrico Forestieri 2015-06-14 18:05:39 +02:00
parent 643f9ad4da
commit bdec44d614
6 changed files with 8 additions and 106 deletions

View File

@ -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<docstring> 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_)

View File

@ -20,7 +20,6 @@
#include <boost/signal.hpp>
#include <QObject>
#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.
*/

View File

@ -24,18 +24,12 @@
#include "graphics/PreviewImage.h"
#include "mathed/MacroTable.h"
#include "support/lstrings.h"
#include <sstream>
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());
}

View File

@ -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.

View File

@ -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.

View File

@ -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<docstring>(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);
}