]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.C
Switch from SigC signals to boost::signals
[lyx.git] / src / graphics / GraphicsImage.C
1 /*
2  * \file GraphicsImage.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Baruch Even <baruch.even@writeme.com>
7  * \author Angus Leeming <a.leeming@ic.ac.uk>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "GraphicsImage.h"
17 #include "GraphicsParams.h"
18
19 namespace grfx {
20
21 // This will be connected to a function that will return whichever
22 // whichever derived class we desire.
23 boost::signal0<ImagePtr> GImage::newImage;
24
25 /// Return the list of loadable formats.
26 boost::signal0<GImage::FormatList> GImage::loadableFormats;
27
28 std::pair<unsigned int, unsigned int>
29 GImage::getScaledDimensions(GParams const & params) const
30 {
31         if (params.scale == 0 && params.width == 0 && params.height == 0)
32                 // No scaling
33                 return std::make_pair(getWidth(), getHeight());
34
35         typedef unsigned int dimension;
36         dimension width  = 0;
37         dimension height = 0;
38         if (params.scale != 0) {
39                 width  = dimension(getWidth()  * params.scale / 100.0);
40                 height = dimension(getHeight() * params.scale / 100.0);
41         } else {
42                 width  = params.width;
43                 height = params.height;
44
45                 if (width == 0) {
46                         width = height * getWidth() / getHeight();
47                 } else if (height == 0) {
48                         height = width * getHeight() / getWidth();
49                 }
50         }
51
52         if (width == 0 || height == 0)
53                 // Something is wrong!
54                 return std::make_pair(getWidth(), getHeight());
55
56         return std::make_pair(width, height);
57 }
58
59 } // namespace grfx