]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsParams.cpp
Tweaks.
[lyx.git] / src / graphics / GraphicsParams.cpp
1 /**
2  * \file GraphicsParams.cpp
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 "Length.h"
16
17 #include <sstream>
18
19 using namespace std;
20
21 namespace lyx {
22 namespace graphics {
23
24 Params::Params()
25         : display(ColorDisplay),
26           scale(100),
27           angle(0),
28           icon("")
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                 a.icon == b.icon);
40 }
41
42
43 bool operator!=(Params const & a, Params const & b)
44 {
45         return !(a == b);
46 }
47
48
49 ostream & operator<<(ostream & os, BoundingBox const & bb)
50 {
51         os << bb.xl << ' ' << bb.yb << ' ' << bb.xr << ' ' << bb.yt;
52         return os;
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         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(Length(a).inBP());
74         unsigned int const yb_tmp = abs(Length(b).inBP());
75         unsigned int const xr_tmp = abs(Length(c).inBP());
76         unsigned int const yt_tmp = abs(Length(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