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 bb_orig_str = readBB_from_PSFile(filename);
40 if (!bb_orig_str.empty()) {
42 bb_orig.xl = strToInt(token(bb_orig_str, ' ', 0));
43 bb_orig.yb = strToInt(token(bb_orig_str, ' ', 1));
44 bb_orig.xr = strToInt(token(bb_orig_str, ' ', 2));
45 bb_orig.yt = strToInt(token(bb_orig_str, ' ', 3));
54 int const width = bb.xr - bb.xl;
55 int const height = bb.yt - bb.yb;
57 if (width < 0 || height < 0) {
66 angle = int(iparams.rotateAngle);
68 if (iparams.display == InsetGraphicsParams::DEFAULT) {
70 if (lyxrc.display_graphics == "mono")
72 else if (lyxrc.display_graphics == "gray")
74 else if (lyxrc.display_graphics == "color")
79 } else if (iparams.display == InsetGraphicsParams::NONE) {
82 } else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
85 } else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
88 } else if (iparams.display == InsetGraphicsParams::COLOR) {
92 // Override the above if we're not using a gui
97 if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
98 scale = iparams.lyxscale;
100 } else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
101 if (!iparams.lyxwidth.zero())
102 width = iparams.lyxwidth.inPixels(1, 1);
103 if (!iparams.lyxheight.zero())
104 height = iparams.lyxheight.inPixels(1, 1);
106 // inPixels returns a value scaled by lyxrc.zoom.
107 // We want, therefore, to undo this.
108 double const scaling_factor = 100.0 / double(lyxrc.zoom);
109 width = uint(scaling_factor * width);
110 height = uint(scaling_factor * height);
115 bool operator==(GParams const & a, GParams const & b)
117 return (a.filename == b.filename &&
118 a.display == b.display &&
120 a.width == b.width &&
121 a.height == b.height &&
122 a.scale == b.scale &&
127 bool operator!=(GParams const & a, GParams const & b)
133 BoundingBox::BoundingBox()
134 : xl(0), yb(0), xr(0), yt(0)
138 BoundingBox::BoundingBox(string const & bb)
139 : xl(0), yb(0), xr(0), yt(0)
144 std::istringstream is(bb.c_str());
146 is >> a >> b >> c >> d;
148 // Don't need to check that the strings are valid LyXLength's
149 // because this is done in the LyXLength c-tor.
150 LyXLength const length_xl(a);
151 LyXLength const length_yb(b);
152 LyXLength const length_xr(c);
153 LyXLength const length_yt(d);
155 // inPixels returns the length in inches, scaled by
156 // lyxrc.dpi and lyxrc.zoom.
157 // We want, therefore, to undo all this lyxrc nonsense because we
158 // want the bounding box in Postscript pixels.
159 // Note further that there are 72 Postscript pixels per inch.
160 double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
161 int const xl_tmp = int(scaling_factor * length_xl.inPixels(1, 1));
162 int const yb_tmp = int(scaling_factor * length_yb.inPixels(1, 1));
163 int const xr_tmp = int(scaling_factor * length_xr.inPixels(1, 1));
164 int const yt_tmp = int(scaling_factor * length_yt.inPixels(1, 1));
166 if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
176 bool BoundingBox::empty() const
178 return (!xl && !yb && !xr && !yt);
182 bool operator==(BoundingBox const & a, BoundingBox const & b)
184 return (a.xl == b.xl &&
191 bool operator!=(BoundingBox const & a, BoundingBox const & b)