]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.C
remove unused code
[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 <leeming@lyx.org>
8  * \author Herbert Voss <voss@lyx.org>
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "GraphicsImage.h"
18 #include "GraphicsParams.h"
19 #include "debug.h"
20
21 using std::endl;
22 using std::abs;
23
24 namespace grfx {
25
26 // This is to be connected to a function that will return a new
27 // instance of a viable derived class.
28 boost::function0<Image::ImagePtr> Image::newImage;
29
30 /// Return the list of loadable formats.
31 boost::function0<Image::FormatList> Image::loadableFormats;
32
33
34 std::pair<unsigned int, unsigned int>
35 Image::getScaledDimensions(Params const & params) const
36 {
37         lyxerr[Debug::GRAPHICS]
38                 << "GraphicsImage::getScaledDImensions()"
39                 << "\n\tparams.scale       : " << params.scale
40                 << "\n\tparams.width       : " << params.width
41                 << "\n\tparams.height      : " << params.height
42                 << "\n\tkeepLyXAspectRatio : " << params.keepLyXAspectRatio
43                 << std::endl;
44         if (params.width == 0 && params.height == 0 && params.scale == 0) {
45                 // original size or scale/custom without any input
46                 lyxerr[Debug::GRAPHICS]
47                         << "\treturn with the original values!\n";
48                 return std::make_pair(getWidth(), getHeight());
49         }
50         
51         typedef unsigned int dimension;
52         dimension width  = 0;
53         dimension height = 0;
54         if (params.scale != 0) {
55                 // GraphicsParams::Scale 
56                 width  = dimension(double(getWidth())  * params.scale / 100.0);
57                 height = dimension(getHeight() * params.scale / 100.0);
58                 return std::make_pair(width, height);
59         } 
60         // GraphicsParams::WH
61         width  = (params.width > 0) ? params.width : getWidth();
62         height = (params.height > 0) ? params.height : getHeight(); 
63         if (!params.keepLyXAspectRatio)
64                 return std::make_pair(width, height);
65
66         // calculate aspect ratio
67         float const rw  = getWidth();
68         float const rh = getHeight();
69         // there must be a width for the division
70         float const ratio = (rw > 0.001) ? rh/rw : 1.0;
71         lyxerr[Debug::GRAPHICS]
72                 << "\tValue of LyXAspectRatio: " << ratio << std::endl;
73         // there are now four different cases
74         // w=0 & h=0 -> see above, no more possible at this place
75         // w>0 & h=0 -> calculate h
76         // w=0 & h>0 -> calculate w
77         // w>0 & h>0 -> the greatest difference to the original
78         //              value becomes the same
79         if (params.width > 0 && params.height > 0) {
80                 // both widths are given and keepAspectRatio, too
81                 int const diff_width = abs(int(getWidth() - params.width));
82                 int const diff_height= abs(int(getHeight() - params.height));
83                 if (diff_width > diff_height)
84                         height = int(ratio * params.width);
85                 else
86                         width = int(ratio * params.height);
87                 return std::make_pair(width, height);
88         }
89         if (params.width > 0) {
90                 width = params.width;
91                 height = int(ratio * params.width);
92                 return std::make_pair(width, height);
93         }
94         if (params.height > 0) {
95                 height = params.height;
96                 width = int(ratio * params.height);
97                 return std::make_pair(width, height);
98         }
99         // all other cases ... kind of paranoia :-)
100         return std::make_pair(getWidth(), getHeight());
101 }
102
103 } // namespace grfx
104