]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsParams.cpp
Merge branch 'master' into biblatex2
[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 <cstdlib>
16 #include <sstream>
17
18 using namespace std;
19
20 namespace lyx {
21 namespace graphics {
22
23 Params::Params()
24         : display(true),
25           scale(100),
26           pixel_ratio(1.0),
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.pixel_ratio == b.pixel_ratio &&
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 ostream & operator<<(ostream & os, BoundingBox const & bb)
49 {
50         os << bb.xl.asString() << ' ' << bb.yb.asString() << ' '
51            << bb.xr.asString() << ' ' << bb.yt.asString();
52         return os;
53 }
54
55
56 BoundingBox::BoundingBox()
57 {}
58
59
60 BoundingBox::BoundingBox(string const & bb)
61 {
62         if (bb.empty())
63                 return;
64
65         istringstream is(bb.c_str());
66         string a, b, c, d;
67         is >> a >> b >> c >> d;
68
69         Length xl_tmp = Length(a);
70         if (xl_tmp.value() < 0)
71                 xl_tmp = Length(-xl_tmp.value(), xl_tmp.unit());
72         Length yb_tmp = Length(b);
73         if (yb_tmp.value() < 0)
74                 yb_tmp = Length(-yb_tmp.value(), yb_tmp.unit());
75         Length xr_tmp = Length(c);
76         if (xr_tmp.value() < 0)
77                 xr_tmp = Length(-xr_tmp.value(), xr_tmp.unit());
78         Length yt_tmp = Length(d);
79         if (yt_tmp.value() < 0)
80                 yt_tmp = Length(-yt_tmp.value(), yt_tmp.unit());
81
82         // inBP returns the length in Postscript points.
83         // Note further that there are 72 Postscript pixels per inch.
84         if (xr_tmp.inBP() <= xl_tmp.inBP() || yt_tmp.inBP() <= yb_tmp.inBP())
85                 return;
86
87         xl = xl_tmp;
88         yb = yb_tmp;
89         xr = xr_tmp;
90         yt = yt_tmp;
91 }
92
93
94 bool BoundingBox::empty() const
95 {
96         return xl.zero() && yb.zero() && xr.zero() && yt.zero();
97 }
98
99
100 bool operator==(BoundingBox const & a, BoundingBox const & b)
101 {
102         return (a.xl == b.xl &&
103                 a.yb == b.yb &&
104                 a.xr == b.xr &&
105                 a.yt == b.yt);
106 }
107
108
109 bool operator!=(BoundingBox const & a, BoundingBox const & b)
110 {
111         return !(a == b);
112 }
113
114 } // namespace graphics
115 } // namespace lyx