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