2 * \file GraphicsParams.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming <a.leeming@ic.ac.uk>
12 #pragma implementation
15 #include "GraphicsParams.h"
16 #include "insets/insetgraphicsParams.h"
18 #include "support/filetools.h"
19 #include "support/lstrings.h"
20 #include "support/LAssert.h"
24 GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
30 filename = iparams.filename;
31 if (!filepath.empty()) {
32 filename = MakeAbsPath(filename, filepath);
39 angle = int(iparams.rotateAngle);
41 if (iparams.display == InsetGraphicsParams::DEFAULT) {
43 if (lyxrc.display_graphics == "mono")
45 else if (lyxrc.display_graphics == "gray")
47 else if (lyxrc.display_graphics == "color")
52 } else if (iparams.display == InsetGraphicsParams::NONE) {
55 } else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
58 } else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
61 } else if (iparams.display == InsetGraphicsParams::COLOR) {
65 // Override the above if we're not using a gui
70 if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
71 scale = iparams.lyxscale;
73 } else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
74 if (!iparams.lyxwidth.zero())
75 width = iparams.lyxwidth.inPixels(1, 1);
76 if (!iparams.lyxheight.zero())
77 height = iparams.lyxheight.inPixels(1, 1);
79 // inPixels returns a value scaled by lyxrc.zoom.
80 // We want, therefore, to undo this.
81 double const scaling_factor = 100.0 / double(lyxrc.zoom);
82 width = uint(scaling_factor * width);
83 height = uint(scaling_factor * height);
88 bool operator==(GParams const & a, GParams const & b)
90 return (a.filename == b.filename &&
91 a.display == b.display &&
94 a.height == b.height &&
100 bool operator!=(GParams const & a, GParams const & b)
106 BoundingBox::BoundingBox()
107 : xl(0), yb(0), xr(0), yt(0)
111 BoundingBox::BoundingBox(string const & bb)
117 string tmp2 = split(bb, tmp1, ' ');
118 if (!isValidLength(tmp1))
121 LyXLength const length_xl(tmp1);
123 tmp2 = split(tmp2, tmp1, ' ');
124 if (!isValidLength(tmp1))
127 LyXLength const length_yb(tmp1);
129 tmp2 = split(tmp2, tmp1, ' ');
130 if (!isValidLength(tmp1) || !isValidLength(tmp2))
133 LyXLength const length_xr(tmp1);
134 LyXLength const length_yt(tmp2);
136 // inPixels returns the length in inches, scaled by
137 // lyxrc.dpi and lyxrc.zoom.
138 // We want, therefore, to undo all this lyxrc nonsense because we
139 // want the bounding box in Postscript pixels.
140 // Note further that there are 72 Postscript pixels per inch.
141 double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
142 xl = uint(scaling_factor * length_xl.inPixels(1, 1));
143 yb = uint(scaling_factor * length_yb.inPixels(1, 1));
144 xr = uint(scaling_factor * length_xr.inPixels(1, 1));
145 yt = uint(scaling_factor * length_yt.inPixels(1, 1));
147 if (xr <= xl || yt <= yb) {
157 bool BoundingBox::empty() const
159 return (!xl && !yb && !xr && !yt);
163 bool operator==(BoundingBox const & a, BoundingBox const & b)
165 return (a.xl == b.xl &&
172 bool operator!=(BoundingBox const & a, BoundingBox const & b)