[LyX/master] Factor out the generation of the code to create a preview.
Thibaut Cuvelier
tcuvelier at lyx.org
Wed Oct 13 17:04:19 UTC 2021
commit 3502f5c999f7c91da83d247e1a460ef30a497aa0
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Wed Oct 13 03:01:54 2021 +0200
Factor out the generation of the code to create a preview.
This will be soon reused in InsetText to generate images for DocBook.
---
src/insets/InsetPreview.cpp | 16 +++++++++++-----
src/insets/InsetPreview.h | 2 ++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp
index e08fdcd..c4f1b8d 100644
--- a/src/insets/InsetPreview.cpp
+++ b/src/insets/InsetPreview.cpp
@@ -107,19 +107,25 @@ MacroNameSet gatherMacroDefinitions(const Buffer* buffer, const Inset * inset)
}
-void InsetPreview::preparePreview(DocIterator const & pos) const
+docstring insetToLaTeXSnippet(const Buffer* buffer, const Inset * inset)
{
odocstringstream str;
otexstream os(str);
- OutputParams runparams(&pos.buffer()->params().encoding());
- latex(os, runparams);
+ OutputParams runparams(&buffer->params().encoding());
+ inset->latex(os, runparams);
- MacroNameSet defs = gatherMacroDefinitions(pos.buffer(), this);
+ MacroNameSet defs = gatherMacroDefinitions(buffer, inset);
docstring macro_preamble;
for (const auto& def : defs)
macro_preamble.append(def);
- docstring const snippet = macro_preamble + str.str();
+ return macro_preamble + str.str();
+}
+
+
+void InsetPreview::preparePreview(DocIterator const & pos) const
+{
+ docstring const snippet = insetToLaTeXSnippet(pos.buffer(), this);
preview_->addPreview(snippet, *pos.buffer());
}
diff --git a/src/insets/InsetPreview.h b/src/insets/InsetPreview.h
index 55353e7..db2a2af 100644
--- a/src/insets/InsetPreview.h
+++ b/src/insets/InsetPreview.h
@@ -90,6 +90,8 @@ protected:
/// gathers the list of macro definitions used in the given inset
MacroNameSet gatherMacroDefinitions(const Buffer* buffer, const Inset * inset);
+/// returns the LaTeX snippet to compute the preview of the given inset
+docstring insetToLaTeXSnippet(const Buffer* buffer, const Inset * inset);
} // namespace lyx
More information about the lyx-cvs
mailing list