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