From: Dov Feldstern Date: Thu, 5 Jul 2007 19:19:41 +0000 (+0000) Subject: Fix "default" encoding to match "auto" encoding except for the actual output X-Git-Tag: 1.6.10~9200 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=be01974475eef7690005fd64d375337bfcd42811;p=features.git Fix "default" encoding to match "auto" encoding except for the actual output of \inputencoding commands, which are not needed in some cases (e.g., Hebrew with ivritex). This fixes some of the remaining problems (but not all) from bug 3613 (namely, http://bugzilla.lyx.org/show_bug.cgi?id=3613#c9). See also some example files fixed by this in http://permalink.gmane.org/gmane.editors.lyx.devel/88805 . git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18994 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Font.cpp b/src/Font.cpp index 74f45e5230..ea1b8c17a3 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -40,6 +40,7 @@ using support::subst; using std::endl; using std::string; using std::ostream; +using std::pair; #ifndef CXX_GLOBAL_CSTD using std::strlen; @@ -785,12 +786,12 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, } if (language()->encoding()->package() == Encoding::CJK) { - int const c = switchEncoding(os, bparams, + pair const c = switchEncoding(os, bparams, runparams.moving_arg, *(runparams.encoding), *(language()->encoding())); - if (c > 0) { + if (c.first) { open_encoding_ = true; - count += c; + count += c.second; runparams.encoding = language()->encoding(); } } @@ -943,11 +944,11 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams, // We need to close the encoding even if it does not change // to do correct environment nesting Encoding const * const ascii = encodings.getFromLyXName("ascii"); - int const c = switchEncoding(os, bparams, + pair const c = switchEncoding(os, bparams, runparams.moving_arg, *(runparams.encoding), *ascii); - BOOST_ASSERT(c > 0); - count += c; + BOOST_ASSERT(c.first); + count += c.second; runparams.encoding = ascii; open_encoding_ = false; } diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 8054bb9daa..de4021db3b 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2056,11 +2056,11 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, // Switch file encoding if necessary if (runparams.encoding->package() == Encoding::inputenc && font.language()->encoding()->package() == Encoding::inputenc) { - int const count = switchEncoding(os, bparams, + std::pair const enc_switch = switchEncoding(os, bparams, runparams.moving_arg, *(runparams.encoding), *(font.language()->encoding())); - if (count > 0) { - column += count; + if (enc_switch.first) { + column += enc_switch.second; runparams.encoding = font.language()->encoding(); } } diff --git a/src/output_latex.cpp b/src/output_latex.cpp index a6a48d3da6..55c2e5d546 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -37,6 +37,8 @@ using support::subst; using std::endl; using std::string; +using std::pair; +using std::make_pair; namespace { @@ -295,7 +297,9 @@ TeXOnePar(Buffer const & buf, } } - // Switch file encoding if necessary + // Switch file encoding if necessary; no need to do this for "default" + // encoding, since this only affects the position of the outputted + // \inputencoding command; the encoding switch will occur when necessary if (bparams.inputenc == "auto" && runparams.encoding->package() == Encoding::inputenc) { // Look ahead for future encoding changes. @@ -313,12 +317,14 @@ TeXOnePar(Buffer const & buf, // encoding to that required by the language of c. Encoding const * const encoding = pit->getFontSettings(bparams, i).language()->encoding(); - if (encoding->package() == Encoding::inputenc && - switchEncoding(os, bparams, false, - *(runparams.encoding), *encoding) > 0) { + pair enc_switch = switchEncoding(os, bparams, false, + *(runparams.encoding), *encoding); + if (encoding->package() == Encoding::inputenc && enc_switch.first) { runparams.encoding = encoding; - os << '\n'; - texrow.newline(); + if (enc_switch.second > 0) { + os << '\n'; + texrow.newline(); + } } break; } @@ -598,17 +604,17 @@ void latexParagraphs(Buffer const & buf, } -int switchEncoding(odocstream & os, BufferParams const & bparams, +pair switchEncoding(odocstream & os, BufferParams const & bparams, bool moving_arg, Encoding const & oldEnc, Encoding const & newEnc) { - if ((bparams.inputenc != "auto" || moving_arg) - && bparams.inputenc != "default") - return 0; + if ((bparams.inputenc != "auto" && bparams.inputenc != "default") + || moving_arg) + return make_pair(false, 0); // Do nothing if the encoding is unchanged. if (oldEnc.name() == newEnc.name()) - return 0; + return make_pair(false, 0); // FIXME We ignore encoding switches from/to encodings that do // neither support the inputenc package nor the CJK package here. @@ -617,19 +623,20 @@ int switchEncoding(odocstream & os, BufferParams const & bparams, // but it is the best we can do if (oldEnc.package() == Encoding::none || newEnc.package() == Encoding::none) - return 0; + return make_pair(false, 0); LYXERR(Debug::LATEX) << "Changing LaTeX encoding from " << oldEnc.name() << " to " << newEnc.name() << endl; os << setEncoding(newEnc.iconvName()); if (bparams.inputenc == "default") - return 0; + return make_pair(true, 0); docstring const inputenc(from_ascii(newEnc.latexName())); switch (newEnc.package()) { case Encoding::none: - return 0; + // shouldn't ever reach here, see above + return make_pair(true, 0); case Encoding::inputenc: { int count = inputenc.length(); if (oldEnc.package() == Encoding::CJK) { @@ -637,7 +644,7 @@ int switchEncoding(odocstream & os, BufferParams const & bparams, count += 9; } os << "\\inputencoding{" << inputenc << '}'; - return count + 16; + return make_pair(true, count + 16); } case Encoding::CJK: { int count = inputenc.length(); @@ -646,11 +653,11 @@ int switchEncoding(odocstream & os, BufferParams const & bparams, count += 9; } os << "\\begin{CJK}{" << inputenc << "}{}"; - return count + 15; + return make_pair(true, count + 15); } } // Dead code to avoid a warning: - return 0; + return make_pair(true, 0); } } // namespace lyx diff --git a/src/output_latex.h b/src/output_latex.h index f108f1b360..008564ed79 100644 --- a/src/output_latex.h +++ b/src/output_latex.h @@ -12,6 +12,8 @@ #ifndef OUTPUT_LATEX_H #define OUTPUT_LATEX_H +#include + #include "support/docstream.h" @@ -43,10 +45,11 @@ void latexParagraphs(Buffer const & buf, std::string const & everypar = std::string()); /// Switch the encoding of \p os from \p oldEnc to \p newEnc if needed. -/// \return the number of characters written to \p os. -int switchEncoding(odocstream & os, BufferParams const & bparams, - bool moving_arg, Encoding const & oldEnc, - Encoding const & newEnc); +/// \return (did the encoding change?, number of characters written to \p os) +std::pair switchEncoding(odocstream & os, + BufferParams const & bparams, + bool moving_arg, Encoding const & oldEnc, + Encoding const & newEnc); } // namespace lyx