]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphics.C
(Herbert): strip the extension from the graphics filename when exporting
[lyx.git] / src / insets / insetgraphics.C
index b7e93ddb5b438fe29ff3b8a1aa362003fb950d74..e6e352ec7ea5be784f9b5485c30d5d4fbff7ca7a 100644 (file)
@@ -99,6 +99,7 @@ TODO Before initial production release:
 #include "support/LAssert.h"
 #include "support/filetools.h"
 #include "support/lyxalgo.h" // lyx::count
+#include "support/path.h"
 
 #include <algorithm> // For the std::max
 
@@ -473,19 +474,20 @@ void InsetGraphics::readFigInset(LyXLex & lex)
                } else if (token == "subcaption") {
                        if (lex.eatLine())
                                params_.subcaptionText = lex.getString();
-                       params_.subcaption = true;
                } else if (token == "label") {
                        if (lex.next());
                        // kept for backwards compability. Delete in 0.13.x
                } else if (token == "angle") {
-                       if (lex.next())
+                       if (lex.next()) {
                                params_.rotate = true;
                                params_.rotateAngle = lex.getFloat();
+                       }
                } else if (token == "size") {
                        if (lex.next())
                                params_.lyxwidth = LyXLength(lex.getString()+"pt");
                        if (lex.next())
                                params_.lyxheight = LyXLength(lex.getString()+"pt");
+                       params_.lyxsize_type = InsetGraphicsParams::WH;
                } else if (token == "flags") {
                        if (lex.next())
                                switch (lex.getInteger()) {
@@ -609,14 +611,21 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const
        //   return original filename without the extension
        //
        // if it's a zipped one, than let LaTeX do the rest!!!
-       string filename_  = MakeAbsPath(params().filename, buf->filePath());
+       string filename_  = params().filename;
        bool const zipped = zippedFile(filename_);
 
-       if ((zipped && params().noUnzip) || buf->niceFile) {
+       if (zipped && params().noUnzip) {
                lyxerr[Debug::GRAPHICS] << "don't unzip file or export latex"
                                    << filename_ << endl;
                return filename_;
        }
+       // only export latex without compiling the file
+       if (buf->niceFile)
+               return RemoveExtension(filename_);
+
+       // Enable these helper functions to find the file if it is stored as
+       // a relative path.
+       Path p(buf->filePath());
 
        if (zipped)
                filename_ = unzipFile(filename_);
@@ -629,7 +638,7 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const
                return filename_;
        }
 
-       string const temp = AddName(buf->tmppath, filename_);
+       string const temp = MakeAbsPath(filename_, buf->tmppath);
        string const outfile_base = RemoveExtension(temp);
 
        lyxerr[Debug::GRAPHICS] << "tempname = " << temp << "\n";
@@ -638,26 +647,24 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const
        lyxerr[Debug::GRAPHICS] << "outfile_base = " << outfile_base << endl;
 
        converters.convert(buf, filename_, outfile_base, from, to);
-       return outfile_base;
+       return RemoveExtension(filename_);
 }
 
 
 int InsetGraphics::latex(Buffer const *buf, ostream & os,
                         bool /*fragile*/, bool/*fs*/) const
 {
-       // If there is no file specified, just output a message about it in
-       // the latex output.
-       if (params().filename.empty()) {
-               os  << "\\fbox{\\rule[-0.5in]{0pt}{1in}"
-                       << _("empty figure path") << "}\n";
-               return 1; // One end-of-line marker added to the stream.
-       }
-       // Ditto if the file is not there.
-       if (!IsFileReadable(MakeAbsPath(params().filename, buf->filePath()))) {
-               os  << "\\fbox{\\rule[-0.5in]{0pt}{1in}"
-                   << _("file not found") << "}\n";
-               return 1; // One end-of-line marker added to the stream.
-       }
+       // If there is no file specified or not existing,
+       // just output a message about it in the latex output.
+       lyxerr[Debug::GRAPHICS] << "[latex]filename = "
+                               << params().filename << endl;
+       string const message =
+           (IsFileReadable(MakeAbsPath(params().filename, buf->filePath()))
+               && !params().filename.empty()) ?
+                   string() :
+                   string("bb = 0 0 200 100, draft, type=eps]");
+       lyxerr[Debug::GRAPHICS] << "[latex]Messagestring = " << message << endl;
+
        // These variables collect all the latex code that should be before and
        // after the actual includegraphics command.
        string before;
@@ -669,23 +676,31 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os,
        }
        // We never use the starred form, we use the "clip" option instead.
        before += "\\includegraphics";
+
        // Write the options if there are any.
        string const opts = createLatexOptions();
-       if (!opts.empty()) {
-               before += ("[%\n" + opts +']');
-       }
+       lyxerr[Debug::GRAPHICS] << "[latex]opts = " << opts << endl;
+       if (!opts.empty() && !message.empty())
+               before += ("[" + opts + ',' + message);
+       else if (!message.empty())
+               before += ('[' + message);
+       else if (!opts.empty())
+               before += ("[" + opts + ']');
+       lyxerr[Debug::GRAPHICS] << "[latex]before = " << before << endl;
+       lyxerr[Debug::GRAPHICS] << "[latex]after = " << after << endl;
+
        // Make the filename relative to the lyx file
        // and remove the extension so the LaTeX will use whatever is
        // appropriate (when there are several versions in different formats)
-       string const latex_str = before + '{' + prepareFile(buf) + '}' + after;
+       string const latex_str = message.empty() ?
+               (before + '{' + prepareFile(buf) + '}' + after) :
+               (before + '{' + params().filename + " not found!}" + after);
        os << latex_str;
 
        // Return how many newlines we issued.
        int const newlines =
                int(lyx::count(latex_str.begin(), latex_str.end(),'\n') + 1);
 
-       // lyxerr << "includegraphics: " << newlines << " lines of text"
-       //        << endl;
        return newlines;
 }