]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewImage.cpp
Fix bug noticed by Pavel. Apparently, some changes Abdel made to preview loading...
[lyx.git] / src / graphics / PreviewImage.cpp
index 306c2bfb12c524822f8e27a8b33201eaca2ec675..661c8af8d19f947ac5216a4f2e2a2c252f8999bc 100644 (file)
 #include <config.h>
 
 #include "PreviewImage.h"
+
+#include "Buffer.h"
+#include "Dimension.h"
 #include "GraphicsImage.h"
 #include "GraphicsLoader.h"
 #include "PreviewLoader.h"
 
 #include "support/FileName.h"
 
-#include <boost/bind.hpp>
+#include "support/bind.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -70,6 +73,12 @@ string const & PreviewImage::snippet() const
 }
 
 
+support::FileName const & PreviewImage::filename() const
+{
+       return pimpl_->iloader_.filename();
+}
+
+
 Dimension PreviewImage::dim() const
 {
        Dimension dim;
@@ -77,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;
@@ -97,13 +106,15 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
        : parent_(p), ploader_(l), iloader_(bf),
          snippet_(s), ascent_frac_(af)
 {
-       iloader_.connect(boost::bind(&Impl::statusChanged, this));
+       iloader_.setDisplayPixelRatio(l.displayPixelRatio());
+       iloader_.connect(bind(&Impl::statusChanged, this));
 }
 
 
 PreviewImage::Impl::~Impl()
 {
-       iloader_.filename().removeFile();
+       if (!ploader_.buffer().isClone())
+               iloader_.filename().removeFile();
 }
 
 
@@ -133,7 +144,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();