X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=43f7f7efb59cd86ba82ecf3667e9f06f0faf58ca;hb=35204f8f33d7400a5fefeffea533fb4cb4097211;hp=2206d32966a7ed482f0bae67233d64712a99f954;hpb=354fb450c2c0e63dc96c1764bbbc5233ecae21d9;p=lyx.git diff --git a/src/buffer.C b/src/buffer.C index 2206d32966..43f7f7efb5 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -47,6 +47,7 @@ #include "pariterator.h" #include "sgml.h" #include "texrow.h" +#include "TocBackend.h" #include "undo.h" #include "version.h" @@ -142,7 +143,7 @@ using std::string; namespace { -int const LYX_FORMAT = 252; +int const LYX_FORMAT = 254; } // namespace anon @@ -192,13 +193,16 @@ public: /// MacroTable macros; + + /// + TocBackend toc_backend; }; Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_) : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), - filename(file), file_fully_loaded(false), - inset(params) + filename(file), file_fully_loaded(false), inset(params), + toc_backend(&parent) { inset.setAutoBreakRows(true); lyxvc.buffer(&parent); @@ -326,6 +330,18 @@ TexRow const & Buffer::texrow() const } +TocBackend & Buffer::tocBackend() +{ + return pimpl_->toc_backend; +} + + +TocBackend const & Buffer::tocBackend() const +{ + return pimpl_->toc_backend; +} + + string const Buffer::getLatexName(bool const no_path) const { string const name = changeExtension(makeLatexName(fileName()), ".tex"); @@ -538,11 +554,9 @@ void Buffer::insertStringAsLines(ParagraphList & pars, } space_inserted = true; } -/* FIXME: not needed anymore? } else if (!isPrintable(*cit)) { // Ignore unprintables continue; -*/ } else { // just insert the character par.insertChar(pos, *cit, font, params().trackChanges); @@ -812,26 +826,55 @@ bool Buffer::do_writeFile(ostream & ofs) const } -void Buffer::makeLaTeXFile(string const & fname, +bool Buffer::makeLaTeXFile(string const & fname, string const & original_path, OutputParams const & runparams, bool output_preamble, bool output_body) { - lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl; + string encoding; + if (params().inputenc == "auto") + encoding = params().language->encoding()->iconvName(); + else { + Encoding const * enc = encodings.getFromLaTeXName(params().inputenc); + if (enc) + encoding = enc->iconvName(); + else { + lyxerr << "Unknown inputenc value `" + << params().inputenc + << "'. Using `auto' instead." << endl; + encoding = params().language->encoding()->iconvName(); + } + } + lyxerr[Debug::LATEX] << "makeLaTeXFile encoding: " + << encoding << "..." << endl; - // FIXME UNICODE - // This creates an utf8 encoded file, but the inputenc commands - // specify other encodings - odocfstream ofs; + odocfstream ofs(encoding); if (!openFileWrite(ofs, fname)) - return; + return false; - writeLaTeXSource(ofs, original_path, + try { + writeLaTeXSource(ofs, original_path, runparams, output_preamble, output_body); + } + catch (iconv_codecvt_facet_exception &) { + Alert::error(_("Encoding error"), + _("Some characters of your document are not " + "representable in the chosen encoding.\n" + "Changing the document encoding to utf8 could help.")); + return false; + } ofs.close(); - if (ofs.fail()) + if (ofs.fail()) { lyxerr << "File '" << fname << "' was not closed properly." << endl; + Alert::error(_("Error closing file"), + _("The output file could not be closed properly.\n" + " Probably some characters of your document are not " + "representable in the chosen encoding.\n" + "Changing the document encoding to utf8 could help.")); + return false; + } + return true; } @@ -1119,9 +1162,11 @@ void Buffer::validate(LaTeXFeatures & features) const features.require("dvipost"); // AMS Style is at document level - if (params().use_amsmath == BufferParams::AMS_ON + if (params().use_amsmath == BufferParams::package_on || tclass.provides(LyXTextClass::amsmath)) features.require("amsmath"); + if (params().use_esint == BufferParams::package_on) + features.require("esint"); for_each(paragraphs().begin(), paragraphs().end(), boost::bind(&Paragraph::validate, _1, boost::ref(features))); @@ -1400,6 +1445,18 @@ docstring const Buffer::B_(string const & l10n) const } +docstring const Buffer::translateLabel(docstring const & label) const +{ + if (support::isAscii(label)) + // Probably standard layout, try to translate + return B_(to_ascii(label)); + else + // This must be a user defined layout. We can not translate + // this, since gettext accepts only ascii keys. + return label; +} + + bool Buffer::isClean() const { return pimpl_->lyx_clean; @@ -1511,19 +1568,19 @@ Buffer * Buffer::getMasterBuffer() } -MacroData const & Buffer::getMacro(std::string const & name) const +MacroData const & Buffer::getMacro(docstring const & name) const { return pimpl_->macros.get(name); } -bool Buffer::hasMacro(string const & name) const +bool Buffer::hasMacro(docstring const & name) const { return pimpl_->macros.has(name); } -void Buffer::insertMacro(string const & name, MacroData const & data) +void Buffer::insertMacro(docstring const & name, MacroData const & data) { MacroTable::globalMacros().insert(name, data); pimpl_->macros.insert(name, data); @@ -1562,7 +1619,8 @@ void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc) } -void Buffer::changeRefsIfUnique(string const & from, string const & to, InsetBase::Code code) +void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, + InsetBase::Code code) { //FIXME: This does not work for child documents yet. BOOST_ASSERT(code == InsetBase::CITE_CODE || code == InsetBase::REF_CODE); @@ -1581,20 +1639,20 @@ void Buffer::changeRefsIfUnique(string const & from, string const & to, InsetBas } else getLabelList(labels); - // FIXME UNICODE - if (lyx::count(labels.begin(), labels.end(), from_utf8(from)) > 1) + if (lyx::count(labels.begin(), labels.end(), from) > 1) return; for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) { if (it->lyxCode() == code) { InsetCommand & inset = dynamic_cast(*it); - inset.replaceContents(from, to); + inset.replaceContents(to_utf8(from), to_utf8(to)); } } } -void Buffer::getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end, bool full_source) +void Buffer::getSourceCode(odocstream & os, pit_type par_begin, + pit_type par_end, bool full_source) { OutputParams runparams; runparams.nice = true; @@ -1617,7 +1675,8 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end if (par_begin + 1 == par_end) os << "% Preview source code for paragraph " << par_begin << "\n\n"; else - os << "% Preview source code from paragraph " << par_begin << " to " << par_end - 1 << "\n\n"; + os << "% Preview source code from paragraph " << par_begin + << " to " << par_end - 1 << "\n\n"; // output paragraphs if (isLatex()) { texrow().reset();