]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsParams.C
small unimportant cleanups
[lyx.git] / src / graphics / GraphicsParams.C
1 /*
2  * \file GraphicsParams.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Angus Leeming <leeming@lyx.org>
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <cstdlib>
16
17 #include "GraphicsParams.h"
18 #include "Lsstream.h"
19 #include "lyxlength.h"
20
21 using std::abs;
22
23 namespace grfx {
24
25 Params::Params()
26         : display(ColorDisplay),
27           width(0),
28           height(0),
29           scale(0),
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.width    == b.width &&
40                 a.height   == b.height &&
41                 a.scale    == b.scale &&
42                 a.angle    == b.angle);
43 }
44
45
46 bool operator!=(Params const & a, Params const & b)
47 {
48         return !(a == b);
49 }
50
51
52 BoundingBox::BoundingBox()
53         : xl(0), yb(0), xr(0), yt(0)
54 {}
55
56
57 BoundingBox::BoundingBox(string const & bb)
58         : xl(0), yb(0), xr(0), yt(0)
59 {
60         if (bb.empty())
61                 return;
62
63         std::istringstream is(bb.c_str());
64         string a, b, c, d;
65         is >> a >> b >> c >> d;
66
67         // inBP returns the length in Postscript points.
68         // Note further that there are 72 Postscript pixels per inch.
69         int const xl_tmp = abs(LyXLength(a).inBP());
70         int const yb_tmp = abs(LyXLength(b).inBP());
71         int const xr_tmp = abs(LyXLength(c).inBP());
72         int const yt_tmp = abs(LyXLength(d).inBP());
73
74         if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
75                 return;
76
77         xl = xl_tmp;
78         yb = yb_tmp;
79         xr = xr_tmp;
80         yt = yt_tmp;
81 }
82
83
84 bool BoundingBox::empty() const
85 {
86         return (!xl && !yb && !xr && !yt);
87 }
88
89
90 bool operator==(BoundingBox const & a, BoundingBox const & b)
91 {
92         return (a.xl == b.xl &&
93                 a.yb == b.yb &&
94                 a.xr == b.xr &&
95                 a.yt == b.yt);
96 }
97
98
99 bool operator!=(BoundingBox const & a, BoundingBox const & b)
100 {
101         return !(a == b);
102 }
103
104 } // namespace grfx