2000-07-31 12:30:10 +00:00
|
|
|
/* This file is part of
|
|
|
|
* =================================================
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* This file Copyright 2000 Baruch Even
|
|
|
|
* ================================================= */
|
|
|
|
|
2000-08-14 09:44:53 +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
|
2000-08-14 09:44:53 +00:00
|
|
|
#endif
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "insetgraphicsParams.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
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 Resize enum and corresponding lyx
|
|
|
|
/// file strings.
|
2001-03-20 01:22:46 +00:00
|
|
|
Translator< InsetGraphicsParams::Resize, string >
|
2000-08-14 09:44:53 +00:00
|
|
|
resizeTranslator(InsetGraphicsParams::DEFAULT_SIZE, "default");
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
/// This is the translator between the Origin enum and corresponding lyx
|
|
|
|
/// file strings.
|
2001-03-20 01:22:46 +00:00
|
|
|
Translator< InsetGraphicsParams::Origin, string >
|
2000-08-14 09:44:53 +00:00
|
|
|
originTranslator(InsetGraphicsParams::DEFAULT, "default");
|
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 >
|
2000-08-14 09:44:53 +00:00
|
|
|
displayTranslator(InsetGraphicsParams::MONOCHROME, "monochrome");
|
2000-07-31 12:30:10 +00:00
|
|
|
|
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 resize translator
|
|
|
|
resizeTranslator.addPair(DEFAULT_SIZE, "default");
|
|
|
|
resizeTranslator.addPair(CM, "cm");
|
|
|
|
resizeTranslator.addPair(INCH, "inch");
|
|
|
|
resizeTranslator.addPair(PERCENT_PAGE, "percentOfPage");
|
|
|
|
resizeTranslator.addPair(PERCENT_COLUMN, "percentOfColumn");
|
2001-07-30 13:35:08 +00:00
|
|
|
resizeTranslator.addPair(SCALE, "scale");
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// Fill the origin translator
|
|
|
|
originTranslator.addPair(DEFAULT, "default");
|
|
|
|
originTranslator.addPair(LEFTTOP, "leftTop");
|
|
|
|
originTranslator.addPair(LEFTCENTER, "leftCenter");
|
|
|
|
originTranslator.addPair(LEFTBASELINE, "leftBaseLine");
|
|
|
|
originTranslator.addPair(LEFTBOTTOM, "leftBottom");
|
|
|
|
originTranslator.addPair(CENTERTOP, "centerTop");
|
|
|
|
originTranslator.addPair(CENTER, "center");
|
|
|
|
originTranslator.addPair(CENTERBASELINE, "centerBaseLine");
|
|
|
|
originTranslator.addPair(CENTERBOTTOM, "centerBottom");
|
|
|
|
originTranslator.addPair(RIGHTTOP, "rightTop");
|
|
|
|
originTranslator.addPair(RIGHTCENTER, "rightCenter");
|
|
|
|
originTranslator.addPair(RIGHTBASELINE, "rightBaseLine");
|
|
|
|
originTranslator.addPair(RIGHTBOTTOM, "rightBottom");
|
|
|
|
originTranslator.addPair(REFERENCE_POINT, "referencePoint");
|
|
|
|
|
|
|
|
// Fill the display translator
|
|
|
|
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();
|
|
|
|
display = MONOCHROME;
|
|
|
|
subcaption = false;
|
|
|
|
keepAspectRatio = true;
|
|
|
|
widthResize = DEFAULT_SIZE;
|
|
|
|
widthSize = 0.0;
|
|
|
|
heightResize = DEFAULT_SIZE;
|
|
|
|
heightSize = 0.0;
|
|
|
|
rotateOrigin = DEFAULT;
|
2001-07-28 12:24:16 +00:00
|
|
|
rotateAngle = 0.0;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
testInvariant();
|
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;
|
|
|
|
display = igp.display;
|
|
|
|
subcaption = igp.subcaption;
|
|
|
|
subcaptionText = igp.subcaptionText;
|
|
|
|
keepAspectRatio = igp.keepAspectRatio;
|
|
|
|
widthResize = igp.widthResize;
|
|
|
|
widthSize = igp.widthSize;
|
|
|
|
heightResize = igp.heightResize;
|
|
|
|
heightSize = igp.heightSize;
|
|
|
|
rotateOrigin = igp.rotateOrigin;
|
|
|
|
rotateAngle = igp.rotateAngle;
|
|
|
|
|
|
|
|
testInvariant();
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InsetGraphicsParams::testInvariant() const
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// Filename might be empty (when the dialog is first created).
|
|
|
|
// Assert(!filename.empty());
|
|
|
|
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(display == COLOR ||
|
2000-08-14 09:44:53 +00:00
|
|
|
display == MONOCHROME ||
|
|
|
|
display == GRAYSCALE ||
|
|
|
|
display == NONE
|
|
|
|
);
|
|
|
|
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(widthResize == DEFAULT_SIZE ||
|
2000-08-14 09:44:53 +00:00
|
|
|
widthResize == CM ||
|
|
|
|
widthResize == INCH ||
|
|
|
|
widthResize == PERCENT_PAGE ||
|
2001-07-30 13:35:08 +00:00
|
|
|
widthResize == PERCENT_COLUMN ||
|
|
|
|
widthResize == SCALE
|
2000-08-14 09:44:53 +00:00
|
|
|
);
|
|
|
|
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(heightResize == DEFAULT_SIZE ||
|
2000-08-14 09:44:53 +00:00
|
|
|
heightResize == CM ||
|
|
|
|
heightResize == INCH ||
|
2001-07-30 13:35:08 +00:00
|
|
|
heightResize == PERCENT_PAGE ||
|
|
|
|
heightResize == SCALE
|
2000-08-14 09:44:53 +00:00
|
|
|
);
|
|
|
|
|
2001-07-30 13:35:08 +00:00
|
|
|
// For SCALE these can be negative.
|
|
|
|
//lyx::Assert(widthSize >= 0.0);
|
|
|
|
//lyx::Assert(heightSize >= 0.0);
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// Angle is in degrees and ranges -360 < angle < 360
|
|
|
|
// The reason for this is that in latex there is a meaning for the
|
|
|
|
// different angles and they are not necessarliy interchangeable,
|
|
|
|
// it depends on the rotation origin.
|
2001-07-28 12:24:16 +00:00
|
|
|
lyx::Assert(rotateAngle < 360.0);
|
|
|
|
lyx::Assert(rotateAngle > -360.0);
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
bool operator==(InsetGraphicsParams const & left,
|
|
|
|
InsetGraphicsParams const & right)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
if (left.filename == right.filename &&
|
|
|
|
left.display == right.display &&
|
|
|
|
left.subcaption == right.subcaption &&
|
|
|
|
left.subcaptionText == right.subcaptionText &&
|
|
|
|
left.keepAspectRatio == right.keepAspectRatio &&
|
|
|
|
left.widthResize == right.widthResize &&
|
|
|
|
left.widthSize == right.widthSize &&
|
|
|
|
left.heightResize == right.heightResize &&
|
|
|
|
left.heightSize == right.heightSize &&
|
|
|
|
left.rotateOrigin == right.rotateOrigin &&
|
2001-07-28 12:24:16 +00:00
|
|
|
lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001)
|
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,
|
|
|
|
InsetGraphicsParams const & right)
|
|
|
|
{
|
|
|
|
return !(left == right);
|
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
void writeResize(ostream & os, string const & key,
|
2000-08-14 09:44:53 +00:00
|
|
|
InsetGraphicsParams::Resize resize, double size)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
os << ' ' << key << "Resize ";
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
os << resizeTranslator.find(resize);
|
2001-02-08 13:06:55 +00:00
|
|
|
os << ' ' << key << ' ' << size << '\n';
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
void writeOrigin(ostream & os,
|
2000-08-14 09:44:53 +00:00
|
|
|
InsetGraphicsParams::Origin origin)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
os << " rotateOrigin " << originTranslator.find(origin);
|
2001-02-08 13:06:55 +00:00
|
|
|
os << '\n';
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// If there is no filename, write nothing for it.
|
|
|
|
if (! filename.empty()) {
|
|
|
|
os << "filename "
|
|
|
|
<< MakeRelPath(filename, OnlyPath(buf->fileName()))
|
2001-02-08 13:06:55 +00:00
|
|
|
<< '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the display type
|
2001-02-08 13:06:55 +00:00
|
|
|
os << " display " << displayTranslator.find(display) << '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// Save the subcaption status
|
|
|
|
if (subcaption)
|
|
|
|
os << " subcaption";
|
|
|
|
|
|
|
|
if (! subcaptionText.empty())
|
2001-02-08 13:06:55 +00:00
|
|
|
os << " subcaptionText \"" << subcaptionText << '\"' << '\n';
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
writeResize(os, "width", widthResize, widthSize);
|
|
|
|
writeResize(os, "height", heightResize, heightSize);
|
|
|
|
|
|
|
|
writeOrigin(os, rotateOrigin);
|
2001-12-02 16:21:10 +00:00
|
|
|
if (!lyx::float_equal(rotateAngle, 0.0, 0.001)) {
|
2001-02-08 13:06:55 +00:00
|
|
|
os << " rotateAngle " << rotateAngle << '\n';
|
2001-12-02 16:21:10 +00:00
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2000-11-15 03:22:08 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-11-15 03:22:08 +00:00
|
|
|
void readResize(InsetGraphicsParams * igp, bool height,
|
2000-08-14 09:44:53 +00:00
|
|
|
string const & token)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
InsetGraphicsParams::Resize resize = InsetGraphicsParams::DEFAULT_SIZE;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
resize = resizeTranslator.find(token);
|
|
|
|
|
|
|
|
if (height)
|
|
|
|
igp->heightResize = resize;
|
|
|
|
else
|
|
|
|
igp->widthResize = resize;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2000-11-15 03:22:08 +00:00
|
|
|
|
|
|
|
void readOrigin(InsetGraphicsParams * igp, string const & token)
|
2001-03-20 01:22:46 +00:00
|
|
|
{
|
|
|
|
// TODO: complete this function.
|
2000-08-14 09:44:53 +00:00
|
|
|
igp->rotateOrigin = originTranslator.find(token);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
bool InsetGraphicsParams::Read(Buffer const * buf, 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();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
if (!filename.empty()) {
|
|
|
|
// Make the filename with absolute directory.
|
|
|
|
filename = MakeAbsPath(filename, OnlyPath(buf->fileName()));
|
|
|
|
}
|
|
|
|
} else if (token == "display") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
string const type = lex.getString();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
display = displayTranslator.find(type);
|
|
|
|
} else if (token == "subcaption") {
|
|
|
|
subcaption = true;
|
|
|
|
} else if (token == "subcaptionText") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
subcaptionText = lex.getString();
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "widthResize") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
string const token = lex.getString();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
readResize(this, false, token);
|
|
|
|
} else if (token == "width") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
widthSize = lex.getFloat();
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "heightResize") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
string const token = lex.getString();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
readResize(this, true, token);
|
|
|
|
} else if (token == "height") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
heightSize = lex.getFloat();
|
2000-08-14 09:44:53 +00:00
|
|
|
} else if (token == "rotateOrigin") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
string const token = lex.getString();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
readOrigin(this, token);
|
|
|
|
} else if (token == "rotateAngle") {
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
rotateAngle = lex.getFloat();
|
2000-08-14 09:44:53 +00:00
|
|
|
} else {
|
|
|
|
// If it's none of the above, its not ours.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|