+
+ external::TemplateManager const & etm =
+ external::TemplateManager::get();
+ external::Template const * const et = etm.getTemplateByName(name);
+ if (!et)
+ // Be safe. Don't lose data.
+ return;
+
+ // Ascertain which transforms the template supports.
+ // Empty all those that it doesn't.
+ vector<external::TransformID> const & ids = et->transformIds;
+ clearIfNotFound(clipdata, external::Clip, ids);
+ clearIfNotFound(extradata, external::Extra, ids);
+ clearIfNotFound(resizedata, external::Resize, ids);
+ clearIfNotFound(rotationdata, external::Rotate, ids);
+}
+
+
+void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
+{
+ os << "External\n"
+ << "\ttemplate " << templatename() << '\n';
+
+ if (!filename.empty())
+ os << "\tfilename "
+ << filename.outputFilename(buffer.filePath())
+ << '\n';
+
+ if (display != defaultDisplayType)
+ os << "\tdisplay "
+ << external::displayTranslator().find(display)
+ << '\n';
+
+ if (lyxscale != defaultLyxScale)
+ os << "\tlyxscale " << convert<string>(lyxscale) << '\n';
+
+ if (draft)
+ os << "\tdraft\n";
+
+ if (!clipdata.bbox.empty())
+ os << "\tboundingBox " << clipdata.bbox << '\n';
+ if (clipdata.clip)
+ os << "\tclip\n";
+
+ external::ExtraData::const_iterator it = extradata.begin();
+ external::ExtraData::const_iterator end = extradata.end();
+ for (; it != end; ++it) {
+ if (!it->second.empty())
+ os << "\textra " << it->first << " \""
+ << it->second << "\"\n";
+ }
+
+ if (!rotationdata.no_rotation()) {
+ os << "\trotateAngle " << rotationdata.adjAngle() << '\n';
+ if (rotationdata.origin() != external::RotationData::DEFAULT)
+ os << "\trotateOrigin "
+ << rotationdata.originString() << '\n';
+ }
+
+ if (!resizedata.no_resize()) {
+ using support::float_equal;
+ double const scl = convert<double>(resizedata.scale);
+ if (!float_equal(scl, 0.0, 0.05)) {
+ if (!float_equal(scl, 100.0, 0.05))
+ os << "\tscale "
+ << resizedata.scale << '\n';
+ } else {
+ if (!resizedata.width.zero())
+ os << "\twidth "
+ << resizedata.width.asString() << '\n';
+ if (!resizedata.height.zero())
+ os << "\theight "
+ << resizedata.height.asString() << '\n';
+ }
+ if (resizedata.keepAspectRatio)
+ os << "\tkeepAspectRatio\n";
+ }
+}
+
+
+bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
+{
+ enum ExternalTags {
+ EX_TEMPLATE = 1,
+ EX_FILENAME,
+ EX_DISPLAY,
+ EX_LYXSCALE,
+ EX_DRAFT,
+ EX_BOUNDINGBOX,
+ EX_CLIP,
+ EX_EXTRA,
+ EX_HEIGHT,
+ EX_KEEPASPECTRATIO,
+ EX_ROTATEANGLE,
+ EX_ROTATEORIGIN,
+ EX_SCALE,
+ EX_WIDTH,
+ EX_END
+ };
+
+ keyword_item external_tags[] = {
+ { "\\end_inset", EX_END },
+ { "boundingBox", EX_BOUNDINGBOX },
+ { "clip", EX_CLIP },
+ { "display", EX_DISPLAY},
+ { "draft", EX_DRAFT},
+ { "extra", EX_EXTRA },
+ { "filename", EX_FILENAME},
+ { "height", EX_HEIGHT },
+ { "keepAspectRatio", EX_KEEPASPECTRATIO },
+ { "lyxscale", EX_LYXSCALE},
+ { "rotateAngle", EX_ROTATEANGLE },
+ { "rotateOrigin", EX_ROTATEORIGIN },
+ { "scale", EX_SCALE },
+ { "template", EX_TEMPLATE },
+ { "width", EX_WIDTH }
+ };
+
+ pushpophelper pph(lex, external_tags, EX_END);
+
+ bool found_end = false;
+ bool read_error = false;
+
+ while (lex.isOK()) {
+ switch (lex.lex()) {
+ case EX_TEMPLATE:
+ lex.next();
+ templatename_ = lex.getString();
+ break;
+
+ case EX_FILENAME: {
+ lex.eatLine();
+ string const name = lex.getString();
+ filename.set(name, buffer.filePath());
+ break;
+ }
+
+ case EX_DISPLAY: {
+ lex.next();
+ string const name = lex.getString();
+ display = external::displayTranslator().find(name);
+ break;
+ }
+
+ case EX_LYXSCALE:
+ lex.next();
+ lyxscale = lex.getInteger();
+ break;
+
+ case EX_DRAFT:
+ draft = true;
+ break;
+
+ case EX_BOUNDINGBOX:
+ lex.next();
+ clipdata.bbox.xl = lex.getInteger();
+ lex.next();
+ clipdata.bbox.yb = lex.getInteger();
+ lex.next();
+ clipdata.bbox.xr = lex.getInteger();
+ lex.next();
+ clipdata.bbox.yt = lex.getInteger();
+ break;
+
+ case EX_CLIP:
+ clipdata.clip = true;
+ break;
+
+ case EX_EXTRA: {
+ lex.next();
+ string const name = lex.getString();
+ lex.next();
+ extradata.set(name, lex.getString());
+ break;
+ }
+
+ case EX_HEIGHT:
+ lex.next();
+ resizedata.height = LyXLength(lex.getString());
+ break;
+
+ case EX_KEEPASPECTRATIO:
+ resizedata.keepAspectRatio = true;
+ break;
+
+ case EX_ROTATEANGLE:
+ lex.next();
+ rotationdata.angle = lex.getString();
+ break;
+
+ case EX_ROTATEORIGIN:
+ lex.next();
+ rotationdata.origin(lex.getString());
+ break;
+
+ case EX_SCALE:
+ lex.next();
+ resizedata.scale = lex.getString();
+ break;
+
+ case EX_WIDTH:
+ lex.next();
+ resizedata.width = LyXLength(lex.getString());
+ break;
+
+ case EX_END:
+ found_end = true;
+ break;
+
+ default:
+ lex.printError("ExternalInset::read: "
+ "Wrong tag: $$Token");
+ read_error = true;
+ break;
+ }
+
+ if (found_end || read_error)
+ break;
+ }
+
+ if (!found_end)
+ lex.printError("ExternalInsetParams::read: Missing \\end_inset.");
+
+ // This is a trick to make sure that the data are self-consistent.
+ settemplate(templatename_);
+
+ if (lyxerr.debugging(Debug::EXTERNAL)) {
+ lyxerr << "InsetExternalParams::read:\n";
+ write(buffer, lyxerr);
+ }
+
+ return !read_error;