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"
19 #include "support/filetools.h"
20 #include "support/lstrings.h"
21 #include "support/LAssert.h"
25 GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
31 filename = iparams.filename;
32 if (!filepath.empty()) {
33 filename = MakeAbsPath(filename, filepath);
39 // Get the original Bounding Box from the file
40 string const tmp = readBB_from_PSFile(filename);
41 lyxerr[Debug::GRAPHICS] << "BB_from_File: " << tmp << std::endl;
43 int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
44 int const bb_orig_yb = strToInt(token(tmp, ' ', 1));
52 bb.xl = std::max(0, bb.xl);
53 bb.xr = std::max(0, bb.xr);
54 bb.yb = std::max(0, bb.yb);
55 bb.yt = std::max(0, bb.yt);
58 int const width = bb.xr - bb.xl;
59 int const height = bb.yt - bb.yb;
61 if (width < 0 || height < 0) {
70 angle = int(iparams.rotateAngle);
72 if (iparams.display == InsetGraphicsParams::DEFAULT) {
74 if (lyxrc.display_graphics == "mono")
76 else if (lyxrc.display_graphics == "gray")
78 else if (lyxrc.display_graphics == "color")
83 } else if (iparams.display == InsetGraphicsParams::NONE) {
86 } else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
89 } else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
92 } else if (iparams.display == InsetGraphicsParams::COLOR) {
96 // Override the above if we're not using a gui
101 if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
102 scale = iparams.lyxscale;
104 } else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
105 if (!iparams.lyxwidth.zero())
106 width = iparams.lyxwidth.inPixels(1, 1);
107 if (!iparams.lyxheight.zero())
108 height = iparams.lyxheight.inPixels(1, 1);
110 // inPixels returns a value scaled by lyxrc.zoom.
111 // We want, therefore, to undo this.
112 double const scaling_factor = 100.0 / double(lyxrc.zoom);
113 width = uint(scaling_factor * width);
114 height = uint(scaling_factor * height);
119 bool operator==(GParams const & a, GParams const & b)
121 return (a.filename == b.filename &&
122 a.display == b.display &&
124 a.width == b.width &&
125 a.height == b.height &&
126 a.scale == b.scale &&
131 bool operator!=(GParams const & a, GParams const & b)
137 BoundingBox::BoundingBox()
138 : xl(0), yb(0), xr(0), yt(0)
142 BoundingBox::BoundingBox(string const & bb)
143 : xl(0), yb(0), xr(0), yt(0)
148 std::istringstream is(bb.c_str());
150 is >> a >> b >> c >> d;
152 // inBP returns the length in Postscript points.
153 // Note further that there are 72 Postscript pixels per inch.
154 int const xl_tmp = LyXLength(a).inBP();
155 int const yb_tmp = LyXLength(b).inBP();
156 int const xr_tmp = LyXLength(c).inBP();
157 int const yt_tmp = LyXLength(d).inBP();
159 if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
169 bool BoundingBox::empty() const
171 return (!xl && !yb && !xr && !yt);
175 bool operator==(BoundingBox const & a, BoundingBox const & b)
177 return (a.xl == b.xl &&
184 bool operator!=(BoundingBox const & a, BoundingBox const & b)