1 /* This file is part of
2 * =================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich.
6 * Copyright 1995-2001 The LyX Team.
9 * \author Herbert Voss <voss@lyx.org>
11 * ================================================= */
16 #pragma implementation
19 #include "insetgraphicsParams.h"
21 #include "support/translator.h"
22 #include "support/filetools.h"
23 #include "support/lyxlib.h"
24 #include "support/LOstream.h"
25 #include "support/LAssert.h"
33 /// This variable keeps a tab on whether the translator was set with the
35 bool translatorsSet = false;
37 /// This is the translator between the Display enum and corresponding lyx
39 Translator< InsetGraphicsParams::DisplayType, string >
40 displayTranslator(InsetGraphicsParams::DEFAULT, "default");
45 InsetGraphicsParams::InsetGraphicsParams()
49 if (! translatorsSet) {
50 translatorsSet = true;
51 // Fill the display translator
52 displayTranslator.addPair(DEFAULT, "default");
53 displayTranslator.addPair(MONOCHROME, "monochrome");
54 displayTranslator.addPair(GRAYSCALE, "grayscale");
55 displayTranslator.addPair(COLOR, "color");
56 displayTranslator.addPair(NONE, "none");
61 InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp)
63 // I decided to skip the initialization since the copy will overwrite
70 InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
72 // Are we assigning the object into itself?
79 void InsetGraphicsParams::init()
81 subcaptionText = filename = string();
82 bb = string(); // bounding box
83 draft = false; // draft mode
84 clip = false; // clip image
85 display = DEFAULT; // see pref
86 subcaption = false; // subfigure
87 noUnzip = false; // unzip files
88 width = LyXLength(); // set to 0pt
90 lyxwidth = LyXLength(); // for the view in lyx
91 lyxheight = LyXLength(); // also set to 0pt
92 scale = 0; // unit is %
93 lyxscale = 0; // same for lyxview
94 size_type = DEFAULT_SIZE; // do nothing
95 lyxsize_type = DEFAULT_SIZE; // do nothing
96 keepAspectRatio = false; // only for latex
97 rotate = false; // Rotating
98 rotateOrigin = "center"; // Origin
99 rotateAngle = 0.0; // in degrees
100 special = string(); // userdefined stuff
103 void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
105 filename = igp.filename;
109 display = igp.display;
110 subcaption = igp.subcaption;
111 subcaptionText = igp.subcaptionText;
112 noUnzip = igp.noUnzip;
113 keepAspectRatio = igp.keepAspectRatio;
117 size_type = igp.size_type;
118 lyxsize_type = igp.lyxsize_type;
119 lyxwidth = igp.lyxwidth;
120 lyxheight = igp.lyxheight;
121 lyxscale = igp.lyxscale;
123 rotateOrigin = igp.rotateOrigin;
124 rotateAngle = igp.rotateAngle;
125 special = igp.special;
128 bool operator==(InsetGraphicsParams const & left,
129 InsetGraphicsParams const & right)
131 if (left.filename == right.filename &&
132 left.bb == right.bb &&
133 left.draft == right.draft &&
134 left.clip == right.clip &&
135 left.display == right.display &&
136 left.subcaption == right.subcaption &&
137 left.noUnzip == right.noUnzip &&
138 left.subcaptionText == right.subcaptionText &&
139 left.keepAspectRatio == right.keepAspectRatio &&
140 left.width == right.width &&
141 left.height == right.height &&
142 left.scale == right.scale &&
143 left.size_type == right.size_type &&
144 left.lyxsize_type == right.lyxsize_type &&
145 left.lyxwidth == right.lyxwidth &&
146 left.lyxheight == right.lyxheight &&
147 left.lyxscale == right.lyxscale &&
148 left.rotate == right.rotate &&
149 left.rotateOrigin == right.rotateOrigin &&
150 lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001 &&
151 left.special == right.special)
158 bool operator!=(InsetGraphicsParams const & left,
159 InsetGraphicsParams const & right)
161 return !(left == right);
165 void InsetGraphicsParams::Write(ostream & os) const
167 // If there is no filename, write nothing for it.
168 if (!filename.empty()) {
169 os << "\tfilename " << filename << '\n';
171 if (!bb.empty()) // bounding box
172 os << "\tBoundingBox " << bb << '\n';
173 if (clip) // clip image
175 if (draft) // draft mode
177 // Save the display type for the view inside lyx
178 os << "\tdisplay " << displayTranslator.find(display) << '\n';
179 // Save the subcaption status
181 os << "\tsubcaption\n";
182 if (!subcaptionText.empty())
183 os << "\tsubcaptionText \"" << subcaptionText << '\"' << '\n';
186 // we always need the size type
188 // 1: width/height combination
190 os << "\tsize_type " << size_type << '\n';
192 os << "\twidth " << width.asString() << '\n';
194 os << "\theight " << height.asString() << '\n';
196 os << "\tscale " << scale << '\n';
198 os << "\tkeepAspectRatio\n";
201 if (rotateAngle != 0.0)
202 os << "\trotateAngle " << rotateAngle << '\n';
203 if (!rotateOrigin.empty())
204 os << "\trotateOrigin " << rotateOrigin << '\n';
205 if (!special.empty())
206 os << "\tspecial " << special << '\n';
207 // the values for the view in lyx
208 os << "\tlyxsize_type " << lyxsize_type << '\n';
209 if (!lyxwidth.zero()) // the lyx-viewsize
210 os << "\tlyxwidth " << lyxwidth.asString() << '\n';
211 if (!lyxheight.zero())
212 os << "\tlyxheight " << lyxheight.asString();
214 os << "\tlyxscale " << lyxscale << '\n';
218 bool InsetGraphicsParams::Read(LyXLex & lex, string const & token)
220 if (token == "filename") {
222 filename = lex.getString();
223 } else if (token == "BoundingBox") {
224 for (int i=0; i<4 ;i++) {
226 bb += (lex.getString()+" ");
228 } else if (token == "clip") {
230 } else if (token == "draft") {
232 } else if (token == "display") {
234 string const type = lex.getString();
235 display = displayTranslator.find(type);
236 } else if (token == "subcaption") {
238 } else if (token == "subcaptionText") {
240 subcaptionText = lex.getString();
241 } else if (token == "noUnzip") {
243 } else if (token == "size_type") {
245 switch (lex.getInteger()) {
247 size_type = DEFAULT_SIZE;
256 } else if (token == "width") {
258 width = LyXLength(lex.getString());
259 } else if (token == "height") {
261 height = LyXLength(lex.getString());
262 } else if (token == "keepAspectRatio") {
263 keepAspectRatio = true;
264 } else if (token == "scale") {
266 scale = lex.getInteger();
267 } else if (token == "rotate") {
269 } else if (token == "rotateAngle") {
271 rotateAngle = lex.getFloat();
272 } else if (token == "rotateOrigin") {
274 rotateOrigin=lex.getString();
275 } else if (token == "lyxsize_type") {
277 switch (lex.getInteger()) {
279 lyxsize_type = DEFAULT_SIZE;
285 lyxsize_type = SCALE;
288 } else if (token == "lyxwidth") {
290 lyxwidth = LyXLength(lex.getString());
291 } else if (token == "lyxheight") {
293 lyxheight = LyXLength(lex.getString());
294 } else if (token == "lyxscale") {
296 lyxscale = lex.getInteger();
297 } else if (token == "special") {
299 special = lex.getString();
300 } else { // If it's none of the above, its not ours.