]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewImage.cpp
Use call_once to ensure something is only called once
[lyx.git] / src / graphics / PreviewImage.cpp
index 7fe9f2a769303fa408d4df8f2048313973ed5cae..80e8e2013513575cc8dfc500a7d9f554d70c10b7 100644 (file)
@@ -11,6 +11,9 @@
 #include <config.h>
 
 #include "PreviewImage.h"
+
+#include "Buffer.h"
+#include "Dimension.h"
 #include "GraphicsImage.h"
 #include "GraphicsLoader.h"
 #include "PreviewLoader.h"
@@ -25,7 +28,7 @@ using namespace lyx::support;
 namespace lyx {
 namespace graphics {
 
-class PreviewImage::Impl : public boost::signals::trackable {
+class PreviewImage::Impl : public boost::signals2::trackable {
 public:
        ///
        Impl(PreviewImage & p, PreviewLoader & l,
@@ -83,7 +86,7 @@ Dimension PreviewImage::dim() const
        if (!image)
                return dim;
 
-       dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
+       dim.asc = int(pimpl_->ascent_frac_ * double(image->height()) + 0.5);
        dim.des = image->height() - dim.asc;
        dim.wid = image->width();
        return dim;
@@ -103,13 +106,18 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
        : parent_(p), ploader_(l), iloader_(bf),
          snippet_(s), ascent_frac_(af)
 {
+       iloader_.setDisplayPixelRatio(l.displayPixelRatio());
        iloader_.connect(bind(&Impl::statusChanged, this));
 }
 
 
 PreviewImage::Impl::~Impl()
 {
-       iloader_.filename().removeFile();
+       // If these images are generated for a clone, then that may be
+       // because we are previewing. We therefore do not want to delete
+       // them when this Buffer is destroyed.
+       if (!ploader_.buffer().isClone())
+               iloader_.filename().removeFile();
 }
 
 
@@ -139,7 +147,10 @@ void PreviewImage::Impl::statusChanged()
        case ErrorUnknown:
                //iloader_.filename().removeFile();
                ploader_.remove(snippet_);
-               break;
+               // FIXME: We need to return here, because PreviewLoader::remove
+               // removes the preview image from the cache, which deletes this
+               // object, so we should not try to do anything here.
+               return;
 
        case Ready:
                iloader_.filename().removeFile();