mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
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:
parent
643f9ad4da
commit
bdec44d614
@ -207,10 +207,6 @@ public:
|
|||||||
void add(string const & latex_snippet);
|
void add(string const & latex_snippet);
|
||||||
///
|
///
|
||||||
void remove(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,
|
/// \p wait whether to wait for the process to complete or, instead,
|
||||||
/// to do it in the background.
|
/// to do it in the background.
|
||||||
void startLoading(bool wait = false);
|
void startLoading(bool wait = false);
|
||||||
@ -250,9 +246,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
InProgressProcesses in_progress_;
|
InProgressProcesses in_progress_;
|
||||||
|
|
||||||
///
|
|
||||||
set<docstring> macrodefs_;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
PreviewLoader & parent_;
|
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
|
void PreviewLoader::startLoading(bool wait) const
|
||||||
{
|
{
|
||||||
pimpl_->startLoading(wait);
|
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)
|
void PreviewLoader::Impl::startLoading(bool wait)
|
||||||
{
|
{
|
||||||
if (pending_.empty() || !pconverter_)
|
if (pending_.empty() || !pconverter_)
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <boost/signal.hpp>
|
#include <boost/signal.hpp>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "support/docstring.h"
|
|
||||||
|
|
||||||
#include "ColorCode.h"
|
#include "ColorCode.h"
|
||||||
|
|
||||||
@ -68,11 +67,6 @@ public:
|
|||||||
/// Remove this snippet of LaTeX from the PreviewLoader.
|
/// Remove this snippet of LaTeX from the PreviewLoader.
|
||||||
void remove(std::string const & latex_snippet) const;
|
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".
|
/** We have accumulated several latex snippets with status "InQueue".
|
||||||
* Initiate their transformation into bitmap images.
|
* Initiate their transformation into bitmap images.
|
||||||
*/
|
*/
|
||||||
|
@ -24,18 +24,12 @@
|
|||||||
|
|
||||||
#include "graphics/PreviewImage.h"
|
#include "graphics/PreviewImage.h"
|
||||||
|
|
||||||
#include "mathed/MacroTable.h"
|
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
using support::prefixIs;
|
|
||||||
|
|
||||||
|
|
||||||
InsetPreview::InsetPreview(Buffer * buf)
|
InsetPreview::InsetPreview(Buffer * buf)
|
||||||
: InsetText(buf),
|
: InsetText(buf),
|
||||||
@ -76,33 +70,10 @@ void InsetPreview::preparePreview(DocIterator const & pos) const
|
|||||||
TexRow texrow;
|
TexRow texrow;
|
||||||
odocstringstream str;
|
odocstringstream str;
|
||||||
otexstream os(str, texrow);
|
otexstream os(str, texrow);
|
||||||
Buffer const * buffer = pos.buffer();
|
OutputParams runparams(&pos.buffer()->params().encoding());
|
||||||
OutputParams runparams(&buffer->params().encoding());
|
|
||||||
latex(os, runparams);
|
latex(os, runparams);
|
||||||
// collect macros at this position in case they are used in a math inset
|
docstring const snippet = str.str();
|
||||||
MacroNameSet macros;
|
preview_->addPreview(snippet, *pos.buffer());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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)
|
void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
|
||||||
{
|
{
|
||||||
// Check the current snippet is the same as that previewed.
|
// Check the current snippet is the same as that previewed.
|
||||||
|
@ -74,11 +74,6 @@ public:
|
|||||||
graphics::PreviewLoader & ploader,
|
graphics::PreviewLoader & ploader,
|
||||||
bool ignore_lyxrc = false);
|
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.
|
/// Begin the loading process.
|
||||||
/// \param forexport : whether this is intended for export. if so,
|
/// \param forexport : whether this is intended for export. if so,
|
||||||
/// then we ignore LyXRC and wait for the image to be generated.
|
/// then we ignore LyXRC and wait for the image to be generated.
|
||||||
|
@ -638,22 +638,12 @@ void InsetMathHull::preparePreview(DocIterator const & pos,
|
|||||||
buffer->listMacroNames(macros);
|
buffer->listMacroNames(macros);
|
||||||
MacroNameSet::iterator it = macros.begin();
|
MacroNameSet::iterator it = macros.begin();
|
||||||
MacroNameSet::iterator end = macros.end();
|
MacroNameSet::iterator end = macros.end();
|
||||||
docstring macro_preamble;
|
odocstringstream macro_preamble;
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
MacroData const * data = buffer->getMacro(*it, pos, true);
|
MacroData const * data = buffer->getMacro(*it, pos, true);
|
||||||
if (data) {
|
if (data) {
|
||||||
odocstringstream mac_preamble;
|
data->write(macro_preamble, true);
|
||||||
data->write(mac_preamble, true);
|
macro_preamble << endl;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,7 +668,8 @@ void InsetMathHull::preparePreview(DocIterator const & pos,
|
|||||||
'{' + convert<docstring>(num) + '}';
|
'{' + 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);
|
LYXERR(Debug::MACROS, "Preview snippet: " << snippet);
|
||||||
preview_->addPreview(snippet, *buffer, forexport);
|
preview_->addPreview(snippet, *buffer, forexport);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user