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