X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FinsetgraphicsParams.C;h=405368d2fff93711a48d207ddd486cf875bf461a;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=0b464828270bda406c9e0266de624584ecb9d444;hpb=47910a7a67b9d49ccf410cc9e8d52ab89458dd56;p=lyx.git diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 0b46482827..405368d2ff 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -1,12 +1,13 @@ -// -*- C++ -*- /* This file is part of * ================================================= * * LyX, The Document Processor * Copyright 1995 Matthias Ettrich. - * Copyright 1995-2000 The LyX Team. + * Copyright 1995-2001 The LyX Team. + * + * \author Baruch Even + * \author Herbert Voss * - * This file Copyright 2000 Baruch Even * ================================================= */ #include @@ -19,29 +20,44 @@ #include "support/translator.h" #include "support/filetools.h" - +#include "support/lyxlib.h" +#include "support/LOstream.h" #include "support/LAssert.h" + +using std::ostream; + + namespace { /// This variable keeps a tab on whether the translator was set with the /// translations. bool translatorsSet = false; -/// This is the translator between the Resize enum and corresponding lyx -/// file strings. -Translator< InsetGraphicsParams::Resize, string > -resizeTranslator(InsetGraphicsParams::DEFAULT_SIZE, "default"); - -/// This is the translator between the Origin enum and corresponding lyx -/// file strings. -Translator< InsetGraphicsParams::Origin, string > -originTranslator(InsetGraphicsParams::DEFAULT, "default"); - /// This is the translator between the Display enum and corresponding lyx /// file strings. Translator< InsetGraphicsParams::DisplayType, string > -displayTranslator(InsetGraphicsParams::MONOCHROME, "monochrome"); +displayTranslator(InsetGraphicsParams::DEFAULT, "default"); + +// 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(); + string value = lex.getString(); // "width" or "height" + 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 +} } // namespace anon @@ -49,41 +65,16 @@ displayTranslator(InsetGraphicsParams::MONOCHROME, "monochrome"); InsetGraphicsParams::InsetGraphicsParams() { 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"); - - // 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(DEFAULT, "default"); displayTranslator.addPair(MONOCHROME, "monochrome"); displayTranslator.addPair(GRAYSCALE, "grayscale"); displayTranslator.addPair(COLOR, "color"); displayTranslator.addPair(NONE, "none"); } - } @@ -101,7 +92,6 @@ InsetGraphicsParams::operator=(InsetGraphicsParams const & params) // Are we assigning the object into itself? if (this == ¶ms) return * this; - copy(params); return *this; } @@ -109,90 +99,77 @@ InsetGraphicsParams::operator=(InsetGraphicsParams const & params) void InsetGraphicsParams::init() { subcaptionText = filename = string(); - display = MONOCHROME; - inlineFigure = false; - subcaption = false; - keepAspectRatio = true; - widthResize = DEFAULT_SIZE; - widthSize = 0.0; - heightResize = DEFAULT_SIZE; - heightSize = 0.0; - rotateOrigin = DEFAULT; - rotateAngle = 0; - - testInvariant(); + bb = string(); // bounding box + draft = false; // draft mode + clip = false; // clip image + display = DEFAULT; // see pref + subcaption = false; // subfigure + noUnzip = false; // unzip files + width = LyXLength(); // set to 0pt + height = LyXLength(); + lyxwidth = LyXLength(); // for the view in lyx + lyxheight = LyXLength(); // also set to 0pt + scale = 0; // unit is % + lyxscale = 0; // same for lyxview + size_type = DEFAULT_SIZE; // do nothing + lyxsize_type = DEFAULT_SIZE; // do nothing + keepAspectRatio = false; // only for latex + rotate = false; // Rotating + rotateOrigin = "center"; // Origin + rotateAngle = 0.0; // in degrees + special = string(); // userdefined stuff } void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) { filename = igp.filename; + bb = igp.bb; + draft = igp.draft; + clip = igp.clip; display = igp.display; - inlineFigure = igp.inlineFigure; subcaption = igp.subcaption; subcaptionText = igp.subcaptionText; + noUnzip = igp.noUnzip; keepAspectRatio = igp.keepAspectRatio; - widthResize = igp.widthResize; - widthSize = igp.widthSize; - heightResize = igp.heightResize; - heightSize = igp.heightSize; + width = igp.width; + height = igp.height; + scale = igp.scale; + size_type = igp.size_type; + lyxsize_type = igp.lyxsize_type; + lyxwidth = igp.lyxwidth; + lyxheight = igp.lyxheight; + lyxscale = igp.lyxscale; + rotate = igp.rotate; rotateOrigin = igp.rotateOrigin; rotateAngle = igp.rotateAngle; - - testInvariant(); -} - -void InsetGraphicsParams::testInvariant() const -{ - // Filename might be empty (when the dialog is first created). - // Assert(!filename.empty()); - - lyx::Assert(display == COLOR || - display == MONOCHROME || - display == GRAYSCALE || - display == NONE - ); - - lyx::Assert(widthResize == DEFAULT_SIZE || - widthResize == CM || - widthResize == INCH || - widthResize == PERCENT_PAGE || - widthResize == PERCENT_COLUMN - ); - - lyx::Assert(heightResize == DEFAULT_SIZE || - heightResize == CM || - heightResize == INCH || - heightResize == PERCENT_PAGE - ); - - lyx::Assert(widthSize >= 0.0); - lyx::Assert(heightSize >= 0.0); - - // 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. - lyx::Assert(rotateAngle < 360); - lyx::Assert(rotateAngle > -360); - + special = igp.special; } bool operator==(InsetGraphicsParams const & left, InsetGraphicsParams const & right) { if (left.filename == right.filename && + left.bb == right.bb && + left.draft == right.draft && + left.clip == right.clip && left.display == right.display && - left.inlineFigure == right.inlineFigure && left.subcaption == right.subcaption && + left.noUnzip == right.noUnzip && 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.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 && - left.rotateAngle == right.rotateAngle - ) + lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001 && + left.special == right.special) + ) return true; return false; @@ -205,135 +182,161 @@ bool operator!=(InsetGraphicsParams const & left, } -namespace { - -void writeResize(ostream & os, string const & key, - InsetGraphicsParams::Resize resize, double size) -{ - os << ' ' << key << "Resize "; - - os << resizeTranslator.find(resize); - os << ' ' << key << ' ' << size << '\n'; -} - -void writeOrigin(ostream & os, - InsetGraphicsParams::Origin origin) -{ - os << " rotateOrigin " << originTranslator.find(origin); - os << '\n'; -} - -} // namespace anon - - void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const { // If there is no filename, write nothing for it. if (! filename.empty()) { - os << "filename " - << MakeRelPath(filename, OnlyPath(buf->fileName())) + os << "\tfilename " + << MakeRelPath(filename, buf->filePath()) << '\n'; } - - // Save the display type - os << " display " << displayTranslator.find(display) << '\n'; - - // Save the inline status - if (inlineFigure) - os << " inline"; - + if (!bb.empty()) // bounding box + os << "\tBoundingBox " << bb << '\n'; + if (clip) // clip image + os << "\tclip\n"; + if (draft) // draft mode + os << "\tdraft\n"; + // Save the display type for the view inside lyx + os << "\tdisplay " << displayTranslator.find(display) << '\n'; // Save the subcaption status if (subcaption) - os << " subcaption"; - - if (! subcaptionText.empty()) - os << " subcaptionText \"" << subcaptionText << '\"' << '\n'; - - writeResize(os, "width", widthResize, widthSize); - writeResize(os, "height", heightResize, heightSize); - - writeOrigin(os, rotateOrigin); - if (rotateAngle != 0) - os << " rotateAngle " << rotateAngle << '\n'; -} - - -namespace { - -void readResize(InsetGraphicsParams * igp, bool height, - string const & token) -{ - InsetGraphicsParams::Resize resize = InsetGraphicsParams::DEFAULT_SIZE; - - resize = resizeTranslator.find(token); - - if (height) - igp->heightResize = resize; - else - igp->widthResize = resize; -} - - -void readOrigin(InsetGraphicsParams * igp, string const & token) -{ - // TODO: complete this function. - igp->rotateOrigin = originTranslator.find(token); + os << "\tsubcaption\n"; + if (!subcaptionText.empty()) + os << "\tsubcaptionText \"" << subcaptionText << '\"' << '\n'; + if (noUnzip) + os << "\tnoUnzip\n"; + // 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"; + if (rotate) + os << "\trotate\n"; + 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'; + // the values for the view in lyx + os << "\tlyxsize_type " << lyxsize_type << '\n'; + if (!lyxwidth.zero()) // the lyx-viewsize + os << "\tlyxwidth " << lyxwidth.asString() << '\n'; + if (!lyxheight.zero()) + os << "\tlyxheight " << lyxheight.asString(); + if (lyxscale != 0) + os << "\tlyxscale " << lyxscale << '\n'; } -} // namespace anon - bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex, string const& token) { if (token == "filename") { lex.next(); - filename = lex.GetString(); - + filename = lex.getString(); if (!filename.empty()) { // Make the filename with absolute directory. - filename = MakeAbsPath(filename, OnlyPath(buf->fileName())); + filename = MakeAbsPath(filename, buf->filePath()); + } + } 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; } else if (token == "display") { lex.next(); - string const type = lex.GetString(); - + string const type = lex.getString(); display = displayTranslator.find(type); - } else if (token == "inline") { - inlineFigure = true; } else if (token == "subcaption") { subcaption = true; } else if (token == "subcaptionText") { lex.next(); - subcaptionText = lex.GetString(); - } else if (token == "widthResize") { + subcaptionText = lex.getString(); + } else if (token == "noUnzip") { + noUnzip = true; + } else if (token == "size_type") { lex.next(); - string const token = lex.GetString(); - - readResize(this, false, token); + switch (lex.getInteger()) { + case 0 : size_type = DEFAULT_SIZE; + break; + case 1 : size_type = WH; + break; + case 2 : size_type = SCALE; + } } else if (token == "width") { lex.next(); - widthSize = lex.GetFloat(); - } else if (token == "heightResize") { - lex.next(); - string const token = lex.GetString(); - - readResize(this, true, token); + width = LyXLength(lex.getString()); + size_type = WH; } else if (token == "height") { lex.next(); - heightSize = lex.GetFloat(); - } else if (token == "rotateOrigin") { + height = LyXLength(lex.getString()); + size_type = WH; + } else if (token == "keepAspectRatio") { + keepAspectRatio = true; + } else if (token == "scale") { lex.next(); - string const token = lex.GetString(); - - readOrigin(this, token); + scale = lex.getInteger(); + } else if (token == "rotate") { + rotate = true; } else if (token == "rotateAngle") { lex.next(); - rotateAngle = lex.GetInteger(); - } else { - // If it's none of the above, its not ours. + rotateAngle = lex.getFloat(); + } else if (token == "rotateOrigin") { + lex.next(); + rotateOrigin=lex.getString(); + } 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; + } + } else if (token == "lyxwidth") { + lex.next(); + lyxwidth = LyXLength(lex.getString()); + } else if (token == "lyxheight") { + lex.next(); + lyxheight = LyXLength(lex.getString()); + } else if (token == "lyxscale") { + lex.next(); + lyxscale = lex.getInteger(); + // 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. return false; } - return true; }