]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsParams.C
This file is part of LyX, the document processor.
[lyx.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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <cstdlib>
18
19 #include "GraphicsParams.h"
20 #include "Lsstream.h"
21 #include "lyxlength.h"
22
23 using std::abs;
24
25 namespace grfx {
26
27 Params::Params()
28         : display(ColorDisplay),
29           scale(100),
30           angle(0)
31 {}
32
33
34 bool operator==(Params const & a, Params const & b)
35 {
36         return (a.filename == b.filename &&
37                 a.display == b.display &&
38                 a.bb == b.bb &&
39                 a.scale == b.scale &&
40                 a.angle == b.angle);
41 }
42
43
44 bool operator!=(Params const & a, Params const & b)
45 {
46         return !(a == b);
47 }
48
49
50 BoundingBox::BoundingBox()
51         : xl(0), yb(0), xr(0), yt(0)
52 {}
53
54
55 BoundingBox::BoundingBox(string const & bb)
56         : xl(0), yb(0), xr(0), yt(0)
57 {
58         if (bb.empty())
59                 return;
60
61         std::istringstream is(bb.c_str());
62         string a, b, c, d;
63         is >> a >> b >> c >> d;
64
65         // inBP returns the length in Postscript points.
66         // Note further that there are 72 Postscript pixels per inch.
67         unsigned int const xl_tmp = abs(LyXLength(a).inBP());
68         unsigned int const yb_tmp = abs(LyXLength(b).inBP());
69         unsigned int const xr_tmp = abs(LyXLength(c).inBP());
70         unsigned int const yt_tmp = abs(LyXLength(d).inBP());
71
72         if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
73                 return;
74
75         xl = xl_tmp;
76         yb = yb_tmp;
77         xr = xr_tmp;
78         yt = yt_tmp;
79 }
80
81
82 bool BoundingBox::empty() const
83 {
84         return (!xl && !yb && !xr && !yt);
85 }
86
87
88 bool operator==(BoundingBox const & a, BoundingBox const & b)
89 {
90         return (a.xl == b.xl &&
91                 a.yb == b.yb &&
92                 a.xr == b.xr &&
93                 a.yt == b.yt);
94 }
95
96
97 bool operator!=(BoundingBox const & a, BoundingBox const & b)
98 {
99         return !(a == b);
100 }
101
102 } // namespace grfx