]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Fix loop when opening TOC widget in an empty document, basically by Richard Heck.
[lyx.git] / src / paragraph.C
index 2d5ad8671d14329891229c317b4a858a3c617ba6..05b480c2b519966c0551b13d03c3d235f3ca4053 100644 (file)
@@ -33,6 +33,7 @@
 #include "lyxrow.h"
 #include "messages.h"
 #include "outputparams.h"
+#include "output_latex.h"
 #include "paragraph_funcs.h"
 
 #include "rowpainter.h"
@@ -938,7 +939,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                                odocstream & os, TexRow & texrow,
                                OutputParams const & runparams) const
 {
-       lyxerr[Debug::LATEX] << "SimpleTeXOnePar...     " << this << endl;
+       LYXERR(Debug::LATEX) << "SimpleTeXOnePar...     " << this << endl;
 
        bool return_value = false;
 
@@ -963,7 +964,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
        // As long as we are in the label, this font is the base font of the
        // label. Before the first body character it is set to the base font
        // of the body.
-       // This must be identical to basefont in TeXOnePar().
        LyXFont basefont;
 
        // output change tracking marks only if desired,
@@ -1007,15 +1007,13 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                                                    runparams.moving_arg);
        }
 
-       // Computed only once per paragraph since bparams.encoding() is expensive
-       Encoding const & doc_encoding = bparams.encoding();
        for (pos_type i = 0; i < size(); ++i) {
                // First char in paragraph or after label?
                if (i == body_pos) {
                        if (body_pos > 0) {
                                if (open_font) {
                                        column += running_font.latexWriteEndChanges(
-                                               os, basefont, basefont, bparams);
+                                               os, basefont, basefont);
                                        open_font = false;
                                }
                                basefont = getLayoutFont(bparams, outerfont);
@@ -1054,10 +1052,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                        changeType, output);
                runningChangeType = changeType;
 
-               value_type c = getChar(i);
+               value_type const c = getChar(i);
 
                // Fully instantiated font
-               LyXFont font = getFont(bparams, i, outerfont);
+               LyXFont const font = getFont(bparams, i, outerfont);
 
                LyXFont const last_font = running_font;
 
@@ -1068,19 +1066,27 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                {
                        column += running_font.latexWriteEndChanges(
                                        os, basefont,
-                                       (i == body_pos-1) ? basefont : font,
-                                       bparams);
+                                       (i == body_pos-1) ? basefont : font);
                        running_font = basefont;
                        open_font = false;
                }
 
+               // Switch file encoding if necessary
+               int const count = switchEncoding(os, bparams,
+                               runparams.moving_arg, *(runparams.encoding),
+                               *(font.language()->encoding()));
+               if (count > 0) {
+                       column += count;
+                       runparams.encoding = font.language()->encoding();
+               }
+
                // Do we need to change font?
                if ((font != running_font ||
                     font.language() != running_font.language()) &&
                        i != body_pos - 1)
                {
-                       column += font.latexWriteStartChanges(
-                                       os, basefont, last_font, bparams);
+                       column += font.latexWriteStartChanges(os, basefont,
+                                                             last_font);
                        running_font = font;
                        open_font = true;
                }
@@ -1091,8 +1097,8 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                        // simpleTeXSpecialChars ignores spaces if
                        // style->pass_thru is false.
                        if (i != body_pos - 1) {
-                               if (pimpl_->simpleTeXBlanks(bparams,
-                                               doc_encoding, os, texrow,
+                               if (pimpl_->simpleTeXBlanks(
+                                               *(runparams.encoding), os, texrow,
                                                i, column, font, *style))
                                        // A surrogate pair was output. We
                                        // must not call simpleTeXSpecialChars
@@ -1108,7 +1114,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                rp.free_spacing = style->free_spacing;
                rp.local_font = &font;
                rp.intitle = style->intitle;
-               pimpl_->simpleTeXSpecialChars(buf, bparams, doc_encoding, os,
+               pimpl_->simpleTeXSpecialChars(buf, bparams, os,
                                        texrow, rp, running_font,
                                        basefont, outerfont, open_font,
                                        runningChangeType, *style, i, column, c);
@@ -1120,11 +1126,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                if (next_) {
                        running_font
                                .latexWriteEndChanges(os, basefont,
-                                       next_->getFont(bparams, 0, outerfont),
-                                       bparams);
+                                       next_->getFont(bparams, 0, outerfont));
                } else {
                        running_font.latexWriteEndChanges(os, basefont,
-                                                         basefont, bparams);
+                                                         basefont);
                }
 #else
 #ifdef WITH_WARNINGS
@@ -1132,8 +1137,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
 //#warning there as we start another \selectlanguage with the next paragraph if
 //#warning we are in need of this. This should be fixed sometime (Jug)
 #endif
-               running_font.latexWriteEndChanges(os, basefont, basefont,
-                                                 bparams);
+               running_font.latexWriteEndChanges(os, basefont, basefont);
 #endif
        }
 
@@ -1151,7 +1155,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                                          runparams.moving_arg);
        }
 
-       lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
+       LYXERR(Debug::LATEX) << "SimpleTeXOnePar...done " << this << endl;
        return return_value;
 }
 
@@ -1550,11 +1554,7 @@ bool Paragraph::allowEmpty() const
 char_type Paragraph::transformChar(char_type c, pos_type pos) const
 {
        if (!Encodings::is_arabic(c))
-               if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isDigit(c))
-                       // FIXME UNICODE What does this do?
-                       return c + (0xb0 - '0');
-               else
-                       return c;
+               return c;
 
        value_type const prev_char = pos > 0 ? getChar(pos - 1) : ' ';
        value_type next_char = ' ';