+ string const file_out = support::MakeAbsPath(mangled, dir);
+
+ return copyFileIfNeeded(file_in, file_out);
+}
+
+
+string const stripExtensionIfPossible(string const & file)
+{
+ // Remove the extension so the LaTeX will use whatever
+ // is appropriate (when there are several versions in
+ // different formats)
+ // This works only if the filename contains no dots besides
+ // the just removed one. We can fool here by replacing all
+ // dots with a macro whose definition is just a dot ;-)
+ // The automatic format selection does not work if the file
+ // name is escaped.
+ string const latex_name = latex_path(file,
+ lyx::support::EXCLUDE_EXTENSION);
+ if (contains(latex_name, '"'))
+ return latex_name;
+ return latex_path(RemoveExtension(file),
+ lyx::support::PROTECT_EXTENSION,
+ lyx::support::ESCAPE_DOTS);
+}
+
+
+string const stripExtensionIfPossible(string const & file, string const & to)
+{
+ // No conversion is needed. LaTeX can handle the graphic file as is.
+ // This is true even if the orig_file is compressed.
+ string const to_format = formats.getFormat(to)->extension();
+ string const file_format = GetExtension(file);
+ // for latex .ps == .eps
+ if (to_format == file_format ||
+ (to_format == "eps" && file_format == "ps") ||
+ (to_format == "ps" && file_format == "eps"))
+ return stripExtensionIfPossible(file);
+ return latex_path(file, lyx::support::EXCLUDE_EXTENSION);
+}
+
+} // namespace anon
+
+
+string const InsetGraphics::prepareFile(Buffer const & buf,
+ OutputParams const & runparams) const
+{
+ // The following code depends on non-empty filenames
+ if (params().filename.empty())
+ return string();
+
+ string const orig_file = params().filename.absFilename();
+ string const rel_file = params().filename.relFilename(buf.filePath());
+
+ // If the file is compressed and we have specified that it
+ // should not be uncompressed, then just return its name and
+ // let LaTeX do the rest!
+ bool const zipped = params().filename.isZipped();
+
+ // temp_file will contain the file for LaTeX to act on if, for example,
+ // we move it to a temp dir or uncompress it.
+ string temp_file = orig_file;
+
+ // The master buffer. This is useful when there are multiple levels
+ // of include files
+ Buffer const * m_buffer = buf.getMasterBuffer();
+
+ // Return the output name if the file does not exist.
+ // We are not going to change the extension or using the name of the
+ // temporary file, the code is already complicated enough.
+ if (!IsFileReadable(orig_file))
+ return params().filename.outputFilename(m_buffer->filePath());