#include "Cursor.h"
#include "debug.h"
#include "DispatchResult.h"
+#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "FuncRequest.h"
#include "Mover.h"
#include "OutputParams.h"
#include "sgml.h"
+#include "EmbeddedFiles.h"
#include "frontends/alert.h"
#include "support/convert.h"
#include "support/filetools.h"
-#include "support/lyxalgo.h" // count
#include "support/lyxlib.h" // sum
#include "support/lstrings.h"
#include "support/os.h"
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
+#include <algorithm>
#include <sstream>
using support::float_equal;
using support::getExtension;
using support::isFileReadable;
+using support::isValidLaTeXFilename;
using support::latex_path;
using support::onlyFilename;
using support::removeExtension;
using support::rtrim;
using support::subst;
+using support::suffixIs;
using support::Systemcall;
using support::unzipFile;
using support::unzippedFileName;
using std::endl;
using std::string;
-using std::auto_ptr;
using std::istringstream;
using std::ostream;
using std::ostringstream;
}
-auto_ptr<Inset> InsetGraphics::doClone() const
+Inset * InsetGraphics::clone() const
{
- return auto_ptr<Inset>(new InsetGraphics(*this));
+ return new InsetGraphics(*this);
}
{
switch (cmd.action) {
case LFUN_GRAPHICS_EDIT: {
- Buffer const & buffer = *cur.bv().buffer();
+ Buffer const & buffer = cur.bv().buffer();
InsetGraphicsParams p;
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
editGraphics(p, buffer);
}
+void InsetGraphics::registerEmbeddedFiles(Buffer const &,
+ EmbeddedFiles & files, ParConstIterator const & pit) const
+{
+ files.registerFile(params().filename.absFilename(),
+ EmbeddedFile::AUTO, pit);
+}
+
+
void InsetGraphics::edit(Cursor & cur, bool)
{
InsetGraphicsMailer(*this).showDialog(&cur.bv());
options << "draft,";
if (params().clip)
options << "clip,";
+ ostringstream size;
double const scl = convert<double>(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
- options << "scale=" << scl / 100.0 << ',';
+ size << "scale=" << scl / 100.0 << ',';
} else {
if (!params().width.zero())
- options << "width=" << params().width.asLatexString() << ',';
+ size << "width=" << params().width.asLatexString() << ',';
if (!params().height.zero())
- options << "height=" << params().height.asLatexString() << ',';
+ size << "height=" << params().height.asLatexString() << ',';
if (params().keepAspectRatio)
- options << "keepaspectratio,";
+ size << "keepaspectratio,";
}
+ if (params().scaleBeforeRotation && !size.str().empty())
+ options << size.str();
// Make sure rotation angle is not very close to zero;
// a float can be effectively zero but not exactly zero.
options << ',';
}
}
+ if (!params().scaleBeforeRotation && !size.str().empty())
+ options << size.str();
if (!params().special.empty())
options << params().special << ',';
string opts = options.str();
// delete last ','
- return opts.substr(0, opts.size() - 1);
+ if (suffixIs(opts, ','))
+ opts = opts.substr(0, opts.size() - 1);
+
+ return opts;
}
string output_file = support::os::external_path(runparams.nice ?
params().filename.outputFilename(m_buffer->filePath()) :
onlyFilename(temp_file.absFilename()));
+
+ if (runparams.nice && !isValidLaTeXFilename(output_file)) {
+ frontend::Alert::warning(_("Invalid filename"),
+ _("The following filename is likely to cause trouble "
+ "when running the exported file through LaTeX: ") +
+ from_utf8(output_file));
+ }
+
FileName source_file = runparams.nice ? FileName(params().filename) : temp_file;
string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
"latex" : "pdflatex";
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
if (theConverters().convert(&buf, temp_file, to_file, params().filename,
- from, to, el,
- Converters::try_default | Converters::try_cache)) {
+ from, to, el,
+ Converters::try_default | Converters::try_cache)) {
runparams.exportdata->addExternalFile(tex_format,
to_file, output_to_file);
runparams.exportdata->addExternalFile("dvi",
int InsetGraphics::latex(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
// If there is no file specified or not existing,
// just output a message about it in the latex output.
params().filename.relFilename(buf.filePath());
bool const file_exists = !params().filename.empty() &&
- isFileReadable(params().filename);
+ isFileReadable(params().filename);
string const message = file_exists ?
string() : string("bb = 0 0 200 100, draft, type=eps");
// if !message.empty() then there was no existing file
LYXERR(Debug::GRAPHICS) << "InsetGraphics::latex outputting:\n"
<< latex_str << endl;
// Return how many newlines we issued.
- return int(lyx::count(latex_str.begin(), latex_str.end(),'\n'));
+ return int(std::count(latex_str.begin(), latex_str.end(),'\n'));
}
int InsetGraphics::plaintext(Buffer const & buf, odocstream & os,
- OutputParams const &) const
+ OutputParams const &) const
{
// No graphics in ascii output. Possible to use gifscii to convert
// images to ascii approximation.
// FIXME: We have no idea what the encoding of the filename is
docstring const str = bformat(buf.B_("Graphics file: %1$s"),
- from_utf8(params().filename.absFilename()));
+ from_utf8(params().filename.absFilename()));
os << '<' << str << '>';
return 2 + str.size();
namespace {
-int writeImageObject(char * format, odocstream & os, OutputParams const & runparams,
- docstring const graphic_label, docstring const attributes)
+int writeImageObject(char const * format,
+ odocstream & os,
+ OutputParams const & runparams,
+ docstring const & graphic_label,
+ docstring const & attributes)
{
if (runparams.flavor != OutputParams::XML) {
os << "<![ %output.print."
- << format
- << "; ["
- << std::endl;
+ << format
+ << "; ["
+ << std::endl;
}
os <<"<imageobject><imagedata fileref=\"&"
<< graphic_label
- << ";."
- << format
- << "\" "
- << attributes;
+ << ";."
+ << format
+ << "\" "
+ << attributes;
if (runparams.flavor == OutputParams::XML) {
os << " role=\"" << format << "\"/>" ;
}