]> git.lyx.org Git - features.git/commitdiff
Allow images to be export even when LyXRC says no previews.
authorRichard Heck <rgheck@comcast.net>
Thu, 29 Jul 2010 15:17:58 +0000 (15:17 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 29 Jul 2010 15:17:58 +0000 (15:17 +0000)
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
src/insets/RenderPreview.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathHull.h

index 1b97bef14e9f1038dd30649f4f38b4da788f567d..5a51d793b213900b6bf76fd1fbdd6aa8b0fe6ffe 100644 (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;
 
        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
index 01df8c60000e88cbde59d34ab2544b5c624c64f1..0476e687e59fbcfcaaaf8b1b6383d05ee3831243 100644 (file)
@@ -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.
index 234bb56d8231451d0d4cb7c45ba9fddb8463cf0e..ae9511051cae6ccd5029c8d0e7f7ffa3b4c0f452 100644 (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();
 
        // 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?
index d2ca3f6d2bec84a0cca6814bf5dd4cba53ab9f70..eba5c5199dfc4379f4a92972fd2add12b9947e6b 100644 (file)
@@ -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);
        ///