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/lstrings.h"
22 GParams::GParams(InsetGraphicsParams const & iparams)
23 : filename(iparams.filename),
33 angle = int(iparams.rotateAngle);
35 if (iparams.display == InsetGraphicsParams::DEFAULT) {
37 if (lyxrc.display_graphics == "mono")
39 else if (lyxrc.display_graphics == "gray")
41 else if (lyxrc.display_graphics == "color")
46 } else if (iparams.display == InsetGraphicsParams::NONE) {
49 } else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
52 } else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
55 } else if (iparams.display == InsetGraphicsParams::COLOR) {
59 // Override the above if we're not using a gui
64 if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
65 scale = iparams.lyxscale;
67 } else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
68 if (!iparams.lyxwidth.zero())
69 width = iparams.lyxwidth.inPixels(1, 1);
70 if (!iparams.lyxheight.zero())
71 height = iparams.lyxheight.inPixels(1, 1);
73 // inPixels returns a value scaled by lyxrc.zoom.
74 // We want, therefore, to undo this.
75 double const scaling_factor = 100.0 / double(lyxrc.zoom);
76 width = uint(scaling_factor * width);
77 height = uint(scaling_factor * height);
82 bool operator==(GParams const & a, GParams const & b)
84 return (a.filename == b.filename &&
85 a.display == b.display &&
88 a.height == b.height &&
94 bool operator!=(GParams const & a, GParams const & b)
100 BoundingBox::BoundingBox()
101 : xl(0), yb(0), xr(0), yt(0)
105 BoundingBox::BoundingBox(string const & bb)
111 string tmp2 = split(bb, tmp1, ' ');
112 if (!isValidLength(tmp1))
115 LyXLength const length_xl(tmp1);
117 tmp2 = split(tmp2, tmp1, ' ');
118 if (!isValidLength(tmp1))
121 LyXLength const length_yb(tmp1);
123 tmp2 = split(tmp2, tmp1, ' ');
124 if (!isValidLength(tmp1) || !isValidLength(tmp2))
127 LyXLength const length_xr(tmp1);
128 LyXLength const length_yt(tmp2);
130 // inPixels returns the length in inches, scaled by
131 // lyxrc.dpi and lyxrc.zoom.
132 // We want, therefore, to undo all this lyxrc nonsense because we
133 // want the bounding box in Postscript pixels.
134 // Note further that there are 72 Postscript pixels per inch.
135 double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
136 xl = uint(scaling_factor * length_xl.inPixels(1, 1));
137 yb = uint(scaling_factor * length_yb.inPixels(1, 1));
138 xr = uint(scaling_factor * length_xr.inPixels(1, 1));
139 yt = uint(scaling_factor * length_yt.inPixels(1, 1));
141 if (xr <= xl || yt <= yb) {
151 bool BoundingBox::empty() const
153 return (!xl && !yb && !xr && !yt);
157 bool operator==(BoundingBox const & a, BoundingBox const & b)
159 return (a.xl == b.xl &&
166 bool operator!=(BoundingBox const & a, BoundingBox const & b)