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