]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
fix some C++ parsing bugs
[lyx.git] / src / paragraph.C
index 866d42471fb5f609de6ec6128fac91dd14008849..b83a8a77a5331fed5ce6f47a447ee440dd6795d3 100644 (file)
@@ -15,7 +15,6 @@
 #include "lyxrc.h"
 #include "layout.h"
 #include "language.h"
-#include "tex-strings.h"
 #include "buffer.h"
 #include "bufferparams.h"
 #include "debug.h"
@@ -165,58 +164,7 @@ void Paragraph::write(Buffer const * buf, ostream & os,
        // First write the layout
        os << "\n\\layout " << layout()->name() << '\n';
 
-       // Maybe some vertical spaces.
-       if (params().spaceTop().kind() != VSpace::NONE)
-               os << "\\added_space_top "
-                  << params().spaceTop().asLyXCommand() << ' ';
-       if (params().spaceBottom().kind() != VSpace::NONE)
-               os << "\\added_space_bottom "
-                  << params().spaceBottom().asLyXCommand() << ' ';
-
-       // Maybe the paragraph has special spacing
-       params().spacing().writeFile(os, true);
-
-       // The labelwidth string used in lists.
-       if (!params().labelWidthString().empty())
-               os << "\\labelwidthstring "
-                  << params().labelWidthString() << '\n';
-
-       // Lines above or below?
-       if (params().lineTop())
-               os << "\\line_top ";
-       if (params().lineBottom())
-               os << "\\line_bottom ";
-
-       // Pagebreaks above or below?
-       if (params().pagebreakTop())
-               os << "\\pagebreak_top ";
-       if (params().pagebreakBottom())
-               os << "\\pagebreak_bottom ";
-
-       // Start of appendix?
-       if (params().startOfAppendix())
-               os << "\\start_of_appendix ";
-
-       // Noindent?
-       if (params().noindent())
-               os << "\\noindent ";
-
-       // Do we have a manual left indent?
-       if (!params().leftIndent().zero())
-               os << "\\leftindent " << params().leftIndent().asString()
-                  << ' ';
-
-       // Alignment?
-       if (params().align() != LYX_ALIGN_LAYOUT) {
-               int h = 0;
-               switch (params().align()) {
-               case LYX_ALIGN_LEFT: h = 1; break;
-               case LYX_ALIGN_RIGHT: h = 2; break;
-               case LYX_ALIGN_CENTER: h = 3; break;
-               default: h = 0; break;
-               }
-               os << "\\align " << string_align[h] << ' ';
-       }
+       params().write(os);
 
        LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
 
@@ -261,10 +209,6 @@ void Paragraph::write(Buffer const * buf, ostream & os,
                                }
                }
                break;
-               case META_NEWLINE:
-                       os << "\n\\newline \n";
-                       column = 0;
-                       break;
                case '\\':
                        os << "\n\\backslash \n";
                        column = 0;
@@ -839,19 +783,22 @@ int Paragraph::beginningOfBody() const
        // and remember the previous character to
        // remove unnecessary GetChar() calls
        pos_type i = 0;
-       if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
+       if (i < size() && !isNewline(i)) {
                ++i;
                char previous_char = 0;
                char temp = 0;
-               if (i < size()
-                   && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
-                       // Yes, this  ^ is supposed to be "= " not "=="
-                       ++i;
-                       while (i < size()
-                              && previous_char != ' '
-                              && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
+               if (i < size()) {
+                       previous_char = getChar(i);
+                       if (!isNewline(i)) {
                                ++i;
-                               previous_char = temp;
+                               while (i < size() && previous_char != ' ') {
+                                       temp = getChar(i);
+                                       if (isNewline(i))
+                                               break;
+
+                                       ++i;
+                                       previous_char = temp;
+                               }
                        }
                }
        }
@@ -1202,38 +1149,12 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
                column += Changes::latexMarkChange(os, running_change, change);
                running_change = change;
 
-               if (c == Paragraph::META_NEWLINE) {
-                       // newlines are handled differently here than
-                       // the default in SimpleTeXSpecialChars().
-                       if (!style->newline_allowed) {
-                               os << '\n';
-                       } else {
-                               if (open_font) {
-                                       column += running_font.latexWriteEndChanges(os, basefont, basefont);
-                                       open_font = false;
-                               }
-                               basefont = getLayoutFont(bparams);
-                               running_font = basefont;
-                               if (font.family() ==
-                                   LyXFont::TYPEWRITER_FAMILY) {
-                                       os << '~';
-                               }
-                               if (moving_arg)
-                                       os << "\\protect ";
-
-                               os << "\\\\\n";
-                       }
-                       texrow.newline();
-                       texrow.start(this, i + 1);
-                       column = 0;
-               } else {
-                       pimpl_->simpleTeXSpecialChars(buf, bparams,
-                                                     os, texrow, moving_arg,
-                                                     font, running_font,
-                                                     basefont, open_font,
-                                                     running_change,
-                                                     *style, i, column, c);
-               }
+               pimpl_->simpleTeXSpecialChars(buf, bparams,
+                                             os, texrow, moving_arg,
+                                             font, running_font,
+                                             basefont, open_font,
+                                             running_change,
+                                             *style, i, column, c);
        }
 
        column += Changes::latexMarkChange(os,
@@ -1281,7 +1202,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
 bool Paragraph::isHfill(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
-                                       && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
+              && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
 }
 
 
@@ -1293,7 +1214,8 @@ bool Paragraph::isInset(pos_type pos) const
 
 bool Paragraph::isNewline(pos_type pos) const
 {
-       return pos >= 0 && IsNewlineChar(getChar(pos));
+       return IsInsetChar(getChar(pos))
+              && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
 }
 
 
@@ -1423,9 +1345,7 @@ string const Paragraph::asString(Buffer const * buffer,
                value_type const c = getUChar(buffer->params, i);
                if (IsPrintable(c))
                        os << c;
-               else if (c == META_NEWLINE)
-                       os << '\n';
-               else if (c == META_INSET) 
+               else if (c == META_INSET)
                        getInset(i)->ascii(buffer, os);
        }
 
@@ -1438,7 +1358,7 @@ void Paragraph::setInsetOwner(Inset * i)
        pimpl_->inset_owner = i;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
-       for (; it != end; ++it) 
+       for (; it != end; ++it)
                if (it.getInset())
                        it.getInset()->setOwner(i);
 }