2000-07-31 12:30:10 +00:00
|
|
|
/* This file is part of
|
|
|
|
* =================================================
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2000-07-31 12:30:10 +00:00
|
|
|
* LyX, The Document Processor
|
|
|
|
* Copyright 1995 Matthias Ettrich.
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-01-29 09:26:24 +00:00
|
|
|
* \author Baruch Even
|
|
|
|
* \author Herbert Voss <voss@lyx.org>
|
|
|
|
*
|
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
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
2002-03-21 17:09:55 +00:00
|
|
|
#endif
|
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
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "support/translator.h"
|
|
|
|
#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-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
/// This variable keeps a tab on whether the translator was set with the
|
|
|
|
/// translations.
|
2001-03-20 01:22:46 +00:00
|
|
|
bool translatorsSet = false;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
/// This is the translator between the Display enum and corresponding lyx
|
|
|
|
/// file strings.
|
2001-03-20 01:22:46 +00:00
|
|
|
Translator< InsetGraphicsParams::DisplayType, string >
|
2002-02-01 18:53:50 +00:00
|
|
|
displayTranslator(InsetGraphicsParams::DEFAULT, "default");
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
// this is only compatibility stuff for the first 1.2 version
|
|
|
|
// it is obselete until 1.3
|
|
|
|
LyXLength convertResizeValue(string const token, LyXLex & lex) {
|
|
|
|
lex.next();
|
2002-03-21 17:09:55 +00:00
|
|
|
string value = lex.getString(); // "width" or "height"
|
2002-01-29 09:26:24 +00:00
|
|
|
lex.next(); // anyway not interesting
|
|
|
|
value = lex.getString();
|
|
|
|
if (token == "default")
|
|
|
|
return (LyXLength(value+"pt"));
|
|
|
|
else if (token == "cm")
|
|
|
|
return (LyXLength(value+"cm"));
|
|
|
|
else if (token == "inch")
|
|
|
|
return (LyXLength(value+"in"));
|
|
|
|
else if (token == "percentOfColumn")
|
|
|
|
return (LyXLength(value+"c%"));
|
|
|
|
else if (token == "percentOfPage")
|
|
|
|
return (LyXLength(value+"p%"));
|
|
|
|
else return LyXLength("0pt"); // nothing with figinset
|
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
InsetGraphicsParams::InsetGraphicsParams()
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
init();
|
|
|
|
// Set translators
|
|
|
|
if (! translatorsSet) {
|
|
|
|
translatorsSet = true;
|
|
|
|
// Fill the display translator
|
2002-02-01 18:53:50 +00:00
|
|
|
displayTranslator.addPair(DEFAULT, "default");
|
2000-08-14 09:44:53 +00:00
|
|
|
displayTranslator.addPair(MONOCHROME, "monochrome");
|
|
|
|
displayTranslator.addPair(GRAYSCALE, "grayscale");
|
|
|
|
displayTranslator.addPair(COLOR, "color");
|
|
|
|
displayTranslator.addPair(NONE, "none");
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
return * this;
|
|
|
|
copy(params);
|
|
|
|
return *this;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InsetGraphicsParams::init()
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
subcaptionText = filename = string();
|
2002-01-29 09:26:24 +00:00
|
|
|
bb = string(); // bounding box
|
|
|
|
draft = false; // draft mode
|
|
|
|
clip = false; // clip image
|
2002-02-11 10:42:11 +00:00
|
|
|
display = DEFAULT; // see pref
|
2002-01-29 09:26:24 +00:00
|
|
|
subcaption = false; // subfigure
|
2002-02-11 10:42:11 +00:00
|
|
|
noUnzip = false; // unzip files
|
2002-01-29 09:26:24 +00:00
|
|
|
width = LyXLength(); // set to 0pt
|
|
|
|
height = LyXLength();
|
|
|
|
lyxwidth = LyXLength(); // for the view in lyx
|
2002-02-11 10:42:11 +00:00
|
|
|
lyxheight = LyXLength(); // also set to 0pt
|
|
|
|
scale = 0; // unit is %
|
|
|
|
lyxscale = 0; // same for lyxview
|
2002-01-31 14:20:09 +00:00
|
|
|
size_type = DEFAULT_SIZE; // do nothing
|
2002-02-05 12:19:32 +00:00
|
|
|
lyxsize_type = DEFAULT_SIZE; // do nothing
|
2002-02-11 10:42:11 +00:00
|
|
|
keepAspectRatio = false; // only for latex
|
2002-03-21 17:09:55 +00:00
|
|
|
rotate = false; // Rotating
|
2002-02-05 18:43:28 +00:00
|
|
|
rotateOrigin = "center"; // Origin
|
2002-01-29 09:26:24 +00:00
|
|
|
rotateAngle = 0.0; // in degrees
|
|
|
|
special = string(); // userdefined stuff
|
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-01-29 09:26:24 +00:00
|
|
|
bb = igp.bb;
|
|
|
|
draft = igp.draft;
|
|
|
|
clip = igp.clip;
|
2000-08-14 09:44:53 +00:00
|
|
|
display = igp.display;
|
|
|
|
subcaption = igp.subcaption;
|
|
|
|
subcaptionText = igp.subcaptionText;
|
2002-02-11 10:42:11 +00:00
|
|
|
noUnzip = igp.noUnzip;
|
2000-08-14 09:44:53 +00:00
|
|
|
keepAspectRatio = igp.keepAspectRatio;
|
2002-01-29 09:26:24 +00:00
|
|
|
width = igp.width;
|
|
|
|
height = igp.height;
|
|
|
|
scale = igp.scale;
|
|
|
|
size_type = igp.size_type;
|
2002-02-05 12:19:32 +00:00
|
|
|
lyxsize_type = igp.lyxsize_type;
|
2002-01-29 09:26:24 +00:00
|
|
|
lyxwidth = igp.lyxwidth;
|
|
|
|
lyxheight = igp.lyxheight;
|
2002-02-05 12:19:32 +00:00
|
|
|
lyxscale = igp.lyxscale;
|
2002-02-05 18:43:28 +00:00
|
|
|
rotate = igp.rotate;
|
2000-08-14 09:44:53 +00:00
|
|
|
rotateOrigin = igp.rotateOrigin;
|
|
|
|
rotateAngle = igp.rotateAngle;
|
2002-01-29 09:26:24 +00:00
|
|
|
special = igp.special;
|
2000-07-31 12:30:10 +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-03-21 17:09:55 +00:00
|
|
|
left.bb == right.bb &&
|
|
|
|
left.draft == right.draft &&
|
|
|
|
left.clip == right.clip &&
|
|
|
|
left.display == right.display &&
|
|
|
|
left.subcaption == right.subcaption &&
|
2002-02-11 10:42:11 +00:00
|
|
|
left.noUnzip == right.noUnzip &&
|
2002-03-21 17:09:55 +00:00
|
|
|
left.subcaptionText == right.subcaptionText &&
|
|
|
|
left.keepAspectRatio == right.keepAspectRatio &&
|
|
|
|
left.width == right.width &&
|
|
|
|
left.height == right.height &&
|
|
|
|
left.scale == right.scale &&
|
|
|
|
left.size_type == right.size_type &&
|
|
|
|
left.lyxsize_type == right.lyxsize_type &&
|
|
|
|
left.lyxwidth == right.lyxwidth &&
|
|
|
|
left.lyxheight == right.lyxheight &&
|
|
|
|
left.lyxscale == right.lyxscale &&
|
|
|
|
left.rotate == right.rotate &&
|
|
|
|
left.rotateOrigin == right.rotateOrigin &&
|
|
|
|
lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001 &&
|
|
|
|
left.special == right.special)
|
2002-02-16 15:59:55 +00:00
|
|
|
)
|
2000-08-14 09:44:53 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2000-07-31 12:30:10 +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
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2002-03-25 11:04:34 +00:00
|
|
|
void InsetGraphicsParams::Write(ostream & os) const
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// If there is no filename, write nothing for it.
|
2002-03-25 11:04:34 +00:00
|
|
|
if (!filename.empty()) {
|
|
|
|
os << "\tfilename " << filename << '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
2002-01-29 09:26:24 +00:00
|
|
|
if (!bb.empty()) // bounding box
|
|
|
|
os << "\tBoundingBox " << bb << '\n';
|
|
|
|
if (clip) // clip image
|
|
|
|
os << "\tclip\n";
|
|
|
|
if (draft) // draft mode
|
|
|
|
os << "\tdraft\n";
|
2002-02-11 10:42:11 +00:00
|
|
|
// Save the display type for the view inside lyx
|
2002-01-29 09:26:24 +00:00
|
|
|
os << "\tdisplay " << displayTranslator.find(display) << '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
// Save the subcaption status
|
|
|
|
if (subcaption)
|
2002-01-29 09:26:24 +00:00
|
|
|
os << "\tsubcaption\n";
|
|
|
|
if (!subcaptionText.empty())
|
|
|
|
os << "\tsubcaptionText \"" << subcaptionText << '\"' << '\n';
|
2002-02-11 10:42:11 +00:00
|
|
|
if (noUnzip)
|
|
|
|
os << "\tnoUnzip\n";
|
2002-01-29 09:26:24 +00:00
|
|
|
// we always need the size type
|
|
|
|
// 0: no special
|
|
|
|
// 1: width/height combination
|
|
|
|
// 2: scale
|
|
|
|
os << "\tsize_type " << size_type << '\n';
|
|
|
|
if (!width.zero())
|
|
|
|
os << "\twidth " << width.asString() << '\n';
|
|
|
|
if (!height.zero())
|
|
|
|
os << "\theight " << height.asString() << '\n';
|
|
|
|
if (scale != 0)
|
|
|
|
os << "\tscale " << scale << '\n';
|
|
|
|
if (keepAspectRatio)
|
|
|
|
os << "\tkeepAspectRatio\n";
|
2002-02-05 18:43:28 +00:00
|
|
|
if (rotate)
|
|
|
|
os << "\trotate\n";
|
2002-01-29 09:26:24 +00:00
|
|
|
if (!lyx::float_equal(rotateAngle, 0.0, 0.001))
|
|
|
|
os << "\trotateAngle " << rotateAngle << '\n';
|
|
|
|
if (!rotateOrigin.empty())
|
|
|
|
os << "\trotateOrigin " << rotateOrigin << '\n';
|
|
|
|
if (!special.empty())
|
|
|
|
os << "\tspecial " << special << '\n';
|
2002-02-11 10:42:11 +00:00
|
|
|
// the values for the view in lyx
|
2002-02-05 12:19:32 +00:00
|
|
|
os << "\tlyxsize_type " << lyxsize_type << '\n';
|
2002-01-29 09:26:24 +00:00
|
|
|
if (!lyxwidth.zero()) // the lyx-viewsize
|
|
|
|
os << "\tlyxwidth " << lyxwidth.asString() << '\n';
|
|
|
|
if (!lyxheight.zero())
|
|
|
|
os << "\tlyxheight " << lyxheight.asString();
|
2002-02-05 12:19:32 +00:00
|
|
|
if (lyxscale != 0)
|
|
|
|
os << "\tlyxscale " << lyxscale << '\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
|
|
|
|
2002-03-22 16:37:52 +00:00
|
|
|
bool InsetGraphicsParams::Read(LyXLex & lex, string const& token)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
if (token == "filename") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
filename = lex.getString();
|
2002-01-29 09:26:24 +00:00
|
|
|
} else if (token == "BoundingBox") {
|
|
|
|
for (int i=0; i<4 ;i++) {
|
|
|
|
lex.next();
|
|
|
|
bb += (lex.getString()+" ");
|
|
|
|
}
|
|
|
|
} else if (token == "clip") {
|
|
|
|
clip = true;
|
|
|
|
} else if (token == "draft") {
|
|
|
|
draft = true;
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "display") {
|
|
|
|
lex.next();
|
2002-03-25 16:15:46 +00:00
|
|
|
if (IsFileReadable(filename)) {
|
|
|
|
string const type = lex.getString();
|
|
|
|
display = displayTranslator.find(type);
|
|
|
|
} else
|
|
|
|
display = NONE;
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "subcaption") {
|
|
|
|
subcaption = true;
|
|
|
|
} else if (token == "subcaptionText") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
subcaptionText = lex.getString();
|
2002-02-11 10:42:11 +00:00
|
|
|
} else if (token == "noUnzip") {
|
|
|
|
noUnzip = true;
|
2002-01-29 09:26:24 +00:00
|
|
|
} else if (token == "size_type") {
|
2000-08-14 09:44:53 +00:00
|
|
|
lex.next();
|
2002-01-29 09:26:24 +00:00
|
|
|
switch (lex.getInteger()) {
|
|
|
|
case 0 : size_type = DEFAULT_SIZE;
|
|
|
|
break;
|
|
|
|
case 1 : size_type = WH;
|
|
|
|
break;
|
|
|
|
case 2 : size_type = SCALE;
|
|
|
|
}
|
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());
|
|
|
|
size_type = WH;
|
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());
|
|
|
|
size_type = WH;
|
|
|
|
} else if (token == "keepAspectRatio") {
|
|
|
|
keepAspectRatio = true;
|
2002-01-31 14:20:09 +00:00
|
|
|
} else if (token == "scale") {
|
|
|
|
lex.next();
|
|
|
|
scale = lex.getInteger();
|
2002-02-05 18:43:28 +00:00
|
|
|
} else if (token == "rotate") {
|
|
|
|
rotate = 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-02-05 12:19:32 +00:00
|
|
|
} else if (token == "lyxsize_type") {
|
|
|
|
lex.next();
|
|
|
|
switch (lex.getInteger()) {
|
|
|
|
case 0 : lyxsize_type = DEFAULT_SIZE;
|
|
|
|
break;
|
|
|
|
case 1 : lyxsize_type = WH;
|
|
|
|
break;
|
|
|
|
case 2 : lyxsize_type = SCALE;
|
|
|
|
}
|
2002-01-29 09:26:24 +00:00
|
|
|
} else if (token == "lyxwidth") {
|
|
|
|
lex.next();
|
|
|
|
lyxwidth = LyXLength(lex.getString());
|
|
|
|
} else if (token == "lyxheight") {
|
|
|
|
lex.next();
|
|
|
|
lyxheight = LyXLength(lex.getString());
|
2002-02-05 12:19:32 +00:00
|
|
|
} else if (token == "lyxscale") {
|
|
|
|
lex.next();
|
|
|
|
lyxscale = lex.getInteger();
|
2002-02-11 10:42:11 +00:00
|
|
|
// now the compytibility stuff for "old" 1.2.0 files which uses
|
|
|
|
// the first try of the new graphic inset. Can be deleted, when
|
|
|
|
// 1.3 comes out
|
|
|
|
} else if (token == "widthResize") {
|
|
|
|
if (lex.next()) {
|
|
|
|
string const token = lex.getString();
|
|
|
|
if (token == "scale") {
|
|
|
|
lex.next();
|
|
|
|
scale = lex.getInteger();
|
|
|
|
size_type = SCALE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
width = convertResizeValue(token, lex);
|
|
|
|
size_type = WH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (token == "heightResize") {
|
|
|
|
if (lex.next())
|
|
|
|
height = convertResizeValue(lex.getString(), lex);
|
|
|
|
// end compytibility stuff
|
|
|
|
} else { // If it's none of the above, its not ours.
|
2000-08-14 09:44:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|