]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / paragraph.C
index 439e42187eee99646fc093438df410cdf227154e..f95d48d1a22f4cba54b6ab67da3aac1822b2603d 100644 (file)
@@ -33,8 +33,8 @@
 #include "lyxrow.h"
 #include "messages.h"
 #include "outputparams.h"
+#include "output_latex.h"
 #include "paragraph_funcs.h"
-#include "ParagraphList_fwd.h"
 
 #include "rowpainter.h"
 
@@ -564,7 +564,7 @@ void Paragraph::makeSameLayout(Paragraph const & par)
 bool Paragraph::stripLeadingSpaces(bool trackChanges)
 {
        if (isFreeSpacing())
-               return 0;
+               return false;
 
        int pos = 0;
        int count = 0;
@@ -576,7 +576,7 @@ bool Paragraph::stripLeadingSpaces(bool trackChanges)
                        ++pos;
        }
 
-       return count + pos > 0;
+       return count > 0 || pos > 0;
 }
 
 
@@ -793,13 +793,14 @@ string const corrected_env(string const & suffix, string const & env,
 }
 
 
-int adjust_column_count(string const & str, int oldcol)
+void adjust_row_column(string const & str, TexRow & texrow, int & column)
 {
        if (!contains(str, "\n"))
-               return oldcol + str.size();
+               column += str.size();
        else {
                string tmp;
-               return rsplit(str, tmp, '\n').size();
+               texrow.newline();
+               column = rsplit(str, tmp, '\n').size();
        }
 }
 
