2002-02-27 09:59:52 +00:00
|
|
|
/*
|
|
|
|
* \file GraphicsParams.C
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "GraphicsParams.h"
|
|
|
|
#include "insets/insetgraphicsParams.h"
|
|
|
|
#include "lyxrc.h"
|
2002-03-22 16:37:52 +00:00
|
|
|
#include "support/filetools.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-03-22 16:37:52 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
namespace grfx {
|
|
|
|
|
2002-03-22 16:37:52 +00:00
|
|
|
GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
|
|
|
|
: width(0),
|
2002-02-27 09:59:52 +00:00
|
|
|
height(0),
|
|
|
|
scale(0),
|
|
|
|
angle(0)
|
|
|
|
{
|
2002-03-22 16:37:52 +00:00
|
|
|
filename = iparams.filename;
|
|
|
|
if (!filepath.empty()) {
|
|
|
|
filename = MakeAbsPath(filename, filepath);
|
|
|
|
}
|
2002-03-26 12:14:23 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
if (iparams.clip)
|
|
|
|
bb = iparams.bb;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
if (iparams.rotate)
|
|
|
|
angle = int(iparams.rotateAngle);
|
|
|
|
|
|
|
|
if (iparams.display == InsetGraphicsParams::DEFAULT) {
|
|
|
|
|
|
|
|
if (lyxrc.display_graphics == "mono")
|
|
|
|
display = MONOCHROME;
|
|
|
|
else if (lyxrc.display_graphics == "gray")
|
|
|
|
display = GRAYSCALE;
|
|
|
|
else if (lyxrc.display_graphics == "color")
|
|
|
|
display = COLOR;
|
|
|
|
else
|
|
|
|
display = NONE;
|
|
|
|
|
|
|
|
} else if (iparams.display == InsetGraphicsParams::NONE) {
|
|
|
|
display = NONE;
|
|
|
|
|
|
|
|
} else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
|
|
|
|
display = MONOCHROME;
|
|
|
|
|
|
|
|
} else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
|
|
|
|
display = GRAYSCALE;
|
|
|
|
|
|
|
|
} else if (iparams.display == InsetGraphicsParams::COLOR) {
|
|
|
|
display = COLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override the above if we're not using a gui
|
|
|
|
if (!lyxrc.use_gui) {
|
|
|
|
display = NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
|
|
|
|
scale = iparams.lyxscale;
|
|
|
|
|
|
|
|
} else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
|
|
|
|
if (!iparams.lyxwidth.zero())
|
|
|
|
width = iparams.lyxwidth.inPixels(1, 1);
|
|
|
|
if (!iparams.lyxheight.zero())
|
|
|
|
height = iparams.lyxheight.inPixels(1, 1);
|
|
|
|
|
|
|
|
// inPixels returns a value scaled by lyxrc.zoom.
|
|
|
|
// We want, therefore, to undo this.
|
|
|
|
double const scaling_factor = 100.0 / double(lyxrc.zoom);
|
2002-02-28 11:50:42 +00:00
|
|
|
width = uint(scaling_factor * width);
|
|
|
|
height = uint(scaling_factor * height);
|
2002-02-27 09:59:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(GParams const & a, GParams const & b)
|
|
|
|
{
|
2002-04-04 10:47:47 +00:00
|
|
|
return (a.filename == b.filename &&
|
|
|
|
a.display == b.display &&
|
|
|
|
a.bb == b.bb &&
|
|
|
|
a.width == b.width &&
|
|
|
|
a.height == b.height &&
|
|
|
|
a.scale == b.scale &&
|
|
|
|
a.angle == b.angle);
|
2002-02-27 09:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(GParams const & a, GParams const & b)
|
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BoundingBox::BoundingBox()
|
|
|
|
: xl(0), yb(0), xr(0), yt(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
BoundingBox::BoundingBox(string const & bb)
|
2002-04-04 10:24:33 +00:00
|
|
|
: xl(0), yb(0), xr(0), yt(0)
|
2002-02-27 09:59:52 +00:00
|
|
|
{
|
|
|
|
if (bb.empty())
|
|
|
|
return;
|
|
|
|
|
2002-04-04 14:49:54 +00:00
|
|
|
std::istringstream is(bb.c_str());
|
|
|
|
string a, b, c, d;
|
|
|
|
is >> a >> b >> c >> d;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-04-04 14:49:54 +00:00
|
|
|
// Don't need to check that the strings are valid LyXLength's
|
|
|
|
// because this is done in the LyXLength c-tor.
|
|
|
|
LyXLength const length_xl(a);
|
|
|
|
LyXLength const length_yb(b);
|
|
|
|
LyXLength const length_xr(c);
|
|
|
|
LyXLength const length_yt(d);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
// inPixels returns the length in inches, scaled by
|
|
|
|
// lyxrc.dpi and lyxrc.zoom.
|
|
|
|
// We want, therefore, to undo all this lyxrc nonsense because we
|
|
|
|
// want the bounding box in Postscript pixels.
|
|
|
|
// Note further that there are 72 Postscript pixels per inch.
|
|
|
|
double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
|
2002-04-04 10:24:33 +00:00
|
|
|
unsigned int const xl_tmp =
|
|
|
|
uint(scaling_factor * length_xl.inPixels(1, 1));
|
|
|
|
unsigned int const yb_tmp =
|
|
|
|
uint(scaling_factor * length_yb.inPixels(1, 1));
|
|
|
|
unsigned int const xr_tmp =
|
|
|
|
uint(scaling_factor * length_xr.inPixels(1, 1));
|
|
|
|
unsigned int const yt_tmp =
|
|
|
|
uint(scaling_factor * length_yt.inPixels(1, 1));
|
|
|
|
|
2002-04-04 14:49:54 +00:00
|
|
|
if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
|
2002-02-27 09:59:52 +00:00
|
|
|
return;
|
2002-04-04 10:24:33 +00:00
|
|
|
|
|
|
|
xl = xl_tmp;
|
|
|
|
yb = yb_tmp;
|
|
|
|
xr = xr_tmp;
|
|
|
|
yt = yt_tmp;
|
2002-02-27 09:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
bool BoundingBox::empty() const
|
2002-02-27 09:59:52 +00:00
|
|
|
{
|
|
|
|
return (!xl && !yb && !xr && !yt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(BoundingBox const & a, BoundingBox const & b)
|
|
|
|
{
|
|
|
|
return (a.xl == b.xl &&
|
|
|
|
a.yb == b.yb &&
|
|
|
|
a.xr == b.xr &&
|
|
|
|
a.yt == b.yt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(BoundingBox const & a, BoundingBox const & b)
|
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace grfx
|