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);
38 // Get the original Bounding Box from the file
39 string const tmp = readBB_from_PSFile(filename);
41 int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
42 int const bb_orig_yb = strToInt(token(tmp, ' ', 1));
50 bb.xl = std::max(0, bb.xl);
51 bb.xr = std::max(0, bb.xr);
52 bb.yb = std::max(0, bb.yb);
53 bb.yt = std::max(0, bb.yt);
56 int const width = bb.xr - bb.xl;
57 int const height = bb.yt - bb.yb;
59 if (width < 0 || height < 0) {
68 angle = int(iparams.rotateAngle);
70 if (iparams.display == InsetGraphicsParams::DEFAULT) {
72 if (lyxrc.display_graphics == "mono")
74 else if (lyxrc.display_graphics == "gray")
76 else if (lyxrc.display_graphics == "color")
81 } else if (iparams.display == InsetGraphicsParams::NONE) {
84 } else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
87 } else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
90 } else if (iparams.display == InsetGraphicsParams::COLOR) {
94 // Override the above if we're not using a gui
99 if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
100 scale = iparams.lyxscale;
102 } else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
103 if (!iparams.lyxwidth.zero())
104 width = iparams.lyxwidth.inPixels(1, 1);
105 if (!iparams.lyxheight.zero())
106 height = iparams.lyxheight.inPixels(1, 1);
108 // inPixels returns a value scaled by lyxrc.zoom.
109 // We want, therefore, to undo this.
110 double const scaling_factor = 100.0 / double(lyxrc.zoom);
111 width = uint(scaling_factor * width);
112 height = uint(scaling_factor * height);
117 bool operator==(GParams const & a, GParams const & b)
119 return (a.filename == b.filename &&
120 a.display == b.display &&
122 a.width == b.width &&
123 a.height == b.height &&
124 a.scale == b.scale &&
129 bool operator!=(GParams const & a, GParams const & b)
135 BoundingBox::BoundingBox()
136 : xl(0), yb(0), xr(0), yt(0)
140 BoundingBox::BoundingBox(string const & bb)
141 : xl(0), yb(0), xr(0), yt(0)
146 std::istringstream is(bb.c_str());
148 is >> a >> b >> c >> d;
150 // Don't need to check that the strings are valid LyXLength's
151 // because this is done in the LyXLength c-tor.
152 LyXLength const length_xl(a);
153 LyXLength const length_yb(b);
154 LyXLength const length_xr(c);
155 LyXLength const length_yt(d);
157 // inPixels returns the length in inches, scaled by
158 // lyxrc.dpi and lyxrc.zoom.
159 // We want, therefore, to undo all this lyxrc nonsense because we
160 // want the bounding box in Postscript pixels.
161 // Note further that there are 72 Postscript pixels per inch.
162 double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
163 int const xl_tmp = int(scaling_factor * length_xl.inPixels(1, 1));
164 int const yb_tmp = int(scaling_factor * length_yb.inPixels(1, 1));
165 int const xr_tmp = int(scaling_factor * length_xr.inPixels(1, 1));
166 int const yt_tmp = int(scaling_factor * length_yt.inPixels(1, 1));
168 if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
178 bool BoundingBox::empty() const
180 return (!xl && !yb && !xr && !yt);
184 bool operator==(BoundingBox const & a, BoundingBox const & b)
186 return (a.xl == b.xl &&
193 bool operator!=(BoundingBox const & a, BoundingBox const & b)