@@ -808,7 +809,8 @@ int adjust_column_count(string const & str, int oldcol)
 
 // This could go to ParagraphParameters if we want to
 int Paragraph::startTeXParParams(BufferParams const & bparams,
-                                 odocstream & os, bool moving_arg) const
+                                 odocstream & os, TexRow & texrow, 
+                                bool moving_arg) const
 {
        int column = 0;
 
@@ -846,7 +848,7 @@ int Paragraph::startTeXParParams(BufferParams const & bparams,
                else
                        output = corrected_env("\\begin", "flushright", ownerCode());
                os << from_ascii(output);
-               column = adjust_column_count(output, column);
+               adjust_row_column(output, texrow, column);
                break;
        } case LYX_ALIGN_RIGHT: {
                string output;
@@ -855,13 +857,13 @@ int Paragraph::startTeXParParams(BufferParams const & bparams,
                else
                        output = corrected_env("\\begin", "flushleft", ownerCode());
                os << from_ascii(output);
-               column = adjust_column_count(output, column);
+               adjust_row_column(output, texrow, column);
                break;
        } case LYX_ALIGN_CENTER: {
                string output;
                output = corrected_env("\\begin", "center", ownerCode());
                os << from_ascii(output);
-               column = adjust_column_count(output, column);
+               adjust_row_column(output, texrow, column);
                break;
        }
        }
@@ -871,8 +873,9 @@ int Paragraph::startTeXParParams(BufferParams const & bparams,
 
 
 // This could go to ParagraphParameters if we want to
-int Paragraph::endTeXParParams(BufferParams const & bparams,
-                               odocstream & os, bool moving_arg) const
+int Paragraph::endTeXParParams(BufferParams const & bparams,  
+                               odocstream & os, TexRow & texrow,
+                              bool moving_arg) const
 {
        int column = 0;
 
@@ -905,7 +908,7 @@ int Paragraph::endTeXParParams(BufferParams const & bparams,
                else
                        output = corrected_env("\n\\par\\end", "flushright", ownerCode());
                os << from_ascii(output);
-               column = adjust_column_count(output, column);
+               adjust_row_column(output, texrow, column);
                break;
        } case LYX_ALIGN_RIGHT: {
                string output;
@@ -914,13 +917,13 @@ int Paragraph::endTeXParParams(BufferParams const & bparams,
                else
                        output = corrected_env("\n\\par\\end", "flushleft", ownerCode());
                os << from_ascii(output);
-               column = adjust_column_count(output, column);
+               adjust_row_column(output, texrow, column);
                break;
        } case LYX_ALIGN_CENTER: {
                string output;
                output = corrected_env("\n\\par\\end", "center", ownerCode());
                os << from_ascii(output);
-               column = adjust_column_count(output, column);
+               adjust_row_column(output, texrow, column);
                break;
        }
        }
@@ -961,17 +964,14 @@ 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;
 
-       LaTeXFeatures features(buf, bparams, runparams);
-
        // output change tracking marks only if desired,
        // if dvipost is installed,
        // and with dvi/ps (other formats don't work)
        bool const output = bparams.outputChanges
                && runparams.flavor == OutputParams::LATEX
-               && features.isAvailable("dvipost");
+               && LaTeXFeatures::isAvailable("dvipost");
 
        // Maybe we have to create a optional argument.
        pos_type body_pos = beginOfBody();
@@ -1003,22 +1003,29 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                        ++column;
                }
                if (!asdefault)
-                       column += startTeXParParams(bparams, os,
+                       column += startTeXParParams(bparams, os, texrow,
                                                    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) {
-               ++column;
                // 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);
                                running_font = basefont;
+
+                               column += Changes::latexMarkChange(os,
+                                               runningChangeType, Change::UNCHANGED, output);
+                               runningChangeType = Change::UNCHANGED;
+
                                os << "}] ";
                                column +=3;
                        }
@@ -1028,49 +1035,52 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                        }
 
                        if (!asdefault)
-                               column += startTeXParParams(bparams, os,
+                               column += startTeXParParams(bparams, os, 
+                                                           texrow,
                                                            runparams.moving_arg);
                }
 
-               value_type c = getChar(i);
+               Change::Type changeType = pimpl_->lookupChange(i).type;
+
+               // do not output text which is marked deleted
+               // if change tracking output is disabled
+               if (!output && changeType == Change::DELETED) {
+                       runningChangeType = changeType;
+                       continue;
+               }
+
+               ++column;
+               
+               column += Changes::latexMarkChange(os, runningChangeType,
+                       changeType, output);
+               runningChangeType = changeType;
+
+               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;
 
-               // Spaces at end of font change are simulated to be
-               // outside font change, i.e. we write "\textXX{text} "
-               // rather than "\textXX{text }". (Asger)
-               if (open_font && c == ' ' && i <= size() - 2) {
-                       LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
-                       if (next_font != running_font && next_font != font) {
-                               font = next_font;
-                       }
-               }
-
-               // We end font definition before blanks
+               // Do we need to close the previous font?
                if (open_font &&
                    (font != running_font ||
                     font.language() != running_font.language()))
                {
                        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;
                }
 
-               // Blanks are printed before start of fontswitch
-               if (c == ' ') {
-                       // Do not print the separation of the optional argument
-                       if (i != body_pos - 1) {
-                               // FIXME: change tracking
-                               // Is this correct WRT change tracking?
-                               pimpl_->simpleTeXBlanks(os, texrow, i,
-                                                      column, font, *style);
-                       }
+               // Switch file encoding if necessary
+               int const count = switchEncoding(os, bparams,
+                               *(runparams.encoding),
+                               *(font.language()->encoding()));
+               if (count > 0) {
+                       column += count;
+                       runparams.encoding = font.language()->encoding();
                }
 
                // Do we need to change font?
@@ -1078,39 +1088,40 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                     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;
                }
 
-               Change::Type changeType = pimpl_->lookupChange(i).type;
-
-               column += Changes::latexMarkChange(os, runningChangeType,
-                       changeType, output);
-               runningChangeType = changeType;
-
-               // do not output text which is marked deleted
-               // if change tracking output is not desired
-               if (output || runningChangeType != Change::DELETED) {
-                       // FIXME: change tracking
-                       // simpleTeXSpecialChars does not output anything if
-                       // c is a space. Is this correct WRT change tracking?
-                       OutputParams rp = runparams;
-                       rp.free_spacing = style->free_spacing;
-                       rp.local_font = &font;
-                       rp.intitle = style->intitle;
-                       pimpl_->simpleTeXSpecialChars(buf, bparams,
-                                               os, texrow, rp,
-                                               font, running_font,
-                                               basefont, outerfont, open_font,
-                                               runningChangeType,
-                                               *style, i, column, c);
+               if (c == ' ') {
+                       // Do not print the separation of the optional argument
+                       // if style->pass_thru is false. This works because
+                       // simpleTeXSpecialChars ignores spaces if
+                       // style->pass_thru is false.
+                       if (i != body_pos - 1) {
+                               if (pimpl_->simpleTeXBlanks(bparams,
+                                               doc_encoding, os, texrow,
+                                               i, column, font, *style))
+                                       // A surrogate pair was output. We
+                                       // must not call simpleTeXSpecialChars
+                                       // in this iteration, since
+                                       // simpleTeXBlanks incremented i, and
+                                       // simpleTeXSpecialChars would output
+                                       // the combining character again.
+                                       continue;
+                       }
                }
-       }
 
-       column += Changes::latexMarkChange(os,
-                       runningChangeType, Change::UNCHANGED, output);
+               OutputParams rp = runparams;
+               rp.free_spacing = style->free_spacing;
+               rp.local_font = &font;
+               rp.intitle = style->intitle;
+               pimpl_->simpleTeXSpecialChars(buf, bparams, doc_encoding, os,
+                                       texrow, rp, running_font,
+                                       basefont, outerfont, open_font,
+                                       runningChangeType, *style, i, column, c);
+       }
 
        // If we have an open font definition, we have to close it
        if (open_font) {
@@ -1118,11 +1129,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
@@ -1130,11 +1140,13 @@ 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
        }
 
+       column += Changes::latexMarkChange(os,
+                       runningChangeType, Change::UNCHANGED, output);
+
        // Needed if there is an optional argument but no contents.
        if (body_pos > 0 && body_pos == size()) {
                os << "}]~";
@@ -1142,7 +1154,8 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
        }
 
        if (!asdefault) {
-               column += endTeXParParams(bparams, os, runparams.moving_arg);
+               column += endTeXParParams(bparams, os, texrow, 
+                                         runparams.moving_arg);
        }
 
        lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
@@ -1510,12 +1523,6 @@ InsetBase::Code Paragraph::ownerCode() const
 }
 
 
-void Paragraph::clearContents()
-{
-       text_.clear();
-}
-
-
 ParagraphParameters & Paragraph::params()
 {
        return pimpl_->params;