#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 "support/lyxlib.h"
-
-#include <boost/bind.hpp>
-using std::string;
+#include "support/bind.h"
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-
-using support::FileName;
-
namespace graphics {
class PreviewImage::Impl : public boost::signals::trackable {
}
-int PreviewImage::ascent() const
+support::FileName const & PreviewImage::filename() const
{
- Image const * const image = pimpl_->iloader_.image();
- if (!image)
- return 0;
-
- return int(pimpl_->ascent_frac_ * double(image->getHeight()));
+ return pimpl_->iloader_.filename();
}
-int PreviewImage::descent() const
+Dimension PreviewImage::dim() const
{
+ Dimension dim;
Image const * const image = pimpl_->iloader_.image();
if (!image)
- return 0;
+ return dim;
- // Avoids rounding errors.
- return image->getHeight() - ascent();
-}
-
-
-int PreviewImage::width() const
-{
- Image const * const image = pimpl_->iloader_.image();
- return image ? image->getWidth() : 0;
+ dim.asc = int(pimpl_->ascent_frac_ * double(image->height()) + 0.5);
+ dim.des = image->height() - dim.asc;
+ dim.wid = image->width();
+ return dim;
}
: 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()
{
- support::unlink(iloader_.filename());
+ // 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();
}
case ErrorLoading:
case ErrorGeneratingPixmap:
case ErrorUnknown:
- //lyx::unlink(iloader_.filename());
+ //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:
- support::unlink(iloader_.filename());
+ iloader_.filename().removeFile();
break;
}
ploader_.emitSignal(parent_);