]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
* Painter.h:
[lyx.git] / src / buffer.C
index e500fab155a750dd949a1f129524804590139b1f..41185b825dfc5c961f915b70df0ae34b02ff01f2 100644 (file)
@@ -812,26 +812,44 @@ 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 const encoding = (params().inputenc == "auto") ?
+               params().language->encoding()->iconvName() :
+               encodings.getEncoding(params().inputenc)->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;
 }
 
 
@@ -1026,7 +1044,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
                else
                        os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\"";
 
-               string preamble = params().preamble;
+               docstring preamble = from_utf8(params().preamble);
                if (runparams.flavor != OutputParams::XML ) {
                        preamble += "<!ENTITY % output.print.png \"IGNORE\">\n";
                        preamble += "<!ENTITY % output.print.pdf \"IGNORE\">\n";
@@ -1040,7 +1058,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
                preamble += features.getLyXSGMLEntities();
 
                if (!preamble.empty()) {
-                        os << "\n [ " << from_ascii(preamble) << " ]";
+                        os << "\n [ " << preamble << " ]";
                }
                os << ">\n\n";
        }
@@ -1511,19 +1529,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 +1580,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);
@@ -1582,19 +1601,20 @@ void Buffer::changeRefsIfUnique(string const & from, string const & to, InsetBas
                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<InsetCommand &>(*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 +1637,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();