2002-09-25 14:26:13 +00:00
|
|
|
/**
|
|
|
|
* \file insetgraphicsParams.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-01-29 09:26:24 +00:00
|
|
|
* \author Baruch Even
|
2002-09-12 08:44:23 +00:00
|
|
|
* \author Herbert Voss
|
2002-01-29 09:26:24 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
#include <config.h>
|
2000-08-08 09:18:39 +00:00
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "insetgraphicsParams.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
#include "graphics/GraphicsParams.h"
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "support/filetools.h"
|
2001-07-28 12:24:16 +00:00
|
|
|
#include "support/lyxlib.h"
|
2001-07-30 10:50:37 +00:00
|
|
|
#include "support/LOstream.h"
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-05-28 11:50:04 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-07-26 23:04:39 +00:00
|
|
|
#include "support/translator.h"
|
2002-05-28 11:50:04 +00:00
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "debug.h"
|
2002-07-21 21:21:06 +00:00
|
|
|
#include "lyxlex.h"
|
2003-03-31 02:59:34 +00:00
|
|
|
#include "frontends/lyx_gui.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
2003-07-26 23:04:39 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
|
|
|
/// The translator between the DisplayType and the corresponding lyx string.
|
|
|
|
extern Translator<DisplayType, string> displayTranslator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
InsetGraphicsParams::InsetGraphicsParams()
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
init();
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp)
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// I decided to skip the initialization since the copy will overwrite
|
|
|
|
// everything anyway.
|
|
|
|
// init();
|
|
|
|
copy(igp);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
InsetGraphicsParams &
|
|
|
|
InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// Are we assigning the object into itself?
|
|
|
|
if (this == ¶ms)
|
2003-06-03 15:10:14 +00:00
|
|
|
return *this;
|
2000-08-14 09:44:53 +00:00
|
|
|
copy(params);
|
|
|
|
return *this;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
void InsetGraphicsParams::init()
|
|
|
|
{
|
2002-09-12 08:44:23 +00:00
|
|
|
filename.erase();
|
2002-08-24 22:02:30 +00:00
|
|
|
lyxscale = 100; // lyx scaling in percentage
|
2003-07-21 21:30:57 +00:00
|
|
|
display = lyx::graphics::DefaultDisplay; // display mode; see preferences
|
2002-10-24 11:53:46 +00:00
|
|
|
scale = 100.0; // output scaling in percentage
|
2002-08-24 22:02:30 +00:00
|
|
|
width = LyXLength();
|
2002-01-29 09:26:24 +00:00
|
|
|
height = LyXLength();
|
2002-09-12 08:44:23 +00:00
|
|
|
keepAspectRatio = false; // for LaTeX output
|
2002-08-24 22:02:30 +00:00
|
|
|
draft = false; // draft mode
|
|
|
|
noUnzip = false; // unzip files
|
|
|
|
|
|
|
|
bb = string(); // bounding box
|
|
|
|
clip = false; // clip image
|
|
|
|
|
2002-09-12 08:44:23 +00:00
|
|
|
rotateAngle = 0.0; // angle of rotation in degrees
|
|
|
|
rotateOrigin.erase(); // Origin of rotation
|
2002-08-24 22:02:30 +00:00
|
|
|
subcaption = false; // subfigure
|
2002-09-12 08:44:23 +00:00
|
|
|
subcaptionText.erase(); // subfigure caption
|
|
|
|
special.erase(); // additional userdefined stuff
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
filename = igp.filename;
|
2002-08-24 22:02:30 +00:00
|
|
|
lyxscale = igp.lyxscale;
|
2000-08-14 09:44:53 +00:00
|
|
|
display = igp.display;
|
2002-08-24 22:02:30 +00:00
|
|
|
scale = igp.scale;
|
2002-01-29 09:26:24 +00:00
|
|
|
width = igp.width;
|
|
|
|
height = igp.height;
|
2002-08-24 22:02:30 +00:00
|
|
|
keepAspectRatio = igp.keepAspectRatio;
|
|
|
|
draft = igp.draft;
|
|
|
|
noUnzip = igp.noUnzip;
|
|
|
|
|
|
|
|
bb = igp.bb;
|
|
|
|
clip = igp.clip;
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
rotateAngle = igp.rotateAngle;
|
2002-08-24 22:02:30 +00:00
|
|
|
rotateOrigin = igp.rotateOrigin;
|
|
|
|
subcaption = igp.subcaption;
|
|
|
|
subcaptionText = igp.subcaptionText;
|
2002-01-29 09:26:24 +00:00
|
|
|
special = igp.special;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
bool operator==(InsetGraphicsParams const & left,
|
2002-03-21 17:09:55 +00:00
|
|
|
InsetGraphicsParams const & right)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
if (left.filename == right.filename &&
|
2002-08-24 22:02:30 +00:00
|
|
|
left.lyxscale == right.lyxscale &&
|
2002-05-01 10:23:51 +00:00
|
|
|
left.display == right.display &&
|
2002-08-24 22:02:30 +00:00
|
|
|
left.scale == right.scale &&
|
2002-05-01 10:23:51 +00:00
|
|
|
left.width == right.width &&
|
|
|
|
left.height == right.height &&
|
2002-08-24 22:02:30 +00:00
|
|
|
left.keepAspectRatio == right.keepAspectRatio &&
|
|
|
|
left.draft == right.draft &&
|
|
|
|
left.noUnzip == right.noUnzip &&
|
|
|
|
|
|
|
|
|
|
|
|
left.bb == right.bb &&
|
|
|
|
left.clip == right.clip &&
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
float_equal(left.rotateAngle, right.rotateAngle, 0.001) &&
|
2002-05-01 10:23:51 +00:00
|
|
|
left.rotateOrigin == right.rotateOrigin &&
|
2002-08-24 22:02:30 +00:00
|
|
|
left.subcaption == right.subcaption &&
|
|
|
|
left.subcaptionText == right.subcaptionText &&
|
|
|
|
left.special == right.special
|
|
|
|
)
|
2000-08-14 09:44:53 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2001-03-28 13:16:37 +00:00
|
|
|
bool operator!=(InsetGraphicsParams const & left,
|
2002-03-21 17:09:55 +00:00
|
|
|
InsetGraphicsParams const & right)
|
2001-03-28 13:16:37 +00:00
|
|
|
{
|
2002-03-21 17:09:55 +00:00
|
|
|
return !(left == right);
|
2001-03-28 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2002-08-24 22:02:30 +00:00
|
|
|
// Do not write the default values
|
|
|
|
|
2002-03-25 11:04:34 +00:00
|
|
|
if (!filename.empty()) {
|
2003-07-22 20:42:40 +00:00
|
|
|
os << "\tfilename " << filename.outputFilename(bufpath) << '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
if (lyxscale != 100)
|
|
|
|
os << "\tlyxscale " << lyxscale << '\n';
|
2003-07-21 21:30:57 +00:00
|
|
|
if (display != lyx::graphics::DefaultDisplay)
|
|
|
|
os << "\tdisplay " << lyx::graphics::displayTranslator.find(display) << '\n';
|
2003-06-30 23:56:22 +00:00
|
|
|
if (!float_equal(scale, 0.0, 0.05)) {
|
|
|
|
if (!float_equal(scale, 100.0, 0.05))
|
2002-08-24 22:02:30 +00:00
|
|
|
os << "\tscale " << scale << '\n';
|
|
|
|
} else {
|
|
|
|
if (!width.zero())
|
|
|
|
os << "\twidth " << width.asString() << '\n';
|
2002-10-31 11:33:49 +00:00
|
|
|
if (!height.zero())
|
|
|
|
os << "\theight " << height.asString() << '\n';
|
2002-08-24 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keepAspectRatio)
|
|
|
|
os << "\tkeepAspectRatio\n";
|
|
|
|
if (draft) // draft mode
|
|
|
|
os << "\tdraft\n";
|
|
|
|
if (noUnzip)
|
|
|
|
os << "\tnoUnzip\n";
|
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
if (!bb.empty()) // bounding box
|
|
|
|
os << "\tBoundingBox " << bb << '\n';
|
|
|
|
if (clip) // clip image
|
|
|
|
os << "\tclip\n";
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
if (rotateAngle != 0.0)
|
|
|
|
os << "\trotateAngle " << rotateAngle << '\n';
|
2002-09-12 08:44:23 +00:00
|
|
|
if (!rotateOrigin.empty())
|
2002-08-24 22:02:30 +00:00
|
|
|
os << "\trotateOrigin " << rotateOrigin << '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
if (subcaption)
|
2002-05-01 10:23:51 +00:00
|
|
|
os << "\tsubcaption\n";
|
2002-01-29 09:26:24 +00:00
|
|
|
if (!subcaptionText.empty())
|
2002-05-01 10:23:51 +00:00
|
|
|
os << "\tsubcaptionText \"" << subcaptionText << '\"' << '\n';
|
2002-01-29 09:26:24 +00:00
|
|
|
if (!special.empty())
|
|
|
|
os << "\tspecial " << special << '\n';
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2000-11-15 03:22:08 +00:00
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
bool InsetGraphicsParams::Read(LyXLex & lex, string const & token, string const & bufpath)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
if (token == "filename") {
|
2002-05-29 22:07:59 +00:00
|
|
|
lex.eatLine();
|
2003-07-22 20:42:40 +00:00
|
|
|
filename.set(lex.getString(), bufpath);
|
2002-08-24 22:02:30 +00:00
|
|
|
} else if (token == "lyxscale") {
|
|
|
|
lex.next();
|
|
|
|
lyxscale = lex.getInteger();
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "display") {
|
|
|
|
lex.next();
|
2002-03-26 12:17:04 +00:00
|
|
|
string const type = lex.getString();
|
2003-07-21 21:30:57 +00:00
|
|
|
display = lyx::graphics::displayTranslator.find(type);
|
2002-08-24 22:02:30 +00:00
|
|
|
} else if (token == "scale") {
|
2002-07-23 12:20:21 +00:00
|
|
|
lex.next();
|
2002-10-24 11:53:46 +00:00
|
|
|
scale = lex.getFloat();
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "width") {
|
|
|
|
lex.next();
|
2002-01-29 09:26:24 +00:00
|
|
|
width = LyXLength(lex.getString());
|
2002-10-24 11:53:46 +00:00
|
|
|
scale = 0.0;
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "height") {
|
|
|
|
lex.next();
|
2002-01-29 09:26:24 +00:00
|
|
|
height = LyXLength(lex.getString());
|
2002-10-31 11:33:49 +00:00
|
|
|
scale = 0.0;
|
2002-01-29 09:26:24 +00:00
|
|
|
} else if (token == "keepAspectRatio") {
|
|
|
|
keepAspectRatio = true;
|
2002-08-24 22:02:30 +00:00
|
|
|
} else if (token == "draft") {
|
|
|
|
draft = true;
|
|
|
|
} else if (token == "noUnzip") {
|
|
|
|
noUnzip = true;
|
|
|
|
} else if (token == "BoundingBox") {
|
2002-10-31 11:33:49 +00:00
|
|
|
bb.erase();
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (i != 0)
|
2002-11-27 10:30:28 +00:00
|
|
|
bb += ' ';
|
2002-08-24 22:02:30 +00:00
|
|
|
lex.next();
|
2002-10-31 11:33:49 +00:00
|
|
|
bb += lex.getString();
|
2002-08-24 22:02:30 +00:00
|
|
|
}
|
|
|
|
} else if (token == "clip") {
|
|
|
|
clip = true;
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "rotateAngle") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
rotateAngle = lex.getFloat();
|
2002-01-29 09:26:24 +00:00
|
|
|
} else if (token == "rotateOrigin") {
|
|
|
|
lex.next();
|
|
|
|
rotateOrigin=lex.getString();
|
2002-08-24 22:02:30 +00:00
|
|
|
} else if (token == "subcaption") {
|
|
|
|
subcaption = true;
|
|
|
|
} else if (token == "subcaptionText") {
|
2003-03-28 03:54:39 +00:00
|
|
|
lex.eatLine();
|
|
|
|
string sub = lex.getString();
|
|
|
|
// strip surrounding " "
|
|
|
|
subcaptionText = sub.substr(1, sub.length() - 2);
|
2002-04-08 14:47:21 +00:00
|
|
|
} else if (token == "special") {
|
|
|
|
lex.eatLine();
|
|
|
|
special = lex.getString();
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
// catch and ignore following two old-format tokens and their arguments.
|
2002-10-24 11:53:46 +00:00
|
|
|
// e.g. "size_kind scale" clashes with the setting of the
|
|
|
|
// "scale <value>" keyword.
|
2002-08-24 22:02:30 +00:00
|
|
|
} else if (token == "size_kind" || token == "lyxsize_kind") {
|
|
|
|
lex.next();
|
|
|
|
lex.getString();
|
2002-10-24 11:53:46 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// If it's none of the above, it's not ours.
|
2000-08-14 09:44:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
2002-05-28 11:50:04 +00:00
|
|
|
|
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
|
2002-05-28 11:50:04 +00:00
|
|
|
{
|
2003-07-21 21:30:57 +00:00
|
|
|
lyx::graphics::Params pars;
|
2003-07-22 20:42:40 +00:00
|
|
|
pars.filename = filename.absFilename();
|
2002-08-24 22:02:30 +00:00
|
|
|
pars.scale = lyxscale;
|
|
|
|
pars.angle = rotateAngle;
|
2002-05-28 11:50:04 +00:00
|
|
|
|
|
|
|
if (clip) {
|
|
|
|
pars.bb = bb;
|
|
|
|
|
|
|
|
// Get the original Bounding Box from the file
|
2003-07-22 20:42:40 +00:00
|
|
|
string const tmp = readBB_from_PSFile(filename.absFilename());
|
2002-05-28 11:50:04 +00:00
|
|
|
lyxerr[Debug::GRAPHICS] << "BB_from_File: " << tmp << std::endl;
|
|
|
|
if (!tmp.empty()) {
|
2002-08-24 22:02:30 +00:00
|
|
|
unsigned int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
|
|
|
|
unsigned int const bb_orig_yb = strToInt(token(tmp, ' ', 1));
|
2002-05-28 11:50:04 +00:00
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
// new pars.bb values must be >= zero
|
2002-08-24 22:02:30 +00:00
|
|
|
if (pars.bb.xl > bb_orig_xl)
|
|
|
|
pars.bb.xl -= bb_orig_xl;
|
|
|
|
else
|
|
|
|
pars.bb.xl = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
if (pars.bb.xr > bb_orig_xl)
|
|
|
|
pars.bb.xr -= bb_orig_xl;
|
|
|
|
else
|
|
|
|
pars.bb.xr = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
if (pars.bb.yb > bb_orig_yb)
|
|
|
|
pars.bb.yb -= bb_orig_yb;
|
|
|
|
else
|
|
|
|
pars.bb.yb = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
if (pars.bb.yt > bb_orig_yb)
|
|
|
|
pars.bb.yt -= bb_orig_yb;
|
|
|
|
else
|
|
|
|
pars.bb.yt = 0;
|
2002-05-28 11:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paranoia check.
|
|
|
|
int const width = pars.bb.xr - pars.bb.xl;
|
|
|
|
int const height = pars.bb.yt - pars.bb.yb;
|
|
|
|
|
|
|
|
if (width < 0 || height < 0) {
|
|
|
|
pars.bb.xl = 0;
|
|
|
|
pars.bb.xr = 0;
|
|
|
|
pars.bb.yb = 0;
|
|
|
|
pars.bb.yt = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
if (display == lyx::graphics::DefaultDisplay) {
|
2002-08-27 20:30:20 +00:00
|
|
|
pars.display = lyxrc.display_graphics;
|
|
|
|
} else {
|
|
|
|
pars.display = display;
|
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-05-28 11:50:04 +00:00
|
|
|
// Override the above if we're not using a gui
|
2003-03-31 02:59:34 +00:00
|
|
|
if (!lyx_gui::use_gui) {
|
2003-07-21 21:30:57 +00:00
|
|
|
pars.display = lyx::graphics::NoDisplay;
|
2002-05-28 11:50:04 +00:00
|
|
|
}
|
2002-07-22 12:36:41 +00:00
|
|
|
|
2002-05-28 11:50:04 +00:00
|
|
|
return pars;
|
|
|
|
}
|