+ CopyStatus status = success ? SUCCESS : FAILURE;
+ return std::make_pair(status, file_out);
+}
+
+
+std::pair<CopyStatus, string> const
+copyToDirIfNeeded(string const & file_in, string const & dir, bool zipped)
+{
+ using support::rtrim;
+
+ BOOST_ASSERT(AbsolutePath(file_in));
+
+ string const only_path = support::OnlyPath(file_in);
+ if (rtrim(support::OnlyPath(file_in) , "/") == rtrim(dir, "/"))
+ return std::make_pair(IDENTICAL_PATHS, file_in);
+
+ string mangled = FileName(file_in).mangledFilename();
+ if (zipped) {
+ // We need to change _eps.gz to .eps.gz. The mangled name is
+ // still unique because of the counter in mangledFilename().
+ // We can't just call mangledFilename() with the zip
+ // extension removed, because base.eps and base.eps.gz may
+ // have different content but would get the same mangled
+ // name in this case.
+ string const base = RemoveExtension(unzippedFileName(file_in));
+ string::size_type const ext_len = file_in.length() - base.length();
+ mangled[mangled.length() - ext_len] = '.';
+ }
+ 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();