]> git.lyx.org Git - features.git/commitdiff
** Fix language switch issue introduced by the CJK patch **
authorJürgen Spitzmüller <spitz@lyx.org>
Fri, 25 Jan 2008 13:27:08 +0000 (13:27 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Fri, 25 Jan 2008 13:27:08 +0000 (13:27 +0000)
* src/output_latex.{cpp,h}:
- (latexParagraphs, TeXEnvironment, TeXOnePar, TeXDeeper): pass Text element
   instead of ParagraphList. This is necessary to detect whether we are in the main text.
- check if we are in the main text for language switches, if needed.
* src/Buffer.cpp:
* src/insets/InsetEnvironment.cpp:
* src/insets/InsetText.cpp:
* src/mathed/InsetMathMBox.cpp:
- adapt to new latexParagraphs definition.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22666 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/insets/InsetEnvironment.cpp
src/insets/InsetText.cpp
src/mathed/InsetMathMBox.cpp
src/output_latex.cpp
src/output_latex.h

index bf02199197124afa7f0040b5d14fe8ab5be57205..3ab46a024a733a049ee67dba8ef1d019314cc657 100644 (file)
@@ -1152,7 +1152,7 @@ void Buffer::writeLaTeXSource(odocstream & os,
        }
 
        // the real stuff
-       latexParagraphs(*this, paragraphs(), os, d->texrow, runparams);
+       latexParagraphs(*this, text(), os, d->texrow, runparams);
 
        // Restore the parenthood if needed
        if (output_preamble) {
@@ -2160,7 +2160,7 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
                d->texrow.newline();
                // output paragraphs
                if (isLatex()) {
-                       latexParagraphs(*this, paragraphs(), os, d->texrow, runparams);
+                       latexParagraphs(*this, text(), os, d->texrow, runparams);
                } else {
                        // DocBook
                        docbookParagraphs(paragraphs(), *this, os, runparams);
index 0d263810879872c0d93c123f2bcc221d5ef8ad09..73048ab52e87a8b9bb257c337e12733ed6b131c4 100644 (file)
@@ -70,7 +70,7 @@ int InsetEnvironment::latex(Buffer const & buf, odocstream & os,
        // FIXME UNICODE
        os << from_utf8(layout_->latexheader);
        TexRow texrow;
-       latexParagraphs(buf, paragraphs(), os, texrow, runparams,
+       latexParagraphs(buf, text_, os, texrow, runparams,
                        layout_->latexparagraph);
        // FIXME UNICODE
        os << from_utf8(layout_->latexfooter);
index 9369555c58ea3769342aeb09f148f5999eebffc1..922e47e54dd4cb2befe1891f5a41683acd9fa743 100644 (file)
@@ -258,7 +258,7 @@ int InsetText::latex(Buffer const & buf, odocstream & os,
                     OutputParams const & runparams) const
 {
        TexRow texrow;
-       latexParagraphs(buf, paragraphs(), os, texrow, runparams);
+       latexParagraphs(buf, text_, os, texrow, runparams);
        return texrow.rows();
 }
 
index 65c398b58e28b988e355283554987a3fd5d4f04b..39e500540cd18a42bc252d15d923ff2c2f620156 100644 (file)
@@ -91,7 +91,7 @@ int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
 {
        os << "\\mbox{\n";
        TexRow texrow;
-       latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
+       latexParagraphs(buf, text_, os, texrow, runparams);
        os << "}";
        return texrow.rows();
 }
index 94338898d9097521375dfce93acfe5875b3aa2cc..b0e42693aa5bb9b840db3a68f0517e0e3771b8f2 100644 (file)
@@ -55,14 +55,14 @@ static bool cjk_inherited_ = false;
 
 ParagraphList::const_iterator
 TeXEnvironment(Buffer const & buf,
-              ParagraphList const & paragraphs,
+              Text const & text,
               ParagraphList::const_iterator pit,
               odocstream & os, TexRow & texrow,
               OutputParams const & runparams);
 
 ParagraphList::const_iterator
 TeXOnePar(Buffer const & buf,
-         ParagraphList const & paragraphs,
+         Text const & text,
          ParagraphList::const_iterator pit,
          odocstream & os, TexRow & texrow,
          OutputParams const & runparams,
@@ -71,7 +71,7 @@ TeXOnePar(Buffer const & buf,
 
 ParagraphList::const_iterator
 TeXDeeper(Buffer const & buf,
-         ParagraphList const & paragraphs,
+         Text const & text,
          ParagraphList::const_iterator pit,
          odocstream & os, TexRow & texrow,
          OutputParams const & runparams)
@@ -79,13 +79,15 @@ TeXDeeper(Buffer const & buf,
        LYXERR(Debug::LATEX, "TeXDeeper...     " << &*pit);
        ParagraphList::const_iterator par = pit;
 
+       ParagraphList const & paragraphs = text.paragraphs();
+
        while (par != paragraphs.end() &&
                     par->params().depth() == pit->params().depth()) {
                if (par->layout()->isEnvironment()) {
-                       par = TeXEnvironment(buf, paragraphs, par,
+                       par = TeXEnvironment(buf, text, par,
                                             os, texrow, runparams);
                } else {
-                       par = TeXOnePar(buf, paragraphs, par,
+                       par = TeXOnePar(buf, text, par,
                                             os, texrow, runparams);
                }
        }
@@ -97,7 +99,7 @@ TeXDeeper(Buffer const & buf,
 
 ParagraphList::const_iterator
 TeXEnvironment(Buffer const & buf,
-              ParagraphList const & paragraphs,
+              Text const & text,
               ParagraphList::const_iterator pit,
               odocstream & os, TexRow & texrow,
               OutputParams const & runparams)
@@ -108,6 +110,8 @@ TeXEnvironment(Buffer const & buf,
 
        LayoutPtr const & style = pit->layout();
 
+       ParagraphList const & paragraphs = text.paragraphs();
+
        Language const * const par_language = pit->getParLanguage(bparams);
        Language const * const doc_language = bparams.language;
        Language const * const prev_par_language =
@@ -185,7 +189,7 @@ TeXEnvironment(Buffer const & buf,
 
        ParagraphList::const_iterator par = pit;
        do {
-               par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
+               par = TeXOnePar(buf, text, par, os, texrow, runparams);
 
                if (par == paragraphs.end()) {
                        // Make sure that the last paragraph is
@@ -213,7 +217,7 @@ TeXEnvironment(Buffer const & buf,
                                os << '\n';
                                texrow.newline();
                        }
-                       par = TeXDeeper(buf, paragraphs, par, os, texrow,
+                       par = TeXDeeper(buf, text, par, os, texrow,
                                        runparams);
                }
        } while (par != paragraphs.end()
@@ -271,7 +275,7 @@ namespace {
 
 ParagraphList::const_iterator
 TeXOnePar(Buffer const & buf,
-         ParagraphList const & paragraphs,
+         Text const & text,
          ParagraphList::const_iterator pit,
          odocstream & os, TexRow & texrow,
          OutputParams const & runparams_in,
@@ -281,6 +285,7 @@ TeXOnePar(Buffer const & buf,
                << everypar << "'");
        BufferParams const & bparams = buf.params();
        LayoutPtr style;
+       ParagraphList const & paragraphs = text.paragraphs();
 
        if (runparams_in.verbatim) {
                int const dist = distance(paragraphs.begin(), pit);
@@ -308,32 +313,13 @@ TeXOnePar(Buffer const & buf,
        OutputParams runparams = runparams_in;
        runparams.moving_arg |= style->needprotect;
 
+       bool const maintext = text.isMainText(buf);
        // we are at the beginning of an inset and CJK is already open.
-       if (pit == paragraphs.begin() && runparams.local_font != 0 &&
-           open_encoding_ == CJK) {
+       if (pit == paragraphs.begin() && !maintext && open_encoding_ == CJK) {
                cjk_inherited_ = true;
                open_encoding_ = none;
        }
 
-       if (pit == paragraphs.begin() && runparams.local_font == 0) {
-               // Open a CJK environment at the beginning of the main buffer
-               // if the document's language is a CJK language
-               if (bparams.encoding().package() == Encoding::CJK) {
-                       os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName())
-                       << "}{}%\n";
-                       texrow.newline();
-                       open_encoding_ = CJK;
-               }
-               if (!lyxrc.language_auto_begin && !bparams.language->babel().empty()) {
-                       // FIXME UNICODE
-                       os << from_utf8(subst(lyxrc.language_command_begin,
-                                            "$$lang",
-                                            bparams.language->babel()))
-                          << '\n';
-               texrow.newline();
-               }
-       }
-
        // This paragraph's language
        Language const * const par_language = pit->getParLanguage(bparams);
        // The document's language
@@ -439,17 +425,18 @@ TeXOnePar(Buffer const & buf,
                // sections.
                for (pos_type i = 0; i < pit->size(); ++i) {
                        char_type const c = pit->getChar(i);
-                       if (runparams.encoding->package() == Encoding::inputenc && c < 0x80)
+                       Encoding const * const encoding =
+                               pit->getFontSettings(bparams, i).language()->encoding();
+                       if (encoding->package() != Encoding::CJK &&
+                           runparams.encoding->package() == Encoding::inputenc &&
+                           c < 0x80)
                                continue;
                        if (pit->isInset(i))
                                break;
                        // All characters before c are in the ASCII range, and
                        // c is non-ASCII (but no inset), so change the
                        // encoding to that required by the language of c.
-                       Encoding const * const encoding =
-                               pit->getFontSettings(bparams, i).language()->encoding();
-
-                       // with CJK, only add switch if we have CJK content at the beginning
+                       // With CJK, only add switch if we have CJK content at the beginning
                        // of the paragraph
                        if (encoding->package() != Encoding::CJK || i == 0) {
                                OutputParams tmp_rp = runparams;
@@ -688,7 +675,7 @@ TeXOnePar(Buffer const & buf,
                switch (open_encoding_) {
                        case CJK: {
                                // end of main text
-                               if (runparams.local_font == 0) {
+                               if (maintext) {
                                        os << '\n';
                                        texrow.newline();
                                        os << "\\end{CJK}\n";
@@ -709,16 +696,6 @@ TeXOnePar(Buffer const & buf,
                                // do nothing
                                break;
                }
-               // auto_end tag only if the last par is in a babel language
-               if (runparams.local_font == 0 && !lyxrc.language_auto_end && 
-                   !bparams.language->babel().empty() &&
-                   font.language()->encoding()->package() != Encoding::CJK) {
-                       os << from_utf8(subst(lyxrc.language_command_end,
-                                             "$$lang",
-                                             bparams.language->babel()))
-                          << '\n';
-                       texrow.newline();
-               }
        }
 
        // If this is the last paragraph, and a local_font was set upon entering
@@ -758,7 +735,7 @@ TeXOnePar(Buffer const & buf,
 
 // LaTeX all paragraphs
 void latexParagraphs(Buffer const & buf,
-                    ParagraphList const & paragraphs,
+                    Text const & text,
                     odocstream & os,
                     TexRow & texrow,
                     OutputParams const & runparams,
@@ -766,7 +743,9 @@ void latexParagraphs(Buffer const & buf,
 {
        bool was_title = false;
        bool already_title = false;
-       TextClass const & tclass = buf.params().getTextClass();
+       BufferParams const & bparams = buf.params();
+       TextClass const & tclass = bparams.getTextClass();
+       ParagraphList const & paragraphs = text.paragraphs();
        ParagraphList::const_iterator par = paragraphs.begin();
        ParagraphList::const_iterator endpar = paragraphs.end();
 
@@ -781,9 +760,32 @@ void latexParagraphs(Buffer const & buf,
                const_cast<OutputParams&>(runparams).par_end = 0;
        }
 
+       bool const maintext = text.isMainText(buf);
+
+       // Open a CJK environment at the beginning of the main buffer
+       // if the document's language is a CJK language
+       if (maintext && bparams.encoding().package() == Encoding::CJK) {
+               os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName())
+               << "}{}%\n";
+               texrow.newline();
+               open_encoding_ = CJK;
+       }
+       // if "auto begin" is switched off, explicitely switch the
+       // language on at start
+       if (maintext && !lyxrc.language_auto_begin &&
+           !bparams.language->babel().empty()) {
+               // FIXME UNICODE
+               os << from_utf8(subst(lyxrc.language_command_begin,
+                                       "$$lang",
+                                       bparams.language->babel()))
+                       << '\n';
+       texrow.newline();
+       }
+
+       ParagraphList::const_iterator lastpar;
        // if only_body
        while (par != endpar) {
-               ParagraphList::const_iterator lastpar = par;
+               lastpar = par;
                // well we have to check if we are in an inset with unlimited
                // length (all in one row) if that is true then we don't allow
                // any special options in the paragraph and also we don't allow
@@ -821,18 +823,18 @@ void latexParagraphs(Buffer const & buf,
                        }
 
                        if (layout->is_environment) {
-                               par = TeXOnePar(buf, paragraphs, par, os, texrow,
+                               par = TeXOnePar(buf, text, par, os, texrow,
                                                runparams, everypar);
                        } else if (layout->isEnvironment() ||
                                   !par->params().leftIndent().zero()) {
-                               par = TeXEnvironment(buf, paragraphs, par, os,
+                               par = TeXEnvironment(buf, text, par, os,
                                                     texrow, runparams);
                        } else {
-                               par = TeXOnePar(buf, paragraphs, par, os, texrow,
+                               par = TeXOnePar(buf, text, par, os, texrow,
                                                runparams, everypar);
                        }
                } else {
-                       par = TeXOnePar(buf, paragraphs, par, os, texrow,
+                       par = TeXOnePar(buf, text, par, os, texrow,
                                        runparams, everypar);
                }
                if (distance(lastpar, par) >= distance(lastpar, endpar))
@@ -850,9 +852,19 @@ void latexParagraphs(Buffer const & buf,
                                }
                texrow.newline();
        }
+       // if "auto end" is switched off, explicitely close the language at the end
+       // but only if the last par is in a babel language
+       if (maintext && !lyxrc.language_auto_end && !bparams.language->babel().empty() &&
+               lastpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK) {
+               os << from_utf8(subst(lyxrc.language_command_end,
+                                       "$$lang",
+                                       bparams.language->babel()))
+                       << '\n';
+               texrow.newline();
+       }
        // If the last paragraph is an environment, we'll have to close
        // CJK at the very end to do proper nesting.
-       if (open_encoding_ == CJK) {
+       if (maintext && open_encoding_ == CJK) {
                os << "\\end{CJK}\n";
                texrow.newline();
                open_encoding_ = none;
index 886306fdd3ba872d07115c20c33d76e2308b78b6..9777eab0b4837f1f6dde0d37b1597918959765fc 100644 (file)
@@ -23,9 +23,9 @@ class Buffer;
 class BufferParams;
 class Encoding;
 class Paragraph;
-class ParagraphList;
 class OutputParams;
 class TexRow;
+class Text;
 
 /// Export up to \p number optarg insets
 int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
@@ -38,7 +38,7 @@ int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
     \sa Buffer::writeLaTeXSource for the reason.
  */
 void latexParagraphs(Buffer const & buf,
-                    ParagraphList const & paragraphs,
+                    Text const & text,
                     odocstream & ofs,
                     TexRow & texrow,
                     OutputParams const &,