2002-02-27 09:59:52 +00:00
|
|
|
/*
|
|
|
|
* \file GraphicsImage.C
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Baruch Even <baruch.even@writeme.com>
|
2002-07-15 10:19:45 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "GraphicsImage.h"
|
|
|
|
#include "GraphicsParams.h"
|
2002-05-29 12:23:43 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
namespace grfx {
|
|
|
|
|
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-07-04 17:45:35 +00:00
|
|
|
boost::function0<Image::ImagePtr> Image::newImage;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Return the list of loadable formats.
|
2002-07-04 17:45:35 +00:00
|
|
|
boost::function0<Image::FormatList> Image::loadableFormats;
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
std::pair<unsigned int, unsigned int>
|
2002-06-28 11:22:56 +00:00
|
|
|
Image::getScaledDimensions(Params const & params) const
|
2002-02-27 09:59:52 +00:00
|
|
|
{
|
|
|
|
if (params.scale == 0 && params.width == 0 && params.height == 0)
|
|
|
|
// No scaling
|
|
|
|
return std::make_pair(getWidth(), getHeight());
|
|
|
|
|
2002-02-28 11:50:42 +00:00
|
|
|
typedef unsigned int dimension;
|
|
|
|
dimension width = 0;
|
|
|
|
dimension height = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
if (params.scale != 0) {
|
2002-02-28 11:50:42 +00:00
|
|
|
width = dimension(getWidth() * params.scale / 100.0);
|
|
|
|
height = dimension(getHeight() * params.scale / 100.0);
|
2002-02-27 09:59:52 +00:00
|
|
|
} else {
|
|
|
|
width = params.width;
|
|
|
|
height = params.height;
|
|
|
|
|
|
|
|
if (width == 0) {
|
|
|
|
width = height * getWidth() / getHeight();
|
|
|
|
} else if (height == 0) {
|
|
|
|
height = width * getHeight() / getWidth();
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
if (width == 0 || height == 0)
|
|
|
|
// Something is wrong!
|
|
|
|
return std::make_pair(getWidth(), getHeight());
|
|
|
|
|
|
|
|
return std::make_pair(width, height);
|
|
|
|
}
|
2002-05-29 12:23:43 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
} // namespace grfx
|