}
+EmbeddedFiles::EmbeddedFileList::const_iterator EmbeddedFiles::find(std::string filename) const
+{
+ EmbeddedFileList::const_iterator it = file_list_.begin();
+ EmbeddedFileList::const_iterator it_end = file_list_.end();
+ for (; it != it_end; ++it)
+ if (it->absFilename() == filename || it->embeddedFile(buffer_) == filename)
+ return it;
+ return file_list_.end();
+}
+
+
bool EmbeddedFiles::extractAll() const
{
EmbeddedFileList::const_iterator it = file_list_.begin();
EmbeddedFileList::iterator end() { return file_list_.end(); }
EmbeddedFileList::const_iterator begin() const { return file_list_.begin(); }
EmbeddedFileList::const_iterator end() const { return file_list_.end(); }
+ // try to locate filename, using either absFilename() or embeddedFile()
+ EmbeddedFileList::const_iterator find(std::string filename) const;
///
bool extractAll() const;
///
using std::ostringstream;
using std::vector;
+using lyx::support::DocFileName;
namespace {
os << "External\n"
<< "\ttemplate " << templatename() << '\n';
- if (!filename.empty())
- os << "\tfilename "
- << filename.outputFilename(buffer.filePath())
- << '\n';
+ if (!filename.empty()) {
+ // when we save, we still use the original filename
+ EmbeddedFiles::EmbeddedFileList::const_iterator it =
+ buffer.embeddedFiles().find(filename.toFilesystemEncoding());
+ if (it != buffer.embeddedFiles().end())
+ os << "\tfilename " << DocFileName(it->absFilename()).outputFilename(buffer.filePath()) << '\n';
+ else
+ os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
+ }
if (display != defaultDisplayType)
os << "\tdisplay "
lex.eatLine();
string const name = lex.getString();
filename.set(name, buffer.filePath());
+ // maybe this file is embedded
+ EmbeddedFiles::EmbeddedFileList::const_iterator it = buffer.embeddedFiles().find(filename.toFilesystemEncoding());
+ if (it != buffer.embeddedFiles().end())
+ // using available file, embedded or external, depending on file availability and
+ // embedding status.
+ filename = DocFileName(it->availableFile(&buffer));
break;
}
void InsetGraphics::write(Buffer const & buf, ostream & os) const
{
os << "Graphics\n";
- params().Write(os, buf.filePath());
+ params().Write(os, buf);
}
else
LYXERR(Debug::GRAPHICS) << "Not a Graphics inset!" << endl;
+ // InsetGraphics is read, with filename in params_. We do not know if this file actually
+ // exists or is embedded so we need to get the 'availableFile' from buf.embeddedFiles()
+ EmbeddedFiles::EmbeddedFileList::const_iterator it = buf.embeddedFiles().find(params_.filename.toFilesystemEncoding());
+ if (it != buf.embeddedFiles().end())
+ // using available file, embedded or external, depending on file availability and
+ // embedding status.
+ params_.filename = DocFileName(it->availableFile(&buf));
graphic_->update(params().as_grfxParams());
}
{
ostringstream data;
data << name_ << ' ';
- params.Write(data, buffer.filePath());
+ params.Write(data, buffer);
data << "\\end_inset\n";
return data.str();
}
#include "LyX.h" // for use_gui
#include "Lexer.h"
#include "LyXRC.h"
+#include "Buffer.h"
+#include "EmbeddedFiles.h"
#include "graphics/GraphicsParams.h"
using support::float_equal;
using support::readBB_from_PSFile;
using support::token;
+using support::DocFileName;
using std::string;
using std::ostream;
}
-void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
+void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
{
// Do not write the default values
if (!filename.empty()) {
- os << "\tfilename " << filename.outputFilename(bufpath) << '\n';
+ // when we save, we still use the original filename
+ EmbeddedFiles::EmbeddedFileList::const_iterator it =
+ buffer.embeddedFiles().find(filename.toFilesystemEncoding());
+ if (it != buffer.embeddedFiles().end())
+ os << "\tfilename " << DocFileName(it->absFilename()).outputFilename(buffer.filePath()) << '\n';
+ else
+ os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
}
if (lyxscale != 100)
os << "\tlyxscale " << lyxscale << '\n';
namespace graphics { class Params; }
class Lexer;
+class Buffer;
/// This class holds all the parameters needed by insetGraphics.
///
InsetGraphicsParams & operator=(InsetGraphicsParams const &);
/// Save the parameters in the LyX format stream.
- void Write(std::ostream & os, std::string const & bufpath) const;
+ /// Buffer is needed to figure out if a figure is embedded.
+ void Write(std::ostream & os, Buffer const & buf) const;
/// If the token belongs to our parameters, read it.
bool Read(Lexer & lex, std::string const & token, std::string const & bufpath);
/// convert