]> git.lyx.org Git - features.git/blob - src/graphics/GraphicsParams.C
Re-add the RasterImage template.
[features.git] / src / graphics / GraphicsParams.C
1 /**
2  * \file GraphicsParams.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GraphicsParams.h"
14
15 #include "lyxlength.h"
16
17 #include "support/std_sstream.h"
18
19 using std::abs;
20
21
22 namespace lyx {
23 namespace graphics {
24
25 string const BoundingBox::asString() const
26 {
27         std::ostringstream os;
28         os << xl << ' ' << yb << ' ' << xr << ' ' << yt;
29         return os.str();
30 }
31
32
33 Params::Params()
34         : display(ColorDisplay),
35           scale(100),
36           angle(0)
37 {}
38
39
40 bool operator==(Params const & a, Params const & b)
41 {
42         return (a.filename == b.filename &&
43                 a.display == b.display &&
44                 a.bb == b.bb &&
45                 a.scale == b.scale &&
46                 a.angle == b.angle);
47 }
48
49
50 bool operator!=(Params const & a, Params const & b)
51 {
52         return !(a == b);
53 }
54
55
56 BoundingBox::BoundingBox()
57         : xl(0), yb(0), xr(0), yt(0)
58 {}
59
60
61 BoundingBox::BoundingBox(string const & bb)
62         : xl(0), yb(0), xr(0), yt(0)
63 {
64         if (bb.empty())
65                 return;
66
67         std::istringstream is(bb.c_str());
68         string a, b, c, d;
69         is >> a >> b >> c >> d;
70
71         // inBP returns the length in Postscript points.
72         // Note further that there are 72 Postscript pixels per inch.
73         unsigned int const xl_tmp = abs(LyXLength(a).inBP());
74         unsigned int const yb_tmp = abs(LyXLength(b).inBP());
75         unsigned int const xr_tmp = abs(LyXLength(c).inBP());
76         unsigned int const yt_tmp = abs(LyXLength(d).inBP());
77
78         if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
79                 return;
80
81         xl = xl_tmp;
82         yb = yb_tmp;
83         xr = xr_tmp;
84         yt = yt_tmp;
85 }
86
87
88 bool BoundingBox::empty() const
89 {
90         return (!xl && !yb && !xr && !yt);
91 }
92
93
94 bool operator==(BoundingBox const & a, BoundingBox const & b)
95 {
96         return (a.xl == b.xl &&
97                 a.yb == b.yb &&
98                 a.xr == b.xr &&
99                 a.yt == b.yt);
100 }
101
102
103 bool operator!=(BoundingBox const & a, BoundingBox const & b)
104 {
105         return !(a == b);
106 }
107
108 } // namespace graphics
109 } // namespace lyx