2002-02-27 09:59:52 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2003-08-23 00:17:00 +00:00
|
|
|
* \file GraphicsImage.h
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Baruch Even
|
|
|
|
* \author Angus Leeming
|
2002-09-05 11:31:30 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* An abstract base class for the images themselves.
|
|
|
|
* Allows the user to retrieve the pixmap, once loaded and to issue commands
|
|
|
|
* to modify it.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* The boost::functions newImage and loadableFormats are connected to the
|
|
|
|
* appropriate derived classes elsewhere, allowing the graphics cache to
|
|
|
|
* access them without knowing anything about their instantiation.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* The loading process can be asynchronous, but cropping, rotating and
|
|
|
|
* scaling block execution.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICSIMAGE_H
|
|
|
|
#define GRAPHICSIMAGE_H
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
#include "support/std_string.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2002-07-04 17:45:35 +00:00
|
|
|
#include <boost/function/function0.hpp>
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/signals/signal1.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class Params;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class Image {
|
2002-02-27 09:59:52 +00:00
|
|
|
public:
|
2002-06-28 11:22:56 +00:00
|
|
|
/** This is to be connected to a function that will return a new
|
|
|
|
* instance of a viable derived class.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef boost::shared_ptr<Image> ImagePtr;
|
|
|
|
///
|
2002-07-04 17:45:35 +00:00
|
|
|
static boost::function0<ImagePtr> newImage;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Return the list of loadable formats.
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef std::vector<string> FormatList;
|
|
|
|
///
|
2002-07-04 17:45:35 +00:00
|
|
|
static boost::function0<FormatList> loadableFormats;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual ~Image() {}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Create a copy
|
2003-09-16 15:34:39 +00:00
|
|
|
Image * clone() const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Get the image width
|
2003-09-16 15:34:39 +00:00
|
|
|
unsigned int getWidth() const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Get the image height
|
2003-09-16 15:34:39 +00:00
|
|
|
unsigned int getHeight() const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2003-09-16 15:34:39 +00:00
|
|
|
/// Is the image drawable ?
|
|
|
|
bool isDrawable() const;
|
2002-07-17 16:56:42 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/** At the end of the loading process inform the outside world
|
|
|
|
* by emitting a signal.
|
|
|
|
*/
|
2002-05-29 16:21:03 +00:00
|
|
|
typedef boost::signal1<void, bool> SignalType;
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
SignalType finishedLoading;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/** Start loading the image file.
|
|
|
|
* The caller should expect this process to be asynchronous and
|
|
|
|
* so should connect to the "finished" signal above.
|
|
|
|
*/
|
2003-09-16 15:34:39 +00:00
|
|
|
void load(string const & filename);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** Generate the pixmap.
|
|
|
|
* Uses the params to decide on color, grayscale etc.
|
|
|
|
* Returns true if the pixmap is created.
|
|
|
|
*/
|
2003-09-16 15:34:39 +00:00
|
|
|
bool setPixmap(Params const & params);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Clip the image using params.
|
2003-09-16 15:34:39 +00:00
|
|
|
void clip(Params const & params);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Rotate the image using params.
|
2003-09-16 15:34:39 +00:00
|
|
|
void rotate(Params const & params);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Scale the image using params.
|
2003-09-16 15:34:39 +00:00
|
|
|
void scale(Params const & params);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
protected:
|
2003-09-16 15:34:39 +00:00
|
|
|
/// Must define default c-tor explicitly as we define a copy c-tor.
|
|
|
|
Image() {}
|
|
|
|
/// Don't copy the signal finishedLoading
|
|
|
|
Image(Image const &) {}
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Uses the params to ascertain the dimensions of the scaled image.
|
|
|
|
* Returned as make_pair(width, height).
|
2002-06-28 11:22:56 +00:00
|
|
|
* If something goes wrong, returns make_pair(getWidth(), getHeight())
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
|
|
|
std::pair<unsigned int, unsigned int>
|
2002-06-28 11:22:56 +00:00
|
|
|
getScaledDimensions(Params const & params) const;
|
2003-09-16 15:34:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Create a copy
|
|
|
|
virtual Image * clone_impl() const = 0;
|
|
|
|
/// Get the image width
|
|
|
|
virtual unsigned int getWidth_impl() const = 0;
|
|
|
|
|
|
|
|
/// Get the image height
|
|
|
|
virtual unsigned int getHeight_impl() const = 0;
|
|
|
|
|
|
|
|
/// is the image drawable ?
|
|
|
|
virtual bool isDrawable_impl() const = 0;
|
|
|
|
|
|
|
|
/** Start loading the image file.
|
|
|
|
* The caller should expect this process to be asynchronous and
|
|
|
|
* so should connect to the "finished" signal above.
|
|
|
|
*/
|
|
|
|
virtual void load_impl(string const & filename) = 0;
|
|
|
|
|
|
|
|
/** Generate the pixmap.
|
|
|
|
* Uses the params to decide on color, grayscale etc.
|
|
|
|
* Returns true if the pixmap is created.
|
|
|
|
*/
|
|
|
|
virtual bool setPixmap_impl(Params const & params) = 0;
|
|
|
|
|
|
|
|
/// Clip the image using params.
|
|
|
|
virtual void clip_impl(Params const & params) = 0;
|
|
|
|
|
|
|
|
/// Rotate the image using params.
|
|
|
|
virtual void rotate_impl(Params const & params) = 0;
|
|
|
|
|
|
|
|
/// Scale the image using params.
|
|
|
|
virtual void scale_impl(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
};
|
|
|
|
|
2003-09-16 15:34:39 +00:00
|
|
|
|
|
|
|
inline
|
|
|
|
Image * Image::clone() const
|
|
|
|
{
|
|
|
|
return clone_impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
unsigned int Image::getWidth() const
|
|
|
|
{
|
|
|
|
return getWidth_impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
unsigned int Image::getHeight() const
|
|
|
|
{
|
|
|
|
return getHeight_impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool Image::isDrawable() const
|
|
|
|
{
|
|
|
|
return isDrawable_impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
void Image::load(string const & filename)
|
|
|
|
{
|
|
|
|
return load_impl(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool Image::setPixmap(Params const & params)
|
|
|
|
{
|
|
|
|
return setPixmap_impl(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
void Image::clip(Params const & params)
|
|
|
|
{
|
|
|
|
return clip_impl(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
void Image::rotate(Params const & params)
|
|
|
|
{
|
|
|
|
return rotate_impl(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
void Image::scale(Params const & params)
|
|
|
|
{
|
|
|
|
return scale_impl(params);
|
|
|
|
}
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
#endif // GRAPHICSIMAGE_H
|