2007-09-11 Bo Peng <ben.bob@gmail.com>
* Format incremented to 285: Tweaks to embedded file format.
- Add manifest to .lyx file.
Remove inzip parameter from graphics insets.
2007-09-09 Helge Hafting <helge.hafting@aitel.hist.no>
self.default_layout = ''
self.header = []
self.preamble = []
- self.manifest = []
self.body = []
self.status = 0
self.encoding = encoding
def read(self):
- """Reads a file into the self.header, self.manifest and
+ """Reads a file into the self.header and
self.body parts, from self.input."""
while True:
if check_token(line, '\\end_preamble'):
continue
- if check_token(line, '\\begin_manifest'):
- while 1:
- line = self.input.readline()
- if not line:
- self.error("Invalid LyX file.")
-
- line = trim_eol(line)
- if check_token(line, "\\end_manifest"):
- break
-
- if not line.startswith('\\filename') and \
- not line.startswith('\\inzipName') and \
- not line.startswith('\\embed'):
- self.warning("Malformed LyX file: Missing"
- "'\\end_manifest'.")
-
- self.manifest.append(line)
-
- if check_token(line, '\\end_manifest'):
- continue
-
line = line.strip()
if not line:
continue
else:
header = self.header
- # LyX file format <= 284 does not have a manifest section
- # so this section is set to None
- if self.manifest is None:
- manifest = []
- else:
- manifest = ['\\begin_manifest'] + self.manifest + ['\\end_manifest', '']
-
- for line in header + [''] + manifest + self.body:
+ for line in header + [''] + self.body:
self.output.write(line.encode(self.encoding)+"\n")
document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
-def remove_manifest(document):
- "Remove the manifest section"
- document.manifest = None
-
-
# Discard PDF options for hyperref
def revert_pdf_options(document):
"Revert PDF options for hyperref."
[282, []],
[283, [convert_flex]],
[284, []],
- [285, []], # an empty manifest is automatically added
+ [285, []],
[286, []],
[287, [convert_wrapfig_options]],
[288, [convert_inset_command]],
[287, [revert_inset_command]],
[286, [revert_wrapfig_options]],
[285, [revert_pdf_options]],
- [284, [remove_manifest, remove_inzip_options]],
+ [284, [remove_inzip_options]],
[283, []],
[282, [revert_flex]],
[281, []],
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
}
}
- // read manifest after header
- embeddedFiles().readManifest(lex, errorList);
// read main text
bool const res = text().read(*this, lex, errorList);
params().writeFile(ofs);
ofs << "\\end_header\n";
- // write the manifest after header
- ofs << "\n\\begin_manifest\n";
- pimpl_->embedded_files.update();
- embeddedFiles().writeManifest(ofs);
- ofs << "\\end_manifest\n";
-
// write the text
ofs << "\n\\begin_body\n";
text().write(*this, ofs);
}
-bool EmbeddedFiles::readManifest(Lexer & lex, ErrorList & errorList)
-{
- int line = -1;
- int begin_manifest_line = -1;
-
- file_list_.clear();
- string filename;
- string inzipName;
- bool embedded = false;
-
- while (lex.isOK()) {
- lex.next();
- string const token = lex.getString();
-
- if (token.empty())
- continue;
-
- if (token == "\\end_manifest")
- break;
-
- ++line;
- if (token == "\\begin_manifest") {
- begin_manifest_line = line;
- continue;
- }
-
- LYXERR(Debug::PARSER) << "Handling document manifest token: `"
- << token << '\'' << endl;
-
- if (token == "\\filename")
- lex >> filename;
- else if (token == "\\inzipName")
- lex >> inzipName;
- else if (token == "\\embed") {
- lex >> embedded;
- registerFile(filename, embedded, NULL, inzipName);
- filename = "";
- inzipName = "";
- } else {
- docstring const s = _("\\begin_file is missing");
- errorList.push_back(ErrorItem(_("Manifest error"),
- s, -1, 0, 0));
- }
- }
- if (begin_manifest_line) {
- docstring const s = _("\\begin_manifest is missing");
- errorList.push_back(ErrorItem(_("Manifest error"),
- s, -1, 0, 0));
- }
- return true;
-}
-
-
-void EmbeddedFiles::writeManifest(ostream & os) const
-{
- EmbeddedFiles::EmbeddedFileList::const_iterator it = begin();
- EmbeddedFiles::EmbeddedFileList::const_iterator it_end = end();
- for (; it != it_end; ++it) {
- // only saved 'extra' files. Other embedded files are saved
- // with insets.
- if (!it->valid() || it->refCount() > 0)
- continue;
- // save the relative path
- os << "\\filename "
- << to_utf8(makeRelPath(from_utf8(it->absFilename()),
- from_utf8(buffer_->filePath()))) << '\n'
- << "\\inzipName " << it->inzipName() << '\n'
- << "\\embed " << (it->embedded() ? "true" : "false") << '\n';
- }
-}
-
-
void EmbeddedFiles::updateInsets() const
{
EmbeddedFiles::EmbeddedFileList::const_iterator it = begin();
/// update all files from external, used when enable embedding
bool updateFromExternalFile() const;
///
- bool readManifest(Lexer & lex, ErrorList & errorList);
- void writeManifest(std::ostream & os) const;
/// update all insets to use embedded files when embedding status is changed
void updateInsets() const;
private: