From e48fb0b66182f401d882fd88e578b4a66f5340dc Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 29 Jul 2010 15:17:58 +0000 Subject: [PATCH] Allow images to be export even when LyXRC says no previews. I'll try to figure out how to get rid of the magic booleans. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35022 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/RenderPreview.cpp | 18 ++++++++++-------- src/insets/RenderPreview.h | 12 +++++++++--- src/mathed/InsetMathHull.cpp | 24 +++++++++++++++++++----- src/mathed/InsetMathHull.h | 12 +++++++++--- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/insets/RenderPreview.cpp b/src/insets/RenderPreview.cpp index 1b97bef14e..5a51d793b2 100644 --- a/src/insets/RenderPreview.cpp +++ b/src/insets/RenderPreview.cpp @@ -175,31 +175,33 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const } -void RenderPreview::startLoading(Buffer const & buffer, bool wait) const +void RenderPreview::startLoading(Buffer const & buffer, bool forexport) const { - if (status() == LyXRC::PREVIEW_OFF || snippet_.empty()) + if (!forexport && (status() == LyXRC::PREVIEW_OFF || snippet_.empty())) return; graphics::PreviewLoader const & loader = getPreviewLoader(buffer); - loader.startLoading(wait); + loader.startLoading(forexport); } void RenderPreview::addPreview(docstring const & latex_snippet, - Buffer const & buffer) + Buffer const & buffer, + bool ignore_lyxrc) { - if (status() == LyXRC::PREVIEW_OFF) + if (status() == LyXRC::PREVIEW_OFF && !ignore_lyxrc) return; graphics::PreviewLoader & loader = getPreviewLoader(buffer); - addPreview(latex_snippet, loader); + addPreview(latex_snippet, loader, ignore_lyxrc); } void RenderPreview::addPreview(docstring const & latex_snippet, - graphics::PreviewLoader & ploader) + graphics::PreviewLoader & ploader, + bool ignore_lyxrc) { - if (status() == LyXRC::PREVIEW_OFF) + if (status() == LyXRC::PREVIEW_OFF && !ignore_lyxrc) return; // FIXME UNICODE diff --git a/src/insets/RenderPreview.h b/src/insets/RenderPreview.h index 01df8c6000..0476e687e5 100644 --- a/src/insets/RenderPreview.h +++ b/src/insets/RenderPreview.h @@ -59,17 +59,23 @@ public: /** Find the PreviewLoader and add a LaTeX snippet to it. * Do not start the loading process. + * \param ignore_lyxrc: generate the preview no matter what LyXRC says */ - void addPreview(docstring const & latex_snippet, Buffer const &); + void addPreview(docstring const & latex_snippet, Buffer const &, + bool ignore_lyxrc = false); /** Add a LaTeX snippet to the PreviewLoader. * Do not start the loading process. + * \param ignore_lyxrc: generate the preview no matter what LyXRC says */ void addPreview(docstring const & latex_snippet, - graphics::PreviewLoader & ploader); + graphics::PreviewLoader & ploader, + bool ignore_lyxrc = false); /// Begin the loading process. - void startLoading(Buffer const & buffer, bool wait = false) const; + /// \param forexport : whether this is intended for export. if so, + /// then we ignore LyXRC and wait for the image to be generated. + void startLoading(Buffer const & buffer, bool forexport = false) const; /** Remove a snippet from the cache of previews. * Useful if previewing the contents of a file that has changed. diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 234bb56d82..ae9511051c 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -516,8 +516,14 @@ void InsetMathHull::addPreview(DocIterator const & inset_pos, } -void InsetMathHull::preparePreview(DocIterator const & pos) const +void InsetMathHull::preparePreview(DocIterator const & pos, + bool forexport) const { + // there is no need to do all the macro stuff if we're not + // actually going to generate the preview. + if (RenderPreview::status() != LyXRC::PREVIEW_ON && !forexport) + return; + Buffer const * buffer = pos.buffer(); // collect macros at this position @@ -536,14 +542,22 @@ void InsetMathHull::preparePreview(DocIterator const & pos) const docstring const snippet = macro_preamble.str() + latexString(*this); LYXERR(Debug::MACROS, "Preview snippet: " << snippet); - preview_->addPreview(snippet, *buffer); + preview_->addPreview(snippet, *buffer, forexport); } -void InsetMathHull::reloadPreview(DocIterator const & pos, bool wait) const +void InsetMathHull::reloadPreview(DocIterator const & pos) const { preparePreview(pos); - preview_->startLoading(*pos.buffer(), wait); + preview_->startLoading(*pos.buffer()); +} + + +void InsetMathHull::loadPreview(DocIterator const & pos) const +{ + bool const forexport = true; + preparePreview(pos, forexport); + preview_->startLoading(*pos.buffer(), forexport); } @@ -1871,7 +1885,7 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const break; } case BufferParams::Images: { - reloadPreview(docit_, true); + loadPreview(docit_); graphics::PreviewImage const * pimage = preview_->getPreviewImage(buffer()); if (pimage) { // FIXME Do we always have png? diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index d2ca3f6d2b..eba5c5199d 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -139,10 +139,8 @@ public: /// void addPreview(DocIterator const & inset_pos, graphics::PreviewLoader &) const; - /// Prepare the preview if preview is enabled. - void preparePreview(DocIterator const & pos) const; /// Recreates the preview if preview is enabled. - void reloadPreview(DocIterator const & pos, bool wait = false) const; + void reloadPreview(DocIterator const & pos) const; /// void initUnicodeMath() const; @@ -172,6 +170,14 @@ protected: private: virtual Inset * clone() const; + /// Prepare the preview if preview is enabled. + /// \param forexport: whether this is intended for export + /// If so, we ignore LyXRC and wait for the image to be generated. + void preparePreview(DocIterator const & pos, + bool forexport = false) const; + /// like reloadPreview, but forces load + /// used by image export + void loadPreview(DocIterator const & pos) const; /// void setType(HullType type); ///