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)
112 : xl(0), yb(0), xr(0), yt(0)
117 std::istringstream is(bb.c_str());
119 is >> a >> b >> c >> d;
121 // Don't need to check that the strings are valid LyXLength's
122 // because this is done in the LyXLength c-tor.
123 LyXLength const length_xl(a);
124 LyXLength const length_yb(b);
125 LyXLength const length_xr(c);
126 LyXLength const length_yt(d);
128 // inPixels returns the length in inches, scaled by
129 // lyxrc.dpi and lyxrc.zoom.
130 // We want, therefore, to undo all this lyxrc nonsense because we
131 // want the bounding box in Postscript pixels.
132 // Note further that there are 72 Postscript pixels per inch.
133 double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
134 unsigned int const xl_tmp =
135 uint(scaling_factor * length_xl.inPixels(1, 1));
136 unsigned int const yb_tmp =
137 uint(scaling_factor * length_yb.inPixels(1, 1));
138 unsigned int const xr_tmp =
139 uint(scaling_factor * length_xr.inPixels(1, 1));
140 unsigned int const yt_tmp =
141 uint(scaling_factor * length_yt.inPixels(1, 1));
143 if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
153 bool BoundingBox::empty() const
155 return (!xl && !yb && !xr && !yt);
159 bool operator==(BoundingBox const & a, BoundingBox const & b)
161 return (a.xl == b.xl &&
168 bool operator!=(BoundingBox const & a, BoundingBox const & b)