mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
Factor out the list of macro definitions for InsetPreview.
This will be soon reused in InsetText to generate images for DocBook.
This commit is contained in:
parent
48a507694e
commit
46b8101800
@ -28,8 +28,8 @@ class MathAtom;
|
|||||||
class Paragraph;
|
class Paragraph;
|
||||||
class Text;
|
class Text;
|
||||||
|
|
||||||
DocIterator doc_iterator_begin(Buffer const * buf, Inset const * inset = 0);
|
DocIterator doc_iterator_begin(Buffer const * buf, Inset const * inset = nullptr);
|
||||||
DocIterator doc_iterator_end(Buffer const * buf, Inset const * inset = 0);
|
DocIterator doc_iterator_end(Buffer const * buf, Inset const * inset = nullptr);
|
||||||
|
|
||||||
|
|
||||||
class DocIterator
|
class DocIterator
|
||||||
|
@ -79,6 +79,34 @@ void InsetPreview::addPreview(DocIterator const & inset_pos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MacroNameSet gatherMacroDefinitions(const Buffer* buffer, const Inset * inset)
|
||||||
|
{
|
||||||
|
// Collect macros for this inset.
|
||||||
|
// Not done yet: this function returns a list of macro *definitions*.
|
||||||
|
MacroNameSet macros;
|
||||||
|
buffer->listMacroNames(macros);
|
||||||
|
|
||||||
|
// Look for math insets and collect definitions for the used macros.
|
||||||
|
MacroNameSet defs;
|
||||||
|
DocIterator const dbeg = doc_iterator_begin(buffer, inset);
|
||||||
|
DocIterator dit = dbeg;
|
||||||
|
DocIterator const dend = doc_iterator_end(buffer, inset);
|
||||||
|
if (!dit.nextInset())
|
||||||
|
dit.forwardInset();
|
||||||
|
|
||||||
|
for (; dit != dend; dit.forwardInset()) {
|
||||||
|
InsetMath * im = dit.nextInset()->asInsetMath();
|
||||||
|
InsetMathHull * hull = im ? im->asHullInset() : nullptr;
|
||||||
|
if (!hull)
|
||||||
|
continue;
|
||||||
|
for (idx_type idx = 0; idx < hull->nargs(); ++idx)
|
||||||
|
hull->usedMacros(hull->cell(idx), dbeg, macros, defs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetPreview::preparePreview(DocIterator const & pos) const
|
void InsetPreview::preparePreview(DocIterator const & pos) const
|
||||||
{
|
{
|
||||||
odocstringstream str;
|
odocstringstream str;
|
||||||
@ -86,29 +114,10 @@ void InsetPreview::preparePreview(DocIterator const & pos) const
|
|||||||
OutputParams runparams(&pos.buffer()->params().encoding());
|
OutputParams runparams(&pos.buffer()->params().encoding());
|
||||||
latex(os, runparams);
|
latex(os, runparams);
|
||||||
|
|
||||||
// collect macros at this position
|
MacroNameSet defs = gatherMacroDefinitions(pos.buffer(), this);
|
||||||
MacroNameSet macros;
|
|
||||||
pos.buffer()->listMacroNames(macros);
|
|
||||||
|
|
||||||
// look for math insets and collect definitions for the used macros
|
|
||||||
MacroNameSet defs;
|
|
||||||
DocIterator dit = doc_iterator_begin(pos.buffer(), this);
|
|
||||||
DocIterator const dend = doc_iterator_end(pos.buffer(), this);
|
|
||||||
if (!dit.nextInset())
|
|
||||||
dit.forwardInset();
|
|
||||||
for (; dit != dend; dit.forwardInset()) {
|
|
||||||
InsetMath * im = dit.nextInset()->asInsetMath();
|
|
||||||
InsetMathHull * hull = im ? im->asHullInset() : nullptr;
|
|
||||||
if (!hull)
|
|
||||||
continue;
|
|
||||||
for (idx_type idx = 0; idx < hull->nargs(); ++idx)
|
|
||||||
hull->usedMacros(hull->cell(idx), pos, macros, defs);
|
|
||||||
}
|
|
||||||
MacroNameSet::iterator it = defs.begin();
|
|
||||||
MacroNameSet::iterator end = defs.end();
|
|
||||||
docstring macro_preamble;
|
docstring macro_preamble;
|
||||||
for (; it != end; ++it)
|
for (const auto& def : defs)
|
||||||
macro_preamble.append(*it);
|
macro_preamble.append(def);
|
||||||
|
|
||||||
docstring const snippet = macro_preamble + str.str();
|
docstring const snippet = macro_preamble + str.str();
|
||||||
preview_->addPreview(snippet, *pos.buffer());
|
preview_->addPreview(snippet, *pos.buffer());
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
class Dimension;
|
class Dimension;
|
||||||
|
class MacroNameSet;
|
||||||
class RenderPreview;
|
class RenderPreview;
|
||||||
|
|
||||||
namespace graphics {
|
namespace graphics {
|
||||||
@ -87,6 +88,10 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// gathers the list of macro definitions used in the given inset
|
||||||
|
MacroNameSet gatherMacroDefinitions(const Buffer* buffer, const Inset * inset);
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user