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
This commit is contained in:
Richard Heck 2010-07-29 15:17:58 +00:00
parent 833ef6352f
commit e48fb0b661
4 changed files with 47 additions and 19 deletions

View File

@ -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; return;
graphics::PreviewLoader const & loader = getPreviewLoader(buffer); graphics::PreviewLoader const & loader = getPreviewLoader(buffer);
loader.startLoading(wait); loader.startLoading(forexport);
} }
void RenderPreview::addPreview(docstring const & latex_snippet, 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; return;
graphics::PreviewLoader & loader = getPreviewLoader(buffer); graphics::PreviewLoader & loader = getPreviewLoader(buffer);
addPreview(latex_snippet, loader); addPreview(latex_snippet, loader, ignore_lyxrc);
} }
void RenderPreview::addPreview(docstring const & latex_snippet, 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; return;
// FIXME UNICODE // FIXME UNICODE

View File

@ -59,17 +59,23 @@ public:
/** Find the PreviewLoader and add a LaTeX snippet to it. /** Find the PreviewLoader and add a LaTeX snippet to it.
* Do not start the loading process. * 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. /** Add a LaTeX snippet to the PreviewLoader.
* Do not start the loading process. * Do not start the loading process.
* \param ignore_lyxrc: generate the preview no matter what LyXRC says
*/ */
void addPreview(docstring const & latex_snippet, void addPreview(docstring const & latex_snippet,
graphics::PreviewLoader & ploader); graphics::PreviewLoader & ploader,
bool ignore_lyxrc = false);
/// Begin the loading process. /// 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. /** Remove a snippet from the cache of previews.
* Useful if previewing the contents of a file that has changed. * Useful if previewing the contents of a file that has changed.

View File

@ -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(); Buffer const * buffer = pos.buffer();
// collect macros at this position // collect macros at this position
@ -536,14 +542,22 @@ void InsetMathHull::preparePreview(DocIterator const & pos) const
docstring const snippet = macro_preamble.str() + latexString(*this); docstring const snippet = macro_preamble.str() + latexString(*this);
LYXERR(Debug::MACROS, "Preview snippet: " << snippet); 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); 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; break;
} }
case BufferParams::Images: { case BufferParams::Images: {
reloadPreview(docit_, true); loadPreview(docit_);
graphics::PreviewImage const * pimage = preview_->getPreviewImage(buffer()); graphics::PreviewImage const * pimage = preview_->getPreviewImage(buffer());
if (pimage) { if (pimage) {
// FIXME Do we always have png? // FIXME Do we always have png?

View File

@ -139,10 +139,8 @@ public:
/// ///
void addPreview(DocIterator const & inset_pos, void addPreview(DocIterator const & inset_pos,
graphics::PreviewLoader &) const; graphics::PreviewLoader &) const;
/// Prepare the preview if preview is enabled.
void preparePreview(DocIterator const & pos) const;
/// Recreates the preview if preview is enabled. /// 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; void initUnicodeMath() const;
@ -172,6 +170,14 @@ protected:
private: private:
virtual Inset * clone() const; 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); void setType(HullType type);
/// ///