]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.C
fix typo that put too many include paths for most people
[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 #include <iostream>
19
20 namespace grfx {
21
22 // This will be connected to a function that will return whichever
23 // whichever derived class we desire.
24 SigC::Signal0<ImagePtr> GImage::newImage;
25
26 /// Return the list of loadable formats.
27 SigC::Signal0<GImage::FormatList> GImage::loadableFormats;
28
29 std::pair<unsigned int, unsigned int>
30 GImage::getScaledDimensions(GParams const & params) const
31 {
32         if (params.scale == 0 && params.width == 0 && params.height == 0)
33                 // No scaling
34                 return std::make_pair(getWidth(), getHeight());
35
36         typedef unsigned int dimension;
37         dimension width  = 0;
38         dimension height = 0;
39         if (params.scale != 0) {
40                 width  = dimension(getWidth()  * params.scale / 100.0);
41                 height = dimension(getHeight() * params.scale / 100.0);
42         } else {
43                 width  = params.width;
44                 height = params.height;
45
46                 if (width == 0) {
47                         width = height * getWidth() / getHeight();
48                 } else if (height == 0) {
49                         height = width * getHeight() / getWidth();
50                 }
51         }
52
53         if (width == 0 || height == 0)
54                 // Something is wrong!
55                 return std::make_pair(getWidth(), getHeight());
56
57         return std::make_pair(width, height);
58 }
59 } // namespace grfx